Beispiel #1
0
 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
    def get_payload(self, repeat_record, test_case):
        occurence_case = get_occurrence_case_from_test(test_case.domain, test_case.get_id)
        episode_case = get_associated_episode_case_for_test(test_case, occurence_case.get_id)
        person_case = get_person_case_from_occurrence(test_case.domain, occurence_case.get_id)

        test_case_properties = test_case.dynamic_case_properties()
        episode_case_properties = episode_case.dynamic_case_properties()
        use_2b_app_structure = self.use_2b_app_structure(person_case)

        interval_id, lab_serial_number, result_grade, dmc_code = self._get_mandatory_fields(
            test_case, test_case_properties, occurence_case,
            use_2b_app_structure
        )

        test_reported_on = _format_date_or_null_date(test_case_properties, 'date_reported')
        properties_dict = self._base_properties(repeat_record)
        properties_dict.update({
            "PatientID": episode_case_properties.get('nikshay_id'),
            "TestDate": test_reported_on,
            "LabNo": lab_serial_number,
            "Local_ID": person_case.get_id,
            "IntervalId": interval_id,
            # since weight is not taken and is mandatory we send 1
            "PatientWeight": test_case_properties.get('weight', 1),
            "SmearResult": result_grade,
            "DMC": dmc_code
        })

        return json.dumps(properties_dict)
 def get_occurrence(self, test_case):
     if 'occurrence' not in self.context:
         self.context['occurrence'] = get_occurrence_case_from_test(
             DOMAIN, test_case.case_id)
     if not self.context['occurrence']:
         raise Exception("could not find occurrrence for test %s" %
                         test_case.case_id)
     return self.context['occurrence']
 def get_occurrence(self, test_case):
     if 'occurrence' not in self.context:
         try:
             self.context['occurrence'] = get_occurrence_case_from_test(
                 DOMAIN, test_case.case_id)
         except ENikshayCaseNotFound:
             self.context['occurrence'] = None
     if not self.context['occurrence']:
         raise Exception("could not find occurrrence for test %s" %
                         test_case.case_id)
     return self.context['occurrence']