Skip to content

Commit

Permalink
Merge pull request #354 from noharm-ai/develop
Browse files Browse the repository at this point in the history
v3.22-beta
  • Loading branch information
marceloarocha committed Aug 19, 2024
2 parents 5daacf9 + c8184d3 commit 34fafdf
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 194 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.21-beta"}, status.HTTP_200_OK
return {"status": "success", "data": "v3.22-beta"}, status.HTTP_200_OK


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions models/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def getPatients(
drugAttributes=[],
idPatient=[],
intervals=[],
prescriber=None,
):
q = (
db.session.query(
Expand Down Expand Up @@ -491,6 +492,9 @@ def getPatients(
)
)

if prescriber != None:
q = q.filter(Prescription.prescriber.ilike(f"%{prescriber}%"))

if endDate is None:
endDate = startDate

Expand Down
71 changes: 71 additions & 0 deletions routes/admin/exam.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,43 @@ def get_most_frequent():
}, status.HTTP_200_OK


@app_admin_exam.route("/admin/exam/list", methods=["POST"])
@jwt_required()
def list_exams():
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
data = request.get_json()

try:
list = exam_service.get_segment_exams(
user=user, id_segment=data.get("idSegment", None)
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return {
"status": "success",
"data": list,
}, status.HTTP_200_OK


@app_admin_exam.route("/admin/exam/types", methods=["GET"])
@jwt_required()
def list_exam_types():
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)

try:
list = exam_service.get_exam_types()
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return {
"status": "success",
"data": list,
}, status.HTTP_200_OK


@app_admin_exam.route("/admin/exam/most-frequent/add", methods=["POST"])
@jwt_required()
def add_most_frequent():
Expand All @@ -67,3 +104,37 @@ def add_most_frequent():
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return tryCommit(db, True)


@app_admin_exam.route("/admin/exam/upsert", methods=["POST"])
@jwt_required()
def upsert_seg_exam():
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
data = request.get_json()

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

return tryCommit(db, result)


@app_admin_exam.route("/admin/exam/order", methods=["POST"])
@jwt_required()
def set_exams_order():
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
data = request.get_json()

try:
result = exam_service.set_exams_order(
exams=data.get("exams", None),
id_segment=data.get("idSegment", None),
user=user,
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return tryCommit(db, result)
12 changes: 2 additions & 10 deletions routes/drugList.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .utils import *
from models.appendix import *
from utils.dateutils import to_iso
from services import drug_service


def _get_legacy_alert(kind):
Expand Down Expand Up @@ -327,7 +328,7 @@ def getDrugType(self, pDrugs, source):
"cpoe_group": pd[0].cpoe_group,
"infusionKey": self.getInfusionKey(pd),
"formValues": pd[0].form,
"drugAttributes": self.getDrugAttributes(pd),
"drugAttributes": drug_service.to_dict(pd[6]),
"prescriptionDate": to_iso(pd.prescription_date),
}
)
Expand All @@ -340,15 +341,6 @@ def getInfusionKey(self, pd):

return str(pd[0].idPrescription) + str(pd[0].solutionGroup)

def getDrugAttributes(self, pd):
attr_list = get_bool_drug_attributes_list()
attributes = {}

for a in attr_list:
attributes[a] = 1 if pd[6] and getattr(pd[6], a) else 0

return attributes

def getInfusionList(self):
result = {}
for pd in self.drugList:
Expand Down
2 changes: 2 additions & 0 deletions routes/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def getPrescriptions():
substanceClasses = request.args.getlist("substanceClasses[]")
patientStatus = request.args.get("patientStatus", None)
patientReviewType = request.args.get("patientReviewType", None)
prescriber = request.args.get("prescriber", None)

patients = Patient.getPatients(
idSegment=idSegment,
Expand All @@ -94,6 +95,7 @@ def getPrescriptions():
drugAttributes=drugAttributes,
idPatient=idPatient,
intervals=intervals,
prescriber=prescriber,
)

results = []
Expand Down
59 changes: 1 addition & 58 deletions routes/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
get_jwt_identity,
)
from sqlalchemy import asc, func
from .utils import tryCommit
from datetime import date, timedelta

from utils import status
from models.main import *
from models.appendix import *
from models.prescription import *
from services import exams_service, segment_service
from services import segment_service
from exception.validation_error import ValidationError

app_seg = Blueprint("app_seg", __name__)
Expand Down Expand Up @@ -143,27 +141,6 @@ def getSegmentsId(idSegment, idHospital=None):
}, status.HTTP_200_OK


@app_seg.route("/segments/exams/types", methods=["GET"])
@jwt_required()
def getCodes():
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)

typesExam = (
db.session.query(Exams.typeExam)
.filter(Exams.date > (date.today() - timedelta(days=30)))
.group_by(Exams.typeExam)
.order_by(asc(Exams.typeExam))
.all()
)

results = ["mdrd", "ckd", "ckd21", "cg", "swrtz2", "swrtz1"]
for t in typesExam:
results.append(t[0].lower())

return {"status": "success", "data": {"types": results}}, status.HTTP_200_OK


@app_seg.route("/segments/exams/refs", methods=["GET"])
@jwt_required()
def getRefs():
Expand Down Expand Up @@ -193,37 +170,3 @@ def getRefs():
)

return {"status": "success", "data": results}, status.HTTP_200_OK


@app_seg.route("/segments/<int:idSegment>/exams", methods=["PUT"])
@jwt_required()
def setExams(idSegment):
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
data = request.get_json()

try:
result = exams_service.upsert_seg_exam(
data=data, id_segment=idSegment, user=user
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return tryCommit(db, escape_html(result.typeExam))


@app_seg.route("/segments/<int:idSegment>/exams-order", methods=["PUT"])
@jwt_required()
def setExamsOrder(idSegment):
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
data = request.get_json()

try:
result = exams_service.exams_reorder(
exams=data.get("exams", None), id_segment=idSegment, user=user
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return tryCommit(db, result)
9 changes: 5 additions & 4 deletions routes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def tryCommit(db, recId, allow=True):
}, status.HTTP_500_INTERNAL_SERVER_ERROR


def get_bool_drug_attributes_list():
def get_numeric_drug_attributes_list():
return [
"antimicro",
"mav",
Expand All @@ -461,6 +461,7 @@ def get_bool_drug_attributes_list():
"chemo",
"dialyzable",
"fasting",
"fallRisk",
]


Expand All @@ -480,7 +481,7 @@ def getFeatures(result, agg_date: datetime = None, intervals_for_agg_date=False)
alert_levels = []
alert_level = "low"

for attr in get_bool_drug_attributes_list():
for attr in get_numeric_drug_attributes_list():
drug_attributes[attr] = 0

for d in drugList:
Expand All @@ -490,10 +491,10 @@ def getFeatures(result, agg_date: datetime = None, intervals_for_agg_date=False)
if d["idSubstanceClass"] != None:
substanceClassIDs.append(d["idSubstanceClass"])

if "drugAttributes" in d:
if "drugAttributes" in d and d["drugAttributes"] != None:
for attr in d["drugAttributes"]:
if attr in drug_attributes:
drug_attributes[attr] += int(d["drugAttributes"][attr])
drug_attributes[attr] += int(none2zero(d["drugAttributes"][attr]))

if d["whiteList"] or d["suspended"]:
continue
Expand Down
Loading

0 comments on commit 34fafdf

Please sign in to comment.