Example #1
0
 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')
Example #2
0
def is_valid_test_submission(test_case):
    try:
        lab_referral_case = get_lab_referral_from_test(test_case.domain, test_case.get_id)
    except ENikshayCaseNotFound:
        return False

    try:
        dmc_location = SQLLocation.objects.get(location_id=lab_referral_case.owner_id)
    except SQLLocation.DoesNotExist:
        raise NikshayLocationNotFound(
            "Location with id {location_id} not found. This is the owner for lab referral with id: \
            {lab_referral_id}"
            .format(location_id=lab_referral_case.owner_id, lab_referral_id=lab_referral_case.case_id)
        )
    return dmc_location.metadata.get('is_test', "yes") == "yes"