Search in sources :

Example 1 with VisitAttribute

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
    }
}
Also used : APIException(org.openmrs.api.APIException) Visit(org.openmrs.Visit) VisitAttributeType(org.openmrs.VisitAttributeType) VisitAttribute(org.openmrs.VisitAttribute) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 2 with VisitAttribute

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;
}
Also used : VisitAttribute(org.openmrs.VisitAttribute)

Example 3 with VisitAttribute

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;
}
Also used : VisitAttributeType(org.openmrs.VisitAttributeType) VisitAttribute(org.openmrs.VisitAttribute)

Example 4 with 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());
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitType(org.openmrs.VisitType) VisitAttribute(org.openmrs.VisitAttribute) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with VisitAttribute

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());
}
Also used : Visit(org.openmrs.Visit) VisitAttributeType(org.openmrs.VisitAttributeType) VisitAttribute(org.openmrs.VisitAttribute) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

VisitAttribute (org.openmrs.VisitAttribute)8 Test (org.junit.Test)5 Visit (org.openmrs.Visit)5 VisitAttributeType (org.openmrs.VisitAttributeType)5 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)5 Date (java.util.Date)4 SimpleDateFormat (java.text.SimpleDateFormat)2 Patient (org.openmrs.Patient)2 VisitType (org.openmrs.VisitType)2 APIException (org.openmrs.api.APIException)1