Skip to content

Commit

Permalink
Merge pull request #431 from noharm-ai/develop
Browse files Browse the repository at this point in the history
v4.26-beta
  • Loading branch information
marceloarocha authored Jan 22, 2025
2 parents a847f09 + 9ed065b commit acbe189
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 100 deletions.
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class Config:
VERSION = "v4.25-beta"
FRONTEND_VERSION = "4.0.18"
VERSION = "v4.26-beta"
FRONTEND_VERSION = "4.0.20"
ENV = getenv("ENV") or NoHarmENV.DEVELOPMENT.value
SECRET_KEY = getenv("SECRET_KEY") or "secret_key"
API_KEY = getenv("API_KEY") or ""
Expand Down
1 change: 1 addition & 0 deletions models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class NifiQueueActionTypeEnum(Enum):
CLEAR_QUEUE = "CLEAR_QUEUE"
LIST_QUEUE = "LIST_QUEUE"
CLEAR_STATE = "CLEAR_STATE"
VIEW_STATE = "VIEW_STATE"
TERMINATE_PROCESS = "TERMINATE_PROCESS"
CUSTOM_CALLBACK = "CUSTOM_CALLBACK"
REFRESH_TEMPLATE = "REFRESH_TEMPLATE"
Expand Down
10 changes: 9 additions & 1 deletion repository/drug_attributes_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def update_dose_max(update_list: list[dict], schema: str):


def copy_dose_max_from_ref(schema: str, update_by: int):
"""
Updates dosemax attribute if its empty or updated by internal staff
"""

query = text(
f"""
with update_table as (
Expand All @@ -45,8 +49,12 @@ def copy_dose_max_from_ref(schema: str, update_by: int):
end as dosemaxima
from
{schema}.medatributos m
left join public.usuario u on (m.update_by = u.idusuario)
where
m.dosemaxima is null
(
m.dosemaxima is null
or u."schema" = 'hsc_test'
)
and (
(m.usapeso = true and m.ref_dosemaxima_peso is not null)
or
Expand Down
39 changes: 30 additions & 9 deletions repository/drugs_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def get_admin_drug_list(
has_max_dose=None,
source_list=None,
tp_ref_max_dose=None,
substance_list=[],
tp_substance_list=None,
id_drug_list=[],
):
SegmentOutlier = db.aliased(Segment)
ConversionsAgg = db.aliased(MeasureUnitConvert)
Expand Down Expand Up @@ -280,31 +283,49 @@ def get_admin_drug_list(
if source_list and len(source_list) > 0:
q = q.filter(Drug.source.in_(source_list))

if substance_list:
if tp_substance_list == "in":
q = q.filter(Substance.id.in_(substance_list))
else:
q = q.filter(~Substance.id.in_(substance_list))

if id_drug_list:
q = q.filter(DrugAttributes.idDrug.in_(id_drug_list))

return q.order_by(Drug.name, Segment.description).limit(limit).offset(offset).all()


def get_all_drug_attributes():
def get_drug_attributes(id_drug: int = None, id_segment: int = None):
"""
Returns a list of drugs (with substances) from medatributos table
"""

return (
query = (
db.session.query(DrugAttributes, Drug, Substance, Segment)
.join(Drug, Drug.id == DrugAttributes.idDrug)
.join(Substance, Drug.sctid == Substance.id)
.join(Segment, Segment.id == DrugAttributes.idSegment)
.all()
)

if id_drug:
query = query.filter(DrugAttributes.idDrug == id_drug)

if id_segment:
query = query.filter(DrugAttributes.idSegment == id_segment)

def get_all_conversions():
return query.all()


def get_conversions(id_drug: int = None):
"""
Returns all conversion records
"""

return (
db.session.query(MeasureUnitConvert, MeasureUnit)
.join(MeasureUnit, MeasureUnitConvert.idMeasureUnit == MeasureUnit.id)
.order_by(MeasureUnitConvert.idDrug)
.all()
query = db.session.query(MeasureUnitConvert, MeasureUnit).join(
MeasureUnit, MeasureUnitConvert.idMeasureUnit == MeasureUnit.id
)

if id_drug:
query = query.filter(MeasureUnitConvert.idDrug == id_drug)

return query.order_by(MeasureUnitConvert.idDrug).all()
6 changes: 4 additions & 2 deletions routes/admin/admin_drug.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def get_drug_list():
limit=request_data.get("limit", 10),
offset=request_data.get("offset", 0),
tp_ref_max_dose=request_data.get("tpRefMaxDose", None),
substance_list=request_data.get("substanceList", []),
tp_substance_list=request_data.get("tpSubstanceList", "in"),
)


Expand Down Expand Up @@ -105,5 +107,5 @@ def add_new_outlier():

@app_admin_drug.route("/admin/drug/calculate-dosemax", methods=["POST"])
@api_endpoint()
def calculate_dosemax():
return admin_drug_service.calculate_dosemax()
def calculate_dosemax_bulk():
return admin_drug_service.calculate_dosemax_bulk()
4 changes: 1 addition & 3 deletions routes/drugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def update_substance():
id_drug = data.get("idDrug", None)
sctid = data.get("sctid", None)

drug_service.update_substance(
return drug_service.update_substance(
id_drug=id_drug,
sctid=sctid,
)

return {"idDrug": escape_html(id_drug), "sctid": escape_html(str(sctid))}
Loading

0 comments on commit acbe189

Please sign in to comment.