Skip to content

Commit

Permalink
substance filter
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloarocha committed Jan 23, 2025
1 parent fadf70b commit 8f316c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions routes/admin/admin_substance.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def get_substances():
has_max_dose_pediatric=data.get("hasMaxDosePediatric", None),
has_max_dose_pediatric_weight=data.get("hasMaxDosePediatricWeight", None),
tags=data.get("tags", []),
tp_substance_tag_list=data.get("tpSubstanceTagList", "in"),
)

return list
Expand Down
12 changes: 11 additions & 1 deletion services/admin/admin_substance_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def get_substances(
has_max_dose_pediatric=None,
has_max_dose_pediatric_weight=None,
tags=[],
tp_substance_tag_list="in",
):

q = (
Expand Down Expand Up @@ -92,7 +93,16 @@ def get_substances(
q = q.filter(Substance.maxdose_pediatric_weight == None)

if tags:
q = q.filter(cast(tags, postgresql.ARRAY(db.String)).overlap(Substance.tags))
if tp_substance_tag_list == "notin":
q = q.filter(
~cast(tags, postgresql.ARRAY(db.String)).overlap(
func.coalesce(Substance.tags, [])
)
)
else:
q = q.filter(
cast(tags, postgresql.ARRAY(db.String)).overlap(Substance.tags)
)

q = (
q.options(undefer(Substance.handling), undefer(Substance.admin_text))
Expand Down

0 comments on commit 8f316c2

Please sign in to comment.