Пример #1
0
def config_openmrs_repeater(request, domain, repeater_id):
    helper = OpenmrsModelListViewHelper(request, domain, repeater_id)
    repeater = helper.repeater

    if request.method == 'POST':
        form = OpenmrsConfigForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            repeater.openmrs_config.openmrs_provider = data['openmrs_provider']
            repeater.openmrs_config.case_config = OpenmrsCaseConfig.wrap(
                data['case_config'])
            repeater.openmrs_config.form_configs = list(
                map(OpenmrsFormConfig.wrap, data['form_configs']))
            repeater.save()

    else:
        form = OpenmrsConfigForm(
            data={
                'openmrs_provider':
                repeater.openmrs_config.openmrs_provider,
                'form_configs':
                json.dumps([
                    form_config.to_json()
                    for form_config in repeater.openmrs_config.form_configs
                ]),
                'case_config':
                json.dumps(repeater.openmrs_config.case_config.to_json()),
            })
    return render(request, 'openmrs/edit_config.html', {
        'domain': domain,
        'repeater_id': repeater_id,
        'form': form
    })
Пример #2
0
    def test_create_patient(self):
        """
        ValueSource instances with direction set to DIRECTION_IMPORT
        should not be exported.
        """
        requests = mock.Mock()
        requests.post.side_effect = RequestException()
        info = mock.Mock(
            updates={'sex': 'M', 'dob': '1918-07-18'},
            extra_fields={},
        )
        case_config = copy.deepcopy(CASE_CONFIG)
        case_config['patient_identifiers'] = {}
        case_config['person_preferred_name'] = {}
        case_config['person_preferred_address'] = {}
        case_config['person_attributes'] = {}

        case_config['person_properties']['gender']['direction'] = DIRECTION_IMPORT
        case_config['person_properties']['birthdate']['direction'] = DIRECTION_EXPORT
        case_config = OpenmrsCaseConfig(case_config)

        with self.assertRaises(RequestException):
            create_patient(requests, info, case_config)
        requests.post.assert_called_with(
            '/ws/rest/v1/patient/',
            json={'person': {'birthdate': '1918-07-18'}},
            raise_for_status=True,
        )
Пример #3
0
def openmrs_edit_config(request, domain, repeater_id):
    helper = OpenmrsModelListViewHelper(request, domain, repeater_id)
    repeater = helper.repeater

    if request.method == 'POST':
        form = OpenmrsConfigForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            repeater.openmrs_config.openmrs_provider = data['openmrs_provider']
            repeater.openmrs_config.case_config = OpenmrsCaseConfig.wrap(data['case_config'])
            repeater.openmrs_config.form_configs = list(map(OpenmrsFormConfig.wrap, data['form_configs']))
            repeater.save()

    else:
        form = OpenmrsConfigForm(
            data={
                'openmrs_provider': repeater.openmrs_config.openmrs_provider,
                'form_configs': json.dumps([
                    form_config.to_json()
                    for form_config in repeater.openmrs_config.form_configs]),
                'case_config': json.dumps(repeater.openmrs_config.case_config.to_json()),
            }
        )
    return render(request, 'openmrs/edit_config.html', {
        'domain': domain,
        'repeater_id': repeater_id,
        'form': form
    })
