Ejemplo n.º 1
0
 def run(self):
     """
     Returns WorkflowTasks for creating visits, encounters and observations
     """
     subtasks = []
     provider_uuid = getattr(self.openmrs_config, 'openmrs_provider', None)
     location_uuid = (
         get_ancestor_location_openmrs_uuid(self.domain, self.info.case_id) or
         get_unknown_location_uuid(self.requests)  # If we don't set
         # a location, OpenMRS sets it to NULL. That's OK for
         # OpenMRS, but it breaks Bahmni. Bahmni has an "Unknown
         # Location". Use that, if it exists.
     )
     self.info.form_question_values.update(self.form_question_values)
     for form_config in self.openmrs_config.form_configs:
         if form_config.xmlns == self.form_json['form']['@xmlns']:
             start_datetime, stop_datetime = self._get_start_stop_datetime(form_config)
             subtasks.append(
                 CreateVisitTask(
                     self.requests,
                     person_uuid=self.person_uuid,
                     provider_uuid=provider_uuid,
                     start_datetime=start_datetime,
                     stop_datetime=stop_datetime,
                     values_for_concept={obs.concept: [obs.value.get_value(self.info)]
                                         for obs in form_config.openmrs_observations
                                         if obs.value.get_value(self.info)},
                     encounter_type=form_config.openmrs_encounter_type,
                     openmrs_form=form_config.openmrs_form,
                     visit_type=form_config.openmrs_visit_type,
                     location_uuid=location_uuid,
                 )
             )
     return subtasks
Ejemplo n.º 2
0
 def run(self):
     """
     Returns WorkflowTasks for creating visits, encounters and observations
     """
     subtasks = []
     provider_uuid = getattr(self.openmrs_config, 'openmrs_provider', None)
     location_uuid = (
         get_ancestor_location_openmrs_uuid(self.domain, self.info.case_id) or
         get_unknown_location_uuid(self.requests)  # If we don't set
         # a location, OpenMRS sets it to NULL. That's OK for
         # OpenMRS, but it breaks Bahmni. Bahmni has an "Unknown
         # Location". Use that, if it exists.
     )
     self.info.form_question_values.update(self.form_question_values)
     for form_config in self.openmrs_config.form_configs:
         if form_config.xmlns == self.form_json['form']['@xmlns']:
             start_datetime, stop_datetime = self._get_start_stop_datetime(form_config)
             subtasks.append(
                 CreateVisitTask(
                     self.requests,
                     person_uuid=self.person_uuid,
                     provider_uuid=provider_uuid,
                     start_datetime=start_datetime,
                     stop_datetime=stop_datetime,
                     values_for_concept={obs.concept: [obs.value.get_value(self.info)]
                                         for obs in form_config.openmrs_observations
                                         if obs.value.get_value(self.info)},
                     encounter_type=form_config.openmrs_encounter_type,
                     openmrs_form=form_config.openmrs_form,
                     visit_type=form_config.openmrs_visit_type,
                     location_uuid=location_uuid,
                 )
             )
     return subtasks
Ejemplo n.º 3
0
 def run(self):
     """
     Returns WorkflowTasks for creating visits, encounters and observations
     """
     subtasks = []
     provider_uuid = getattr(self.openmrs_config, 'openmrs_provider', None)
     location_uuid = get_ancestor_location_openmrs_uuid(
         self.domain, self.info.case_id)
     self.info.form_question_values.update(self.form_question_values)
     for form_config in self.openmrs_config.form_configs:
         if form_config.xmlns == self.form_json['form']['@xmlns']:
             subtasks.append(
                 CreateVisitTask(
                     self.requests,
                     person_uuid=self.person_uuid,
                     provider_uuid=provider_uuid,
                     visit_datetime=string_to_utc_datetime(
                         self.form_json['form']['meta']['timeEnd']),
                     values_for_concept={
                         obs.concept: [obs.value.get_value(self.info)]
                         for obs in form_config.openmrs_observations
                         if obs.value.get_value(self.info)
                     },
                     encounter_type=form_config.openmrs_encounter_type,
                     openmrs_form=form_config.openmrs_form,
                     visit_type=form_config.openmrs_visit_type,
                     location_uuid=location_uuid,
                 ))
     return subtasks
