Search in sources :

Example 21 with VisitType

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

the class VisitServiceTest method saveVisit_shouldSaveNewVisitWithEncountersSuccessfully.

/**
 * @see VisitService#saveVisit(Visit)
 */
@Test
public void saveVisit_shouldSaveNewVisitWithEncountersSuccessfully() {
    Integer originalSize = visitService.getAllVisits().size();
    Visit visit = new Visit(new Patient(2), new VisitType(1), new Date());
    Encounter encounter = Context.getEncounterService().getEncounter(4);
    visit.addEncounter(encounter);
    visitService.saveVisit(visit);
    int visitId = visit.getVisitId();
    Context.flushSession();
    Context.clearSession();
    // reload the visit
    visit = visitService.getVisit(visitId);
    assertNotNull(visit.getId());
    assertNotNull(visit.getUuid());
    assertNotNull(visit.getCreator());
    assertNotNull(visit.getDateCreated());
    assertEquals(originalSize + 1, visitService.getAllVisits().size());
    assertEquals(1, visit.getEncounters().size());
    assertEquals(Integer.valueOf(4), ((Encounter) visit.getEncounters().toArray()[0]).getEncounterId());
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitType(org.openmrs.VisitType) Encounter(org.openmrs.Encounter) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with VisitType

use of org.openmrs.VisitType 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 23 with VisitType

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

the class VisitServiceTest method getVisits_shouldGetVisitsByVisitType.

@Test
public void getVisits_shouldGetVisitsByVisitType() {
    List<VisitType> visitTypes = new ArrayList<>();
    visitTypes.add(new VisitType(1));
    assertEquals(4, visitService.getVisits(visitTypes, null, null, null, null, null, null, null, null, true, false).size());
}
Also used : ArrayList(java.util.ArrayList) VisitType(org.openmrs.VisitType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with VisitType

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

the class VisitServiceTest method saveVisitType_shouldSaveEditedVisitType.

@Test
public void saveVisitType_shouldSaveEditedVisitType() {
    VisitType visitType = visitService.getVisitType(1);
    assertNotNull(visitType);
    assertEquals("Initial HIV Clinic Visit", visitType.getName());
    visitType.setName("Edited Name");
    visitType.setDescription("Edited Description");
    visitService.saveVisitType(visitType);
    visitType = visitService.getVisitType(1);
    assertNotNull(visitType);
    assertEquals("Edited Name", visitType.getName());
    assertEquals("Edited Description", visitType.getDescription());
    // Should not change the number of visit types.
    assertEquals(3, visitService.getAllVisitTypes().size());
}
Also used : VisitType(org.openmrs.VisitType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 25 with VisitType

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

the class VisitServiceTest method purgeVisitType_shouldDeleteGivenVisitType.

@Test
public void purgeVisitType_shouldDeleteGivenVisitType() {
    VisitType visitType = visitService.getVisitType(3);
    assertNotNull(visitType);
    visitService.purgeVisitType(visitType);
    visitType = visitService.getVisitType(3);
    assertNull(visitType);
    // Should reduce the existing number of visit types.
    assertEquals(2, visitService.getAllVisitTypes().size());
}
Also used : VisitType(org.openmrs.VisitType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

VisitType (org.openmrs.VisitType)30 Test (org.junit.Test)18 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)18 Visit (org.openmrs.Visit)11 Encounter (org.openmrs.Encounter)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Patient (org.openmrs.Patient)5 EncounterType (org.openmrs.EncounterType)4 Location (org.openmrs.Location)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 Calendar (java.util.Calendar)2 Concept (org.openmrs.Concept)2 VisitAttribute (org.openmrs.VisitAttribute)2 VisitAttributeType (org.openmrs.VisitAttributeType)2 APIException (org.openmrs.api.APIException)2 VisitService (org.openmrs.api.VisitService)2 PatientDomainWrapper (org.openmrs.module.emrapi.patient.PatientDomainWrapper)2 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)2