Program: 189672
Project: 189672
Buggy source:
/** 
 * @see PregnantAtArtStartCalculation#evaluate(java.util.Collection,java.util.Map,org.openmrs.calculation.patient.PatientCalculationContext)
 * @verifies calculate recorded pregnancy status at ART start for all patients
 */
@Test public void evaluate_shouldCalculatePregnancyStatusAtArtStart() throws Exception {
  PatientService ps=Context.getPatientService();
  Concept pregnancyStatus=Dictionary.getConcept(Dictionary.PREGNANCY_STATUS);
  Concept yes=Dictionary.getConcept(Dictionary.YES);
  Concept no=Dictionary.getConcept(Dictionary.NO);
  Concept stavudine=Context.getConceptService().getConcept(84309);
  TestUtils.saveObs(ps.getPatient(2),pregnancyStatus,yes,TestUtils.date(2007,12,25));
  TestUtils.saveObs(ps.getPatient(6),pregnancyStatus,yes,TestUtils.date(2012,1,1));
  TestUtils.saveDrugOrder(Context.getPatientService().getPatient(6),stavudine,TestUtils.date(2012,1,8),null);
  TestUtils.saveObs(ps.getPatient(7),pregnancyStatus,yes,TestUtils.date(2012,1,1));
  TestUtils.saveObs(ps.getPatient(7),pregnancyStatus,no,TestUtils.date(2012,1,3));
  TestUtils.saveDrugOrder(Context.getPatientService().getPatient(7),stavudine,TestUtils.date(2012,1,8),null);
  TestUtils.saveObs(ps.getPatient(8),pregnancyStatus,yes,TestUtils.date(2012,1,1));
  TestUtils.saveObs(ps.getPatient(8),pregnancyStatus,no,TestUtils.date(2012,1,15));
  TestUtils.saveDrugOrder(Context.getPatientService().getPatient(8),stavudine,TestUtils.date(2012,1,8),null);
  Context.flushSession();
  List<Integer> ptIds=Arrays.asList(2,6,7,8,999);
  CalculationResultMap resultMap=Context.getService(PatientCalculationService.class).evaluate(ptIds,new PregnantAtArtStartCalculation());
  Assert.assertTrue((Boolean)resultMap.get(2).getValue());
  Assert.assertTrue((Boolean)resultMap.get(6).getValue());
  Assert.assertFalse((Boolean)resultMap.get(7).getValue());
  Assert.assertTrue((Boolean)resultMap.get(8).getValue());
  Assert.assertFalse((Boolean)resultMap.get(999).getValue());
}

Fixed version (ground truth):
/** 
 * @see PregnantAtArtStartCalculation#evaluate(java.util.Collection,java.util.Map,org.openmrs.calculation.patient.PatientCalculationContext)
 * @verifies calculate recorded pregnancy status at ART start for all patients
 */
@Test public void evaluate_shouldCalculatePregnancyStatusAtArtStart() throws Exception {
  Concept pregnancyStatus=Dictionary.getConcept(Dictionary.PREGNANCY_STATUS);
  Concept yes=Dictionary.getConcept(Dictionary.YES);
  Concept no=Dictionary.getConcept(Dictionary.NO);
  Concept stavudine=Dictionary.getConcept(Dictionary.STAVUDINE);
  TestUtils.saveObs(TestUtils.getPatient(2),pregnancyStatus,yes,TestUtils.date(2007,12,25));
  TestUtils.saveObs(TestUtils.getPatient(6),pregnancyStatus,yes,TestUtils.date(2012,1,1));
  TestUtils.saveDrugOrder(TestUtils.getPatient(6),stavudine,TestUtils.date(2012,1,8),null);
  TestUtils.saveObs(TestUtils.getPatient(7),pregnancyStatus,yes,TestUtils.date(2012,1,1));
  TestUtils.saveObs(TestUtils.getPatient(7),pregnancyStatus,no,TestUtils.date(2012,1,3));
  TestUtils.saveDrugOrder(TestUtils.getPatient(7),stavudine,TestUtils.date(2012,1,8),null);
  TestUtils.saveObs(TestUtils.getPatient(8),pregnancyStatus,yes,TestUtils.date(2012,1,1));
  TestUtils.saveObs(TestUtils.getPatient(8),pregnancyStatus,no,TestUtils.date(2012,1,15));
  TestUtils.saveDrugOrder(TestUtils.getPatient(8),stavudine,TestUtils.date(2012,1,8),null);
  Context.flushSession();
  List<Integer> ptIds=Arrays.asList(2,6,7,8,999);
  CalculationResultMap resultMap=Context.getService(PatientCalculationService.class).evaluate(ptIds,new PregnantAtArtStartCalculation());
  Assert.assertTrue((Boolean)resultMap.get(2).getValue());
  Assert.assertTrue((Boolean)resultMap.get(6).getValue());
  Assert.assertFalse((Boolean)resultMap.get(7).getValue());
  Assert.assertTrue((Boolean)resultMap.get(8).getValue());
  Assert.assertFalse((Boolean)resultMap.get(999).getValue());
}