Ejemplo n.º 4
0
    def test_openmrs_location_uuid_none(self):
        """
        get_ancestor_location_openmrs_uuid should return None if a
        case's location and its ancestors do not have an OpenMRS
        location UUID
        """
        joburg = self.locations['Johannesburg']
        self.assertIsNone(joburg.metadata.get(LOCATION_OPENMRS_UUID))

        case_id = uuid.uuid4().hex
        form, (case, ) = _create_case(domain=self.domain, case_id=case_id, owner_id=joburg.location_id)

        self.assertIsNone(get_ancestor_location_openmrs_uuid(self.domain, case_id))
Ejemplo n.º 5
0
    def test_openmrs_location_uuid_set(self):
        """
        get_ancestor_location_openmrs_uuid should return the OpenMRS
        location UUID that corresponds to a case's location
        """
        cape_town = self.locations['Cape Town']
        case_id = uuid.uuid4().hex
        form, (case, ) = _create_case(domain=self.domain, case_id=case_id, owner_id=cape_town.location_id)

        self.assertEqual(
            get_ancestor_location_openmrs_uuid(self.domain, case_id),
            self.openmrs_capetown_uuid
        )
Ejemplo n.º 6
0
    def test_openmrs_location_uuid_none(self):
        """
        get_ancestor_location_openmrs_uuid should return None if a
        case's location and its ancestors do not have an OpenMRS
        location UUID
        """
        joburg = self.locations['Johannesburg']
        self.assertIsNone(joburg.metadata.get(LOCATION_OPENMRS_UUID))

        case_id = uuid.uuid4().hex
        form, (case, ) = _create_case(domain=self.domain, case_id=case_id, owner_id=joburg.location_id)

        self.assertIsNone(get_ancestor_location_openmrs_uuid(self.domain, case_id))
Ejemplo n.º 7
0
    def test_openmrs_location_uuid_set(self):
        """
        get_ancestor_location_openmrs_uuid should return the OpenMRS
        location UUID that corresponds to a case's location
        """
        cape_town = self.locations['Cape Town']
        case_id = uuid.uuid4().hex
        form, (case, ) = _create_case(domain=self.domain, case_id=case_id, owner_id=cape_town.location_id)

        self.assertEqual(
            get_ancestor_location_openmrs_uuid(self.domain, case_id),
            self.openmrs_capetown_uuid
        )
Ejemplo n.º 8
0
    def test_openmrs_location_uuid_ancestor(self):
        """
        get_ancestor_location_openmrs_uuid should return the OpenMRS
        location UUID that corresponds to a case's location's ancestor
        """
        gardens = self.locations['Gardens']
        self.assertIsNone(gardens.metadata.get(LOCATION_OPENMRS_UUID))

        case_id = uuid.uuid4().hex
        form, (case, ) = _create_case(domain=self.domain, case_id=case_id, owner_id=gardens.location_id)

        self.assertEqual(
            get_ancestor_location_openmrs_uuid(self.domain, case_id),
            self.openmrs_capetown_uuid
        )
Ejemplo n.º 9
0
    def test_openmrs_location_uuid_ancestor(self):
        """
        get_ancestor_location_openmrs_uuid should return the OpenMRS
        location UUID that corresponds to a case's location's ancestor
        """
        gardens = self.locations['Gardens']
        self.assertIsNone(gardens.metadata.get(LOCATION_OPENMRS_UUID))

        case_id = uuid.uuid4().hex
        form, (case, ) = _create_case(domain=self.domain, case_id=case_id, owner_id=gardens.location_id)

        self.assertEqual(
            get_ancestor_location_openmrs_uuid(self.domain, case_id),
            self.openmrs_capetown_uuid
        )