Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.14-beta #333

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.13-beta"}, status.HTTP_200_OK
return {"status": "success", "data": "v3.14-beta"}, status.HTTP_200_OK


@app.route("/exc", methods=["GET"])
Expand Down
17 changes: 17 additions & 0 deletions routes/admin/drug.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,20 @@
"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
Dismissed Show dismissed Hide dismissed

return tryCommit(db, result.rowcount)
Dismissed Show dismissed Hide dismissed
42 changes: 41 additions & 1 deletion services/admin/drug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion services/alert_interaction_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 27 additions & 17 deletions services/alert_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Loading