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