The following class is implemented in a module and I think it cannot be serialized because of patientCalculationService field. The class is used in CohortDefinition classes that run the calculation when they are evaluated.
I would like to keep using @Autowired and not something like Context.getService(PatientCalculationService.class), is it possible to do?
public abstract class AbstractPatientCalculation extends BaseCalculation
implements PatientCalculation {
@Autowired private PatientCalculationService patientCalculationService;
protected static CalculationResultMap passing(CalculationResultMap results) {
CalculationResultMap ret = new CalculationResultMap();
for (Map.Entry<Integer, CalculationResult> e : results.entrySet()) {
ret.put(e.getKey(), new BooleanResult(ResultUtil.isTrue(e.getValue()), null));
}
return ret;
}
protected CalculationResultMap calculate(
PatientCalculation calculation,
Collection<Integer> cohort,
PatientCalculationContext calculationContext) {
return patientCalculationService.evaluate(cohort, calculation, calculationContext);
}
}
@yassin , the stack trace in the link and the use-case described seem not to correlate. Any ways, a simple thought on this is, what happens when you implement
of-course bearing in mind that you may have to transform
@ruhanga The reason is unit testing. I need to mock the patientCalculationService.
With Context.getService(PatientCalculationService.class). I can’t use ContextMockHelper because it is deprecated so I am forced to use PowerMockito to be able to mock the static method.
I would prefer not to use PowerMockito if possible.
Sorry for the late response here @yassin , are you still being blocked with this approach?
Trying out with @Autowired in place of Context.get....Service returned several NullPointerExceptions in the test environment for me. I am thinking like you mentioned PowerMockito may do the trick.