@Override protected ConceptMapType getExistingObject() { return conceptService.getConceptMapType(EXISTING_ID); } }
@Override public void setAsText(String text) throws IllegalArgumentException { log.debug("Setting text: " + text); if (StringUtils.hasText(text)) { try { setValue(Context.getConceptService().getConceptMapType(Integer.valueOf(text))); } catch (Exception ex) { ConceptMapType value = Context.getConceptService().getConceptMapTypeByUuid(text); setValue(value); if (value == null) { throw new IllegalArgumentException("ConceptMapType not found: " + text, ex); } } } else { setValue(null); } }
/** * @see ConceptServiceImpl#purgeConceptMapType(ConceptMapType) */ @Test public void purgeConceptMapType_shouldDeleteTheSpecifiedConceptMapTypeFromTheDatabase() { Integer conceptMapTypeId = 8; ConceptMapType mapType = conceptService.getConceptMapType(conceptMapTypeId); assertNotNull(mapType); conceptService.purgeConceptMapType(mapType); assertNull(conceptService.getConceptMapType(conceptMapTypeId)); }
/** * @see ConceptService#getDrugByMapping(String, org.openmrs.ConceptSource, java.util.Collection */ @Test(expected = DAOException.class) public void getDrugByMapping_shouldFailIfMultipleDrugsAreFoundMatchingTheBestMapType() { executeDataSet(GET_DRUG_MAPPINGS); ConceptSource source = conceptService.getConceptSource(1); conceptService.getDrugByMapping("CD41003", source, Collections.singleton(conceptService.getConceptMapType(2))); }
/** * @see ConceptService#purgeConceptMapType(ConceptMapType) */ @Test public void purgeConceptMapType_shouldDeleteTheSpecifiedConceptMapTypeFromTheDatabase() { //sanity check ConceptMapType mapType = Context.getConceptService().getConceptMapType(1); Assert.assertNotNull(mapType); Context.getConceptService().purgeConceptMapType(mapType); Assert.assertNull(Context.getConceptService().getConceptMapType(1)); }
/** * @see ConceptService#getDrugsByMapping(String, org.openmrs.ConceptSource, * java.util.Collection, boolean) */ @Test public void getDrugsByMapping_shouldGetAListOfAllDrugsThatMatchOnAllTheParameterValues() { executeDataSet(GET_DRUG_MAPPINGS); List<ConceptMapType> conceptMapTypeList = new ArrayList<>(); conceptMapTypeList.add(conceptService.getConceptMapType(1)); ConceptSource source = conceptService.getConceptSource(1); List<Drug> drugs = conceptService.getDrugsByMapping("WGT234", source, conceptMapTypeList, false); assertEquals(1, drugs.size()); assertTrue(containsId(drugs, 2)); }
/** * @see ConceptDAO#isConceptMapTypeInUse(ConceptMapType) */ @Test public void isConceptMapTypeInUse_shouldReturnTrueIfAMapTypeHasAConceptMapOrMoreUsingIt() { Assert.assertTrue(dao.isConceptMapTypeInUse(Context.getConceptService().getConceptMapType(6))); }
/** * @see ConceptDAO#isConceptMapTypeInUse(ConceptMapType) */ @Test public void isConceptMapTypeInUse_shouldReturnTrueIfAMapTypeHasAConceptReferenceTermMapOrMoreUsingIt() { Assert.assertTrue(dao.isConceptMapTypeInUse(Context.getConceptService().getConceptMapType(4))); }
/** * @see ConceptDAO#isConceptMapTypeInUse(ConceptMapType) */ @Test public void isConceptMapTypeInUse_shouldReturnFalseIfAMapTypeHasNoMapsUsingIt() { Assert.assertFalse(dao.isConceptMapTypeInUse(Context.getConceptService().getConceptMapType(3))); }
@Test public void validate_shouldNotFailIfATermHasTwoNewMappingsOnIt() { concept.addName(new ConceptName("my name", Context.getLocale())); ConceptReferenceTerm newTerm = new ConceptReferenceTerm(conceptService.getConceptSource(1), "1234", "term one two three four"); ConceptMap map1 = new ConceptMap(newTerm, conceptService.getConceptMapType(1)); concept.addConceptMapping(map1); ConceptReferenceTerm newTermTwo = new ConceptReferenceTerm(conceptService.getConceptSource(1), "12345", "term one two three four five"); ConceptMap map2 = new ConceptMap(newTermTwo, conceptService.getConceptMapType(1)); concept.addConceptMapping(map2); validator.validate(concept, errors); assertThat(errors, not(hasFieldErrors("conceptMappings[1]"))); }
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldRejectDrugMultipleMappingsToTheSameTerm() { Drug drug = new Drug(); DrugReferenceMap term1 = new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService .getConceptMapType(1)); DrugReferenceMap term2 = new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService .getConceptMapType(2)); drug.addDrugReferenceMap(term1); drug.addDrugReferenceMap(term2); Assert.assertEquals(2, drug.getDrugReferenceMaps().size()); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[1].conceptReferenceTerm")); }
/** * @see ConceptService#retireConceptMapType(ConceptMapType,String) */ @Test public void retireConceptMapType_shouldShouldSetTheDefaultRetireReasonIfNoneIsGiven() { //sanity check ConceptMapType mapType = Context.getConceptService().getConceptMapType(1); Assert.assertNull(mapType.getRetireReason()); ConceptMapType retiredMapType = Context.getConceptService().retireConceptMapType(mapType, null); Assert.assertNotNull(retiredMapType.getRetireReason()); }
@Test public void validate_shouldFailIfATermIsMappedMultipleTimesToTheSameConcept() { concept.setConceptClass(new ConceptClass()); concept.setDatatype(new ConceptDatatype()); concept.addName(new ConceptName("my name", Context.getLocale())); concept.addDescription(new ConceptDescription("some description",null)); ConceptMap map1 = new ConceptMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)); concept.addConceptMapping(map1); ConceptMap map2 = new ConceptMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)); concept.addConceptMapping(map2); validator.validate(concept, errors); assertThat(errors, hasFieldErrors("conceptMappings[1]")); }
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassIfAllFieldsAreCorrect() { Drug drug = new Drug(); drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService .getConceptMapType(1))); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); Assert.assertFalse(errors.hasFieldErrors()); }
/** * @see ConceptReferenceTermValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfATermIsMappedMultipleTimesToTheSameTerm() { ConceptReferenceTerm term = new ConceptReferenceTerm(); ConceptService cs = Context.getConceptService(); term.setCode("unique code"); term.setConceptSource(Context.getConceptService().getConceptSource(1)); ConceptReferenceTermMap map1 = new ConceptReferenceTermMap(cs.getConceptReferenceTerm(1), cs.getConceptMapType(1)); term.addConceptReferenceTermMap(map1); //test should fail if we change the term below ConceptReferenceTermMap map2 = new ConceptReferenceTermMap(cs.getConceptReferenceTerm(1), cs.getConceptMapType(1)); term.addConceptReferenceTermMap(map2); Errors errors = new BindException(term, "term"); new ConceptReferenceTermValidator().validate(term, errors); System.err.println(errors.getAllErrors()); //the term for second mapping should be rejected Assert.assertEquals(true, errors.hasFieldErrors("conceptReferenceTermMaps[1].termB")); }
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Drug drug = new Drug(); drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService .getConceptMapType(1))); drug.setName("name"); drug.setStrength("strength"); drug.setRetireReason("retireReason"); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); Assert.assertFalse(errors.hasFieldErrors()); }
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { Drug drug = new Drug(); drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService .getConceptMapType(1))); drug .setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); drug .setStrength("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); drug .setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("strength")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); } }
/** * @see ConceptService#unretireConceptMapType(ConceptMapType) */ @Test public void unretireConceptMapType_shouldUnretireTheSpecifiedConceptMapTypeAndDropAllRetireRelatedFields() { ConceptMapType mapType = Context.getConceptService().getConceptMapType(6); Assert.assertTrue(mapType.getRetired()); Assert.assertNotNull(mapType.getRetiredBy()); Assert.assertNotNull(mapType.getDateRetired()); Assert.assertNotNull(mapType.getRetireReason()); ConceptMapType unRetiredMapType = Context.getConceptService().unretireConceptMapType(mapType); Assert.assertFalse(unRetiredMapType.getRetired()); Assert.assertNull(unRetiredMapType.getRetireReason()); Assert.assertNull(unRetiredMapType.getRetiredBy()); Assert.assertNull(unRetiredMapType.getDateRetired()); }
/** * @see ConceptService#retireConceptMapType(ConceptMapType,String) */ @Test public void retireConceptMapType_shouldRetireTheSpecifiedConceptMapTypeWithTheGivenRetireReason() { ConceptMapType mapType = Context.getConceptService().getConceptMapType(1); Assert.assertFalse(mapType.getRetired()); Assert.assertNull(mapType.getRetiredBy()); Assert.assertNull(mapType.getDateRetired()); Assert.assertNull(mapType.getRetireReason()); ConceptMapType retiredMapType = Context.getConceptService().retireConceptMapType(mapType, "test retire reason"); Assert.assertTrue(retiredMapType.getRetired()); Assert.assertEquals(retiredMapType.getRetireReason(), "test retire reason"); Assert.assertNotNull(retiredMapType.getRetiredBy()); Assert.assertNotNull(retiredMapType.getDateRetired()); }
/** * @see ConceptService#saveConceptMapType(ConceptMapType) */ @Test public void saveConceptMapType_shouldUpdateAnExistingConceptMapType() { ConceptMapType mapType = Context.getConceptService().getConceptMapType(1); //sanity checks Assert.assertNull(mapType.getDateChanged()); Assert.assertNull(mapType.getChangedBy()); mapType.setName("random name"); mapType.setDescription("random description"); ConceptMapType editedMapType = Context.getConceptService().saveConceptMapType(mapType); Context.flushSession(); Assert.assertEquals("random name", editedMapType.getName()); Assert.assertEquals("random description", editedMapType.getDescription()); //date changed and changed by should have been updated Assert.assertNotNull(editedMapType.getDateChanged()); Assert.assertNotNull(editedMapType.getChangedBy()); }