Search in sources :

Example 76 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class EncounterServiceTest method saveEncounter_shouldCascadeDeleteEncounterProviders.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeDeleteEncounterProviders() {
    // given
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterType(new EncounterType(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(new Patient(3));
    EncounterRole role = new EncounterRole();
    role.setName("role");
    role = Context.getEncounterService().saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    Provider provider2 = new Provider();
    provider2.setIdentifier("id2");
    provider2.setPerson(newPerson("name2"));
    provider2 = Context.getProviderService().saveProvider(provider2);
    encounter.addProvider(role, provider);
    encounter.addProvider(role, provider2);
    EncounterService es = Context.getEncounterService();
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // when
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    encounter.setProvider(role, provider);
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // then
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    Assert.assertEquals(1, encounter.getProvidersByRole(role).size());
    Assert.assertTrue("Role", encounter.getProvidersByRole(role).contains(provider));
}
Also used : Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 77 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class EncounterServiceTest method transferEncounter_shouldTransferAnEncounterWithObservationsButNotOrdersToGivenPatient.

/**
 * @see EncounterService#transferEncounter(Encounter,Patient)
 */
@Test
public void transferEncounter_shouldTransferAnEncounterWithObservationsButNotOrdersToGivenPatient() {
    executeDataSet(TRANSFER_ENC_DATA_XML);
    Patient targetPatient = Context.getPatientService().getPatient(201);
    // encounter has 2 obs which are connected with the same order
    Encounter sourceEncounter = Context.getEncounterService().getEncounter(201);
    Assert.assertEquals(2, sourceEncounter.getOrders().size());
    Assert.assertEquals(2, sourceEncounter.getObs().size());
    // transfer
    Encounter transferredEncounter = Context.getEncounterService().transferEncounter(sourceEncounter, targetPatient);
    List<Order> transferredOrders = new ArrayList<>(transferredEncounter.getOrders());
    List<Obs> transferredObservations = new ArrayList<>(transferredEncounter.getObs());
    // check if transferredEncounter is newly created encounter
    Assert.assertNotEquals(sourceEncounter.getId(), transferredEncounter.getId());
    Assert.assertEquals(targetPatient, transferredEncounter.getPatient());
    // check order
    Assert.assertEquals(0, transferredOrders.size());
    // check obs
    Assert.assertEquals(2, transferredObservations.size());
    Assert.assertEquals(targetPatient, transferredObservations.get(0).getPerson());
    Assert.assertEquals(targetPatient, transferredObservations.get(1).getPerson());
    Assert.assertNull(transferredObservations.get(0).getOrder());
    Assert.assertNull(transferredObservations.get(1).getOrder());
    // check if form is transferred
    Assert.assertNotNull(transferredEncounter.getForm());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) Obs(org.openmrs.Obs) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 78 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class EncounterServiceTest method transferEncounter_shouldVoidGivenEncounter.

/**
 * @see EncounterService#transferEncounter(Encounter,Patient)
 */
@Test
public void transferEncounter_shouldVoidGivenEncounter() {
    executeDataSet(TRANSFER_ENC_DATA_XML);
    Patient anyPatient = new Patient(2);
    Encounter sourceEncounter = Context.getEncounterService().getEncounter(200);
    Context.getEncounterService().transferEncounter(sourceEncounter, anyPatient);
    // get fresh encounter from db
    Encounter sourceEncounterAfterTransfer = Context.getEncounterService().getEncounter(sourceEncounter.getId());
    Assert.assertTrue(sourceEncounterAfterTransfer.getVoided());
}
Also used : Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 79 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class EncounterServiceTest method saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered() {
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(2));
    encounter.setEncounterType(new EncounterType(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(new Patient(2));
    encounter.setCreator(new User(4));
    // We should have no visit
    assertNull(encounter.getVisit());
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER);
    gp.setPropertyValue("org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(encounter.getEncounterDatetime());
    calendar.set(Calendar.YEAR, 1900);
    encounter.setEncounterDatetime(calendar.getTime());
    Context.getEncounterService().saveEncounter(encounter);
    // We should have a visit.
    assertNotNull(encounter.getVisit());
    // The visit should be persisted.
    assertNotNull(encounter.getVisit().getVisitId());
}
Also used : User(org.openmrs.User) Calendar(java.util.Calendar) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 80 with Patient

use of org.openmrs.Patient in project openmrs-core by openmrs.

the class DiagnosisServiceImplTest method getDiagnoses_shouldGetDiagnosesOfPatientWithoutDate.

/**
 * @see DiagnosisService#getDiagnoses(Patient, Date)
 */
@Test
public void getDiagnoses_shouldGetDiagnosesOfPatientWithoutDate() {
    Patient patient = patientService.getPatient(2);
    List<Diagnosis> diagnoses = diagnosisService.getDiagnoses(patient, null);
    Assert.assertEquals(3, diagnoses.size());
    Assert.assertEquals("68802cce-6880-17e4-6880-a68804d22fb7", diagnoses.get(0).getUuid());
    Assert.assertEquals("688804ce-6880-8804-6880-a68804d88047", diagnoses.get(1).getUuid());
    Assert.assertEquals("88042cce-8804-17e4-8804-a68804d22fb7", diagnoses.get(2).getUuid());
}
Also used : Patient(org.openmrs.Patient) Diagnosis(org.openmrs.Diagnosis) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Patient (org.openmrs.Patient)389 Test (org.junit.Test)345 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)284 Date (java.util.Date)106 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)91 Encounter (org.openmrs.Encounter)76 PatientIdentifier (org.openmrs.PatientIdentifier)60 Location (org.openmrs.Location)57 OrderUtilTest (org.openmrs.order.OrderUtilTest)47 PersonName (org.openmrs.PersonName)43 DrugOrder (org.openmrs.DrugOrder)42 BindException (org.springframework.validation.BindException)38 Concept (org.openmrs.Concept)37 Order (org.openmrs.Order)36 PatientIdentifierType (org.openmrs.PatientIdentifierType)33 Errors (org.springframework.validation.Errors)33 Visit (org.openmrs.Visit)29 ArrayList (java.util.ArrayList)28 Obs (org.openmrs.Obs)28 TestOrder (org.openmrs.TestOrder)28