def allowed_to_forward(self, adherence_case): allowed_case_types_and_users = ( self._allowed_case_type(adherence_case) and self._allowed_user(adherence_case) ) if not allowed_case_types_and_users: return False try: episode_case = get_episode_case_from_adherence(adherence_case.domain, adherence_case.case_id) if episode_case.closed: return False except ENikshayCaseNotFound: return False episode_case_properties = episode_case.dynamic_case_properties() adherence_case_properties = adherence_case.dynamic_case_properties() enabled = episode_case_properties.get('dots_99_enabled') == 'true' registered = episode_case_properties.get('dots_99_registered') == 'true' from_enikshay = adherence_case_properties.get('adherence_source') == 'enikshay' previously_updated = adherence_case_properties.get('dots_99_updated') == 'true' return ( enabled and registered and from_enikshay and not previously_updated and case_was_created(adherence_case) and is_valid_episode_submission(episode_case) )
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, 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_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)
def create_repeat_records_on_dest_repeater(self, source_repeater_id, dest_repeater_id, state): dest_repeater = Repeater.get(dest_repeater_id) retriggered = set() records = iter_repeat_records_by_domain(domain, repeater_id=source_repeater_id, state=state) record_count = get_repeat_record_count(domain, repeater_id=source_repeater_id, state=state) accessor = CaseAccessors(domain) print("Iterating over records and adding new record for them") for record in with_progress_bar(records, length=record_count): if record.payload_id in retriggered: self.record_failure(record.get_id, record.payload_id, error_message="Already triggered") continue try: episode = accessor.get_case(record.payload_id) episode_case_properties = episode.dynamic_case_properties() if (episode_case_properties.get('nikshay_registered', 'false') == 'false' and episode_case_properties.get( 'private_nikshay_registered', 'false') == 'false' and not episode_case_properties.get('nikshay_id') and episode_case_properties.get('episode_type') == 'confirmed_tb' and is_valid_episode_submission(episode)): new_record = RepeatRecord( domain=domain, next_check=datetime.utcnow(), repeater_id=dest_repeater_id, repeater_type=dest_repeater.doc_type, payload_id=record.payload_id, ) if not self.dry_run: new_record.save() retriggered.add(record.payload_id) self.add_row( record, episode_case_properties.get('migration_created_case'), new_record.get_id) else: self.record_failure(record.get_id, record.payload_id, error_message="Not to be re-triggered") except Exception as e: self.record_failure(record.get_id, record.payload_id, error_message="{error}: {message}".format( error=e.__name__, message=e.message))
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): 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): 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): 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))
and not case_properties_changed(episode_case, 'dots_99_registered')) 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 """
elif case.type == CASE_TYPE_EPISODE: episode_case = case 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)")