use of org.openmrs.VisitAttributeType in project openmrs-core by openmrs.
the class AttributeIntegrationTest method shouldTestAddingAnAttributeToSomethingAndSavingIt.
@Test
public void shouldTestAddingAnAttributeToSomethingAndSavingIt() throws InvalidCustomValueException, ParseException {
Visit visit = service.getVisit(1);
VisitAttributeType auditDate = service.getVisitAttributeType(1);
VisitAttribute legalDate = new VisitAttribute();
legalDate.setAttributeType(auditDate);
// try using a subclass of java.util.Date, to make sure the handler can take subclasses.
legalDate.setValue(new java.sql.Date(new SimpleDateFormat("yyyy-MM-dd").parse("2011-04-15").getTime()));
visit.addAttribute(legalDate);
service.saveVisit(visit);
// saving the visit should have caused the date to be validated and saved
Assert.assertNotNull(legalDate.getValueReference());
Assert.assertEquals("2011-04-15", legalDate.getValueReference());
VisitAttribute badDate = new VisitAttribute();
badDate.setAttributeType(auditDate);
// no value
visit.addAttribute(badDate);
try {
service.saveVisit(visit);
Assert.fail("Should have failed because of bad date attribute");
} catch (APIException ex) {
// expected this
}
}
use of org.openmrs.VisitAttributeType in project openmrs-core by openmrs.
the class VisitServiceTest method saveVisitAttributeType_shouldEditAnExistingVisitAttributeType.
/**
* @see VisitService#saveVisitAttributeType(VisitAttributeType)
*/
@Test
public void saveVisitAttributeType_shouldEditAnExistingVisitAttributeType() {
executeDataSet(VISITS_ATTRIBUTES_XML);
assertEquals(3, visitService.getAllVisitAttributeTypes().size());
VisitAttributeType vat = visitService.getVisitAttributeType(1);
vat.setName("A new name");
visitService.saveVisitAttributeType(vat);
assertEquals(3, visitService.getAllVisitAttributeTypes().size());
assertEquals("A new name", visitService.getVisitAttributeType(1).getName());
}
use of org.openmrs.VisitAttributeType in project openmrs-core by openmrs.
the class VisitServiceTest method saveVisitAttributeType_shouldCreateANewVisitAttributeType.
/**
* @see VisitService#saveVisitAttributeType(VisitAttributeType)
*/
@Test
public void saveVisitAttributeType_shouldCreateANewVisitAttributeType() {
executeDataSet(VISITS_ATTRIBUTES_XML);
assertEquals(3, visitService.getAllVisitAttributeTypes().size());
VisitAttributeType vat = new VisitAttributeType();
vat.setName("Another one");
vat.setDatatypeClassname(FreeTextDatatype.class.getName());
visitService.saveVisitAttributeType(vat);
assertNotNull(vat.getId());
assertEquals(4, visitService.getAllVisitAttributeTypes().size());
}
use of org.openmrs.VisitAttributeType in project openmrs-core by openmrs.
the class VisitServiceTest method createVisitAttribute.
private VisitAttribute createVisitAttribute(Object typedValue) {
VisitAttribute visitAttribute = new VisitAttribute();
VisitAttributeType attributeType = visitService.getVisitAttributeType(1);
attributeType.setName("visit type");
visitAttribute.setValue(typedValue);
visitAttribute.setAttributeType(attributeType);
return visitAttribute;
}
use of org.openmrs.VisitAttributeType in project openmrs-core by openmrs.
the class VisitServiceTest method saveVisit_shouldBeAbleToAddAnAttributeToAVisit.
/**
* @see VisitService#saveVisit(Visit)
*/
@Test
public void saveVisit_shouldBeAbleToAddAnAttributeToAVisit() {
Date now = new Date();
Visit visit = visitService.getVisit(1);
VisitAttributeType attrType = visitService.getVisitAttributeType(1);
VisitAttribute attr = new VisitAttribute();
attr.setAttributeType(attrType);
attr.setValue(now);
visit.addAttribute(attr);
visitService.saveVisit(visit);
assertEquals(new SimpleDateFormat("yyyy-MM-dd").format(now), attr.getValueReference());
}
Aggregations