Search in sources :

Example 6 with EncounterService

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());
    }
}
Also used : Order(org.openmrs.Order) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) User(org.openmrs.User) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) OrderService(org.openmrs.api.OrderService) EncounterService(org.openmrs.api.EncounterService) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with EncounterService

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));
}
Also used : UiSessionContext(org.openmrs.module.appui.UiSessionContext) EncounterProvider(org.openmrs.EncounterProvider) User(org.openmrs.User) SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) TestUiUtils(org.openmrs.module.appui.TestUiUtils) Patient(org.openmrs.Patient) EmrApiProperties(org.openmrs.module.emrapi.EmrApiProperties) EncounterService(org.openmrs.api.EncounterService) Date(java.util.Date) EncounterProvider(org.openmrs.EncounterProvider) Provider(org.openmrs.Provider) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) AdministrationService(org.openmrs.api.AdministrationService) CoreAppsProperties(org.openmrs.module.coreapps.CoreAppsProperties) EncounterRole(org.openmrs.EncounterRole) Encounter(org.openmrs.Encounter) AppFrameworkService(org.openmrs.module.appframework.service.AppFrameworkService) ArrayList(java.util.ArrayList) List(java.util.List) EncounterType(org.openmrs.EncounterType) Location(org.openmrs.Location) TestUiUtils(org.openmrs.module.appui.TestUiUtils) UiUtils(org.openmrs.ui.framework.UiUtils) Test(org.junit.Test)

Example 8 with EncounterService

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

Example 9 with EncounterService

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);
    }
}
Also used : LocationService(org.openmrs.api.LocationService) VisitService(org.openmrs.api.VisitService) PatientService(org.openmrs.api.PatientService) FormService(org.openmrs.api.FormService) IdentifierSourceService(org.openmrs.module.idgen.service.IdentifierSourceService) Module(org.openmrs.module.Module) ConceptService(org.openmrs.api.ConceptService) EncounterService(org.openmrs.api.EncounterService) MetadataMappingService(org.openmrs.module.metadatamapping.api.MetadataMappingService)

Example 10 with EncounterService

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

Aggregations

EncounterService (org.openmrs.api.EncounterService)11 Encounter (org.openmrs.Encounter)9 Patient (org.openmrs.Patient)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Order (org.openmrs.Order)3 OrderService (org.openmrs.api.OrderService)3 EncounterSearchCriteria (org.openmrs.parameter.EncounterSearchCriteria)3 EncounterSearchCriteriaBuilder (org.openmrs.parameter.EncounterSearchCriteriaBuilder)3 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)3 EncounterType (org.openmrs.EncounterType)2 Person (org.openmrs.Person)2 User (org.openmrs.User)2 ConceptService (org.openmrs.api.ConceptService)2 PatientService (org.openmrs.api.PatientService)2 VisitService (org.openmrs.api.VisitService)2 Message (ca.uhn.hl7v2.model.Message)1 Date (java.util.Date)1 List (java.util.List)1 ConceptProposal (org.openmrs.ConceptProposal)1