@Override @SuppressWarnings("unchecked") protected void process(File csvFile) throws Exception { Transaction t = createTransaction(); Query q = createQuery(t); List<Object[]> list = (List<Object[]>) q.list(); if (list.size() < 1) throw new EmptyResultException(); ArrayList<String> row; Table out = new Table(); for (Object[] o : list) { TestResult tr = (TestResult) o[0]; PatientAttributeValue pc = (PatientAttributeValue) o[1]; PatientAttributeValue bdt = (PatientAttributeValue) o[2]; Date bd = DateUtils.parseDate(bdt.getValue()); Date tDate = tr.getTestDate(); int testCode = TestCode.T4.getCode(); if (bd != null && tDate != null && DateUtils.getDateOffset(bd, Calendar.YEAR, 15).after(tDate)) { // < 15 years old at time of test testCode = TestCode.T4PERCENT.getCode(); if (!tr.getTest() .getTestType() .getDescription() .equals(StandardObjects.getCd4PercentageTestType().getDescription())) continue; } else { if (tr.getTest() .getTestType() .getDescription() .equals(StandardObjects.getCd4PercentageTestType().getDescription())) continue; } String value = tr.getValue(); row = new ArrayList<String>(); row.add(getCentreName()); row.add(OriginCode.ARC.getCode() + ""); row.add(pc.getValue()); row.add(getFormattedDate(tDate)); row.add(TypeOfInformationCode.LAB_RESULT.getCode() + ""); row.add(testCode + ""); row.add(getFormattedDecimal(value, 0, 0)); row.add(""); out.addRow(row); } t.commit(); out.exportAsCsv(new FileOutputStream(csvFile), ';', false); }