@Test public void evaluate_shouldCalculateAllDeliveriesOnOrAfterMonths() throws Exception { Form deliveryForm = MetadataUtils.existing(Form.class, MchMetadata._Form.MCHMS_DELIVERY); EncounterType ancEncounterType = MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_CONSULTATION); { Patient patient = TestUtils.getPatient(7); TestUtils.saveEncounter(patient, ancEncounterType, deliveryForm, computeWithinRangeEncounterDate(3)); TestUtils.saveEncounter(patient, ancEncounterType, deliveryForm, computeWithinRangeEncounterDate(5)); } { Patient patient = TestUtils.getPatient(8); TestUtils.saveEncounter(patient, ancEncounterType, deliveryForm, computeWithinRangeEncounterDate(10)); TestUtils.saveEncounter(patient, ancEncounterType, deliveryForm, computeWithinRangeEncounterDate(5)); TestUtils.saveEncounter(patient, ancEncounterType, deliveryForm, computeWithinRangeEncounterDate(20)); } List<Integer> ptIds = Arrays.asList(7, 8, 999); Map<String, Object> params = new HashMap<String, Object>(); params.put("onOrAfter", 4); CalculationResultMap resultMap = new AllDeliveriesOnOrAfterMonthsCalculation().evaluate(ptIds, params, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(8).getValue()); Assert.assertFalse((Boolean) resultMap.get(999).getValue()); }
@Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Integer onOrAfter = (Integer)parameterValues.get("onOrAfter"); Calendar cal = Calendar.getInstance(); cal.setTime(context.getNow()); cal.add(Calendar.MONTH, -(onOrAfter)); Date effectiveDate = cal.getTime(); Set<Integer> female = Filters.female(cohort, context); Form deliveryForm = MetadataUtils.existing(Form.class,MchMetadata._Form.MCHMS_DELIVERY); CalculationResultMap allEncountersForMCHConsultation = Calculations.allEncountersOnOrAfter(MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_CONSULTATION), effectiveDate, female, context); Set<Integer> deliveries = allEncountersForMCHConsultation.keySet(); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (deliveries != null && deliveries.contains(ptId)){ ListResult mchcsEncountersResult = (ListResult) allEncountersForMCHConsultation.get(ptId); List<Encounter> encounters = CalculationUtils.extractResultValues(mchcsEncountersResult); for(Encounter e: encounters){ if(deliveryForm.getUuid().equals(e.getForm().getUuid())){ result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; }
AllDeliveriesOnOrAfterMonthsCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Integer onOrAfter = (Integer)parameterValues.get("onOrAfter"); Calendar cal = Calendar.getInstance(); cal.setTime(context.getNow()); cal.add(Calendar.MONTH, -(onOrAfter)); Date effectiveDate = cal.getTime(); Set<Integer> female = Filters.female(cohort, context); Form deliveryForm = MetadataUtils.existing(Form.class,MchMetadata._Form.MCHMS_DELIVERY); CalculationResultMap allEncountersForMCHConsultation = Calculations.allEncountersOnOrAfter(MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_CONSULTATION), effectiveDate, female, context); Set<Integer> deliveries = allEncountersForMCHConsultation.keySet(); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (deliveries != null && deliveries.contains(ptId)){ ListResult mchcsEncountersResult = (ListResult) allEncountersForMCHConsultation.get(ptId); List<Encounter> encounters = CalculationUtils.extractResultValues(mchcsEncountersResult); for(Encounter e: encounters){ if(deliveryForm.getUuid().equals(e.getForm().getUuid())){ result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; } }
AllDeliveriesOnOrAfterMonthsCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Integer onOrAfter = (Integer)parameterValues.get("onOrAfter"); Calendar cal = Calendar.getInstance(); cal.setTime(context.getNow()); cal.add(Calendar.MONTH, -(onOrAfter)); Date effectiveDate = cal.getTime(); Set<Integer> female = Filters.female(cohort, context); Form deliveryForm = MetadataUtils.existing(Form.class,MchMetadata._Form.MCHMS_DELIVERY); CalculationResultMap allEncountersForMCHConsultation = Calculations.allEncountersOnOrAfter(MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_CONSULTATION), effectiveDate, female, context); Set<Integer> deliveries = allEncountersForMCHConsultation.keySet(); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (deliveries != null && deliveries.contains(ptId)){ ListResult mchcsEncountersResult = (ListResult) allEncountersForMCHConsultation.get(ptId); List<Encounter> encounters = CalculationUtils.extractResultValues(mchcsEncountersResult); for(Encounter e: encounters){ if(deliveryForm.getUuid().equals(e.getForm().getUuid())){ result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; }  }
AllDeliveriesOnOrAfterMonthsCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Integer onOrAfter = (Integer)parameterValues.get("onOrAfter"); Calendar cal = Calendar.getInstance(); cal.setTime(context.getNow()); cal.add(Calendar.MONTH, -(onOrAfter)); Date effectiveDate = cal.getTime(); Set<Integer> female = Filters.female(cohort, context); Form deliveryForm = MetadataUtils.existing(Form.class,MchMetadata._Form.MCHMS_DELIVERY); CalculationResultMap allEncountersForMCHConsultation = Calculations.allEncountersOnOrAfter(MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_CONSULTATION), effectiveDate, female, context); Set<Integer> deliveries = allEncountersForMCHConsultation.keySet(); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (deliveries != null && deliveries.contains(ptId)){ ListResult mchcsEncountersResult = (ListResult) allEncountersForMCHConsultation.get(ptId); List<Encounter> encounters = CalculationUtils.extractResultValues(mchcsEncountersResult); for(Encounter e: encounters){ if(deliveryForm.getUuid().equals(e.getForm().getUuid())){ result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context); }
AllDeliveriesOnOrAfterMonthsCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Integer onOrAfter = (Integer)parameterValues.get("onOrAfter"); Calendar cal = Calendar.getInstance(); cal.setTime(context.getNow()); cal.add(Calendar.MONTH, -(onOrAfter)); Date effectiveDate = cal.getTime(); Set<Integer> female = Filters.female(cohort, context); Form deliveryForm = MetadataUtils.existing(Form.class,MchMetadata._Form.MCHMS_DELIVERY); CalculationResultMap allEncountersForMCHConsultation = Calculations.allEncountersOnOrAfter(MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_CONSULTATION), effectiveDate, female, context); Set<Integer> deliveries = allEncountersForMCHConsultation.keySet(); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { boolean result = false; if (deliveries != null && deliveries.contains(ptId)){ ListResult mchcsEncountersResult = (ListResult) allEncountersForMCHConsultation.get(ptId); List<Encounter> encounters = CalculationUtils.extractResultValues(mchcsEncountersResult); for(Encounter e: encounters){ if(deliveryForm.getUuid().equals(e.getForm().getUuid())){ result = true; } } } ret.put(ptId, new BooleanResult(result, this)); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context);  }