Пример #4
0
 def setUp(self):
     self.case_config = OpenmrsCaseConfig.wrap({
         'patient_identifiers': {
             'uuid': {'doc_type': 'CaseProperty', 'case_property': 'openmrs_uuid'},
             'e2b97b70-1d5f-11e0-b929-000c29ad1d07': {'doc_type': 'CaseProperty', 'case_property': 'nid'}
         },
         'match_on_ids': ['uuid'],
         'person_properties': {
             'gender': {'doc_type': 'CaseProperty', 'case_property': 'sex'},
             'birthdate': {'doc_type': 'CaseProperty', 'case_property': 'dob'},
         },
         'person_preferred_name': {
             'givenName': {'doc_type': 'CaseProperty', 'case_property': 'first_name'},
             'familyName': {'doc_type': 'CaseProperty', 'case_property': 'last_name'},
         },
         'person_preferred_address': {
             'address1': {'doc_type': 'CaseProperty', 'case_property': 'address_1'},
             'address2': {'doc_type': 'CaseProperty', 'case_property': 'address_2'},
         },
         'person_attributes': {
             'c1f4239f-3f10-11e4-adec-0800271c1b75': {'doc_type': 'CaseProperty', 'case_property': 'caste'},
             'c1f455e7-3f10-11e4-adec-0800271c1b75': {
                 'doc_type': 'CasePropertyMap',
                 'case_property': 'class',
                 'value_map': {
                     'sc': 'c1fcd1c6-3f10-11e4-adec-0800271c1b75',
                     'general': 'c1fc20ab-3f10-11e4-adec-0800271c1b75',
                     'obc': 'c1fb51cc-3f10-11e4-adec-0800271c1b75',
                     'other_caste': 'c207073d-3f10-11e4-adec-0800271c1b75',
                     'st': 'c20478b6-3f10-11e4-adec-0800271c1b75'
                 }
             },
         },
     })
     self.finder = WeightedPropertyPatientFinder.wrap({
         'doc_type': 'WeightedPropertyPatientFinder',
         'searchable_properties': ['last_name'],
         'property_weights': [
             {
                 "case_property": "first_name",
                 "weight": 0.45,
                 "match_type": "levenshtein",
                 "match_params": [0.2]
             },
             {"case_property": "last_name", "weight": 0.45},
             {
                 "case_property": "dob",
                 "weight": 0.2,
                 "match_type": "days_diff",
                 "match_params": [364]
             },
             {"case_property": "address_2", "weight": 0.2},
         ],
     })
     self.finder._property_map = get_property_map(self.case_config)
Пример #5
0
 def setUp(self):
     self.case_config = OpenmrsCaseConfig.wrap({
         'patient_identifiers': {
             'uuid': {'doc_type': 'CaseProperty', 'case_property': 'openmrs_uuid'},
             'e2b97b70-1d5f-11e0-b929-000c29ad1d07': {'doc_type': 'CaseProperty', 'case_property': 'nid'}
         },
         'match_on_ids': ['uuid'],
         'person_properties': {
             'gender': {'doc_type': 'CaseProperty', 'case_property': 'sex'},
             'birthdate': {'doc_type': 'CaseProperty', 'case_property': 'dob'},
         },
         'person_preferred_name': {
             'givenName': {'doc_type': 'CaseProperty', 'case_property': 'first_name'},
             'familyName': {'doc_type': 'CaseProperty', 'case_property': 'last_name'},
         },
         'person_preferred_address': {
             'address1': {'doc_type': 'CaseProperty', 'case_property': 'address_1'},
             'address2': {'doc_type': 'CaseProperty', 'case_property': 'address_2'},
         },
         'person_attributes': {
             'c1f4239f-3f10-11e4-adec-0800271c1b75': {'doc_type': 'CaseProperty', 'case_property': 'caste'},
             'c1f455e7-3f10-11e4-adec-0800271c1b75': {
                 'doc_type': 'CasePropertyMap',
                 'case_property': 'class',
                 'value_map': {
                     'sc': 'c1fcd1c6-3f10-11e4-adec-0800271c1b75',
                     'general': 'c1fc20ab-3f10-11e4-adec-0800271c1b75',
                     'obc': 'c1fb51cc-3f10-11e4-adec-0800271c1b75',
                     'other_caste': 'c207073d-3f10-11e4-adec-0800271c1b75',
                     'st': 'c20478b6-3f10-11e4-adec-0800271c1b75'
                 }
             },
         },
     })
     self.finder = WeightedPropertyPatientFinder.wrap({
         'doc_type': 'WeightedPropertyPatientFinder',
         'searchable_properties': ['last_name'],
         'property_weights': [
             {
                 "case_property": "first_name",
                 "weight": 0.45,
                 "match_type": "levenshtein",
                 "match_params": [0.2]
             },
             {"case_property": "last_name", "weight": 0.45},
             {
                 "case_property": "dob",
                 "weight": 0.2,
                 "match_type": "days_diff",
                 "match_params": [364]
             },
             {"case_property": "address_2", "weight": 0.2},
         ],
     })
     self.finder._property_map = get_property_map(self.case_config)