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));
}
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());
}
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());
}
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());
}
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());
}
Aggregations