/** * @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()); }
String name = conceptMapType.getName(); if (!StringUtils.hasText(name)) { errors.rejectValue("name", "ConceptMapType.error.nameRequired", if (duplicate != null && !OpenmrsUtil.nullSafeEquals(duplicate.getUuid(), conceptMapType.getUuid())) { errors.rejectValue("name", "ConceptMapType.duplicate.name", "Duplicate concept map type name: " + name);
/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { ConceptMapType mapType = new ConceptMapType(); mapType.setName("unique-name"); mapType.setDescription("Description"); mapType.setRetireReason("RetireReason"); Errors errors = new BindException(mapType, "mapType"); new ConceptMapTypeValidator().validate(mapType, errors); Assert.assertEquals(false, errors.hasErrors()); }
/** * <p>This method calculates a weight used to decide the object's order in a collection.</p> * @param conceptMapType the ConceptMapType object the weight of which is to be calculated * @return * <ol> * <li>Regular: 0</li> * <li>Retired: 1</li> * <li>Hidden: 2</li> * <li>Retired and Hidden: 3</li> * </ol> */ public static int getConceptMapTypeSortWeight(ConceptMapType conceptMapType) { return ((conceptMapType.getRetired() ? 1 : 0) + (conceptMapType.getIsHidden() ? 2 : 0)); } }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("isHidden", getObject().getIsHidden()); assertPropEquals("retired", getObject().isRetired()); }
@Test public void shouldGetAnConceptMapTypeByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); ConceptMapType conceptMapTypeType = service.getConceptMapTypeByUuid(getUuid()); assertEquals(conceptMapTypeType.getUuid(), PropertyUtils.getProperty(result, "uuid")); assertEquals(conceptMapTypeType.getName(), PropertyUtils.getProperty(result, "name")); assertEquals(conceptMapTypeType.isHidden(), PropertyUtils.getProperty(result, "isHidden")); assertEquals(conceptMapTypeType.getDescription(), PropertyUtils.getProperty(result, "description")); }
/** * @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()); }
/** * Returns concept reference term code of the mapping to the SNOMED CT concept source * * @param durationUnits * @return a string which is reference term code * @should return null if the concept has no mapping to the SNOMED CT source * @should return the code for the term of the mapping to the SNOMED CT source */ public static String getCode(Concept durationUnits) { for (ConceptMap conceptMapping : durationUnits.getConceptMappings()) { ConceptReferenceTerm conceptReferenceTerm = conceptMapping.getConceptReferenceTerm(); if (ConceptMapType.SAME_AS_MAP_TYPE_UUID.equals(conceptMapping.getConceptMapType().getUuid()) && Duration.SNOMED_CT_CONCEPT_SOURCE_HL7_CODE.equals(conceptReferenceTerm.getConceptSource() .getHl7Code())) { return conceptReferenceTerm.getCode(); } } return null; } }
/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheNameIsAnEmptyString() { ConceptMapType mapType = new ConceptMapType(); mapType.setName(""); Errors errors = new BindException(mapType, "mapType"); new ConceptMapTypeValidator().validate(mapType, errors); Assert.assertEquals(true, errors.hasFieldErrors("name")); }
/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test(expected = IllegalArgumentException.class) public void validate_shouldFailIfTheConceptMapTypeObjectIsNull() { Errors errors = new BindException(new ConceptMapType(), "mapType"); new ConceptMapTypeValidator().validate(null, errors); }
/** * @see ConceptService#getConceptMapTypeByName(String) */ @Test public void getConceptMapTypeByName_shouldBeCaseInsensitive() { String name = "SAME-as"; ConceptMapType mt = Context.getConceptService().getConceptMapTypeByName(name); Assert.assertNotNull(mt); //sanity check in case the test dataset is edited Assert.assertNotSame(name, mt.getName()); Assert.assertEquals(2, mt.getId().intValue()); }
/** * @see ConceptService#saveConceptMapType(ConceptMapType) */ @Test public void saveConceptMapType_shouldAddTheSpecifiedConceptMapTypeToTheDatabaseAndAssignToItAnId() { ConceptMapType mapType = new ConceptMapType(); mapType.setName("test type"); mapType = Context.getConceptService().saveConceptMapType(mapType); Assert.assertNotNull(mapType.getId()); Assert.assertNotNull(Context.getConceptService().getConceptMapTypeByName("test type")); }
private static ConceptMap getConceptMap(String sourceHl7Code, String code, String mapTypeUuid) { ConceptMap conceptMap = new ConceptMap(); ConceptReferenceTerm conceptReferenceTerm = new ConceptReferenceTerm(); ConceptSource conceptSource = new ConceptSource(); conceptSource.setHl7Code(sourceHl7Code); conceptReferenceTerm.setConceptSource(conceptSource); conceptReferenceTerm.setCode(code); conceptMap.setConceptReferenceTerm(conceptReferenceTerm); ConceptMapType conceptMapType = new ConceptMapType(); if (mapTypeUuid != null) { conceptMapType.setUuid(mapTypeUuid); } else { conceptMapType.setUuid(ConceptMapType.SAME_AS_MAP_TYPE_UUID); } conceptMap.setConceptMapType(conceptMapType); return conceptMap; }
@Test public void shouldRetireAConceptMapType() throws Exception { assertEquals(false, service.getConceptMapTypeByUuid(getUuid()).isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); req.addParameter("!purge", ""); final String reason = "none"; req.addParameter("reason", reason); handle(req); assertEquals(true, service.getConceptMapTypeByUuid(getUuid()).isRetired()); assertEquals(reason, service.getConceptMapTypeByUuid(getUuid()).getRetireReason()); }
/** * Returns true if this concept map type is hidden otherwise false * * @return true if this concept map type is hidden otherwise false * * @deprecated as of 2.0, use {@link #getIsHidden()} */ @Deprecated @JsonIgnore public boolean isHidden() { return getIsHidden(); } }
/** * @see org.openmrs.api.ConceptService#retireConceptMapType(org.openmrs.ConceptMapType, * java.lang.String) */ @Override public ConceptMapType retireConceptMapType(ConceptMapType conceptMapType, String retireReason) throws APIException { String tmpRetireReason = retireReason; if (!StringUtils.hasText(tmpRetireReason)) { tmpRetireReason = Context.getMessageSourceService().getMessage("general.default.retireReason"); } conceptMapType.setRetireReason(tmpRetireReason); return dao.saveConceptMapType(conceptMapType); }
/** * @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()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("isHidden", getObject().getIsHidden()); assertPropEquals("retired", getObject().isRetired()); assertPropPresent("auditInfo"); }
/** * @see ConceptService#getConceptMapTypeByName(String) */ @Test public void getConceptMapTypeByName_shouldReturnAConceptMapTypeMatchingTheSpecifiedName() { Assert.assertEquals("same-as", Context.getConceptService().getConceptMapTypeByName("same-as").getName()); }