Пример #1
0
    def test_get_case_location_ancestor_repeaters_multi(self):
        """
        get_case_location_ancestor_repeaters should return the repeater at the closest ancestor location
        """
        form, (gardens_case, ) = _create_case(
            domain=self.domain,
            case_id=uuid.uuid4().hex,
            owner_id=self.locations['Gardens'].location_id)
        cape_town_repeater = OpenmrsRepeater.wrap({
            'doc_type':
            'OpenmrsRepeater',
            'domain':
            self.domain,
            'location_id':
            self.locations['Cape Town'].location_id,
        })
        cape_town_repeater.save()
        western_cape_repeater = OpenmrsRepeater.wrap({
            'doc_type':
            'OpenmrsRepeater',
            'domain':
            self.domain,
            'location_id':
            self.locations['Western Cape'].location_id,
        })
        western_cape_repeater.save()

        repeaters = get_case_location_ancestor_repeaters(gardens_case)
        self.assertEqual(repeaters, [cape_town_repeater])
Пример #2
0
 def test_allowed_to_forward(self):
     """
     If all criteria pass, the payload should be allowed to forward
     :return:
     """
     case_id = uuid.uuid4().hex
     form_payload, cases = _create_case(domain=DOMAIN, case_id=case_id, owner_id=self.owner.get_id)
     repeater = OpenmrsRepeater()
     self.assertTrue(repeater.allowed_to_forward(form_payload))
Пример #3
0
 def test_allowed_to_forward(self):
     """
     If all criteria pass, the payload should be allowed to forward
     :return:
     """
     case_id = uuid.uuid4().hex
     form_payload, cases = _create_case(domain=DOMAIN, case_id=case_id, owner_id=self.owner.get_id)
     repeater = OpenmrsRepeater()
     self.assertTrue(repeater.allowed_to_forward(form_payload))
Пример #4
0
 def test_update_from_openmrs(self):
     """
     payloads from OpenMRS should not be forwarded back to OpenMRS
     """
     payload = XFormInstanceSQL(
         domain=DOMAIN,
         xmlns=XMLNS_OPENMRS,
     )
     repeater = OpenmrsRepeater()
     self.assertFalse(repeater.allowed_to_forward(payload))
Пример #5
0
 def test_update_from_openmrs(self):
     """
     payloads from OpenMRS should not be forwarded back to OpenMRS
     """
     payload = XFormInstanceSQL(
         domain=DOMAIN,
         xmlns=XMLNS_OPENMRS,
     )
     repeater = OpenmrsRepeater()
     self.assertFalse(repeater.allowed_to_forward(payload))
Пример #6
0
 def test_excluded_case_type(self):
     """
     If the repeater has white-listed case types, excluded case types should not be forwarded
     """
     case_id = uuid.uuid4().hex
     form_payload, cases = _create_case(
         domain=DOMAIN, case_id=case_id, case_type='notpatient', owner_id=self.owner.get_id
     )
     repeater = OpenmrsRepeater()
     repeater.white_listed_case_types = ['patient']
     self.assertFalse(repeater.allowed_to_forward(form_payload))
Пример #7
0
 def test_excluded_case_type(self):
     """
     If the repeater has white-listed case types, excluded case types should not be forwarded
     """
     case_id = uuid.uuid4().hex
     form_payload, cases = _create_case(
         domain=DOMAIN, case_id=case_id, case_type='notpatient', owner_id=self.owner.get_id
     )
     repeater = OpenmrsRepeater()
     repeater.white_listed_case_types = ['patient']
     self.assertFalse(repeater.allowed_to_forward(form_payload))
