From 441d8a07155fda56f0bcce1bd530b15dac5090d1 Mon Sep 17 00:00:00 2001 From: David Semujju Chosen <32744078+semujju@users.noreply.github.com> Date: Fri, 1 Nov 2024 09:05:50 +0300 Subject: [PATCH] U4X-728: Delete unused tasks from UgandaEMR (#658) --- .../tasks/MigrateARTPatientTransfersTask.java | 174 ------------------ api/src/main/resources/liquibase.xml | 96 +++++++--- 2 files changed, 70 insertions(+), 200 deletions(-) delete mode 100644 api/src/main/java/org/openmrs/module/ugandaemr/tasks/MigrateARTPatientTransfersTask.java diff --git a/api/src/main/java/org/openmrs/module/ugandaemr/tasks/MigrateARTPatientTransfersTask.java b/api/src/main/java/org/openmrs/module/ugandaemr/tasks/MigrateARTPatientTransfersTask.java deleted file mode 100644 index b2ddb250..00000000 --- a/api/src/main/java/org/openmrs/module/ugandaemr/tasks/MigrateARTPatientTransfersTask.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.openmrs.module.ugandaemr.tasks; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Query; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.openmrs.*; -import org.openmrs.api.context.Context; -import org.openmrs.module.ugandaemr.metadata.core.EncounterTypes; -import org.openmrs.scheduler.SchedulerException; -import org.openmrs.scheduler.TaskDefinition; -import org.openmrs.scheduler.tasks.AbstractTask; -import org.openmrs.util.OpenmrsUtil; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; - -import static org.openmrs.module.ugandaemr.UgandaEMRConstants.*; - -public class MigrateARTPatientTransfersTask extends AbstractTask { - protected final Log log = LogFactory.getLog(this.getClass()); - - public void execute() { - log.info("Start Migrate Transfer Outs From Art Summary Page To Transfer Out Encounters"); - transferOut(); - log.info("Completed Transfer Out Migration"); - - log.info("Start Migrate Transfer Ins From Art Summary Page To Transfer Out Encounters"); - transferIn(); - log.info("Completed Transfer In Migration"); - stopTransferService(); - } - - - private void transferOut() { - String queryStringTransferOut = "from Obs obs where obs.concept =" + TRANSFER_OUT_DATE_CONCEPT_ID + " and voided=false"; - Query query = getSession().createQuery(queryStringTransferOut); - List obsList = query.list(); - List encounters = new ArrayList<>(); - List transferEncounters = new ArrayList<>(); - for (Obs obs : obsList) { - if (!encounters.contains(obs.getEncounter())) { - Encounter encounter = generateTransferInOutEncounter(obs, TRANSFER_OUT_PLACE_CONCEPT_ID, EncounterTypes.TRANSFER_OUT.name(), obs.getValueDate()); - } - } - } - - private void transferIn() { - String queryStringTransferOut = "from Obs obs where obs.concept =" + TRANSFER_IN_CONCEPT_ID + " and voided=false"; - Query query = getSession().createQuery(queryStringTransferOut); - List obsList = query.list(); - List encounters = new ArrayList<>(); - List transferEncounters = new ArrayList<>(); - for (Obs obs : obsList) { - if (!encounters.contains(obs.getEncounter())) { - Encounter encounter = generateTransferInOutEncounter(obs, TRANSFER_IN_FROM_PLACE_CONCEPT_ID, EncounterTypes.TRANSFER_IN.name(), obs.getEncounter().getEncounterDatetime()); - ; - } - } - } - - private void stopTransferService() { - TaskDefinition task = new TaskDefinition(); - task = Context.getSchedulerService().getTaskByName(ART_TRANSFER_SCHEDULE_NAME); - if (task != null) { - try { - Context.getSchedulerService().shutdownTask(task); - } catch (SchedulerException e) { - log.error("Faied to shutdown task",e); - } - } - } - - /** - * This Method gets an encounter uses its information and creates another encounter basing on obs the encounter has - * - * @param obs - * @return - */ - private Encounter generateTransferInOutEncounter(Obs obs, String transferPlace, String encounterTypeName, Date visitEncounterDate) { - Visit visit = new Visit(); - Encounter encounter = new Encounter(); - EncounterType encounterType = Context.getEncounterService().getEncounterType(encounterTypeName); - Form form = Context.getFormService().getFormByUuid("45d9db68-e4b5-11e7-80c1-9a214cf093ae"); - - Collection patients = new ArrayList<>(); - patients.add(obs.getEncounter().getPatient()); - - List visits = Context.getVisitService().getVisits(null, patients, null, null, OpenmrsUtil.firstSecondOfDay(visitEncounterDate), OpenmrsUtil.getLastMomentOfDay(visitEncounterDate), OpenmrsUtil.firstSecondOfDay(visitEncounterDate), OpenmrsUtil.getLastMomentOfDay(visitEncounterDate), null, true, false); - - if (visits.size() <= 0) { - visit.setLocation(Context.getLocationService().getLocation("ART Clinic")); - visit.setPatient(obs.getEncounter().getPatient()); - visit.setStartDatetime(visitEncounterDate); - visit.setStopDatetime(visitEncounterDate); - visit.setVisitType(Context.getVisitService().getVisitTypeByUuid(FACILITY_VISIT_TYPE_UUID)); - visit.setCreator(Context.getAuthenticatedUser()); - visit.setDateCreated(obs.getDateCreated()); - Context.getVisitService().saveVisit(visit); - } else { - visit = visits.get(0); - } - - - List obs1 = new ArrayList<>(); - encounter.setEncounterDatetime(visitEncounterDate); - encounter.setVisit(visit); - encounter.setLocation(visit.getLocation()); - encounter.setEncounterType(encounterType); - encounter.setForm(form); - encounter.setPatient(obs.getEncounter().getPatient()); - encounter.setCreator(obs.getCreator()); - encounter.setLocation(obs.getLocation()); - encounter.setDateCreated(visitEncounterDate); - encounter.addObs(createObs(getConceptFromString(TRANSFER_FROM_CLINIC_CONCEPT_ID), "", getConceptFromString(ART_CLINIC_CONCEPT_ID), encounter)); - encounter.addObs(createObs(getConceptFromString(transferPlace), getTransferPlaceObs(obs.getEncounter(), transferPlace).getValueText(), null, encounter)); - encounter = Context.getEncounterService().saveEncounter(encounter); - return encounter; - } - - private Obs getTransferPlaceObs(Encounter encounter, String transferPlace) { - List obsList = new ArrayList<>(); - Obs obs = new Obs(); - Concept concept = Context.getConceptService().getConcept(transferPlace); - obsList = Context.getObsService().getObservationsByPersonAndConcept(encounter.getPatient().getPerson(), concept); - if (obsList.size() > 0) { - obs = obsList.get(0); - } - return obs; - } - - private Obs createObs(Concept concept, String answer, Concept conceptAnswer, Encounter newEncounter) { - if (concept != null) { - Obs obs = new Obs(newEncounter.getPatient(), concept, newEncounter.getEncounterDatetime(), newEncounter.getLocation()); - if (conceptAnswer != null && concept.getDatatype().isCoded()) { - obs.setValueCoded(conceptAnswer); - return obs; - } else if (answer != null && concept.getDatatype().isText()) { - obs.setValueText(answer); - return obs; - } else if (answer == null && concept.getDatatype().isText()) { - obs.setValueText("Unknown"); - return obs; - } else { - return null; - } - - } else { - return null; - } - } - - - private Concept getConceptFromString(String conceptString) { - if (Context.getConceptService().getConcept(conceptString) != null) { - return Context.getConceptService().getConcept(conceptString); - } else { - return null; - } - } - - private Date getTransformDate(Date date, long time) { - return date; - } - - public Session getSession() { - return Context.getRegisteredComponent("sessionFactory", SessionFactory.class).getCurrentSession(); - } - - -} diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index bcc81783..aa895e1b 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -318,32 +318,7 @@ - - - - - SELECT COUNT(*) FROM scheduler_task_config - WHERE schedulable_class = 'org.openmrs.module.ugandaemr.tasks.MigrateARTPatientTransfersTask' - - - DELETE FROM scheduler_task_config where uuid='8b5caeea-2c3b-11e8-b467-0ed5f89f718b' - Inserting ART Summary Patient Transfer Migration into 'schedule_task_config' table - - - - - - - - - - - - - - - - + @@ -1105,6 +1080,75 @@ VALUES + + + + select count(*) from scheduler_task_config where uuid = "8c17b376-1a2b-11e1-a51a-00248140a5eb"; + + + + Delete the following redundant sync task - Auto close visits task + + + delete from scheduler_task_config where uuid ="8c17b376-1a2b-11e1-a51a-00248140a5eb"; + + + + + + + select count(*) from scheduler_task_config where uuid = "1428cdc3-b340-4c86-8553-7886b88dc4c2"; + + + + Delete the following redundant sync task - Intialize logic rule providers + + + delete from scheduler_task_config where uuid = "1428cdc3-b340-4c86-8553-7886b88dc4c2"; + + + + + + + select count(*) from scheduler_task_config where uuid = "eb9e447d-5ef9-4771-9e88-21916340b69c"; + + + + Delete redundant sync task - Process HL7 task + + + delete from scheduler_task_config where uuid = "eb9e447d-5ef9-4771-9e88-21916340b69c"; + + + + + + + select count(*) from scheduler_task_config where uuid = "8b5caeea-2c3b-11e8-b467-0ed5f89f718b"; + + + + Delete redundant sync task - Art summary patient transfer migration + + + delete from scheduler_task_config where uuid = "8b5caeea-2c3b-11e8-b467-0ed5f89f718b"; + + + + + + + select count(*) from scheduler_task_config where uuid ="08a36b06-7a71-11eb-9439-0242ac130002"; + + + + Delete redundant sync task - Sync FHIR records a given server + + + delete from scheduler_task_config where uuid ="08a36b06-7a71-11eb-9439-0242ac130002"; + +