Skip to content

Commit

Permalink
BAH-4106 | Fix. Create beans for scheduler task classes to initialize…
Browse files Browse the repository at this point in the history
… context properly (#83)

* BAH-4106 | Fix. Create beans for scheduler task classes to initialize context properly

* BAH-4106 | Refactor. Use Context class to get bean of IPDEventManager
  • Loading branch information
mohan-13 authored Sep 13, 2024
1 parent 0fd367c commit ea00e3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
package org.openmrs.module.ipd.api.scheduler.tasks;

import org.openmrs.api.context.Context;
import org.openmrs.module.ipd.api.events.IPDEventManager;
import org.openmrs.module.ipd.api.events.model.IPDEvent;
import org.openmrs.module.ipd.api.events.model.IPDEventType;
import org.openmrs.scheduler.tasks.AbstractTask;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


public class RollOverNonMedicationTasks extends AbstractTask implements ApplicationContextAware {

private static ApplicationContext context;
public class RollOverNonMedicationTasks extends AbstractTask {

@Override
public void execute() {
IPDEventManager eventManager = context.getBean(IPDEventManager.class);
IPDEventManager eventManager = Context.getRegisteredComponents(IPDEventManager.class).get(0);
IPDEventType eventType = eventManager.getEventTypeForEncounter(String.valueOf(IPDEventType.ROLLOVER_TASK));
if (eventType != null) {
IPDEvent ipdEvent = new IPDEvent(null, null, eventType);
eventManager.processEvent(ipdEvent);
}
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.context = applicationContext;
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
package org.openmrs.module.ipd.api.scheduler.tasks;

import org.openmrs.api.context.Context;
import org.openmrs.module.ipd.api.events.IPDEventManager;
import org.openmrs.module.ipd.api.events.model.IPDEvent;
import org.openmrs.module.ipd.api.events.model.IPDEventType;
import org.openmrs.scheduler.tasks.AbstractTask;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


public class ShiftStartTasks extends AbstractTask implements ApplicationContextAware {
public class ShiftStartTasks extends AbstractTask {

private static ApplicationContext context;
@Override
public void execute() {
IPDEventManager eventManager = context.getBean(IPDEventManager.class);
IPDEventManager eventManager = Context.getRegisteredComponents(IPDEventManager.class).get(0);
IPDEventType eventType = eventManager.getEventTypeForEncounter(String.valueOf(IPDEventType.SHIFT_START_TASK));
if (eventType != null) {
IPDEvent ipdEvent = new IPDEvent(null, null, eventType);
eventManager.processEvent(ipdEvent);
}
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.context = applicationContext;
}
}

0 comments on commit ea00e3a

Please sign in to comment.