/** * @see RequireVoidReasonSaveHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldNotThrowExceptionIfVoidReasonIsNotBlank() { Encounter e = Context.getEncounterService().getEncounter(3); e.setVoided(true); e.setVoidReason("Some Reason"); Context.getEncounterService().saveEncounter(e); }
@Override protected EncounterType getExistingObject() { return encounterService.getEncounterType(EXISTING_ID); } }
/** * @see EncounterService#getEncounters(String,Integer,Integer,Integer,null) */ @Test public void getEncounters_shouldMatchOnTheProviderPersonName() { //Should match on Super User and John3 Doe Assert.assertEquals(1, Context.getEncounterService().getEncounters("er jo", 3, null, null, false).size()); Assert.assertEquals(2, Context.getEncounterService().getEncounters("er jo", 3, null, null, true).size()); Assert.assertEquals(0, Context.getEncounterService().getEncounters("none", 3, null, null, true).size()); }
/** * @see EncounterService#retireEncounterType(EncounterType,String) */ @Test(expected = IllegalArgumentException.class) public void retireEncounterType_shouldThrowErrorIfGivenNullReasonParameter() { EncounterService encounterService = Context.getEncounterService(); EncounterType type = encounterService.getEncounterType(1); encounterService.retireEncounterType(type, null); }
/** * @see EncounterService#voidEncounter(Encounter,String) */ @Test(expected = IllegalArgumentException.class) public void voidEncounter_shouldThrowErrorWithNullReasonParameter() { EncounterService encounterService = Context.getEncounterService(); Encounter type = encounterService.getEncounter(1); encounterService.voidEncounter(type, null); }
/** * @see EncounterService#purgeEncounterType(EncounterType) */ @Test public void purgeEncounterType_shouldPurgeType() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterTypeToPurge = encounterService.getEncounterType(4); assertNotNull(encounterTypeToPurge); // check deletion encounterService.purgeEncounterType(encounterTypeToPurge); assertNull(encounterService.getEncounterType(4)); }
encounter.setEncounterType(Context.getEncounterService().getEncounterType(1)); encounter.setEncounterDatetime(new Date()); Context.getEncounterService().saveEncounter(encounter); Integer encounterId = Context.getEncounterService().getEncounterByUuid(encounter.getUuid()).getId(); orderGroup.setOrderSet(orderSet); orderGroup.setPatient(encounter.getPatient()); orderGroup.setEncounter(Context.getEncounterService().getEncounter(encounterId)); encounter.addOrder(secondOrderWithOrderGroup); Context.getEncounterService().saveEncounter(encounter); Context.getEncounterService().getEncounterByUuid(encounter.getUuid()).getOrders());
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldCreateAnEncounterAndFindTheProviderByPersonId() throws Exception { int patientId = 2; Patient patient = new Patient(patientId); List<Encounter> encForPatient1 = Context.getEncounterService().getEncountersByPatient(patient); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||" + patientId + "^^^^||Hornblower^Horatio^Test||\r" + "PV1||O|1^Unknown Location||||1^name|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT"; Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Encounter> encForPatient2 = Context.getEncounterService().getEncountersByPatient(patient); assertTrue("An encounter should have been created", (encForPatient1.size() + 1) == encForPatient2.size()); encForPatient2.removeAll(encForPatient1); Assert.assertTrue(encForPatient2.size() == 1); Provider newProvider = encForPatient2.get(0).getProvidersByRole( Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID)).iterator() .next(); Assert.assertEquals("c2299800-cca9-11e0-9572-0800200c9a66", newProvider.getUuid()); }
private void mergeEncounters(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) { // change all encounters. This will cascade to obs and orders contained in those encounters // TODO: this should be a copy, not a move EncounterService es = Context.getEncounterService(); EncounterSearchCriteria notPreferredPatientEncounterSearchCriteria = new EncounterSearchCriteriaBuilder() .setIncludeVoided(true) .setPatient(notPreferred) .createEncounterSearchCriteria(); for (Encounter e : es.getEncounters(notPreferredPatientEncounterSearchCriteria)) { e.setPatient(preferred); log.debug("Merging encounter " + e.getEncounterId() + " to " + preferred.getPatientId()); Encounter persisted = es.saveEncounter(e); mergedData.addMovedEncounter(persisted.getUuid()); } }
@Override protected Encounter getObjectByUuid(String uuid) { return Context.getEncounterService().getEncounterByUuid(uuid); } }
/** * @see org.openmrs.api.EncounterService#canEditAllEncounterTypes(org.openmrs.User) */ @Override @Transactional(readOnly = true) public boolean canEditAllEncounterTypes(User subject) { boolean canEdit = Boolean.TRUE; for (EncounterType et : Context.getEncounterService().getAllEncounterTypes()) { if (!userHasEncounterPrivilege(et.getEditPrivilege(), subject)) { canEdit = Boolean.FALSE; break; } } return canEdit; }
/** * Fetches a encounterType by uuid, if no match is found, it tries to look up one with a * matching name with the assumption that the passed parameter is a encounterType name * * @see DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public EncounterType getByUniqueId(String uuid) { EncounterType encounterType = Context.getEncounterService().getEncounterTypeByUuid(uuid); //We assume the caller was fetching by name if (encounterType == null) encounterType = Context.getEncounterService().getEncounterType(uuid); return encounterType; }
/** * @see EncounterService#getEncounterType(String) */ @Test public void getEncounterType_shouldNotGetRetiredTypes() { EncounterService encounterService = Context.getEncounterService(); // loop over all types to make sure // that the retired "Test Enc Type C" exists boolean foundRetired = false; for (EncounterType encType : encounterService.getAllEncounterTypes(true)) { if (encType.getName().equals("Test Enc Type C") && encType.getRetired()) { foundRetired = true; } } assertTrue(foundRetired); assertNull(encounterService.getEncounterType("Test Enc Type C")); }
/** * @see EncounterService#getEncounterRoleByUuid(String) */ @Test public void getEncounterRoleByUuid_shouldFindEncounterRoleBasedOnUuid() { EncounterService encounterService = Context.getEncounterService(); EncounterRole encounterRole = encounterService.getEncounterRoleByUuid("430bbb70-6a9c-4e1e-badb-9d1054b1b5e9"); assertNotNull("valid uuid should be returned", encounterRole); encounterRole = encounterService.getEncounterRoleByUuid("invaid uuid"); assertNull("returns null for invalid uuid", encounterRole); }
encounter = Context.getEncounterService().getEncounter(encounterId); } else { if (unknownRole == null) { unknownRole = Context.getEncounterService() .getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID);
@Override protected Encounter getExistingObject() { return encounterService.getEncounter(EXISTING_ID); } }
/** * @see EncounterService#getEncountersByPatient(Patient) */ @Test(expected = IllegalArgumentException.class) public void getEncountersByPatient_shouldThrowErrorWhenGivenNullParameter() { Context.getEncounterService().getEncountersByPatient((Patient) null); }
/** * @see PatientService#mergePatients(org.openmrs.Patient, org.openmrs.Patient) */ @Test public void mergePatients_shouldMoveAllObsWithSameHierarchy() throws Exception { executeDataSet(PATIENT_MERGE_OBS_WITH_GROUP_MEMBER); Patient notPreffered = patientService.getPatient(11); Patient preffered = patientService.getPatient(21); EncounterService encounterService = Context.getEncounterService(); assertEquals(57, encounterService.getEncountersByPatient(notPreffered).get(0).getId().intValue()); assertEquals(3, encounterService.getEncounter(57).getAllObs(false).size()); assertEquals(4, encounterService.getEncounter(57).getAllObs(true).size()); assertEquals(1, encounterService.getEncounter(57).getObsAtTopLevel(false).size()); assertEquals(1, encounterService.getEncounter(57).getObsAtTopLevel(true).size()); patientService.mergePatients(preffered, notPreffered); assertEquals(3, encounterService.getEncounter(57).getAllObs(false).size()); assertEquals(8, encounterService.getEncounter(57).getAllObs(true).size()); assertEquals(1, encounterService.getEncounter(57).getObsAtTopLevel(false).size()); assertEquals(2, encounterService.getEncounter(57).getObsAtTopLevel(true).size()); }
@Override protected EncounterType getObjectByUuid(String uuid) { return Context.getEncounterService().getEncounterTypeByUuid(uuid); } }
/** * @see EncounterService#canEditAllEncounterTypes(User) */ @Test public void canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesEditPrivilegeColumnIsNull() { EncounterService encounterService = Context.getEncounterService(); // set editPrivilege on each encounter type to null for (EncounterType encounterType : encounterService.getAllEncounterTypes()) { encounterType.setEditPrivilege(null); encounterService.saveEncounterType(encounterType); } User user = Context.getUserService().getUserByUsername("test_user"); assertNotNull(user); assertTrue(encounterService.canEditAllEncounterTypes(user)); }