Search in sources :

Example 6 with VisitService

use of org.openmrs.api.VisitService in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTask method execute.

public void execute() {
    AdtService adtService = Context.getService(AdtService.class);
    VisitService visitService = Context.getVisitService();
    LocationService locationService = Context.getLocationService();
    LocationTag visitLocationTag = locationService.getLocationTagByName(EmrApiConstants.LOCATION_TAG_SUPPORTS_VISITS);
    List<Location> locations = locationService.getLocationsByTag(visitLocationTag);
    List<Visit> openVisits = visitService.getVisits(null, null, locations, null, null, null, null, null, null, false, false);
    for (Visit visit : openVisits) {
        if ((isOldEDVisit(adtService.wrap(visit), ED_VISIT_EXPIRE_VERY_OLD_TIME_IN_HOURS)) || (adtService.shouldBeClosed(visit) && !isActiveEDVisit(adtService.wrap(visit), ED_VISIT_EXPIRE_TIME_IN_HOURS)) || wasDischargedAndNotAdmitted(adtService.wrap(visit), HUM_VISIT_EXPIRE_TIME_IN_HOURS)) {
            try {
                adtService.closeAndSaveVisit(visit);
            } catch (Exception ex) {
                log.warn("Failed to close inactive visit " + visit, ex);
            }
        }
    }
}
Also used : LocationTag(org.openmrs.LocationTag) AdtService(org.openmrs.module.emrapi.adt.AdtService) LocationService(org.openmrs.api.LocationService) VisitService(org.openmrs.api.VisitService) Visit(org.openmrs.Visit) Location(org.openmrs.Location)

Example 7 with VisitService

use of org.openmrs.api.VisitService 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 8 with VisitService

use of org.openmrs.api.VisitService in project openmrs-core by openmrs.

the class PatientServiceImpl method mergeVisits.

private void mergeVisits(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) {
    // move all visits, including voided ones (encounters will be handled below)
    // TODO: this should be a copy, not a move
    VisitService visitService = Context.getVisitService();
    for (Visit visit : visitService.getVisitsByPatient(notPreferred, true, true)) {
        if (log.isDebugEnabled()) {
            log.debug("Merging visit " + visit.getVisitId() + " to " + preferred.getPatientId());
        }
        visit.setPatient(preferred);
        Visit persisted = visitService.saveVisit(visit);
        mergedData.addMovedVisit(persisted.getUuid());
    }
}
Also used : VisitService(org.openmrs.api.VisitService) Visit(org.openmrs.Visit)

Example 9 with VisitService

use of org.openmrs.api.VisitService in project openmrs-core by openmrs.

the class ExistingOrNewVisitAssignmentHandler method loadVisitType.

/**
 * Get the visit type corresponding to an encounter type by reading valid mappings
 * from a global property
 * @param encounterType
 * @return
 * @throws APIException
 */
private static VisitType loadVisitType(EncounterType encounterType) throws APIException {
    String value = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GP_ENCOUNTER_TYPE_TO_VISIT_TYPE_MAPPING, "");
    // or encounterTypeUuid:visitTypeUuid o a mixture of uuids and id
    if (!StringUtils.isBlank(value)) {
        VisitService visitService = Context.getVisitService();
        String targetEncounterTypeId = encounterType.getId().toString();
        String[] mappings = value.split(",");
        for (String mapping : mappings) {
            int index = mapping.indexOf(':');
            if (index > 0) {
                String encounterTypeIdOrUuid = mapping.substring(0, index).trim();
                if (targetEncounterTypeId.equals(encounterTypeIdOrUuid) || encounterType.getUuid().equals(encounterTypeIdOrUuid)) {
                    String visitTypeIdOrUuid = mapping.substring(index + 1).trim();
                    VisitType visitType;
                    if (StringUtils.isNumeric(visitTypeIdOrUuid)) {
                        visitType = visitService.getVisitType(Integer.parseInt(visitTypeIdOrUuid));
                    } else {
                        visitType = visitService.getVisitTypeByUuid(visitTypeIdOrUuid);
                    }
                    if (visitType != null) {
                        return visitType;
                    }
                }
            }
        }
        // Reaching here means this encounter type is not in the user's mapping.
        throw new APIException("GlobalProperty.error.loadVisitType", new Object[] { encounterType.getName() });
    }
    return Context.getVisitService().getAllVisitTypes().get(0);
}
Also used : APIException(org.openmrs.api.APIException) VisitService(org.openmrs.api.VisitService) VisitType(org.openmrs.VisitType)

Aggregations

VisitService (org.openmrs.api.VisitService)9 Visit (org.openmrs.Visit)4 Test (org.junit.Test)2 VisitType (org.openmrs.VisitType)2 EncounterService (org.openmrs.api.EncounterService)2 LocationService (org.openmrs.api.LocationService)2 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)2 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Encounter (org.openmrs.Encounter)1 Location (org.openmrs.Location)1 LocationTag (org.openmrs.LocationTag)1 Patient (org.openmrs.Patient)1 Person (org.openmrs.Person)1 APIException (org.openmrs.api.APIException)1 AdministrationService (org.openmrs.api.AdministrationService)1 ConceptService (org.openmrs.api.ConceptService)1 FormService (org.openmrs.api.FormService)1