Exemplo n.º 1
0
    def attribute_should_be_unique_for_source_and_locale(self, concept, attribute, error_message):
        self_id = getattr(concept, 'head.id', getattr(concept, 'id', None))

        names = [name for name in concept.saved_unsaved_names if getattr(name, attribute)]
        for name in names:
            if self.no_other_record_has_same_name(name, self_id):
                continue

            raise ValidationError({'names': [message_with_name_details(error_message, name)]})
Exemplo n.º 2
0
    def short_name_cannot_be_marked_as_locale_preferred(concept):
        short_preferred_names_in_concept = list(filter(
            lambda name: (name.is_short or name.is_search_index_term) and name.locale_preferred,
            concept.saved_unsaved_names
        ))

        if short_preferred_names_in_concept:
            raise ValidationError({
                'names': [message_with_name_details(OPENMRS_SHORT_NAME_CANNOT_BE_PREFERRED,
                                                    short_preferred_names_in_concept[0])]
            })
Exemplo n.º 3
0
    def no_more_than_one_short_name_per_locale(concept):
        short_names_per_locale = dict()

        for name in concept.saved_unsaved_names:
            if not name.is_short:
                continue

            if name.locale in short_names_per_locale:
                raise ValidationError(
                    {'names': [message_with_name_details(OPENMRS_NO_MORE_THAN_ONE_SHORT_NAME_PER_LOCALE, name)]})

            short_names_per_locale[name.locale] = True
Exemplo n.º 4
0
    def only_one_fully_specified_name_per_locale(concept):
        fully_specified_names_per_locale = dict()

        for name in concept.saved_unsaved_names:
            if not name.is_fully_specified:
                continue

            if name.locale in fully_specified_names_per_locale:
                raise ValidationError(
                    {'names': [message_with_name_details(OPENMRS_ONE_FULLY_SPECIFIED_NAME_PER_LOCALE, name)]})

            fully_specified_names_per_locale[name.locale] = True
Exemplo n.º 5
0
    def must_have_exactly_one_preferred_name(concept):
        preferred_name_locales_in_concept = dict()

        for name in concept.saved_unsaved_names:
            if not name.locale_preferred:
                continue

            if name.locale in preferred_name_locales_in_concept:
                raise ValidationError({
                    'names': [message_with_name_details(OPENMRS_MUST_HAVE_EXACTLY_ONE_PREFERRED_NAME, name)]
                })

            preferred_name_locales_in_concept[name.locale] = True
Exemplo n.º 6
0
    def name_type_should_be_valid_attribute(self, concept):
        names = concept.saved_unsaved_names
        if not names:
            return

        for name in names:
            if name.type in ['FULLY_SPECIFIED', 'SHORT']:
                continue

            if (name.type or 'None') in self.reference_values['NameTypes']:
                continue

            raise ValidationError({'names': [message_with_name_details(OPENMRS_NAME_TYPE, name)]})