Skip to content

Commit

Permalink
add fasting attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloarocha committed Jul 17, 2024
1 parent 33f8a5e commit 35eb3df
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions models/appendix.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Frequency(db.Model):
idHospital = db.Column("fkhospital", db.BigInteger, nullable=False)
description = db.Column("nome", db.String, nullable=False)
dailyFrequency = db.Column("frequenciadia", db.Float, nullable=True)
fasting = db.Column("jejum", db.Boolean, nullable=True)


class Notes(db.Model):
Expand Down
1 change: 1 addition & 0 deletions models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class DrugAttributesBase:
dialyzable = db.Column("dialisavel", db.Boolean, nullable=True)
pregnant = db.Column("gestante", db.String, nullable=True)
lactating = db.Column("lactante", db.String, nullable=True)
fasting = db.Column("jejum", db.Boolean, nullable=True)
update = db.Column("update_at", db.DateTime, nullable=True)
user = db.Column("update_by", db.BigInteger, nullable=True)

Expand Down
7 changes: 5 additions & 2 deletions routes/admin/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ def update_frequency():
os.environ["TZ"] = "America/Sao_Paulo"

try:
freq = frequency_service.update_daily_frequency(
data.get("id", None), data.get("dailyFrequency", None), user
freq = frequency_service.update_frequency(
id=data.get("id", None),
daily_frequency=data.get("dailyFrequency", None),
fasting=data.get("fasting", None),
user=user,
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus
Expand Down
1 change: 1 addition & 0 deletions routes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ def get_bool_drug_attributes_list():
"whiteList",
"chemo",
"dialyzable",
"fasting",
]


Expand Down
1 change: 1 addition & 0 deletions services/admin/drug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def get_drug_list(
["risco_queda", DrugAttributes.fallRisk],
["lactante", DrugAttributes.lactating],
["gestante", DrugAttributes.pregnant],
["jejum", DrugAttributes.fasting],
]

for a in bool_attributes:
Expand Down
15 changes: 10 additions & 5 deletions services/admin/frequency_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from models.main import db
from models.appendix import *
from models.enums import RoleEnum
from services import permission_service

from exception.validation_error import ValidationError

Expand All @@ -20,9 +20,8 @@ def get_frequencies(has_daily_frequency=None):
return q.order_by(asc(Frequency.description)).all()


def update_daily_frequency(id, daily_frequency, 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:
def update_frequency(id, daily_frequency, fasting, user):
if not permission_service.has_maintainer_permission(user):
raise ValidationError(
"Usuário não autorizado",
"errors.unauthorizedUser",
Expand All @@ -36,6 +35,7 @@ def update_daily_frequency(id, daily_frequency, user):
)

freq.dailyFrequency = float(daily_frequency)
freq.fasting = fasting

db.session.add(freq)
db.session.flush()
Expand All @@ -48,7 +48,12 @@ def list_to_dto(frequencies):

for p in frequencies:
list.append(
{"id": p.id, "name": p.description, "dailyFrequency": p.dailyFrequency}
{
"id": p.id,
"name": p.description,
"dailyFrequency": p.dailyFrequency,
"fasting": p.fasting,
}
)

return list
5 changes: 5 additions & 0 deletions services/drug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def get_attributes(id_segment, id_drug, user):
"dialyzable": attr.dialyzable,
"pregnant": attr.pregnant,
"lactating": attr.lactating,
"fasting": attr.fasting,
}


Expand Down Expand Up @@ -281,6 +282,8 @@ def save_attributes(id_segment, id_drug, data, user):
attr.pregnant = data.get("pregnant", None)
if "lactating" in data.keys():
attr.lactating = data.get("lactating", None)
if "fasting" in data.keys():
attr.fasting = data.get("fasting", None)

attr.update = datetime.today()
attr.user = user.id
Expand Down Expand Up @@ -347,6 +350,7 @@ def copy_substance_default_attributes(id_drug, sctid, user: User, overwrite=True
da.elderly = reference.elderly
da.whiteList = reference.whiteList
da.dialyzable = reference.dialyzable
da.fasting = reference.fasting

da.kidney = reference.kidney
da.liver = reference.liver
Expand Down Expand Up @@ -402,6 +406,7 @@ def create_attributes_from_reference(id_drug, id_segment, user):
da.elderly = reference.elderly
da.whiteList = reference.whiteList
da.dialyzable = reference.dialyzable
da.fasting = reference.fasting

da.kidney = reference.kidney
da.liver = reference.liver
Expand Down

0 comments on commit 35eb3df

Please sign in to comment.