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

v2.00-beta #259

Merged
merged 6 commits into from
Oct 16, 2023
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
27 changes: 15 additions & 12 deletions converter/prescription_converter.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
def search_results(prescriptions):
list = []

for p in prescriptions:
list.append({
'idPrescription': p[0].id,
'admissionNumber': p[0].admissionNumber,
'date': p[0].date.isoformat() if p[0].date else None,
'status': p[0].status,
'agg': p[0].agg,
'birthdate': p[1].isoformat() if p[1] else None,
'gender': p[2],
'department': p[3]
})
list.append(
{
"idPrescription": p[0].id,
"admissionNumber": p[0].admissionNumber,
"date": p[0].date.isoformat() if p[0].date else None,
"status": p[0].status,
"agg": p[0].agg,
"concilia": p[0].concilia,
"birthdate": p[1].isoformat() if p[1] else None,
"gender": p[2],
"department": p[3],
"admissionDate": p[4].isoformat() if p[4] else None,
}
)

return list

4 changes: 2 additions & 2 deletions mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from routes.admin.frequency import app_admin_freq
from routes.admin.intervention_reason import app_admin_interv
from routes.admin.memory import app_admin_memory
from routes.admin.drug import app_admin_drug
import os
import logging
from models.enums import NoHarmENV
Expand All @@ -45,8 +46,6 @@
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = Config.JWT_ACCESS_TOKEN_EXPIRES
app.config["JWT_REFRESH_TOKEN_EXPIRES"] = Config.JWT_REFRESH_TOKEN_EXPIRES
app.config["JWT_COOKIE_SAMESITE"] = "Lax"
# app.config["JWT_SESSION_COOKIE"] = False
# app.config["JWT_COOKIE_DOMAIN"] = Config.APP_DOMAIN
app.config["JWT_COOKIE_SECURE"] = True
app.config["JWT_REFRESH_COOKIE_PATH"] = "/refresh-token"
app.config["MAIL_SERVER"] = "email-smtp.sa-east-1.amazonaws.com"
Expand Down Expand Up @@ -81,6 +80,7 @@
app.register_blueprint(app_admin_freq)
app.register_blueprint(app_admin_interv)
app.register_blueprint(app_admin_memory)
app.register_blueprint(app_admin_drug)

CORS(app, origins=[Config.MAIL_HOST], supports_credentials=True)

Expand Down
119 changes: 119 additions & 0 deletions routes/admin/drug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import os
from flask import Blueprint, request
from flask_jwt_extended import jwt_required, get_jwt_identity

from flask_api import status
from models.main import *
from models.appendix import *
from models.segment import *
from models.prescription import *
from services.admin import drug_service
from exception.validation_error import ValidationError

app_admin_drug = Blueprint("app_admin_drug", __name__)


@app_admin_drug.route("/admin/drug/attributes-list", methods=["POST"])
@jwt_required()
def get_drug_list():
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
request_data = request.get_json()

list = drug_service.get_drug_list(
has_price_conversion=request_data.get("hasPriceConversion", None),
has_substance=request_data.get("hasSubstance", None),
has_default_unit=request_data.get("hasDefaultUnit", None),
has_prescription=request_data.get("hasPrescription", None),
term=request_data.get("term", None),
id_segment_list=request_data.get("idSegmentList", None),
limit=request_data.get("limit", 10),
offset=request_data.get("offset", 0),
)

result = []
for i in list:
result.append(
{
"idDrug": i[0],
"name": i[1],
"idSegment": i[2],
"segment": i[3],
"idMeasureUnitDefault": i[4],
"idMeasureUnitPrice": i[5],
"measureUnitPriceFactor": i[8],
"price": i[6],
"sctid": i[7],
"substance": i[10],
}
)

count = 0
if len(list) > 0:
count = list[0][9]

return {
"status": "success",
"count": count,
"data": result,
}, status.HTTP_200_OK


@app_admin_drug.route("/admin/drug/price-factor", methods=["POST"])
@jwt_required()
def update_price_factor():
data = request.get_json()
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
os.environ["TZ"] = "America/Sao_Paulo"

id_drug = data.get("idDrug", None)
id_segment = data.get("idSegment", None)
factor = data.get("factor", None)

try:
drug_service.update_price_factor(
id_drug=id_drug,
id_segment=id_segment,
factor=factor,
user=user,
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return tryCommit(db, {"idSegment": id_segment, "idDrug": id_drug, "factor": factor})


@app_admin_drug.route("/admin/drug/add-default-units", methods=["POST"])
@jwt_required()
def add_default_units():
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
os.environ["TZ"] = "America/Sao_Paulo"

try:
result = drug_service.add_default_units(user=user)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return tryCommit(db, result.rowcount)


@app_admin_drug.route("/admin/drug/copy-unit-conversion", methods=["POST"])
@jwt_required()
def copy_unit_conversion():
data = request.get_json()
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
os.environ["TZ"] = "America/Sao_Paulo"

try:
result = drug_service.copy_unit_conversion(
user=user,
id_segment_origin=data.get("idSegmentOrigin", None),
id_segment_destiny=data.get("idSegmentDestiny", None),
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return tryCommit(db, result.rowcount)
15 changes: 15 additions & 0 deletions routes/drugList.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def getDrugType(self, pDrugs, source, checked=False, suspended=False):
"ckd" in self.exams
and self.exams["ckd"]["value"]
and pd[6].kidney > self.exams["ckd"]["value"]
and self.exams["age"] > 17
):
alerts.append(
"Medicamento deve sofrer ajuste de posologia ou contraindicado, já que a função renal do paciente ("
Expand All @@ -163,6 +164,20 @@ def getDrugType(self, pDrugs, source, checked=False, suspended=False):
+ " mL/min."
)
self.alertStats["kidney"] += 1
elif (
"swrtz2" in self.exams
and self.exams["swrtz2"]["value"]
and pd[6].kidney > self.exams["swrtz2"]["value"]
and self.exams["age"] <= 17
):
alerts.append(
"Medicamento deve sofrer ajuste de posologia ou contraindicado, já que a função renal do paciente ("
+ str(self.exams["swrtz2"]["value"])
+ " mL/min/1.73m²) está abaixo de "
+ str(pd[6].kidney)
+ " mL/min."
)
self.alertStats["kidney"] += 1

if pd[6].liver:
if (
Expand Down
2 changes: 1 addition & 1 deletion routes/outlier.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def getOutliers(idSegment=1, idDrug=1):
"maxTime": drugAttr.maxTime,
"whiteList": drugAttr.whiteList,
"chemo": drugAttr.chemo,
"sctidA": d[0].sctid if d else "",
"sctidA": str(d[0].sctid) if d else "",
"sctNameA": strNone(d[1]).upper() if d else "",
"relations": relations,
"relationTypes": [
Expand Down
4 changes: 3 additions & 1 deletion routes/substance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def getSubstance():

results = []
for d in drugs:
results.append({"sctid": d.id, "name": d.name.upper(), "idclass": d.idclass})
results.append(
{"sctid": str(d.id), "name": d.name.upper(), "idclass": d.idclass}
)

results.sort(key=sortSubstance)

Expand Down
Loading
Loading