def _get_dmc_code(self, test_case, test_case_properties): dmc_location_id = test_case_properties.get("testing_facility_id", None) if not dmc_location_id: # fallback to lab referral case owner id for older versions of app lab_referral_case = get_lab_referral_from_test( test_case.domain, test_case.get_id) dmc_location_id = lab_referral_case.owner_id if not dmc_location_id: raise NikshayRequiredValueMissing( "Value missing for dmc_code/testing_facility_id for test case: " + test_case.get_id) dmc = SQLLocation.active_objects.get_or_None( location_id=dmc_location_id) if not dmc: raise NikshayLocationNotFound( "Location with id: {location_id} not found." "This is the testing facility id assigned for test: {test_case_id}" .format(location_id=dmc_location_id, test_case_id=test_case.get_id)) nikshay_code = dmc.metadata.get('nikshay_code') if not nikshay_code or (isinstance(nikshay_code, basestring) and not nikshay_code.isdigit()): raise NikshayRequiredValueMissing( "Inappropriate value for dmc, got value: {}".format( nikshay_code)) return dmc.metadata.get('nikshay_code')
def _get_mandatory_fields(self, test_case, test_case_properties, occurence_case, use_2b_app_structure): # list of fields that we want the case to have and should raise an exception if its missing or not in # expected state to highlight missing essentials in repeat records. Check added here instead of # allow_to_forward to bring to notice these records instead of silently ignoring them interval_id = self._get_interval_id( test_case_properties, use_2b_app_structure ) dmc_code = self._get_dmc_code(test_case, test_case_properties) lab_serial_number = test_case_properties.get('lab_serial_number') test_result_grade = test_case_properties.get('result_grade') bacilli_count = test_case_properties.get('max_bacilli_count') try: # Since 9 is the max value supported by Nikshay, notify 9 in case 9+ if bacilli_count and int(bacilli_count) > 9: bacilli_count = '9' except ValueError: pass result_grade = self.get_result_grade(test_result_grade, bacilli_count) if not (lab_serial_number and result_grade): raise NikshayRequiredValueMissing("Mandatory value missing in one of the following " "LabSerialNo: {lab_serial_number}, ResultGrade: {result_grade}, " "Max Bacilli Count: {max_bacilli_count}" .format(lab_serial_number=lab_serial_number, result_grade=test_result_grade, max_bacilli_count=bacilli_count)) return interval_id, lab_serial_number, result_grade, dmc_code
def _get_interval_id(self, testing_purpose, follow_up_test_reason): if testing_purpose == 'diagnostic': interval_id = 0 else: interval_id = purpose_of_testing.get(follow_up_test_reason, None) if interval_id is None: raise NikshayRequiredValueMissing( "Value missing for intervalID, purpose_of_testing: {testing_purpose}, " "follow_up_test_reason: {follow_up_test_reason}".format( testing_purpose=testing_purpose, follow_up_test_reason=follow_up_test_reason)) return interval_id
def _get_interval_id(self, test_case_properties, use_2b_app_structure): if use_2b_app_structure: testing_purpose = test_case_properties.get('rft_general') follow_up_test_reason = test_case_properties.get('rft_dstb_followup') else: testing_purpose = test_case_properties.get('purpose_of_testing') follow_up_test_reason = test_case_properties.get('follow_up_test_reason') if testing_purpose in ['diagnostic', 'diagnosis_dstb', 'diagnosis_drtb']: interval_id = 0 else: interval_id = purpose_of_testing.get(follow_up_test_reason, None) if interval_id is None: raise NikshayRequiredValueMissing( "Value missing for intervalID, purpose_of_testing: {testing_purpose}, " "follow_up_test_reason: {follow_up_test_reason}".format( testing_purpose=testing_purpose, follow_up_test_reason=follow_up_test_reason) ) return interval_id
def _get_mandatory_fields(self, test_case, test_case_properties): # list of fields that we want the case to have and should raise an exception if its missing or not in # expected state to highlight missing essentials in repeat records. Check added here instead of # allow_to_forward to bring to notice these records instead of silently ignoring them interval_id = self._get_interval_id( test_case_properties.get('purpose_of_testing'), test_case_properties.get('follow_up_test_reason')) dmc_code = self._get_dmc_code(test_case, test_case_properties) lab_serial_number = test_case_properties.get('lab_serial_number') test_result_grade = test_case_properties.get('result_grade') bacilli_count = test_case_properties.get('max_bacilli_count') result_grade = self.get_result_grade(test_result_grade, bacilli_count) if not (lab_serial_number and result_grade): raise NikshayRequiredValueMissing( "Mandatory value missing in one of the following " "LabSerialNo: {lab_serial_number}, ResultGrade: {result_grade}" .format(lab_serial_number=lab_serial_number, result_grade=test_result_grade)) return interval_id, lab_serial_number, result_grade, dmc_code