Search in sources :

Example 71 with Encounter

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);
    }
}
Also used : Encounter(org.openmrs.Encounter) EncounterService(org.openmrs.api.EncounterService)

Example 72 with Encounter

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());
}
Also used : Encounter(org.openmrs.Encounter) CodedOrFreeText(org.openmrs.CodedOrFreeText) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 73 with Encounter

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());
}
Also used : Encounter(org.openmrs.Encounter) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 74 with Encounter

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());
}
Also used : Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 75 with Encounter

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())));
}
Also used : Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19