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 person_has_any_nikshay_notifiable_episode(person_case): domain = person_case.domain from custom.enikshay.integrations.utils import is_valid_person_submission from custom.enikshay.integrations.nikshay.repeaters import valid_nikshay_patient_registration if not is_valid_person_submission(person_case): return False episode_cases = get_all_episode_cases_from_person(domain, person_case.case_id) return any(valid_nikshay_patient_registration(episode_case.dynamic_case_properties()) for episode_case in episode_cases)
def _should_be_forwarded(episode_case, episode_case_properties): """ This would add False for cases that have already been forwarded but is a good to have for other cases that are expected to be notified """ person_case = get_person_case_from_episode(DOMAIN, episode_case) return (not episode_case_properties.get('nikshay_registered', 'false') == 'true' and not episode_case_properties.get( 'nikshay_registered', 'false') == 'true' and not episode_case_properties.get('nikshay_id', False) and episode_case_properties.get('episode_type') == DSTB_EPISODE_TYPE and is_valid_person_submission(person_case))
def allowed_to_forward(self, person_case): # episode.nikshay_registered is true and nikshay_id present and # person.hiv_status changed OR # CPTDeliverDate changes OR # InitiatedDate/Art Initiated date changes allowed_case_types_and_users = self._allowed_case_type( person_case) and self._allowed_user(person_case) person_case_properties = person_case.dynamic_case_properties() if allowed_case_types_and_users: return ( # Do not attempt notification for patients registered in private app not (person_case_properties.get(ENROLLED_IN_PRIVATE) == 'true') and (related_dates_changed(person_case) or person_hiv_status_changed(person_case)) and is_valid_person_submission(person_case) and person_has_any_nikshay_notifiable_episode(person_case)) else: return False
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, person_case): # episode.nikshay_registered is true and nikshay_id present and # person.hiv_status changed OR # CPTDeliverDate changes OR # InitiatedDate/Art Initiated date changes allowed_case_types_and_users = self._allowed_case_type( person_case) and self._allowed_user(person_case) if allowed_case_types_and_users: try: episode_case = get_open_episode_case_from_person( person_case.domain, person_case.get_id) except ENikshayCaseNotFound: return False episode_case_properties = episode_case.dynamic_case_properties() return (episode_case_properties.get('nikshay_id') and (related_dates_changed(person_case) or person_hiv_status_changed(person_case)) and is_valid_person_submission(person_case)) else: return False
else: return False except ENikshayCaseNotFound: return False sector = get_sector(episode_case) api_spec = load_api_spec() properties_to_check = api_spec.case_properties_by_case_type(sector, case.type, DIRECTION_OUTBOUND) props_changed = case_properties_changed(case, properties_to_check) return ( registered_episode and props_changed and ( (case.type == CASE_TYPE_EPISODE and is_valid_episode_submission(episode_case)) or (case.type == CASE_TYPE_PERSON and is_valid_person_submission(person_case)) ) ) class NinetyNineDotsAdherenceRepeater(Base99DOTSRepeater): """Send Adherence datapoints to 99DOTS Case Type: Adherence Trigger: When a new adherence datapoint is collected in eNikshay when a patient is enrolled in 99DOTS Side Effects: Success: adherence.dots_99_updated = true Error: adherence.dots_99_updated = false, adherence.dots_99_error = 'error message' Endpoint: https://www.99dots.org/Dimagi99DOTSAPI/updateAdherenceInformation """ friendly_name = _("99DOTS Update Adherence (adherence case type)")
props_changed = case_properties_changed( episode_case, NINETYNINEDOTS_EPISODE_PROPERTIES) registered_episode = ( episode_registered_with_99dots(episode_case) and not case_properties_changed(episode_case, 'dots_99_registered')) else: return False except ENikshayCaseNotFound: return False return (registered_episode and props_changed and ((case.type == CASE_TYPE_EPISODE and is_valid_episode_submission(episode_case)) or (case.type == CASE_TYPE_PERSON and is_valid_person_submission(person_case)))) class NinetyNineDotsAdherenceRepeater(Base99DOTSRepeater): """Send Adherence datapoints to 99DOTS Case Type: Adherence Trigger: When a new adherence datapoint is collected in eNikshay when a patient is enrolled in 99DOTS Side Effects: Success: adherence.dots_99_updated = true Error: adherence.dots_99_updated = false, adherence.dots_99_error = 'error message' Endpoint: https://www.99dots.org/Dimagi99DOTSAPI/updateAdherenceInformation """ friendly_name = _("99DOTS Update Adherence (adherence case type)") payload_generator_classes = (AdherencePayloadGenerator, )