Skip to content

Commit

Permalink
Merge pull request #277 from noharm-ai/feature/presc-group
Browse files Browse the repository at this point in the history
disable solution tab feature
  • Loading branch information
marceloarocha authored Jan 4, 2024
2 parents 995cf3f + 1cd101c commit 3ab63db
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 45 deletions.
1 change: 1 addition & 0 deletions models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FeatureEnum(Enum):
PRIMARY_CARE = "PRIMARYCARE"
OAUTH = "OAUTH"
LOCK_CHECKED_PRESCRIPTION = "LOCK_CHECKED_PRESCRIPTION"
DISABLE_SOLUTION_TAB = "DISABLE_SOLUTION_TAB"


class PrescriptionAuditTypeEnum(Enum):
Expand Down
6 changes: 1 addition & 5 deletions models/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,7 @@ def findByPrescription(
q = q.filter(Prescription.idSegment == idSegment)

if is_cpoe:
return q.order_by(
asc(Prescription.expire),
desc(PrescriptionDrug.cpoe_group),
asc(Drug.name),
).all()
return q.order_by(asc(Drug.name)).all()
else:
return q.order_by(
asc(Prescription.expire),
Expand Down
2 changes: 2 additions & 0 deletions routes/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def auth():
password = data.get("password", None)
schema = data.get("schema", None)
default_roles = data.get("defaultRoles", [])
extra_features = data.get("extraFeatures", [])
run_as_basic_user = data.get("runAsBasicUser", False)
refresh_token = None

Expand All @@ -51,6 +52,7 @@ def auth():
force_schema=schema,
default_roles=default_roles,
run_as_basic_user=run_as_basic_user,
extra_features=extra_features,
)

refresh_token = auth_data["refresh_token"]
Expand Down
22 changes: 2 additions & 20 deletions routes/drugList.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,11 @@ def getIntervention(self, idPrescriptionDrug):
result = i
return result

def getDrugType(self, pDrugs, source, checked=False, suspended=False):
def getDrugType(self, pDrugs, source):
for pd in self.drugList:
belong = False
if pd[0].source is None:
pd[0].source = "Medicamentos"
if pd[0].source != source:
continue
if source == "Soluções":
belong = True
if (
checked
and bool(pd[0].checked) == True
and bool(pd[0].suspendedDate) == False
):
belong = True
if suspended and (bool(pd[0].suspendedDate) == True):
belong = True
if (not checked and not suspended) and (
bool(pd[0].checked) == False and bool(pd[0].suspendedDate) == False
):
belong = True

if not belong:
if pd[0].source not in source:
continue

pdFrequency = (
Expand Down
25 changes: 12 additions & 13 deletions routes/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,15 @@ def getPrescription(
is_cpoe,
)

pDrugs = drugList.getDrugType([], "Medicamentos") # refactor sort
pDrugs = drugList.getDrugType(pDrugs, "Medicamentos", checked=True) # refactor sort
pDrugs = drugList.getDrugType(
pDrugs, "Medicamentos", suspended=True
) # refactor sort
pDrugs.sort(key=drugList.sortDrugs)
disable_solution_tab = memory_service.has_feature(
FeatureEnum.DISABLE_SOLUTION_TAB.value
)

if disable_solution_tab:
pDrugs = drugList.getDrugType([], ["Medicamentos", "Soluções"])
else:
pDrugs = drugList.getDrugType([], ["Medicamentos"])

pDrugs = drugList.sortWhiteList(pDrugs)

conciliaList = []
Expand All @@ -437,16 +440,12 @@ def getPrescription(
conciliaList = drugList.conciliaList(conciliaDrugsT, [])
conciliaList = drugList.conciliaList(conciliaDrugsY, conciliaList)

pSolution = drugList.getDrugType([], "Soluções")
pSolution = drugList.getDrugType([], ["Soluções"])
pInfusion = drugList.getInfusionList()

pProcedures = drugList.getDrugType([], "Proced/Exames")
pProcedures = drugList.getDrugType(pProcedures, "Proced/Exames", checked=True)
pProcedures = drugList.getDrugType(pProcedures, "Proced/Exames", suspended=True)
pProcedures = drugList.getDrugType([], ["Proced/Exames"])

pDiet = drugList.getDrugType([], "Dietas")
pDiet = drugList.getDrugType(pDiet, "Dietas", checked=True)
pDiet = drugList.getDrugType(pDiet, "Dietas", suspended=True)
pDiet = drugList.getDrugType([], ["Dietas"])

drugList.sumAlerts()

Expand Down
27 changes: 24 additions & 3 deletions services/auth_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ def _has_force_schema_permission(roles, schema):
) and RoleEnum.MULTI_SCHEMA.value in roles


def _auth_user(user, force_schema=None, default_roles=[], run_as_basic_user=False):
def _auth_user(
user,
force_schema=None,
default_roles=[],
run_as_basic_user=False,
extra_features=[],
):
roles = user.config["roles"] if user.config and "roles" in user.config else []
user_features = (
user.config["features"] if user.config and "features" in user.config else []
)

if Config.ENV == NoHarmENV.STAGING.value:
if (
Expand All @@ -48,7 +57,13 @@ def _auth_user(user, force_schema=None, default_roles=[], run_as_basic_user=Fals
user_config = user.config
if force_schema and _has_force_schema_permission(roles, user.schema):
user_schema = force_schema
user_config = dict(user.config, **{"roles": roles + default_roles})
user_config = dict(
user.config,
**{
"roles": roles + default_roles,
"features": user_features + extra_features,
}
)

if (
RoleEnum.ADMIN.value in default_roles
Expand Down Expand Up @@ -187,7 +202,12 @@ def pre_auth(email, password):


def auth_local(
email, password, force_schema=None, default_roles=[], run_as_basic_user=False
email,
password,
force_schema=None,
default_roles=[],
run_as_basic_user=False,
extra_features=[],
):
preCheckUser = User.query.filter_by(email=email).first()

Expand Down Expand Up @@ -239,6 +259,7 @@ def auth_local(
force_schema=force_schema,
default_roles=default_roles,
run_as_basic_user=run_as_basic_user,
extra_features=extra_features,
)


Expand Down
11 changes: 7 additions & 4 deletions services/memory_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@


def has_feature(feature):
user = User.query.get(get_jwt_identity())
user_features = (
user.config["features"] if user.config and "features" in user.config else []
)
try:
user = User.find(get_jwt_identity())
user_features = (
user.config["features"] if user.config and "features" in user.config else []
)
except:
user_features = []

if feature in user_features:
return True
Expand Down

0 comments on commit 3ab63db

Please sign in to comment.