Skip to content

Commit

Permalink
Merge pull request #371 from noharm-ai/develop
Browse files Browse the repository at this point in the history
v3.29-beta
  • Loading branch information
marceloarocha committed Sep 4, 2024
2 parents 667a527 + 510371a commit 00832f6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 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.28-beta"}, status.HTTP_200_OK
return {"status": "success", "data": "v3.29-beta"}, status.HTTP_200_OK


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion requirements-prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SQLAlchemy==2.0.29
Flask-SQLAlchemy==3.1.1
troposphere
zappa
flask-cors==4.0.1
flask-cors==5.0.0
psycopg2-binary
pandas==1.3.4
scipy==1.10.0
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Flask-SQLAlchemy==3.1.1
lambda-packages
troposphere
zappa
flask-cors==4.0.1
flask-cors==5.0.0
psycopg2-binary
pytest==5.4.1
pytest-flask
Expand Down
12 changes: 10 additions & 2 deletions routes/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,22 @@ def getPrescription(
.first()
)

if p_cache != None and p_cache.features.get("clinicalNotesStats", None) != None:
if (
p_cache != None
and p_cache.features != None
and p_cache.features.get("clinicalNotesStats", None) != None
):
cn_stats = p_cache.features.get("clinicalNotesStats")
else:
cn_stats = clinical_notes_service.get_admission_stats(
admission_number=prescription[0].admissionNumber,
)

if p_cache != None and p_cache.features.get("clinicalNotes", 0) != 0:
if (
p_cache != None
and p_cache.features != None
and p_cache.features.get("clinicalNotes", 0) != 0
):
cn_count = p_cache.features.get("clinicalNotes", 0)
else:
cn_count = clinical_notes_service.get_count(
Expand Down
70 changes: 44 additions & 26 deletions services/summary_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from models.appendix import *
from models.prescription import *
from models.notes import *
from models.enums import RoleEnum, MemoryEnum, GlobalMemoryEnum
from models.enums import RoleEnum, GlobalMemoryEnum
from services import memory_service, prescription_agg_service
from exception.validation_error import ValidationError

Expand Down Expand Up @@ -35,20 +35,38 @@ def get_structured_info(admission_number, user, mock=False):

draft = memory_service.get_memory(f"draft_summary_{admission_number}")

return {
"patient": _get_patient_data(patient),
"exams": _get_exams(patient.idPatient, user.schema),
"allergies": _get_allergies(patient.idPatient, user.schema),
"drugsUsed": _get_all_drugs_used(
admission_number=admission_number, schema=user.schema
),
"drugsSuspended": _get_all_drugs_suspended(
admission_number=admission_number, schema=user.schema
),
"receipt": _get_receipt(admission_number=admission_number, schema=user.schema),
"summaryConfig": _get_summary_config(admission_number, mock),
"draft": draft.value if draft else None,
}
engine = db.engines["report"]
with engine.connect() as report_connection:
data = {
"patient": _get_patient_data(patient),
"exams": _get_exams(
id_patient=patient.idPatient,
schema=user.schema,
report_connection=report_connection,
),
"allergies": _get_allergies(
patient.idPatient, user.schema, report_connection
),
"drugsUsed": _get_all_drugs_used(
admission_number=admission_number,
schema=user.schema,
report_connection=report_connection,
),
"drugsSuspended": _get_all_drugs_suspended(
admission_number=admission_number,
schema=user.schema,
report_connection=report_connection,
),
"receipt": _get_receipt(
admission_number=admission_number,
schema=user.schema,
report_connection=report_connection,
),
"summaryConfig": _get_summary_config(admission_number, mock),
"draft": draft.value if draft else None,
}

return data


def _get_patient_data(patient: Patient):
Expand Down Expand Up @@ -275,12 +293,12 @@ def _get_annotation(admission_number, field, add, interval, compare_date):
uniqueList.add(i[0])

return {
"value": ". ".join(uniqueList)[:1500].replace('"', '\\"'),
"value": ". ".join(uniqueList)[:2000].replace('"', '\\"'),
"list": list(uniqueList),
}


def _get_exams(id_patient, schema):
def _get_exams(id_patient, schema, report_connection):
query = text(
f"""
select * from (
Expand Down Expand Up @@ -316,7 +334,7 @@ def _get_exams(id_patient, schema):
"""
)

exams = db.session.execute(query, {"id_patient": id_patient})
exams = report_connection.execute(query, {"id_patient": id_patient})

exams_list = []
for e in exams:
Expand All @@ -332,7 +350,7 @@ def _get_exams(id_patient, schema):
return exams_list


def _get_allergies(id_patient, schema):
def _get_allergies(id_patient, schema, report_connection):
query = text(
f"""
select
Expand All @@ -350,7 +368,7 @@ def _get_allergies(id_patient, schema):
"""
)

items = db.session.execute(query, {"id_patient": id_patient})
items = report_connection.execute(query, {"id_patient": id_patient})

list = []
for i in items:
Expand All @@ -363,7 +381,7 @@ def _get_allergies(id_patient, schema):
return list


def _get_all_drugs_used(admission_number, schema):
def _get_all_drugs_used(admission_number, schema, report_connection):
query = text(
f"""
select
Expand Down Expand Up @@ -419,7 +437,7 @@ def _get_all_drugs_used(admission_number, schema):
"""
)

result = db.session.execute(query, {"admission_number": admission_number})
result = report_connection.execute(query, {"admission_number": admission_number})

list = []
for i in result:
Expand All @@ -428,7 +446,7 @@ def _get_all_drugs_used(admission_number, schema):
return list


def _get_all_drugs_suspended(admission_number, schema):
def _get_all_drugs_suspended(admission_number, schema, report_connection):
query = text(
f"""
select
Expand Down Expand Up @@ -457,7 +475,7 @@ def _get_all_drugs_suspended(admission_number, schema):
"""
)

result = db.session.execute(query, {"admission_number": admission_number})
result = report_connection.execute(query, {"admission_number": admission_number})

list = []
for i in result:
Expand All @@ -470,7 +488,7 @@ def _get_all_drugs_suspended(admission_number, schema):
return list


def _get_receipt(admission_number, schema):
def _get_receipt(admission_number, schema, report_connection):
last_agg = prescription_agg_service.get_last_agg_prescription(admission_number)

if last_agg == None:
Expand All @@ -497,7 +515,7 @@ def _get_receipt(admission_number, schema):
"""
)

result = db.session.execute(
result = report_connection.execute(
query, {"admission_number": admission_number, "date": last_agg.date}
)

Expand Down

0 comments on commit 00832f6

Please sign in to comment.