Skip to content

Commit

Permalink
Merge pull request #366 from noharm-ai/develop
Browse files Browse the repository at this point in the history
v3.27-beta
  • Loading branch information
marceloarocha committed Sep 1, 2024
2 parents 036ba8b + 8f38d30 commit 553610a
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 37 deletions.
2 changes: 1 addition & 1 deletion mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

@app.route("/version", methods=["GET"])
def getVersion():
return {"status": "success", "data": "v3.26-beta"}, status.HTTP_200_OK
return {"status": "success", "data": "v3.27-beta"}, status.HTTP_200_OK


if __name__ == "__main__":
Expand Down
46 changes: 46 additions & 0 deletions models/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ def getPatients(
idPatient=[],
intervals=[],
prescriber=None,
diff=None,
global_score_min=None,
global_score_max=None,
pending_interventions=None,
):
q = (
db.session.query(
Expand Down Expand Up @@ -492,6 +496,48 @@ def getPatients(
)
)

if diff != None:
if bool(int(diff)):
q = q.filter(Prescription.features["diff"].astext.cast(Integer) > 0)
else:
q = q.filter(Prescription.features["diff"].astext.cast(Integer) == 0)

if pending_interventions != None:
if bool(int(pending_interventions)):
q = q.filter(
Prescription.features["interventions"].astext.cast(Integer) > 0
)
else:
q = q.filter(
Prescription.features["interventions"].astext.cast(Integer) == 0
)

if global_score_min != None:
q = q.filter(
(
Prescription.features["prescriptionScore"].astext.cast(Integer)
+ Prescription.features["av"].astext.cast(Integer)
+ Prescription.features["am"].astext.cast(Integer)
+ Prescription.features["alertExams"].astext.cast(Integer)
+ Prescription.features["alerts"].astext.cast(Integer)
+ Prescription.features["diff"].astext.cast(Integer)
)
>= global_score_min
)

if global_score_max != None:
q = q.filter(
(
Prescription.features["prescriptionScore"].astext.cast(Integer)
+ Prescription.features["av"].astext.cast(Integer)
+ Prescription.features["am"].astext.cast(Integer)
+ Prescription.features["alertExams"].astext.cast(Integer)
+ Prescription.features["alerts"].astext.cast(Integer)
+ Prescription.features["diff"].astext.cast(Integer)
)
<= global_score_max
)

if prescriber != None:
q = q.filter(Prescription.prescriber.ilike(f"%{prescriber}%"))

Expand Down
11 changes: 11 additions & 0 deletions routes/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def getPrescriptions():
patientStatus = request.args.get("patientStatus", None)
patientReviewType = request.args.get("patientReviewType", None)
prescriber = request.args.get("prescriber", None)
diff = request.args.get("diff", None)
pending_interventions = request.args.get("pendingInterventions", None)
global_score_min = request.args.get("globalScoreMin", None)
global_score_max = request.args.get("globalScoreMax", None)

patients = Patient.getPatients(
idSegment=idSegment,
Expand All @@ -96,6 +100,10 @@ def getPrescriptions():
idPatient=idPatient,
intervals=intervals,
prescriber=prescriber,
diff=diff,
global_score_min=global_score_min,
global_score_max=global_score_max,
pending_interventions=pending_interventions,
)

results = []
Expand All @@ -121,6 +129,7 @@ def getPrescriptions():
"alertExams",
"interventions",
"complication",
"alertLevel",
]

features = {"processed": True}
Expand Down Expand Up @@ -750,6 +759,7 @@ def setPrescriptionStatus():
)
evaluation_time = data.get("evaluationTime", None)
alerts = data.get("alerts", [])
fast_check = data.get("fastCheck", False)

try:
result = prescription_service.check_prescription(
Expand All @@ -758,6 +768,7 @@ def setPrescriptionStatus():
user=user,
evaluation_time=evaluation_time,
alerts=alerts,
fast_check=fast_check,
)
except ValidationError as e:
return {
Expand Down
19 changes: 15 additions & 4 deletions services/prescription_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ def search(search_key):


def check_prescription(
idPrescription, p_status, user, evaluation_time, alerts, service_user=False
idPrescription,
p_status,
user,
evaluation_time,
alerts,
service_user=False,
fast_check=False,
):
roles = user.config["roles"] if user.config and "roles" in user.config else []
if not permission_service.is_pharma(user):
Expand All @@ -102,14 +108,18 @@ def check_prescription(
if p is None:
raise ValidationError(
"Prescrição inexistente",
"errors.invalidRegister",
"errors.businessRules",
status.HTTP_400_BAD_REQUEST,
)

if p.status == p_status:
raise ValidationError(
"Não houve alteração de situação",
"errors.invalidRegister",
(
"Não houve alteração da situação: Prescrição já está checada"
if p_status == "s"
else "Não houve alteração da situação: A checagem já foi desfeita"
),
"errors.businessRules",
status.HTTP_400_BAD_REQUEST,
)

Expand Down Expand Up @@ -147,6 +157,7 @@ def check_prescription(
"evaluationTime": evaluation_time or 0,
"alerts": alerts,
"serviceUser": service_user,
"fastCheck": fast_check,
}

results = []
Expand Down
26 changes: 25 additions & 1 deletion services/support_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ def create_ticket(user, from_url, filelist, category, description, title):
options={"specification": {}},
)

attachments = []

if filelist:
for f in filelist:
client(
att = client(
model="ir.attachment",
action="create",
payload=[
Expand All @@ -65,6 +67,8 @@ def create_ticket(user, from_url, filelist, category, description, title):
options={},
)

attachments.append(att)

ticket = client(
model="helpdesk.ticket",
action="search_read",
Expand All @@ -74,11 +78,31 @@ def create_ticket(user, from_url, filelist, category, description, title):
"id",
"access_token",
"ticket_ref",
"partner_id",
],
"limit": 50,
},
)

if len(ticket) > 0 and ticket[0].get("partner_id", None) != None:
# add message
client(
model="mail.message",
action="create",
payload=[
{
"message_type": "email",
"author_id": ticket[0]["partner_id"][0],
"body": description,
"model": "helpdesk.ticket",
"res_id": result[0]["id"],
"subtype_id": 1,
"attachment_ids": attachments,
}
],
options={},
)

return ticket


Expand Down
Loading

0 comments on commit 553610a

Please sign in to comment.