From 0301cd9d096f5c30a3a393a4f190b599be3e087d Mon Sep 17 00:00:00 2001 From: Marcelo Arocha Date: Thu, 11 Jul 2024 16:14:24 +0200 Subject: [PATCH 1/4] alerts: dose max with no weight --- services/alert_service.py | 44 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/services/alert_service.py b/services/alert_service.py index 96e0896c..d92fc360 100644 --- a/services/alert_service.py +++ b/services/alert_service.py @@ -320,14 +320,19 @@ def _alert_max_dose( doseWeight = round(pd_dose_conv / float(weight), 2) if drug_attributes.maxDose and drug_attributes.maxDose < doseWeight: - alert[ - "text" - ] = f""" - Dose diária prescrita ({strFormatBR(doseWeight)} {str(drug_attributes.idMeasureUnit)}/Kg) - maior que a dose de alerta - ({strFormatBR(drug_attributes.maxDose)} {str(drug_attributes.idMeasureUnit)}/Kg) - usualmente recomendada (considerada a dose diária independente da indicação). - """ + if none2zero(exams["weight"]) == 0: + alert["text"] = ( + "A dose máxima registrada é por kg, mas o peso do paciente não está disponível. Favor preencher manualmente o peso para que o cálculo de dose máxima fique correto." + ) + else: + alert[ + "text" + ] = f""" + Dose diária prescrita ({strFormatBR(doseWeight)} {str(drug_attributes.idMeasureUnit)}/Kg) + maior que a dose de alerta + ({strFormatBR(drug_attributes.maxDose)} {str(drug_attributes.idMeasureUnit)}/Kg) + usualmente recomendada (considerada a dose diária independente da indicação). + """ return alert @@ -379,15 +384,20 @@ def _alert_max_dose_total( and drug_attributes.maxDose < none2zero(dose_total[idDrugAggWeight]["value"]) ): - alert[ - "text" - ] = f""" - Dose diária prescrita SOMADA ( - {str(dose_total[idDrugAggWeight]["value"])} {str(drug_attributes.idMeasureUnit)}/Kg) maior - que a dose de alerta ( - {str(drug_attributes.maxDose)} {str(drug_attributes.idMeasureUnit)}/Kg) - usualmente recomendada (Frequência "AGORA" não é considerada no cálculo)." - """ + if none2zero(exams["weight"]) == 0: + alert["text"] = ( + "A dose máxima registrada é por kg, mas o peso do paciente não está disponível. Favor preencher manualmente o peso." + ) + else: + alert[ + "text" + ] = f""" + Dose diária prescrita SOMADA ( + {str(dose_total[idDrugAggWeight]["value"])} {str(drug_attributes.idMeasureUnit)}/Kg) maior + que a dose de alerta ( + {str(drug_attributes.maxDose)} {str(drug_attributes.idMeasureUnit)}/Kg) + usualmente recomendada (Frequência "AGORA" não é considerada no cálculo)." + """ return alert From 33ad627d4ccaf6e294f91738451bd58c4dbd2882 Mon Sep 17 00:00:00 2001 From: Marcelo Arocha Date: Thu, 11 Jul 2024 20:13:50 +0200 Subject: [PATCH 2/4] fix exception --- services/alert_interaction_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/alert_interaction_service.py b/services/alert_interaction_service.py index 31039534..b500d8fe 100644 --- a/services/alert_interaction_service.py +++ b/services/alert_interaction_service.py @@ -220,7 +220,7 @@ def find_relations(drug_list, id_patient: int, is_cpoe: bool): "level": ( active_relations[key]["level"] if active_relations[key]["level"] != None - else DrugAlertLevelEnum.LOW + else DrugAlertLevelEnum.LOW.value ), "relation": drug_to["id"], "text": alert_text, From 07612a06818412c89a4e70afbaf7b48f8339bf17 Mon Sep 17 00:00:00 2001 From: Marcelo Arocha Date: Thu, 11 Jul 2024 20:18:54 +0200 Subject: [PATCH 3/4] v3.14-beta --- mobile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile.py b/mobile.py index 573a3a2a..f7e3af5a 100644 --- a/mobile.py +++ b/mobile.py @@ -116,7 +116,7 @@ @app.route("/version", methods=["GET"]) def getVersion(): - return {"status": "success", "data": "v3.13-beta"}, status.HTTP_200_OK + return {"status": "success", "data": "v3.14-beta"}, status.HTTP_200_OK @app.route("/exc", methods=["GET"]) From 146b7858e78dfe7051753e45b6310a5eebc33f45 Mon Sep 17 00:00:00 2001 From: Marcelo Arocha Date: Thu, 11 Jul 2024 22:54:28 +0200 Subject: [PATCH 4/4] add new outlier process --- routes/admin/drug.py | 17 ++++++++++++++ services/admin/drug_service.py | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/routes/admin/drug.py b/routes/admin/drug.py index d4bc53de..9f500064 100644 --- a/routes/admin/drug.py +++ b/routes/admin/drug.py @@ -156,3 +156,20 @@ def get_drugs_missing_substance(): "count": len(result), "data": result, }, status.HTTP_200_OK + + +@app_admin_drug.route("/admin/drug/add-new-outlier", methods=["POST"]) +@jwt_required() +def add_new_outlier(): + user = User.find(get_jwt_identity()) + dbSession.setSchema(user.schema) + os.environ["TZ"] = "America/Sao_Paulo" + + try: + result = drug_service.add_new_drugs_to_outlier( + user=user, + ) + except ValidationError as e: + return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus + + return tryCommit(db, result.rowcount) diff --git a/services/admin/drug_service.py b/services/admin/drug_service.py index 418dcb72..bb997fbe 100644 --- a/services/admin/drug_service.py +++ b/services/admin/drug_service.py @@ -7,7 +7,7 @@ from models.segment import * from models.enums import RoleEnum, DrugAdminSegment from services.admin import ai_service -from services import drug_service as main_drug_service +from services import drug_service as main_drug_service, permission_service from exception.validation_error import ValidationError @@ -487,6 +487,46 @@ def predict_substance(id_drugs: List[int], user: User): return ia_results +def add_new_drugs_to_outlier(user: User): + if not permission_service.has_maintainer_permission(user): + raise ValidationError( + "Usuário não autorizado", + "errors.unauthorizedUser", + status.HTTP_401_UNAUTHORIZED, + ) + + query = text( + f""" + insert into {user.schema}.outlier + (fkmedicamento, idsegmento, contagem, doseconv, frequenciadia, escore, update_at, update_by) + select + pm.fkmedicamento, p.idsegmento, 0, 0, 0, 4, :updateAt, :updateBy + from + {user.schema}.presmed pm + inner join {user.schema}.prescricao p on (pm.fkprescricao = p.fkprescricao) + where + p.update_at > now() - interval '5 days' + and pm.idoutlier is null + and p.idsegmento is not null + and not exists ( + select 1 + from {user.schema}.outlier o + where o.fkmedicamento = pm.fkmedicamento and o.idsegmento = p.idsegmento + ) + group by + pm.fkmedicamento, p.idsegmento + """ + ) + + return db.session.execute( + query, + { + "updateAt": datetime.today(), + "updateBy": user.id, + }, + ) + + def get_drugs_missing_substance(): drugs = ( db.session.query(func.distinct(Drug.id))