Ejemplo n.º 1
0
    def test_create_missing(self):
        """
        create_patient should be called if PatientFinder.create_missing is set
        """
        openmrs_config = OpenmrsConfig.wrap({
            'case_config': {
                'patient_finder': {
                    'create_missing': {
                        'doc_type': 'ConstantString',
                        'value': 'True',
                        'external_data_type': OPENMRS_DATA_TYPE_BOOLEAN,
                    },
                    'doc_type': 'WeightedPropertyPatientFinder',
                    'searchable_properties': [],
                    'property_weights': [],
                },
                'patient_identifiers': {},
                'match_on_ids': [],
                'person_properties': {},
                'person_preferred_address': {},
                'person_preferred_name': {},
            },
            'form_configs': [],
        })

        with mock.patch('corehq.motech.openmrs.repeater_helpers.CaseAccessors') as CaseAccessorsPatch, \
                mock.patch('corehq.motech.openmrs.repeater_helpers.create_patient') as create_patient_patch:
            requests = mock.Mock()
            info = mock.Mock(case_id='123')
            CaseAccessorsPatch.return_value = mock.Mock(get_case=mock.Mock())
            create_patient_patch.return_value = None

            find_or_create_patient(requests, DOMAIN, info, openmrs_config)

            create_patient_patch.assert_called()
Ejemplo n.º 2
0
    def test_create_missing(self):
        """
        create_patient should be called if PatientFinder.create_missing is set
        """
        openmrs_config = OpenmrsConfig.wrap({
            'case_config': {
                'patient_finder': {
                    'create_missing': True,
                    'doc_type': 'WeightedPropertyPatientFinder',
                    'searchable_properties': [],
                    'property_weights': [],
                },
                'patient_identifiers': {},
                'match_on_ids': [],
                'person_properties': {},
                'person_preferred_address': {},
                'person_preferred_name': {},
            },
            'form_configs': [],
        })

        with mock.patch('corehq.motech.openmrs.repeater_helpers.CaseAccessors') as CaseAccessorsPatch, \
                mock.patch('corehq.motech.openmrs.repeater_helpers.create_patient') as create_patient_patch:
            requests = mock.Mock()
            info = mock.Mock(case_id='123')
            CaseAccessorsPatch.return_value = mock.Mock(get_case=mock.Mock())
            create_patient_patch.return_value = None

            find_or_create_patient(requests, DOMAIN, info, openmrs_config)

            create_patient_patch.assert_called()
def get_task(info, form_json, form_config_dict):
    return CreateVisitsEncountersObsTask(
        requests=None,
        domain="test-domain",
        info=info,
        form_json=form_json,
        openmrs_config=OpenmrsConfig.wrap({
            "case_config": {},
            "form_configs": [form_config_dict],
        }),
        person_uuid="test-person_uuid",
    )
Ejemplo n.º 4
0
    def test_identifier_case_property_deleted(self, get_patient_mock,
                                              case_blocks_mock):
        """
        CommCare should drop the case's patient ID when an OpenMRS patient is voided
        """
        requests = None
        info = CaseTriggerInfo(
            domain=self.case.domain,
            case_id=self.case.case_id,
            type=self.case.type,
            name=self.case.name,
            extra_fields={
                "external_id": self.case.external_id,
            },
        )
        openmrs_config = OpenmrsConfig.wrap({
            "case_config": {
                "patient_finder": {},
                "patient_identifiers": {
                    "uuid": {
                        "case_property": "external_id"
                    },
                },
                "match_on_ids": ["uuid"],
                "person_properties": {},
                "person_preferred_address": {},
                "person_preferred_name": {},
            },
            "form_configs": [],
        })
        voided_patient = self.get_json("voided_patient")
        get_patient_mock.return_value = voided_patient

        patient = get_patient(requests, DOMAIN, info, openmrs_config)

        self.assertEqual(info.extra_fields, {"external_id": None})
        case_block_re = strip_xml(f"""
            <case case_id="123456" »
                  date_modified="{DATETIME_PATTERN}" »
                  xmlns="http://commcarehq.org/case/transaction/v2">
              <update>
                <external_id />
              </update>
            </case>
        """)
        case_block = case_blocks_mock.call_args[0][0][0]
        self.assertIsNotNone(re.match(case_block_re, case_block))
        self.assertIsNone(patient)
Ejemplo n.º 5
0
def test_concept_directions():
    form_json = {
        "form": {
            "@xmlns": "http://openrosa.org/formdesigner/9ECA0608-307A-4357-954D-5A79E45C3879",
            "pneumonia": "no",
            "malnutrition": "no",
        }
    }
    form_config_dict = get_form_config_dict()
    openmrs_config = OpenmrsConfig.wrap({
        "case_config": {},
        "form_configs": [form_config_dict]
    })
    info = CaseTriggerInfo(
        domain="test-domain",
        case_id="c0ffee",
        form_question_values={
            "/data/pneumonia": "no",
            "/data/malnutrition": "no",
        }
    )
    task = CreateVisitsEncountersObsTask(
        requests=None,
        domain="test-domain",
        info=info,
        form_json=form_json,
        openmrs_config=openmrs_config,
        person_uuid="test-person_uuid",
    )
    values_for_concept = task._get_values_for_concept(
        OpenmrsFormConfig.wrap(form_config_dict)
    )
    eq(values_for_concept, {
        # "direction": "out"
        'e7fdcd25-6d11-4d85-a80a-8979785f0f4b': ['eea8e4e9-4a91-416c-b0f5-ef0acfbc51c0'],
        # "direction": null, or not specified
        '4000cf24-8fab-437d-9950-ea8d9bb05a09': ['eea8e4e9-4a91-416c-b0f5-ef0acfbc51c0'],
        # "direction": "in" should be missing
    })