Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-2921

ConceptValidator should not compare names of a retired concept against the names of other concepts

    Details

    • Complexity:
      Low

      Description

      While doing STAND-36 we discovered that when you call ConceptValidator.validate on a retired concept, it applies excessive validation to concept names.

      For example, imagine that we have concepts 1 and 999, that both have the fully-specified name of "measles", but 999 is retired. Ideally doing validate(1) and validate(999) would both pass. The validation logic correctly handles the case where the other concept is retired, but it does not handle the case where the concept that you are validating is itself retired. So with the current code, doing validate(999) will fail. An example unit test is below.

      The correct approach would be for validating retired concepts to validate the concept's names for internal consistency (e.g. can't have two fully-specified names) but not to do any checks against other concepts.

      Example unit test:

      	@Test
      	public void validate_shouldPassIfAnotherConceptHasADuplicateNameButThisConceptIsRetired() throws Exception {
      		Context.setLocale(new Locale("en"));
      		Concept concept = Context.getConceptService().getConcept(5497);
      		String duplicateName = concept.getFullySpecifiedName(Context.getLocale()).getName();
      		
      		Concept anotherConcept = Context.getConceptService().getConcept(5089);
      		anotherConcept.getFullySpecifiedName(Context.getLocale()).setName(duplicateName);
      		anotherConcept.setRetired(true);
      
      		Errors errors = new BindException(anotherConcept, "concept");
      		new ConceptValidator().validate(anotherConcept, errors);
      		Assert.assertEquals(false, errors.hasErrors());
      	}
      

        Attachments

          Activity

            People

            • Assignee:
              raff Rafal Korytkowski
              Reporter:
              darius Darius Jazayeri
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: