Skip to content

Commit

Permalink
admin drugs adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloarocha committed Oct 15, 2023
1 parent 88c93a6 commit fb04e64
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
11 changes: 8 additions & 3 deletions routes/admin/drug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

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

list = drug_service.get_conversion_list(
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),
Expand All @@ -47,9 +48,13 @@ def get_drug_conversion_list():
}
)

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

return {
"status": "success",
"count": list[0][9] if list != None else 0,
"count": count,
"data": result,
}, status.HTTP_200_OK

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
27 changes: 24 additions & 3 deletions services/admin/drug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@
from exception.validation_error import ValidationError


def get_conversion_list(
def get_drug_list(
has_substance=None,
has_price_conversion=None,
has_default_unit=None,
has_prescription=None,
term=None,
limit=10,
offset=0,
id_segment_list=None,
):
presc_query = (
db.session.query(
Outlier.idDrug.label("idDrug"), Outlier.idSegment.label("idSegment")
)
.group_by(Outlier.idDrug, Outlier.idSegment)
.subquery()
)

q = (
db.session.query(
Drug.id,
Expand All @@ -44,13 +53,19 @@ def get_conversion_list(
),
)
.outerjoin(Substance, Drug.sctid == Substance.id)
.outerjoin(
presc_query,
and_(
presc_query.c.idDrug == Drug.id, presc_query.c.idSegment == Segment.id
),
)
)

if has_substance != None:
if has_substance:
q = q.filter(Drug.sctid != None)
q = q.filter(Substance.id != None)
else:
q = q.filter(Drug.sctid == None)
q = q.filter(Substance.id == None)

if has_default_unit != None:
if has_default_unit:
Expand All @@ -76,6 +91,12 @@ def get_conversion_list(
)
)

if has_prescription != None:
if has_prescription:
q = q.filter(presc_query.c.idDrug != None)
else:
q = q.filter(presc_query.c.idDrug == None)

if term:
q = q.filter(Drug.name.ilike(term))

Expand Down

0 comments on commit fb04e64

Please sign in to comment.