Skip to content

Commit

Permalink
Merge pull request #260 from noharm-ai/develop
Browse files Browse the repository at this point in the history
v2.00-beta
  • Loading branch information
marceloarocha authored Oct 19, 2023
2 parents a86a3d2 + a92a85d commit fdc9ead
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

@app.route("/version", methods=["GET"])
def getVersion():
return {"status": "success", "data": "v1.99-beta"}, status.HTTP_200_OK
return {"status": "success", "data": "v2.00-beta"}, status.HTTP_200_OK


if __name__ == "__main__":
Expand Down
24 changes: 24 additions & 0 deletions routes/admin/drug.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def 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_price_unit=request_data.get("hasPriceUnit", None),
has_prescription=request_data.get("hasPrescription", None),
term=request_data.get("term", None),
id_segment_list=request_data.get("idSegmentList", None),
Expand Down Expand Up @@ -84,6 +85,29 @@ def update_price_factor():
return tryCommit(db, {"idSegment": id_segment, "idDrug": id_drug, "factor": factor})


@app_admin_drug.route("/admin/drug/substance", methods=["POST"])
@jwt_required()
def update_substance():
data = request.get_json()
user = User.find(get_jwt_identity())
dbSession.setSchema(user.schema)
os.environ["TZ"] = "America/Sao_Paulo"

id_drug = data.get("idDrug", None)
sctid = data.get("sctid", None)

try:
drug_service.update_substance(
id_drug=id_drug,
sctid=sctid,
user=user,
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

return tryCommit(db, {"idDrug": id_drug, "sctid": str(sctid)})


@app_admin_drug.route("/admin/drug/add-default-units", methods=["POST"])
@jwt_required()
def add_default_units():
Expand Down
27 changes: 27 additions & 0 deletions services/admin/drug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def get_drug_list(
has_substance=None,
has_price_conversion=None,
has_default_unit=None,
has_price_unit=None,
has_prescription=None,
term=None,
limit=10,
Expand Down Expand Up @@ -73,6 +74,12 @@ def get_drug_list(
else:
q = q.filter(DrugAttributes.idMeasureUnit == None)

if has_price_unit != None:
if has_price_unit:
q = q.filter(DrugAttributes.idMeasureUnitPrice != None)
else:
q = q.filter(DrugAttributes.idMeasureUnitPrice == None)

if has_price_conversion != None:
if has_price_conversion:
q = q.filter(
Expand Down Expand Up @@ -152,6 +159,26 @@ def update_price_factor(id_drug, id_segment, factor, user):
db.session.flush()


def update_substance(id_drug, sctid, user):
roles = user.config["roles"] if user.config and "roles" in user.config else []
if RoleEnum.ADMIN.value not in roles and RoleEnum.TRAINING.value not in roles:
raise ValidationError(
"Usuário não autorizado",
"errors.unauthorizedUser",
status.HTTP_401_UNAUTHORIZED,
)

drug = Drug.query.get(id_drug)

if drug == None:
raise ValidationError(
"Registro inexistente", "errors.invalidRecord", status.HTTP_400_BAD_REQUEST
)

drug.sctid = sctid
db.session.flush()


def add_default_units(user):
roles = user.config["roles"] if user.config and "roles" in user.config else []
if RoleEnum.ADMIN.value not in roles and RoleEnum.TRAINING.value not in roles:
Expand Down

0 comments on commit fdc9ead

Please sign in to comment.