use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class VisitServiceImpl method stopVisits.
/**
* @see org.openmrs.api.VisitService#stopVisits(Date)
*/
@Override
public void stopVisits(Date maximumStartDate) {
final List<VisitType> visitTypesToStop = getVisitTypesToStop();
if (maximumStartDate == null) {
maximumStartDate = new Date();
}
if (visitTypesToStop.isEmpty()) {
return;
}
int counter = 0;
Date stopDate = new Date();
Visit nextVisit = dao.getNextVisit(null, visitTypesToStop, maximumStartDate);
while (nextVisit != null) {
nextVisit.setStopDatetime(stopDate);
dao.saveVisit(nextVisit);
if (counter++ > 50) {
// ensure changes are persisted to DB before reclaiming memory
Context.flushSession();
Context.clearSession();
counter = 0;
}
nextVisit = dao.getNextVisit(nextVisit, visitTypesToStop, maximumStartDate);
}
}
use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class ExistingOrNewVisitAssignmentHandler method beforeCreateEncounter.
/**
* @see org.openmrs.api.handler.ExistingVisitAssignmentHandler#beforeCreateEncounter(org.openmrs.Encounter)
* @should assign existing visit if match found
* @should assign new visit if no match found
* @should resolve encounter and visit type uuids as global property values
*/
@Override
public void beforeCreateEncounter(Encounter encounter) {
// Do the default assignment to an existing visit.
super.beforeCreateEncounter(encounter);
// Do nothing if the encounter already belongs to a visit.
if (encounter.getVisit() != null) {
return;
}
Visit visit = new Visit();
visit.setStartDatetime(encounter.getEncounterDatetime());
visit.setLocation(encounter.getLocation());
visit.setPatient(encounter.getPatient());
if (encounterVisitMapping == null) {
// initial one-time setup
setEncounterVisitMapping(new HashMap<>());
Context.getAdministrationService().addGlobalPropertyListener(this);
}
VisitType visitType = encounterVisitMapping.get(encounter.getEncounterType());
if (visitType == null) {
visitType = loadVisitType(encounter.getEncounterType());
// replace reference instead of synchronizing
Map<EncounterType, VisitType> newMap = new HashMap<>(encounterVisitMapping);
newMap.put(encounter.getEncounterType(), visitType);
setEncounterVisitMapping(newMap);
}
visit.setVisitType(visitType);
// set stop date time to last millisecond of the encounter day.
visit.setStopDatetime(OpenmrsUtil.getLastMomentOfDay(encounter.getEncounterDatetime()));
encounter.setVisit(visit);
}
use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounters_shouldGetEncountersByVisitType.
/**
* @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
* java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection,
* boolean)
*/
@Test
public void getEncounters_shouldGetEncountersByVisitType() {
List<VisitType> visitTypes = new ArrayList<>();
visitTypes.add(new VisitType(2));
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setVisitTypes(visitTypes).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
assertEquals(2, encounters.size());
}
use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class VisitDAOTest method getNextVisit_shouldReturnTheNextUnvoidedActiveVisitMatchingTheSpecifiedTypesAndStartDate.
/**
* @see VisitDAO#getNextVisit(Visit,Collection<VisitType>,Date)
*/
@Test
public void getNextVisit_shouldReturnTheNextUnvoidedActiveVisitMatchingTheSpecifiedTypesAndStartDate() {
executeDataSet(VISITS_INCLUDE_VISITS_TO_AUTO_CLOSE_XML);
ArrayList<VisitType> visitTypes = new ArrayList<>();
visitTypes.add(dao.getVisitType(4));
Calendar cal = Calendar.getInstance();
cal.set(2005, 0, 4, 23, 59, 59);
cal.set(Calendar.MILLISECOND, 999);
Assert.assertEquals(105, dao.getNextVisit(dao.getVisit(1), visitTypes, cal.getTime()).getVisitId().intValue());
}
use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class VisitTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see VisitTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
VisitType visitType = new VisitType();
visitType.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
visitType.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
visitType.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(visitType, "visitType");
new VisitTypeValidator().validate(visitType, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Aggregations