Search in sources :

Example 1 with VisitAttributeType

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
    }
}
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 VisitAttributeType

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());
}
Also used : VisitAttributeType(org.openmrs.VisitAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with VisitAttributeType

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());
}
Also used : FreeTextDatatype(org.openmrs.customdatatype.datatype.FreeTextDatatype) VisitAttributeType(org.openmrs.VisitAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with VisitAttributeType

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

Example 5 with VisitAttributeType

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());
}
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

VisitAttributeType (org.openmrs.VisitAttributeType)17 Test (org.junit.Test)9 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)9 Visit (org.openmrs.Visit)7 VisitAttribute (org.openmrs.VisitAttribute)5 Date (java.util.Date)4 APIException (org.openmrs.api.APIException)3 BindException (org.springframework.validation.BindException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 VisitType (org.openmrs.VisitType)2 PatientDomainWrapper (org.openmrs.module.emrapi.patient.PatientDomainWrapper)2 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 ObjectResult (org.openmrs.ui.framework.fragment.action.ObjectResult)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BindingResult (org.springframework.validation.BindingResult)2 Errors (org.springframework.validation.Errors)2 Criteria (org.hibernate.Criteria)1 Before (org.junit.Before)1 Patient (org.openmrs.Patient)1