Skip to content

Commit

Permalink
Merge pull request #257 from noharm-ai/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloarocha authored Sep 29, 2023
2 parents 8e71bd2 + 897aa57 commit fbf19d1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

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


if __name__ == "__main__":
Expand Down
30 changes: 22 additions & 8 deletions routes/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def getPrescriptions():
features,
**{
"idPrescription": str(p[0].id),
"idPatient": p[0].idPatient,
"idPatient": str(p[0].idPatient),
"name": patient.admissionNumber,
"admissionNumber": patient.admissionNumber,
"birthdate": patient.birthdate.isoformat()
Expand Down Expand Up @@ -290,11 +290,27 @@ def getPrescription(
}, status.HTTP_400_BAD_REQUEST

patient = prescription[1]
patientWeight = None
patientWeightDate = None
patientHeight = None

if patient is None:
patient = Patient()
patient.idPatient = prescription[0].idPatient
patient.admissionNumber = prescription[0].admissionNumber

if patient.weight != None:
patientWeight = patient.weight
patientWeightDate = patient.weightDate
patientHeight = patient.height
else:
patient_previous_data = patient_service.get_patient_weight(patient.idPatient)

if patient_previous_data != None:
patientWeight = patient_previous_data[0]
patientWeightDate = patient_previous_data[1]
patientHeight = patient_previous_data[2]

lastDept = Prescription.lastDeptbyAdmission(
prescription[0].id, patient.admissionNumber, ref_date=prescription[0].date
)
Expand Down Expand Up @@ -367,7 +383,7 @@ def getPrescription(
exams,
**{
"age": age,
"weight": patient.weight,
"weight": patientWeight,
}
)

Expand Down Expand Up @@ -442,7 +458,7 @@ def getPrescription(
"idPrescription": str(prescription[0].id),
"idSegment": prescription[0].idSegment,
"segmentName": prescription[5],
"idPatient": prescription[0].idPatient,
"idPatient": str(prescription[0].idPatient),
"idHospital": prescription[0].idHospital,
"name": prescription[0].admissionNumber,
"agg": prescription[0].agg,
Expand All @@ -454,8 +470,8 @@ def getPrescription(
else None,
"birthdate": patient.birthdate.isoformat() if patient.birthdate else None,
"gender": patient.gender,
"height": patient.height,
"weight": patient.weight,
"height": patientHeight,
"weight": patientWeight,
"dialysis": patient.dialysis,
"observation": prescription[6],
"notes": prescription[7],
Expand All @@ -465,9 +481,7 @@ def getPrescription(
else None,
"age": age,
"weightUser": bool(patient.user),
"weightDate": patient.weightDate.isoformat()
if patient.weightDate
else None,
"weightDate": patientWeightDate.isoformat() if patientWeightDate else None,
"dischargeDate": patient.dischargeDate.isoformat()
if patient.dischargeDate
else None,
Expand Down
11 changes: 11 additions & 0 deletions services/patient_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,14 @@ def get_patient_allergies(id_patient):
.limit(100)
.all()
)


def get_patient_weight(id_patient):
return (
db.session.query(Patient.weight, Patient.weightDate, Patient.height)
.filter(Patient.idPatient == id_patient)
.filter(Patient.weight != None)
.filter(Patient.weightDate > func.now() - func.cast("1 month", INTERVAL))
.order_by(desc(Patient.weightDate))
.first()
)
2 changes: 1 addition & 1 deletion services/summary_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_structured_info(admission_number, user, mock=False):

def _get_patient_data(patient: Patient):
return {
"idPatient": patient.idPatient,
"idPatient": str(patient.idPatient),
"admissionNumber": patient.admissionNumber,
"admissionDate": patient.admissionDate.isoformat()
if patient.admissionDate
Expand Down

0 comments on commit fbf19d1

Please sign in to comment.