Search in sources :

Example 6 with VisitAttribute

use of org.openmrs.VisitAttribute in project openmrs-core by openmrs.

the class VisitServiceTest method createVisitAttributeWithoutCreatorAndDateCreated.

private VisitAttribute createVisitAttributeWithoutCreatorAndDateCreated() {
    VisitAttribute visitAttribute = new VisitAttribute();
    VisitAttributeType attributeType = visitService.getVisitAttributeType(1);
    attributeType.setName("visit type");
    visitAttribute.setValue(new Date());
    visitAttribute.setAttributeType(attributeType);
    return visitAttribute;
}
Also used : VisitAttributeType(org.openmrs.VisitAttributeType) VisitAttribute(org.openmrs.VisitAttribute) Date(java.util.Date)

Example 7 with VisitAttribute

use of org.openmrs.VisitAttribute in project openmrs-core by openmrs.

the class VisitServiceTest method saveVisit_shouldVoidAnAttributeIfMaxOccursIs1AndSameAttributeTypeAlreadyExists.

/**
 * @see VisitService#saveVisit(Visit)
 */
@Test
public void saveVisit_shouldVoidAnAttributeIfMaxOccursIs1AndSameAttributeTypeAlreadyExists() {
    executeDataSet(VISITS_ATTRIBUTES_XML);
    Visit visit = new Visit(new Patient(2), new VisitType(3), new Date());
    visit.setAttribute(createVisitAttribute(new Date()));
    visit.setAttribute(createVisitAttribute(new Date(System.currentTimeMillis() - 1000000)));
    assertEquals(1, visit.getAttributes().size());
    visit = visitService.saveVisit(visit);
    assertNotNull(visit.getId());
    visit.setAttribute(createVisitAttribute("second visit"));
    assertEquals(2, visit.getAttributes().size());
    VisitAttribute firstAttribute = (VisitAttribute) visit.getAttributes().toArray()[0];
    assertTrue(firstAttribute.getVoided());
}
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 8 with VisitAttribute

use of org.openmrs.VisitAttribute in project openmrs-core by openmrs.

the class VisitServiceTest method shouldVoidASimpleAttribute.

@Test
public void shouldVoidASimpleAttribute() {
    executeDataSet(VISITS_ATTRIBUTES_XML);
    Visit visit = visitService.getVisit(1);
    VisitAttributeType attrType = visitService.getVisitAttributeType(1);
    List<VisitAttribute> attributes = visit.getActiveAttributes(attrType);
    assertTrue(attributes.size() > 0);
    VisitAttribute attribute = attributes.get(0);
    attribute.setVoided(true);
    visitService.saveVisit(visit);
    assertNotNull(attribute.getVoidedBy());
    assertNotNull(attribute.getDateVoided());
}
Also used : Visit(org.openmrs.Visit) VisitAttributeType(org.openmrs.VisitAttributeType) VisitAttribute(org.openmrs.VisitAttribute) 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