Example #1
0
    def test_form_processing_with_owner(self):
        info = CaseTriggerInfo(
            domain=DOMAIN,
            case_id=None,
            owner_id='test_location',
            form_question_values=get_form_question_values(self.form),
        )
        event = get_event(DOMAIN,
                          self.repeater.dhis2_config.form_configs[0],
                          form_json=self.form,
                          info=info)

        self.assertDictEqual(
            {
                'dataValues': [{
                    'dataElement': 'dhis2_element_id',
                    'value': 'test event'
                }],
                'status':
                'COMPLETED',
                'completedDate':
                '2017-05-25',
                'program':
                'test program',
                'eventDate':
                '2017-05-26',
                'orgUnit':
                'dhis2_location_id',
                'coordinate': {
                    'latitude': -33.6543,
                    'longitude': 19.1234
                }
            }, event)
def get_programs_by_id(case_trigger_info, case_config):
    programs_by_id = defaultdict(lambda: {"events": []})
    for form_config in case_config.form_configs:
        if case_trigger_info.form_question_values[
                '/metadata/xmlns'] != form_config.xmlns:
            continue
        event = get_event(case_trigger_info.domain,
                          form_config,
                          info=case_trigger_info)
        if event:
            program = programs_by_id[event["program"]]
            program["events"].append(event)
            program["orgUnit"] = get_value(form_config.org_unit_id,
                                           case_trigger_info)
            program["status"] = get_value(form_config.program_status,
                                          case_trigger_info)
            program.update(get_program_dates(form_config, case_trigger_info))
    return programs_by_id
Example #3
0
 def test_form_processing(self):
     form = {
         "domain": DOMAIN,
         "form": {
             "@xmlns": "test_xmlns",
             "event_date": "2017-05-25T21:06:27.012000",
             "completed_date": "2017-05-25T21:06:27.012000",
             "name": "test event",
             "meta": {
                 "location": self.location.location_id,
                 "timeEnd": "2017-05-25T21:06:27.012000",
                 "timeStart": "2017-05-25T21:06:17.739000",
                 "userID": self.user.user_id,
                 "username": self.user.username
             }
         },
         "received_on": "2017-05-26T09:17:23.692083Z",
     }
     config = {
         'form_configs': json.dumps([{
             'xmlns': 'test_xmlns',
             'program_id': 'test program',
             'event_status': 'COMPLETED',
             'completed_date': {
                 'doc_type': 'FormQuestion',
                 'form_question': '/data/completed_date',
                 'external_data_type': DHIS2_DATA_TYPE_DATE
             },
             'org_unit_id': {
                 'doc_type': 'FormUserAncestorLocationField',
                 'form_user_ancestor_location_field': LOCATION_DHIS_ID
             },
             'datavalue_maps': [
                 {
                     'data_element_id': 'dhis2_element_id',
                     'value': {
                         'doc_type': 'FormQuestion',
                         'form_question': '/data/name'
                     }
                 }
             ]
         }])
     }
     config_form = Dhis2ConfigForm(data=config)
     self.assertTrue(config_form.is_valid())
     data = config_form.cleaned_data
     repeater = Dhis2Repeater()
     repeater.dhis2_config.form_configs = [Dhis2FormConfig.wrap(fc) for fc in data['form_configs']]
     repeater.save()
     event = get_event(DOMAIN, repeater.dhis2_config.form_configs[0], form)
     self.assertDictEqual(
         {
             'dataValues': [
                 {
                     'dataElement': 'dhis2_element_id',
                     'value': 'test event'
                 }
             ],
             'status': 'COMPLETED',
             'completedDate': '2017-05-25',
             'program': 'test program',
             'eventDate': '2017-05-26',
             'orgUnit': 'dhis2_location_id'
         },
         event
     )