diff --git a/models/enums.py b/models/enums.py index 24c662f2..8928b830 100644 --- a/models/enums.py +++ b/models/enums.py @@ -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): diff --git a/models/prescription.py b/models/prescription.py index 6f93d408..92a66713 100644 --- a/models/prescription.py +++ b/models/prescription.py @@ -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), diff --git a/routes/authentication.py b/routes/authentication.py index 44bba18f..e6e1e28b 100644 --- a/routes/authentication.py +++ b/routes/authentication.py @@ -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 @@ -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"] diff --git a/routes/drugList.py b/routes/drugList.py index 998b3278..7b6e5d9d 100644 --- a/routes/drugList.py +++ b/routes/drugList.py @@ -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 = ( diff --git a/routes/prescription.py b/routes/prescription.py index ffdce526..40631b28 100644 --- a/routes/prescription.py +++ b/routes/prescription.py @@ -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 = [] @@ -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() diff --git a/services/auth_service.py b/services/auth_service.py index a71bf4c3..d1898ac0 100644 --- a/services/auth_service.py +++ b/services/auth_service.py @@ -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 ( @@ -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 @@ -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() @@ -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, ) diff --git a/services/memory_service.py b/services/memory_service.py index c7e98926..6a0b1d38 100644 --- a/services/memory_service.py +++ b/services/memory_service.py @@ -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