def allowed_to_forward(self, episode_case): if not self.case_types_and_users_allowed(episode_case): return False case_properties = episode_case.dynamic_case_properties() prescription_total_days = _cast_to_int( case_properties.get("prescription_total_days", 0)) treatment_options = case_properties.get("treatment_options") if treatment_options == "fdc": meets_days_threshold = prescription_total_days >= 168 else: meets_days_threshold = prescription_total_days >= 180 enrolled_in_private_sector = case_properties.get( ENROLLED_IN_PRIVATE) == 'true' not_sent = case_properties.get( "event_{}".format(SUCCESSFUL_TREATMENT_EVENT)) != "sent" return ( not_sent and enrolled_in_private_sector and is_valid_archived_submission(episode_case) and (case_properties_changed(episode_case, ["treatment_outcome"]) and case_properties.get("treatment_outcome") in ("cured", "treatment_completed")) or (case_properties_changed(episode_case, ["prescription_total_days"]) and meets_days_threshold))
def allowed_to_forward(self, person_case): return (person_case.type == CASE_TYPE_PERSON and person_case.get_case_property(ENROLLED_IN_PRIVATE) == 'true' and person_case.get_case_property('current_episode_type') == 'confirmed_tb' and is_valid_person_submission(person_case) and (case_was_created(person_case) or case_properties_changed(person_case, self.properties_we_care_about)))
def allowed_to_forward(self, episode_case): if not self.case_types_and_users_allowed(episode_case): return False episode_case_properties = episode_case.dynamic_case_properties() trigger_by_threshold = {} # threshold -> boolean threshold_prop_values_by_threshold = {} # threshold -> date for n in TOTAL_DAY_THRESHOLDS: threshold_case_prop = self._get_threshold_case_prop(n) threshold_prop_values_by_threshold[n] = string_to_date_or_None( episode_case_properties.get(threshold_case_prop)) trigger_for_n = bool( self.prescription_total_days_threshold_in_trigger_state( episode_case_properties, n, check_already_sent=True) and case_properties_changed(episode_case, [threshold_case_prop])) trigger_by_threshold[n] = trigger_for_n trigger_dates_unique = self._list_items_unique( filter(None, threshold_prop_values_by_threshold.values())) if not trigger_dates_unique: self._flag_program_team() return (trigger_dates_unique and any(trigger_by_threshold.values()) and is_valid_episode_submission(episode_case))
def allowed_to_forward(self, test_case): # test.date_reported populates and test.nikshay_registered is false # test.test_type_value = microscopy-zn or test.test_type_value = microscopy-fluorescent # and episode.nikshay_registered is true allowed_case_types_and_users = self._allowed_case_type( test_case) and self._allowed_user(test_case) if allowed_case_types_and_users: try: occurence_case = get_occurrence_case_from_test( test_case.domain, test_case.get_id) episode_case = get_open_episode_case_from_occurrence( test_case.domain, occurence_case.get_id) except ENikshayCaseNotFound: return False test_case_properties = test_case.dynamic_case_properties() episode_case_properties = episode_case.dynamic_case_properties() return ( test_case_properties.get('nikshay_registered', 'false') == 'false' and test_case_properties.get('test_type_value', '') in ['microscopy-zn', 'microscopy-fluorescent'] and episode_case_properties.get('nikshay_id') and (test_case_properties.get('purpose_of_testing') == 'diagnostic' or test_case_properties.get('follow_up_test_reason') in self.followup_for_tests or test_case_properties.get('rft_general') in ['diagnosis_dstb', 'diagnosis_drtb'] or test_case_properties.get('rft_dstb_followup') in self.followup_for_tests) and case_properties_changed(test_case, 'date_reported') and not is_valid_test_submission(test_case)) else: return False
class NinetyNineDotsUpdatePatientRepeater(Base99DOTSRepeater): """Update patient records a patient in 99DOTS Case Type: Person, Episode Trigger: When any pertinent property changes Side Effects: Error: dots_99_error = 'error message' Endpoint: https://www.99dots.org/Dimagi99DOTSAPI/updatePatient """ friendly_name = _("99DOTS Patient Update (person & episode case type)") payload_generator_classes = (UpdatePatientPayloadGenerator,) @classmethod def get_custom_url(cls, domain): from custom.enikshay.integrations.ninetyninedots.views import UpdatePatientRepeaterView return reverse(UpdatePatientRepeaterView.urlname, args=[domain]) def allowed_to_forward(self, case): if not self._allowed_case_type(case) and self._allowed_user(case): return False try: if case.type == CASE_TYPE_PERSON: person_case = case episode_case = get_open_episode_case_from_person(person_case.domain, person_case.case_id) registered_episode = episode_registered_with_99dots(episode_case) elif case.type == CASE_TYPE_EPISODE: episode_case = case registered_episode = (episode_registered_with_99dots(episode_case) and not case_properties_changed(episode_case, 'dots_99_registered'))
def allowed_to_forward(self, episode_case): allowed_case_types_and_users = self._allowed_case_type( episode_case) and self._allowed_user(episode_case) if not allowed_case_types_and_users: return False episode_case_properties = episode_case.dynamic_case_properties() return (episode_case_properties.get('nikshay_id', False) and case_properties_changed(episode_case, [TREATMENT_OUTCOME]) and episode_case_properties.get(TREATMENT_OUTCOME) in treatment_outcome.keys() and is_valid_archived_submission(episode_case))
def allowed_to_forward(self, voucher_case): if not self.case_types_and_users_allowed(voucher_case): return False case_properties = voucher_case.dynamic_case_properties() correct_voucher_type = case_properties[ 'voucher_type'] == self.voucher_type approved = case_properties.get("state") == "approved" not_sent = case_properties.get("event_{}".format( self.event_id)) != "sent" return (approved and correct_voucher_type and not_sent and case_properties_changed(voucher_case, ['state']) and is_valid_voucher_submission(voucher_case))
def allowed_to_forward(self, episode_case): allowed_case_types_and_users = (self._allowed_case_type(episode_case) and self._allowed_user(episode_case)) if not allowed_case_types_and_users: return False episode_case_properties = episode_case.dynamic_case_properties() enabled = episode_case_properties.get('dots_99_enabled') == 'true' registered = episode_case_properties.get( 'dots_99_registered') == 'true' return (enabled and registered and case_properties_changed(episode_case, [TREATMENT_OUTCOME]) and is_valid_episode_submission(episode_case))
def allowed_to_forward(self, episode_case): allowed_case_types_and_users = self._allowed_case_type( episode_case) and self._allowed_user(episode_case) if not allowed_case_types_and_users: return False case_properties = episode_case.dynamic_case_properties() enabled = case_properties.get('dots_99_enabled') == 'true' not_registered = (case_properties.get('dots_99_registered') == 'false' or case_properties.get('dots_99_registered') is None) return (enabled and not_registered and is_valid_episode_submission(episode_case) and case_properties_changed(episode_case, ['dots_99_enabled']))
def allowed_to_forward(self, episode_case): if not self.case_types_and_users_allowed(episode_case): return False case_properties = episode_case.dynamic_case_properties() not_sent = case_properties.get( "event_{}".format(DIAGNOSIS_AND_NOTIFICATION_EVENT)) != "sent" enrolled_in_private_sector = case_properties.get( ENROLLED_IN_PRIVATE) == 'true' return (case_properties.get("bets_first_prescription_voucher_redeemed") == 'true' and case_properties_changed( episode_case, ['bets_first_prescription_voucher_redeemed']) and not_sent and enrolled_in_private_sector and is_valid_episode_submission(episode_case))
def allowed_to_forward(self, episode_case): allowed_case_types_and_users = self._allowed_case_type( episode_case) and self._allowed_user(episode_case) if not allowed_case_types_and_users: return False episode_case_properties = episode_case.dynamic_case_properties() return ( not (episode_case_properties.get(ENROLLED_IN_PRIVATE) == 'true') and ( # has a nikshay id already or is a valid submission probably waiting notification episode_case_properties.get('nikshay_id') or valid_nikshay_patient_registration(episode_case_properties)) and case_properties_changed(episode_case, [TREATMENT_OUTCOME]) and episode_case_properties.get(TREATMENT_OUTCOME) in treatment_outcome and is_valid_archived_submission(episode_case))
def allowed_to_forward(self, episode_case): if not self.case_types_and_users_allowed(episode_case): return False case_properties = episode_case.dynamic_case_properties() not_sent = case_properties.get("event_{}".format(AYUSH_REFERRAL_EVENT)) != "sent" enrolled_in_private_sector = case_properties.get(ENROLLED_IN_PRIVATE) == 'true' return ( case_properties.get("bets_first_prescription_voucher_redeemed") == 'true' and case_properties.get("created_by_user_type") == "pac" and not_sent and enrolled_in_private_sector and case_properties_changed(episode_case, ['bets_first_prescription_voucher_redeemed']) and is_valid_episode_submission(episode_case) and not is_migrated_uatbc_episode(episode_case) )
def allowed_to_forward(self, episode_case): allowed_case_types_and_users = (self._allowed_case_type(episode_case) and self._allowed_user(episode_case)) if not allowed_case_types_and_users: return False episode_case_properties = episode_case.dynamic_case_properties() registered = episode_case_properties.get( 'dots_99_registered') == 'true' unenabled = (episode_case_properties.get('dots_99_enabled') == 'false' and case_properties_changed(episode_case, ['dots_99_enabled'])) closed = episode_case_properties.get('close_reason') in [ 'invalid_episode', 'duplicate', 'invalid_registration' ] return (registered and (unenabled or closed) and is_valid_episode_submission(episode_case))
def allowed_to_forward(self, episode_case): allowed_case_types_and_users = self._allowed_case_type(episode_case) and self._allowed_user(episode_case) if not allowed_case_types_and_users: return False try: person_case = get_person_case_from_episode(episode_case.domain, episode_case.get_id) except ENikshayCaseNotFound: return False episode_case_properties = episode_case.dynamic_case_properties() return ( episode_case_properties.get('private_nikshay_registered', 'false') == 'false' and not episode_case_properties.get('nikshay_id') and valid_nikshay_patient_registration(episode_case_properties, private_registration=True) and case_properties_changed(episode_case, [PRIVATE_PATIENT_EPISODE_PENDING_REGISTRATION]) and is_valid_person_submission(person_case) )
def allowed_to_forward(self, episode_case): # When case property episode.episode_pending_registration transitions from 'yes' to 'no', # and (episode.nikshay_registered != 'true' or episode.nikshay_id != '') allowed_case_types_and_users = self._allowed_case_type(episode_case) and self._allowed_user(episode_case) if allowed_case_types_and_users: episode_case_properties = episode_case.dynamic_case_properties() try: person_case = get_person_case_from_episode(episode_case.domain, episode_case.get_id) except ENikshayCaseNotFound: return False return ( not episode_case_properties.get('nikshay_registered', 'false') == 'true' and not episode_case_properties.get('nikshay_id', False) and valid_nikshay_patient_registration(episode_case_properties) and case_properties_changed(episode_case, [EPISODE_PENDING_REGISTRATION]) and is_valid_person_submission(person_case) ) else: return False
def allowed_to_forward(self, episode_case): if not self.case_types_and_users_allowed(episode_case): return False case_properties = episode_case.dynamic_case_properties() prescription_total_days = _cast_to_int( case_properties.get("prescription_total_days", 0)) treatment_options = case_properties.get("treatment_options") if treatment_options == "fdc": meets_days_threshold = prescription_total_days >= 168 else: meets_days_threshold = prescription_total_days >= 180 enrolled_in_private_sector = case_properties.get( ENROLLED_IN_PRIVATE) == 'true' not_sent = case_properties.get( "event_{}".format(TREATMENT_180_EVENT)) != "sent" return (meets_days_threshold and case_properties_changed( episode_case, ['prescription_total_days']) and not_sent and enrolled_in_private_sector and is_valid_episode_submission(episode_case))
def _met_prescription_days_threshold(self, episode_case): return case_properties_changed(episode_case, [BETS_DATE_PRESCRIPTION_THRESHOLD_MET])
def _treatment_completed(self, episode_case): return (episode_case.get_case_property("treatment_outcome") in ("cured", "treatment_completed") and case_properties_changed(episode_case, ["treatment_outcome"]))