use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class PatientDataVoidHandler method handle.
/**
* @see org.openmrs.api.handler.VoidHandler#handle(org.openmrs.Voidable, org.openmrs.User,
* java.util.Date, java.lang.String)
* @should void the orders encounters and observations associated with the patient
*/
@Override
public void handle(Patient patient, User voidingUser, Date voidedDate, String voidReason) {
// void all the encounters associated with this patient
EncounterService es = Context.getEncounterService();
List<Encounter> encounters = es.getEncountersByPatient(patient);
if (CollectionUtils.isNotEmpty(encounters)) {
for (Encounter encounter : encounters) {
if (!encounter.getVoided()) {
// EncounterServiceImpl.voidEncounter and the requiredDataAdvice will set dateVoided to current date
// if it is null, we need to set it now to match the patient's date voided so that the unvoid
// handler's logic doesn't fail when comparing dates while unvoiding encounters that were voided
// with the patient
encounter.setDateVoided(patient.getDateVoided());
es.voidEncounter(encounter, voidReason);
}
}
}
Context.addProxyPrivilege(PrivilegeConstants.EDIT_COHORTS);
try {
Context.getCohortService().notifyPatientVoided(patient);
} finally {
Context.removeProxyPrivilege(PrivilegeConstants.EDIT_COHORTS);
}
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class DiagnosisValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsAreSupplied.
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsAreSupplied() {
diagnosis.setEncounter(new Encounter());
diagnosis.setDiagnosis(new CodedOrFreeText());
diagnosis.setCertainty(ConditionVerificationStatus.CONFIRMED);
diagnosis.setRank(1);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingHandlerIsRegistered.
/**
* @see EncounterService#saveEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingHandlerIsRegistered() {
Encounter encounter = buildEncounter();
// We should have no visit
assertNull(encounter.getVisit());
GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER);
gp.setPropertyValue("org.openmrs.api.handler.ExistingVisitAssignmentHandler");
Context.getAdministrationService().saveGlobalProperty(gp);
Context.getEncounterService().saveEncounter(encounter);
// We should have a visit.
assertNotNull(encounter.getVisit());
assertNotNull(encounter.getVisit().getVisitId());
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldSaveEncounterWithComplexObs.
@Test
public void saveEncounter_shouldSaveEncounterWithComplexObs() {
executeDataSet(ENC_OBS_HIERARCHY_DATA_XML);
EncounterService es = Context.getEncounterService();
Encounter encounter = es.getEncounter(101);
Obs observation = buildObs();
observation.setLocation(encounter.getLocation());
observation.setPerson(encounter.getPatient());
encounter.addObs(observation);
es.saveEncounter(encounter);
Context.flushSession();
Context.clearSession();
encounter = es.getEncounter(101);
assertEquals(2, encounter.getObsAtTopLevel(true).size());
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldUpdateExistingEncounterWhenNewObsIsAddedToParentObs.
@Test
public void saveEncounter_shouldUpdateExistingEncounterWhenNewObsIsAddedToParentObs() {
executeDataSet(ENC_OBS_HIERARCHY_DATA_XML);
ConceptService cs = Context.getConceptService();
EncounterService es = Context.getEncounterService();
ObsService os = Context.getObsService();
Encounter enc = es.getEncounter(100);
Obs o3 = new Obs();
o3.setConcept(cs.getConcept(3));
o3.setDateCreated(new Date());
o3.setCreator(Context.getAuthenticatedUser());
o3.setLocation(new Location(1));
o3.setObsDatetime(new Date());
o3.setPerson(Context.getPersonService().getPerson(3));
o3.setValueText("third obs value text");
o3.setEncounter(enc);
Obs oParent = os.getObs(100);
oParent.addGroupMember(o3);
es.saveEncounter(enc);
Context.flushSession();
Context.clearSession();
enc = es.getEncounter(100);
Set<Obs> obsAtTopLevelUpdated = enc.getObsAtTopLevel(true);
assertEquals(1, obsAtTopLevelUpdated.size());
assertEquals(3, obsAtTopLevelUpdated.iterator().next().getGroupMembers(true).size());
oParent = os.getObs(100);
assertTrue(oParent.getGroupMembers(true).contains(os.getObs(101)));
assertTrue(oParent.getGroupMembers(true).contains(os.getObs(102)));
assertTrue(oParent.getGroupMembers(true).contains(os.getObs(o3.getObsId())));
}
Aggregations