use of org.openmrs.VisitAttribute 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.VisitAttribute in project openmrs-core by openmrs.
the class VisitValidatorTest method makeAttribute.
private VisitAttribute makeAttribute(Object typedValue) {
VisitAttribute attr = new VisitAttribute();
attr.setAttributeType(visitService.getVisitAttributeType(1));
attr.setValue(typedValue);
return attr;
}
use of org.openmrs.VisitAttribute 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.VisitAttribute in project openmrs-core by openmrs.
the class VisitServiceTest method saveVisit_shouldSaveAVisitThoughChangedByAndDateCreatedAreNotSetForVisitAttributeExplictly.
/**
* @see VisitService#saveVisit(Visit)
*/
@Test
public void saveVisit_shouldSaveAVisitThoughChangedByAndDateCreatedAreNotSetForVisitAttributeExplictly() {
executeDataSet(VISITS_ATTRIBUTES_XML);
Visit visit = new Visit(new Patient(2), new VisitType(3), new Date());
VisitAttribute visitAttribute = createVisitAttributeWithoutCreatorAndDateCreated();
visit.setAttribute(visitAttribute);
visit = visitService.saveVisit(visit);
assertNotNull(visit.getId());
}
use of org.openmrs.VisitAttribute 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