Пример #8
0
def test_observation_mappings():
    repeater = OpenmrsRepeater.wrap({
        "openmrs_config": {
            "openmrs_provider": "",
            "case_config": {},
            "form_configs": [{
                "xmlns": "http://openrosa.org/formdesigner/9ECA0608-307A-4357-954D-5A79E45C3879",
                "openmrs_encounter_type": "81852aee-3f10-11e4-adec-0800271c1b75",
                "openmrs_visit_type": "c23d6c9d-3f10-11e4-adec-0800271c1b75",
                "openmrs_observations": [
                    {
                        "concept": "397b9631-2911-435a-bf8a-ae4468b9c1d4",
                        "case_property": "abnormal_temperature",
                        "value": {
                            "doc_type": "FormQuestionMap",
                            "form_question": "/data/abnormal_temperature",
                            "value_map": {
                                "yes": "05ced69b-0790-4aad-852f-ba31fe82fbd9",
                                "no": "eea8e4e9-4a91-416c-b0f5-ef0acfbc51c0"
                            },
                        },
                    },
                    {
                        "concept": "397b9631-2911-435a-bf8a-ae4468b9c1d4",
                        "case_property": "bahmni_abnormal_temperature",
                        "value": {
                            "doc_type": "ConstantString",
                            "value": "",
                            "direction": "in",
                        },
                    },
                ]
            }]
        }
    })
    observation_mappings = repeater.observation_mappings
    eq(observation_mappings, {
        '397b9631-2911-435a-bf8a-ae4468b9c1d4': [
            ObservationMapping(
                concept='397b9631-2911-435a-bf8a-ae4468b9c1d4',
                case_property='abnormal_temperature',
                value=FormQuestionMap(
                    form_question='/data/abnormal_temperature',
                    value_map={
                        'yes': '05ced69b-0790-4aad-852f-ba31fe82fbd9',
                        'no': 'eea8e4e9-4a91-416c-b0f5-ef0acfbc51c0'
                    }
                )
            ),
            ObservationMapping(
                concept='397b9631-2911-435a-bf8a-ae4468b9c1d4',
                case_property='bahmni_abnormal_temperature',
                value=ConstantString(
                    direction='in',
                    doc_type='ConstantString',
                    value=''
                )
            )
        ]
    })
Пример #9
0
 def setUpClass(cls):
     super().setUpClass()
     cls.domain = create_domain(TEST_DOMAIN)
     cls.location_type = LocationType.objects.create(
         domain=TEST_DOMAIN,
         name='test_location_type',
     )
     cls.location = SQLLocation.objects.create(
         domain=TEST_DOMAIN,
         name='test location',
         location_id='test_location',
         location_type=cls.location_type,
     )
     cls.user = CommCareUser.create(TEST_DOMAIN,
                                    'username',
                                    'password',
                                    None,
                                    None,
                                    location=cls.location)
     cls.repeater = OpenmrsRepeater.wrap({
         "domain": TEST_DOMAIN,
         "url": "https://demo.mybahmni.org/openmrs/",
         "auth_type": BASIC_AUTH,
         "username": "******",
         "password": "******",
         "white_listed_case_types": ["case"],
         "location_id": cls.location.location_id,
         "atom_feed_enabled": True,
         "openmrs_config": {
             "openmrs_provider": "",
             "case_config": {},
             "form_configs": []
         }
     })
     cls.repeater.save()
Пример #10
0
 def setUpRepeater(self):
     observations = [
         {
             "doc_type": "ObservationMapping",
             "concept": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAA",
             "value": {
                 "doc_type": "FormQuestion",
                 "form_question": "/data/height"
             },
             "case_property": "height"
         }
     ]
     diagnoses = [
         {
             "doc_type": "ObservationMapping",
             "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0",
             "value": {
                 "doc_type": "FormQuestionMap",
                 "form_question": "/data/bahmni_hypothermia",
                 "value_map": {
                     "emergency_room_user_id": "Hypothermia",  # Value must match diagnosis name
                 },
                 "direction": "in",
             },
             "case_property": "owner_id"
         }
     ]
     self.repeater = OpenmrsRepeater.wrap(self.get_repeater_dict(observations, diagnoses))
Пример #11
0
def openmrs_test_fire(request, domain, repeater_id, record_id):
    repeater = OpenmrsRepeater.get(repeater_id)
    record = RepeatRecord.get(record_id)
    assert repeater.domain == domain
    assert record.domain == domain
    assert record.repeater_id == repeater.get_id

    attempt = repeater.fire_for_record(record)
    return JsonResponse(attempt.to_json())
Пример #12
0
def openmrs_raw_api(request, domain, repeater_id, rest_uri):
    get_params = dict(request.GET)
    no_links = get_params.pop('links', None) is None
    repeater = OpenmrsRepeater.get(repeater_id)
    assert repeater.domain == domain
    raw_json = repeater.requests.get('/ws/rest/v1' + rest_uri, get_params).json()
    if no_links:
        return JsonResponse(_filter_out_links(raw_json))
    return JsonResponse(raw_json)
