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