Program: 189658
Project: 189658
Buggy source:
public void controller(@FragmentParam("String_Node_Str") Patient patient,@FragmentParam("String_Node_Str") Boolean complete,FragmentModel model){
  Map<String,Object> calculations=new HashMap<String,Object>();
  PatientWrapper patientWrapper=new PatientWrapper(patient);
  Encounter lastMchEnrollment=patientWrapper.lastEncounter(MetadataUtils.existing(EncounterType.class,MchMetadata._EncounterType.MCHMS_ENROLLMENT));
  EncounterWrapper lastMchEnrollmentWrapped=new EncounterWrapper(lastMchEnrollment);
  Obs hivStatusObs=lastMchEnrollmentWrapped.firstObs(Dictionary.getConcept(Dictionary.HIV_STATUS));
  if (hivStatusObs != null) {
    calculations.put("String_Node_Str",hivStatusObs.getValueCoded());
  }
 else {
    calculations.put("String_Node_Str","String_Node_Str");
  }
  Encounter lastMchConsultation=patientWrapper.lastEncounter(MetadataUtils.existing(EncounterType.class,MchMetadata._EncounterType.MCHMS_CONSULTATION));
  if (lastMchConsultation != null) {
    EncounterWrapper lastMchConsultationWrapped=new EncounterWrapper(lastMchConsultation);
    Obs arvUseObs=lastMchConsultationWrapped.firstObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USE_IN_PREGNANCY));
    if (arvUseObs != null) {
      Concept concept=arvUseObs.getValueCoded();
      if (concept.equals(Dictionary.getConcept(Dictionary.MOTHER_ON_PROPHYLAXIS)) || concept.equals(Dictionary.getConcept(Dictionary.MOTHER_ON_HAART))) {
        String regimen="String_Node_Str";
        List<Obs> drugObsList=lastMchConsultationWrapped.allObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USED_IN_PREGNANCY));
        if (!drugObsList.isEmpty()) {
          String rgmn="String_Node_Str";
          for (          Obs obs : drugObsList) {
            if (obs != null) {
              rgmn+=obs.getValueCoded().getName().getName();
              if (!obs.equals(drugObsList.get(drugObsList.size() - 1))) {
                rgmn+="String_Node_Str";
              }
            }
          }
          if (!rgmn.isEmpty()) {
            regimen=rgmn;
          }
        }
        if (concept.equals(Dictionary.getConcept(Dictionary.MOTHER_ON_PROPHYLAXIS))) {
          calculations.put("String_Node_Str","String_Node_Str" + regimen + "String_Node_Str");
          calculations.put("String_Node_Str","String_Node_Str");
        }
 else         if (concept.equals(Dictionary.getConcept(Dictionary.MOTHER_ON_HAART))) {
          calculations.put("String_Node_Str","String_Node_Str");
          calculations.put("String_Node_Str","String_Node_Str" + regimen + "String_Node_Str");
        }
      }
 else {
        calculations.put("String_Node_Str","String_Node_Str");
        calculations.put("String_Node_Str","String_Node_Str");
      }
    }
 else {
      calculations.put("String_Node_Str","String_Node_Str");
      calculations.put("String_Node_Str","String_Node_Str");
    }
  }
 else {
    calculations.put("String_Node_Str","String_Node_Str");
    calculations.put("String_Node_Str","String_Node_Str");
  }
  model.addAttribute("String_Node_Str",calculations);
}

Fixed version (ground truth):
public void controller(@FragmentParam("String_Node_Str") Patient patient,@FragmentParam("String_Node_Str") Boolean complete,FragmentModel model){
  Map<String,Object> calculations=new HashMap<String,Object>();
  PatientWrapper patientWrapper=new PatientWrapper(patient);
  Encounter lastMchEnrollment=patientWrapper.lastEncounter(MetadataUtils.existing(EncounterType.class,MchMetadata._EncounterType.MCHMS_ENROLLMENT));
  EncounterWrapper lastMchEnrollmentWrapped=new EncounterWrapper(lastMchEnrollment);
  Obs hivStatusObs=null;
  if (lastMchEnrollmentWrapped != null) {
    hivStatusObs=lastMchEnrollmentWrapped.firstObs(Dictionary.getConcept(Dictionary.HIV_STATUS));
  }
  if (hivStatusObs != null) {
    calculations.put("String_Node_Str",hivStatusObs.getValueCoded());
  }
 else {
    calculations.put("String_Node_Str","String_Node_Str");
  }
  Encounter lastMchConsultation=patientWrapper.lastEncounter(MetadataUtils.existing(EncounterType.class,MchMetadata._EncounterType.MCHMS_CONSULTATION));
  if (lastMchConsultation != null) {
    EncounterWrapper lastMchConsultationWrapped=new EncounterWrapper(lastMchConsultation);
    Obs arvUseObs=lastMchConsultationWrapped.firstObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USE_IN_PREGNANCY));
    if (arvUseObs != null) {
      Concept concept=arvUseObs.getValueCoded();
      if (concept.equals(Dictionary.getConcept(Dictionary.MOTHER_ON_PROPHYLAXIS)) || concept.equals(Dictionary.getConcept(Dictionary.MOTHER_ON_HAART))) {
        String regimen="String_Node_Str";
        List<Obs> drugObsList=lastMchConsultationWrapped.allObs(Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_USED_IN_PREGNANCY));
        if (!drugObsList.isEmpty()) {
          String rgmn="String_Node_Str";
          for (          Obs obs : drugObsList) {
            if (obs != null) {
              rgmn+=obs.getValueCoded().getName().getName();
              if (!obs.equals(drugObsList.get(drugObsList.size() - 1))) {
                rgmn+="String_Node_Str";
              }
            }
          }
          if (!rgmn.isEmpty()) {
            regimen=rgmn;
          }
        }
        if (concept.equals(Dictionary.getConcept(Dictionary.MOTHER_ON_PROPHYLAXIS))) {
          calculations.put("String_Node_Str","String_Node_Str" + regimen + "String_Node_Str");
          calculations.put("String_Node_Str","String_Node_Str");
        }
 else         if (concept.equals(Dictionary.getConcept(Dictionary.MOTHER_ON_HAART))) {
          calculations.put("String_Node_Str","String_Node_Str");
          calculations.put("String_Node_Str","String_Node_Str" + regimen + "String_Node_Str");
        }
      }
 else {
        calculations.put("String_Node_Str","String_Node_Str");
        calculations.put("String_Node_Str","String_Node_Str");
      }
    }
 else {
      calculations.put("String_Node_Str","String_Node_Str");
      calculations.put("String_Node_Str","String_Node_Str");
    }
  }
 else {
    calculations.put("String_Node_Str","String_Node_Str");
    calculations.put("String_Node_Str","String_Node_Str");
  }
  model.addAttribute("String_Node_Str",calculations);
}