use of org.openmrs.api.EncounterService in project openmrs-core by openmrs.
the class PatientDataUnvoidHandlerTest method handle_shouldUnvoidTheOrdersAndEncountersAssociatedWithThePatient.
/**
* @see PatientDataUnvoidHandler#handle(Patient,User,Date,String)
*/
@Test
public void handle_shouldUnvoidTheOrdersAndEncountersAssociatedWithThePatient() {
Patient patient = Context.getPatientService().getPatient(7);
patient = Context.getPatientService().voidPatient(patient, "Void Reason");
assertTrue(patient.getVoided());
EncounterService es = Context.getEncounterService();
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setPatient(patient).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = es.getEncounters(encounterSearchCriteria);
assertTrue(CollectionUtils.isNotEmpty(encounters));
// all encounters void related fields should be null
for (Encounter encounter : encounters) {
assertTrue(encounter.getVoided());
assertNotNull(encounter.getDateVoided());
assertNotNull(encounter.getVoidedBy());
assertNotNull(encounter.getVoidReason());
}
OrderService os = Context.getOrderService();
List<Order> orders = os.getAllOrdersByPatient(patient);
assertFalse(orders.isEmpty());
// all order void related fields should be null
for (Order order : orders) {
assertTrue(order.getVoided());
assertNotNull(order.getDateVoided());
assertNotNull(order.getVoidedBy());
assertNotNull(order.getVoidReason());
}
User user = Context.getUserService().getUser(1);
new PatientDataUnvoidHandler().handle(patient, user, patient.getDateVoided(), null);
// check that the voided related fields were set null
for (Encounter encounter : encounters) {
assertFalse(encounter.getVoided());
assertNull(encounter.getDateVoided());
assertNull(encounter.getVoidedBy());
assertNull(encounter.getVoidReason());
}
for (Order order : orders) {
assertFalse(order.getVoided());
assertNull(order.getDateVoided());
assertNull(order.getVoidedBy());
assertNull(order.getVoidReason());
}
}
use of org.openmrs.api.EncounterService in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentControllerTest method shouldReturnEncountersForVisit.
@Test
public void shouldReturnEncountersForVisit() throws ParseException {
CoreAppsProperties coreAppsProperties = mock(CoreAppsProperties.class);
when(coreAppsProperties.getPatientDashboardEncounterCount()).thenReturn(100);
UiSessionContext sessionContext = mock(UiSessionContext.class);
User authenticatedUser = new User();
when(sessionContext.getCurrentUser()).thenReturn(authenticatedUser);
AppContextModel appContextModel = new AppContextModel();
when(sessionContext.generateAppContextModel()).thenReturn(appContextModel);
authenticatedUser.addRole(createRoleForUser());
AdministrationService administrationService = mock(AdministrationService.class);
when(administrationService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATETIME_FORMAT)).thenReturn("dd.MMM.yyyy, HH:mm:ss");
AppFrameworkService appFrameworkService = mock(AppFrameworkService.class);
when(appFrameworkService.getExtensionsForCurrentUser(CoreAppsConstants.ENCOUNTER_TEMPLATE_EXTENSION)).thenReturn(generateMockEncounterTemplateExtensions());
EncounterService encounterService = mock(EncounterService.class);
Patient patient = mock(Patient.class);
when(patient.getPatientId()).thenReturn(1);
when(patient.isDead()).thenReturn(false);
Visit visit = new Visit();
Location visitLocation = new Location();
visitLocation.setName("Visit Location");
visit.setVisitId(1);
visit.setLocation(visitLocation);
visit.setStartDatetime(new Date());
visit.setStopDatetime(new Date());
visit.setCreator(authenticatedUser);
visit.setPatient(patient);
Location encounterLocation = new Location();
encounterLocation.setName("Location");
EncounterType encounterType = new EncounterType();
encounterType.setName("Encounter Type");
encounterType.setUuid(encounterTypeUuid);
Provider primaryProvider = new Provider();
primaryProvider.setName("Primary Provider");
EncounterProvider primaryEncounterProvider = new EncounterProvider();
primaryEncounterProvider.setProvider(primaryProvider);
EncounterRole primaryEncounterRole = new EncounterRole();
primaryEncounterRole.setUuid(primaryEncounterRoleUuid);
primaryEncounterProvider.setEncounterRole(primaryEncounterRole);
when(encounterService.getEncounterRoleByUuid(primaryEncounterRoleUuid)).thenReturn(primaryEncounterRole);
Provider secondaryProvider = new Provider();
secondaryProvider.setName("Secondary Provider");
EncounterProvider secondaryEncounterProvider = new EncounterProvider();
secondaryEncounterProvider.setProvider(secondaryProvider);
secondaryEncounterProvider.setEncounterRole(new EncounterRole());
Encounter encounter = new Encounter();
encounter.setEncounterId(7);
encounter.setEncounterDatetime(new Date());
encounter.setLocation(encounterLocation);
encounter.setEncounterType(encounterType);
encounter.setEncounterProviders(new LinkedHashSet<EncounterProvider>());
// add secondary provider so that it is the one that is "arbitrarily" returned first
encounter.getEncounterProviders().add(secondaryEncounterProvider);
encounter.getEncounterProviders().add(primaryEncounterProvider);
encounter.setCreator(authenticatedUser);
encounter.setDateCreated(new Date());
visit.addEncounter(encounter);
UiUtils uiUtils = new TestUiUtils(administrationService);
VisitDetailsFragmentController controller = new VisitDetailsFragmentController();
SimpleObject response = controller.getVisitDetails(mock(EmrApiProperties.class), coreAppsProperties, appFrameworkService, encounterService, visit, null, null, uiUtils, sessionContext);
List<SimpleObject> actualEncounters = (List<SimpleObject>) response.get("encounters");
SimpleObject actualEncounter = actualEncounters.get(0);
assertThat(response.get("startDatetime"), notNullValue());
assertThat(response.get("stopDatetime"), notNullValue());
assertThat((String) response.get("location"), is("Visit Location"));
assertThat(actualEncounters.size(), is(1));
assertThat((Integer) actualEncounter.get("encounterId"), is(7));
assertThat((String) actualEncounter.get("location"), is("Location"));
assertThat((SimpleObject) actualEncounter.get("encounterType"), isSimpleObjectWith("uuid", encounterType.getUuid(), "name", encounterType.getName()));
assertThat(actualEncounter.get("encounterDatetime"), notNullValue());
assertThat(actualEncounter.get("encounterDate"), notNullValue());
assertThat(actualEncounter.get("encounterTime"), notNullValue());
assertTrue((Boolean) actualEncounter.get("canEdit"));
assertThat((String) actualEncounter.get("primaryProvider"), is("Primary Provider"));
List<SimpleObject> actualProviders = (List<SimpleObject>) actualEncounter.get("encounterProviders");
assertThat(actualProviders.size(), is(2));
}
use of org.openmrs.api.EncounterService in project openmrs-module-coreapps by openmrs.
the class VisitTypeHelper method setEncounterBasedOnVisitType.
/**
* Create encounters based on visit type
*
* @param visit
* @param loginLocation
* @param previousType
*/
public void setEncounterBasedOnVisitType(Visit visit, Location loginLocation, VisitType previousType) {
// all types are transfer type
boolean isTransferType = true;
if (visit.getVisitType() == previousType) {
// visit type is not changed: do nothing
return;
}
EncounterService es = Context.getEncounterService();
VisitService vs = Context.getVisitService();
Patient patient = visit.getPatient();
Person person = Context.getUserContext().getAuthenticatedUser().getPerson();
Encounter encounter = new Encounter();
setTransferEncounter(visit, vs, es, encounter, patient, person, loginLocation, previousType, isTransferType);
}
use of org.openmrs.api.EncounterService in project openmrs-module-pihcore by PIH.
the class PihCoreActivator method started.
// TODO test
@Override
public void started() {
try {
MetadataMappingService metadataMappingService = Context.getService(MetadataMappingService.class);
PatientService patientService = Context.getPatientService();
FormService formService = Context.getFormService();
LocationService locationService = Context.getLocationService();
EncounterService encounterService = Context.getEncounterService();
VisitService visitService = Context.getVisitService();
IdentifierSourceService identifierSourceService = Context.getService(IdentifierSourceService.class);
ConceptService conceptService = Context.getService(ConceptService.class);
if (config == null) {
// hack to allow injecting a mock config for testing
// currently only one of these
config = Context.getRegisteredComponents(Config.class).get(0);
}
setDispositionConfig(config);
installMetadataBundles(config);
setGlobalProperties(config);
setExtraIdentifierTypes(metadataMappingService, patientService, config);
MergeActionsSetup.registerMergeActions();
LocationTagSetup.setupLocationTags(locationService, config);
HtmlFormSetup.setupHtmlFormEntryTagHandlers();
MetadataMappingsSetup.setupGlobalMetadataMappings(metadataMappingService, locationService, encounterService, visitService);
MetadataMappingsSetup.setupPrimaryIdentifierTypeBasedOnCountry(metadataMappingService, patientService, config);
MetadataMappingsSetup.setupFormMetadataMappings(metadataMappingService);
PatientIdentifierSetup.setupIdentifierGeneratorsIfNecessary(identifierSourceService, locationService, config);
PacIntegrationSetup.setup(config);
AttachmentsSetup.migrateAttachmentsConceptsIfNecessary(conceptService);
// RetireProvidersSetup.setupRetireProvidersTask();
} catch (Exception e) {
Module mod = ModuleFactory.getModuleById("pihcore");
ModuleFactory.stopModule(mod);
throw new RuntimeException("failed to setup the required modules", e);
}
}
use of org.openmrs.api.EncounterService in project openmrs-core by openmrs.
the class PatientServiceImpl method mergeEncounters.
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());
}
}
Aggregations