Пример #13
0
def poll_openmrs_atom_feeds(domain_name):
    for repeater in OpenmrsRepeater.by_domain(domain_name):
        if repeater.atom_feed_enabled and not repeater.paused:
            patient_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_PATIENT)
            encounter_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_ENCOUNTER)
            for patient_uuid in patient_uuids:
                update_patient(repeater, patient_uuid)
            for encounter_uuid in encounter_uuids:
                import_encounter(repeater, encounter_uuid)
Пример #14
0
def openmrs_test_fire(request, domain, repeater_id, record_id):
    repeater = OpenmrsRepeater.get(repeater_id)
    record = RepeatRecord.get(record_id)
    assert repeater.domain == domain
    assert record.domain == domain
    assert record.repeater_id == repeater.get_id

    attempt = repeater.fire_for_record(record)
    return JsonResponse(attempt.to_json())
Пример #15
0
def poll_openmrs_atom_feeds(domain_name):
    for repeater in OpenmrsRepeater.by_domain(domain_name):
        if repeater.atom_feed_enabled and not repeater.paused:
            patient_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_PATIENT)
            encounter_uuids = get_feed_updates(repeater,
                                               ATOM_FEED_NAME_ENCOUNTER)
            for patient_uuid in patient_uuids:
                update_patient(repeater, patient_uuid)
            for encounter_uuid in encounter_uuids:
                import_encounter(repeater, encounter_uuid)
Пример #16
0
 def setUpRepeater(self):
     observations = [{
         "doc_type": "ObservationMapping",
         "concept": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAA",
         "value": {
             "doc_type": "FormQuestion",
             "form_question": "/data/height"
         },
         "case_property": "height"
     }]
     diagnoses = [
         {
             "doc_type": "ObservationMapping",
             "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0",
             "value": {
                 "doc_type": "FormQuestionMap",
                 "direction": "in",
                 "form_question": "[unused when direction == 'in']",
                 "value_map": {
                     "emergency_room_user_id":
                     "Hypothermia",  # Value must match diagnosis name
                 }
             },
             "case_property": "owner_id"
         },
         {
             "doc_type": "ObservationMapping",
             "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0",
             "value": {
                 "doc_type": "JsonPathCasePropertyMap",
                 "direction": "in",
                 "jsonpath": "codedAnswer.name",
                 "case_property": "[unused when direction == 'in']",
                 "value_map": {
                     "yes": "Hypothermia"
                 }
             },
             "case_property": "hypothermia_diagnosis"
         },
         {
             "doc_type": "ObservationMapping",
             "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0",
             "value": {
                 "doc_type": "JsonPathCaseProperty",
                 "direction": "in",
                 "jsonpath": "diagnosisDateTime",
                 "case_property": "[unused when direction == 'in']",
                 "commcare_data_type": "cc_date",
                 "external_data_type": "omrs_datetime"
             },
             "case_property": "hypothermia_date"
         }
     ]
     self.repeater = OpenmrsRepeater.wrap(
         self.get_repeater_dict(observations, diagnoses))
Пример #17
0
    def test_get_case_location_ancestor_repeaters_same(self):
        """
        get_case_location_ancestor_repeaters should return the repeater at the same location as the case
        """
        gardens = self.locations['Gardens']
        form, (case, ) = _create_case(domain=self.domain, case_id=uuid.uuid4().hex, owner_id=gardens.location_id)
        gardens_repeater = OpenmrsRepeater.wrap({
            'doc_type': 'OpenmrsRepeater',
            'domain': self.domain,
            'location_id': gardens.location_id,
        })
        gardens_repeater.save()

        repeaters = get_case_location_ancestor_repeaters(case)
        self.assertEqual(repeaters, [gardens_repeater])
Пример #18
0
    def test_get_case_location_ancestor_repeaters_same(self):
        """
        get_case_location_ancestor_repeaters should return the repeater at the same location as the case
        """
        gardens = self.locations['Gardens']
        form, (case, ) = _create_case(domain=self.domain, case_id=uuid.uuid4().hex, owner_id=gardens.location_id)
        gardens_repeater = OpenmrsRepeater.wrap({
            'doc_type': 'OpenmrsRepeater',
            'domain': self.domain,
            'location_id': gardens.location_id,
        })
        gardens_repeater.save()

        repeaters = get_case_location_ancestor_repeaters(case)
        self.assertEqual(repeaters, [gardens_repeater])
