use of org.openmrs.EncounterType 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.EncounterType in project openmrs-core by openmrs.
the class EncounterTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see EncounterTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
EncounterType type = new EncounterType();
type.setName("name");
type.setDescription("some descriptin not exceeding the limit");
type.setRetireReason("retireReason");
Errors errors = new BindException(type, "type");
new EncounterTypeValidator().validate(type, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterTypeValidatorTest method validate_shouldPassValidationWhenEditingAnExistingEncounterType.
/**
* @see EncounterTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationWhenEditingAnExistingEncounterType() {
EncounterType type = Context.getEncounterService().getEncounterType("Scheduled");
Assert.assertNotNull(type);
Errors errors = new BindException(type, "encounterType");
new EncounterTypeValidator().validate(type, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounterType_shouldReturnNullWithNullNameParameter.
/**
* Make sure that we are not throwing an error with a null parameter to
*
* @see EncounterService#getEncounterType(String)
*/
@Test
public void getEncounterType_shouldReturnNullWithNullNameParameter() {
EncounterService encounterService = Context.getEncounterService();
// we should not get an error here...but silently return nothing
EncounterType type = encounterService.getEncounterType((String) null);
assertNull(type);
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounterType_shouldSetAuditInfoIfAnyItemInEncounterTypeIsEdited.
/**
* @see EncounterService#saveEncounterType(EncounterType)
*/
@Test
public void saveEncounterType_shouldSetAuditInfoIfAnyItemInEncounterTypeIsEdited() {
EncounterService es = Context.getEncounterService();
// Create encounter type, ensure creator/dateCreated are set, and changedBy and dateChanged are not setDateCreated.
EncounterType encounterType = es.saveEncounterType(new EncounterType("testing", "desc"));
User creator = encounterType.getCreator();
Date dateCreated = encounterType.getDateCreated();
assertNotNull("creator should be set after saving", creator);
assertNotNull("date creates should be set after saving", dateCreated);
assertNull("changed by should not be set after creation", encounterType.getChangedBy());
assertNull("date changed should not be set after creation", encounterType.getDateChanged());
// Edit encounter type.
encounterType.setDescription("This has been a test!");
EncounterType editedEt = es.saveEncounterType(encounterType);
Context.flushSession();
// Ensure creator/dateCreated remain unchanged, and changedBy and dateChanged are set.
assertTrue("creator should not change during edit", creator.equals(editedEt.getCreator()));
assertTrue("date created should not changed during edit", dateCreated.equals(editedEt.getDateCreated()));
assertNotNull("changed by should be set after edit", editedEt.getChangedBy());
assertNotNull("date changed should be set after edit", editedEt.getDateChanged());
}
Aggregations