diff --git a/routes/admin/drug.py b/routes/admin/drug.py index 00f122b5..0ce7b23d 100644 --- a/routes/admin/drug.py +++ b/routes/admin/drug.py @@ -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), @@ -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 diff --git a/routes/outlier.py b/routes/outlier.py index 01e3d90b..41081b18 100644 --- a/routes/outlier.py +++ b/routes/outlier.py @@ -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": [ diff --git a/routes/substance.py b/routes/substance.py index 10269353..751d7853 100644 --- a/routes/substance.py +++ b/routes/substance.py @@ -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) diff --git a/services/admin/drug_service.py b/services/admin/drug_service.py index d304bbd4..663defba 100644 --- a/services/admin/drug_service.py +++ b/services/admin/drug_service.py @@ -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, @@ -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: @@ -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))