Пример #19
0
    def test_get_case_location_ancestor_repeaters_multi(self):
        """
        get_case_location_ancestor_repeaters should return the repeater at the closest ancestor location
        """
        form, (gardens_case, ) = _create_case(
            domain=self.domain,
            case_id=uuid.uuid4().hex,
            owner_id=self.locations['Gardens'].location_id
        )
        cape_town_repeater = OpenmrsRepeater.wrap({
            'doc_type': 'OpenmrsRepeater',
            'domain': self.domain,
            'location_id': self.locations['Cape Town'].location_id,
        })
        cape_town_repeater.save()
        western_cape_repeater = OpenmrsRepeater.wrap({
            'doc_type': 'OpenmrsRepeater',
            'domain': self.domain,
            'location_id': self.locations['Western Cape'].location_id,
        })
        western_cape_repeater.save()

        repeaters = get_case_location_ancestor_repeaters(gardens_case)
        self.assertEqual(repeaters, [cape_town_repeater])
Пример #20
0
def poll_openmrs_atom_feeds(domain_name):
    for repeater in OpenmrsRepeater.by_domain(domain_name):
        errors = []
        if repeater.atom_feed_enabled and not repeater.paused:
            patient_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_PATIENT)
            encounter_uuids = get_feed_updates(repeater,
                                               ATOM_FEED_NAME_ENCOUNTER)
            for patient_uuid in patient_uuids:
                try:
                    update_patient(repeater, patient_uuid)
                except (ConfigurationError, OpenmrsException) as err:
                    errors.append(str(err))
            for encounter_uuid in encounter_uuids:
                try:
                    import_encounter(repeater, encounter_uuid)
                except (ConfigurationError, OpenmrsException) as err:
                    errors.append(str(err))
        if errors:
            repeater.requests.notify_error(
                'Errors importing from Atom feed:\n' + '\n'.join(errors))
            if settings.UNIT_TESTING:
                assert False, errors
Пример #21
0
 def repeater(self):
     repeater = OpenmrsRepeater.get(self.repeater_id)
     assert repeater.domain == self.domain
     return repeater
Пример #22
0
 def tearDown(self):
     delete_all_users()
     for repeater in OpenmrsRepeater.by_domain(self.domain):
         repeater.delete()
Пример #23
0
 def tearDown(self):
     delete_all_users()
     for repeater in OpenmrsRepeater.by_domain(self.domain):
         repeater.delete()
Пример #24
0
 def setUpRepeaterForExtCase(self):
     observations = [
         {
             "doc_type": "ObservationMapping",
             "concept": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAA",
             "value": {
                 "doc_type": "FormQuestion",
                 "form_question": "/data/height"
             },
             "indexed_case_mapping": {
                 "identifier": "parent",
                 "case_type": "observation",
                 "relationship": "extension",
                 "case_properties": [
                     {
                         "doc_type": "JsonPathCaseProperty",
                         "jsonpath": "concept.name",
                         "case_property": "case_name",
                     },
                     {
                         "doc_type": "JsonPathCaseProperty",
                         "jsonpath": "value",
                         "case_property": "observation_value",
                     }
                 ]
             }
         }
     ]
     diagnoses = [
         {
             "doc_type": "ObservationMapping",
             "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0",
             "value": {
                 "doc_type": "FormQuestionMap",
                 "form_question": "/data/bahmni_hypothermia",
                 "value_map": {
                     "emergency_room_user_id": "Hypothermia",  # Value must match diagnosis name
                 },
                 "direction": "in",
             },
             "indexed_case_mapping": {
                 "identifier": "parent",
                 "case_type": "diagnosis",
                 "relationship": "extension",
                 "case_properties": [
                     {
                         "doc_type": "JsonPathCaseProperty",
                         "jsonpath": "codedAnswer.name",
                         "case_property": "case_name",
                     },
                     {
                         "doc_type": "JsonPathCaseProperty",
                         "jsonpath": "certainty",
                         "case_property": "certainty",
                     },
                     {
                         "doc_type": "JsonPathCasePropertyMap",
                         "jsonpath": "order",
                         "case_property": "is_primary",
                         "value_map": {
                             "yes": "PRIMARY",
                             "no": "SECONDARY"
                         }
                     },
                     {
                         "doc_type": "CasePropertyConstantValue",
                         "case_property": "code",
                         "value": "T68 (ICD 10 - WHO)"
                     }
                 ]
             }
         }
     ]
     self.repeater = OpenmrsRepeater.wrap(self.get_repeater_dict(observations, diagnoses))
Пример #25
0
 def repeater(self):
     repeater = OpenmrsRepeater.get(self.repeater_id)
     assert repeater.domain == self.domain
     return repeater