private void searchPatientByAttributes( List<Integer> searchingAttributeId, List<String> searchText) { // total = patientAttributeValueService.countSearchPatients( searchingAttributeId, searchText ); // OrganisationUnit orgUnit = null; organisationUnit = (isSelectedOrg) ? organisationUnit : null; total = patientService.countSearchPatients(searchText, organisationUnit); // Collection<Patient> getPatients( String searchText, Integer min, Integer max ); this.paging = createPaging(total); // patients = patientAttributeValueService.searchPatients( searchingAttributeId, searchText, // paging.getStartPos(),paging.getPageSize() ); patients = patientService.searchPatients( searchText, organisationUnit, paging.getStartPos(), paging.getPageSize()); /* if ( isSelectedOrg ) { Iterator<Patient> patientIterator = patients.iterator(); while ( patientIterator.hasNext() ) { Patient patient = patientIterator.next(); OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); if ( patient.getOrganisationUnit().getId() != orgUnit.getId() ) { patientIterator.remove(); } } total = patients.size(); this.paging = createPaging( total ); } */ Collection<PatientAttributeValue> attributeValues = patientAttributeValueService.getPatientAttributeValues(patients); for (Patient patient : patients) { // programs.addAll( patient.getPrograms() ); mapPatientOrgunit.put(patient.getId(), getHierarchyOrgunit(patient.getOrganisationUnit())); for (PatientAttributeValue attributeValue : attributeValues) { mapPatientPatientAttr.put( patient.getId() + "-" + attributeValue.getPatientAttribute().getId(), attributeValue.getValue()); } // mapPatientPrograms.put( patient.getId(), getProgramsByPatient( patient ) ); } }
private void searchPatientByNameAndOrgUnit( List<String> searchText, OrganisationUnit organisationUnit) { total = patientService.countGetPatientsByOrgUnit(organisationUnit); this.paging = createPaging(total); // Collection<Patient> tempPatients = new ArrayList<Patient>(); for (String text : searchText) { // tPatients( OrganisationUnit organisationUnit, String searchText, int min, int max ) List<Patient> tempPatients = new ArrayList<Patient>( patientService.getPatients( organisationUnit, text, paging.getStartPos(), paging.getPageSize())); patients.addAll(tempPatients); } total = patients.size(); this.paging = createPaging(total); Collection<PatientAttributeValue> attributeValues = patientAttributeValueService.getPatientAttributeValues(patients); for (Patient patient : patients) { // programs.addAll( patient.getPrograms() ); mapPatientOrgunit.put(patient.getId(), getHierarchyOrgunit(patient.getOrganisationUnit())); for (PatientAttributeValue attributeValue : attributeValues) { mapPatientPatientAttr.put( patient.getId() + "-" + attributeValue.getPatientAttribute().getId(), attributeValue.getValue()); } // mapPatientPrograms.put( patient.getId(), getProgramsByPatient( patient ) ); } }
@Override public String execute() throws Exception { patient = patientService.getPatient(patientId); Collection<Program> programs = programService.getProgramsByCurrentUser(Program.MULTIPLE_EVENTS_WITH_REGISTRATION); programs.addAll( programService.getProgramsByCurrentUser(Program.SINGLE_EVENT_WITH_REGISTRATION)); // --------------------------------------------------------------------- // Get relationship // --------------------------------------------------------------------- relationships = relationshipService.getRelationshipsForPatient(patient); Collection<ProgramInstance> programInstances = patient.getProgramInstances(); // --------------------------------------------------------------------- // Get patient-attribute-values // --------------------------------------------------------------------- Collection<PatientAttributeValue> _attributeValues = patientAttributeValueService.getPatientAttributeValues(patient); attributeValues = new HashSet<PatientAttributeValue>(); for (PatientAttributeValue attributeValue : _attributeValues) { String value = attributeValue.getValue(); if (attributeValue.getPatientAttribute().getValueType().equals(PatientAttribute.TYPE_AGE)) { Date date = format.parseDate(value); value = PatientAttribute.getAgeFromDate(date) + ""; attributeValue.setValue(value); } attributeValues.add(attributeValue); } // --------------------------------------------------------------------- // Get patient-identifiers // --------------------------------------------------------------------- Collection<PatientIdentifier> _identifiers = patient.getIdentifiers(); identifiers = new HashSet<PatientIdentifier>(); for (Program program : programs) { Collection<PatientIdentifierType> identifierTypes = program.getIdentifierTypes(); for (PatientIdentifier identifier : _identifiers) { if (!identifierTypes.contains(identifier.getIdentifierType())) { identifiers.add(identifier); } } } // --------------------------------------------------------------------- // Get program enrollment // --------------------------------------------------------------------- activeProgramInstances = new HashSet<ProgramInstance>(); completedProgramInstances = new HashSet<ProgramInstance>(); for (ProgramInstance programInstance : programInstances) { if (programs.contains(programInstance.getProgram())) { if (programInstance.getStatus() == ProgramInstance.STATUS_ACTIVE) { activeProgramInstances.add(programInstance); programIndicatorsMap.putAll( programIndicatorService.getProgramIndicatorValues(programInstance)); } else { completedProgramInstances.add(programInstance); } } } // --------------------------------------------------------------------- // Patient-Audit // --------------------------------------------------------------------- patientAudits = patientAuditService.getPatientAudits(patient); Calendar today = Calendar.getInstance(); PeriodType.clearTimeOfDay(today); Date date = today.getTime(); String visitor = currentUserService.getCurrentUsername(); PatientAudit patientAudit = patientAuditService.getPatientAudit( patient.getId(), visitor, date, PatientAudit.MODULE_PATIENT_DASHBOARD); if (patientAudit == null) { patientAudit = new PatientAudit(patient, visitor, date, PatientAudit.MODULE_PATIENT_DASHBOARD); patientAuditService.savePatientAudit(patientAudit); } return SUCCESS; }
@SuppressWarnings("unchecked") public String execute() { gatewayId = transportService.getDefaultGateway(); if (gatewayId == null || gatewayId.trim().length() == 0) { message = i18n.getString("please_select_a_gateway_type_to_send_sms"); return ERROR; } if (smsMessage == null || smsMessage.trim().length() == 0) { message = i18n.getString("no_message"); return ERROR; } User currentUser = currentUserService.getCurrentUser(); if (sendTarget != null && sendTarget.equals("phone")) { try { ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); recipients = mapper.readValue(recipients.iterator().next(), Set.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } message = messageSender.sendMessage( smsSubject, smsMessage, currentUser, true, recipients, gatewayId); } else if (sendTarget.equals("userGroup")) { UserGroup group = userGroupService.getUserGroup(userGroup); if (group == null) { message = i18n.getString("selected_user_group_is_unavailable"); return ERROR; } if (group.getMembers() == null || group.getMembers().isEmpty()) { message = i18n.getString("selected_user_group_has_no_member"); return ERROR; } message = messageSender.sendMessage( smsSubject, smsMessage, currentUser, false, group.getMembers(), gatewayId); } else if (sendTarget.equals("user")) { Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits(); if (units != null && !units.isEmpty()) { Set<User> users = new HashSet<User>(); for (OrganisationUnit unit : units) { users.addAll(unit.getUsers()); } if (users.isEmpty()) { message = i18n.getString("there_is_no_user_assigned_to_selected_units"); return ERROR; } message = messageSender.sendMessage(smsSubject, smsMessage, currentUser, false, users, gatewayId); } } else if (sendTarget.equals("unit")) { for (OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits()) { if (unit.getPhoneNumber() != null && !unit.getPhoneNumber().isEmpty()) { recipients.add(unit.getPhoneNumber()); } } if (recipients.isEmpty()) { message = i18n.getString("selected_units_have_no_phone_number"); return ERROR; } message = messageSender.sendMessage( smsSubject, smsMessage, currentUser, true, recipients, gatewayId); } else { Patient patient = null; Set<String> phones = new HashSet<String>(); try { ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); recipients = mapper.readValue(recipients.iterator().next(), Set.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } for (String patientId : recipients) { patient = patientService.getPatient(Integer.parseInt(patientId)); if (patient != null && patient.getPhoneNumber() != null && !patient.getPhoneNumber().isEmpty()) { phones.add(patient.getPhoneNumber()); } } if (phones.isEmpty()) { message = i18n.getString("selected_persons_have_no_phone_number"); return ERROR; } message = messageSender.sendMessage(smsSubject, smsMessage, currentUser, true, phones, gatewayId); } if (message != null && !message.equals("success")) { message = i18n.getString(message); return ERROR; } return SUCCESS; }
public void generateReport( Program selProgram, List<OrganisationUnit> orgUnitList, Date sDate, Date eDate) throws Exception { String raFolderName = reportService.getRAFolderName(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); String query = ""; int rowStart = 3; int colStart = 1; int rowCount = rowStart; int colCount = colStart; // String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + // File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls"; String outputReportPath = System.getenv("DHIS2_HOME") + File.separator + Configuration_IN.DEFAULT_TEMPFOLDER; File newdir = new File(outputReportPath); if (!newdir.exists()) { newdir.mkdirs(); } outputReportPath += File.separator + UUID.randomUUID().toString() + ".xls"; WritableWorkbook outputReportWorkbook = Workbook.createWorkbook(new File(outputReportPath)); WritableSheet sheet0 = outputReportWorkbook.createSheet(selProgram.getName(), 0); try { List<PatientIdentifierType> patientIdentifierTypes = new ArrayList<PatientIdentifierType>( patientIdentifierTypeService.getAllPatientIdentifierTypes()); Collections.sort(patientIdentifierTypes, new PatientIdentifierTypeComparator()); List<PatientAttribute> patientAttributes = new ArrayList<PatientAttribute>(patientAttributeService.getAllPatientAttributes()); Collections.sort(patientAttributes, new PatientAttributeComparator()); List<ProgramStage> programStages = new ArrayList<ProgramStage>(selProgram.getProgramStages()); Collections.sort(programStages, new ProgramStageOrderComparator()); Map<ProgramStage, List<DataElement>> programStageDataElementMap = new HashMap<ProgramStage, List<DataElement>>(); for (ProgramStage programStage : programStages) { List<ProgramStageDataElement> programStageDataElements = new ArrayList<ProgramStageDataElement>(programStage.getProgramStageDataElements()); List<DataElement> dataElements = new ArrayList<DataElement>(); for (ProgramStageDataElement programStageDataElement : programStageDataElements) { dataElements.add(programStageDataElement.getDataElement()); } Collections.sort(dataElements, new IdentifiableObjectNameComparator()); programStageDataElementMap.put(programStage, dataElements); } // Printing Header Information sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "OrgUnit Hierarchy", getCellFormat1())); colCount++; sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "OrgUnit", getCellFormat1())); colCount++; for (PatientIdentifierType patientIdentifierType : patientIdentifierTypes) { sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell( new Label(colCount, rowCount - 1, patientIdentifierType.getName(), getCellFormat1())); colCount++; } sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Benificiary ID", getCellFormat1())); colCount++; sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Benificiary Name", getCellFormat1())); colCount++; sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Gender", getCellFormat1())); colCount++; sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Age", getCellFormat1())); colCount++; sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Data of Birth", getCellFormat1())); colCount++; sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Blood Group", getCellFormat1())); colCount++; sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Registration Date", getCellFormat1())); colCount++; for (PatientAttribute patientAttribute : patientAttributes) { sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell( new Label(colCount, rowCount - 1, patientAttribute.getName(), getCellFormat1())); colCount++; } sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Incident Date", getCellFormat1())); colCount++; sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount); sheet0.addCell(new Label(colCount, rowCount - 1, "Enrollment Date", getCellFormat1())); colCount++; for (ProgramStage programStage : programStages) { List<DataElement> dataElementList = new ArrayList<DataElement>(programStageDataElementMap.get(programStage)); sheet0.mergeCells( colCount, rowCount - 1, colCount + dataElementList.size() + 1, rowCount - 1); sheet0.addCell(new Label(colCount, rowCount - 1, programStage.getName(), getCellFormat1())); sheet0.addCell(new Label(colCount, rowCount, "Due Date", getCellFormat1())); colCount++; sheet0.addCell(new Label(colCount, rowCount, "Execution Date", getCellFormat1())); colCount++; for (DataElement dataElement : dataElementList) { sheet0.addCell( new Label( colCount, rowCount, dataElement.getName() + "--" + dataElement.getType(), getCellFormat1())); colCount++; } } rowCount++; for (OrganisationUnit orgUnit : orgUnitList) { if (sDate != null && eDate != null) { query = "SELECT patient.patientid, programinstance.programinstanceid,programinstance.dateofincident,programinstance.enrollmentdate FROM programinstance INNER JOIN patient " + " ON programinstance.patientid = patient.patientid " + " WHERE patient.organisationunitid = " + orgUnit.getId() + " AND programinstance.programid = " + selProgram.getId() + " AND patient.registrationdate >= '" + startDate + "'" + " AND patient.registrationdate <= '" + endDate + "' " + " AND enddate IS NULL"; } else { query = "SELECT patient.patientid, programinstance.programinstanceid,programinstance.dateofincident,programinstance.enrollmentdate FROM programinstance INNER JOIN patient " + " ON programinstance.patientid = patient.patientid " + " WHERE patient.organisationunitid = " + orgUnit.getId() + " AND programinstance.programid = " + selProgram.getId() + " AND enddate IS NULL"; } SqlRowSet sqlResultSet = jdbcTemplate.queryForRowSet(query); if (sqlResultSet != null) { int count = 1; String orgUnitBranch = ""; sqlResultSet.beforeFirst(); while (sqlResultSet.next()) { colCount = colStart; if (orgUnit.getParent() != null) { orgUnitBranch = getOrgunitBranch(orgUnit.getParent()); } else { orgUnitBranch = " "; } sheet0.addCell(new Label(colCount, rowCount, orgUnitBranch, getCellFormat2())); colCount++; sheet0.addCell(new Label(colCount, rowCount, orgUnit.getName(), getCellFormat2())); colCount++; int patientId = sqlResultSet.getInt(1); int programInstanceId = sqlResultSet.getInt(2); Date dateOfIncident = sqlResultSet.getDate(3); Date dateOfEnrollment = sqlResultSet.getDate(4); Patient patient = patientService.getPatient(patientId); // Patient Identifier Details for (PatientIdentifierType patientIdentifierType : patientIdentifierTypes) { query = "SELECT identifier from patientidentifier WHERE patientidentifiertypeid = " + patientIdentifierType.getId() + " AND patientid = " + patient.getId(); SqlRowSet sqlResultSet1 = jdbcTemplate.queryForRowSet(query); if (sqlResultSet1 != null && sqlResultSet1.next()) { String value = sqlResultSet1.getString(1); if (value != null && !value.trim().equalsIgnoreCase("")) { sheet0.addCell(new Label(colCount, rowCount, value, getCellFormat2())); } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2())); } } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2())); } colCount++; } // Patient Properties sheet0.addCell( new Label(colCount, rowCount, patient.getId().toString(), getCellFormat2())); colCount++; sheet0.addCell(new Label(colCount, rowCount, patient.getFullName(), getCellFormat2())); colCount++; sheet0.addCell( new Label(colCount, rowCount, patient.getTextGender(), getCellFormat2())); colCount++; sheet0.addCell(new Label(colCount, rowCount, patient.getAge(), getCellFormat2())); colCount++; sheet0.addCell( new Label( colCount, rowCount, simpleDateFormat.format(patient.getBirthDate()), getCellFormat2())); colCount++; /** * TODO BloodGroup is removed from Patient Object, so need to change this accordingly */ sheet0.addCell( new Label(colCount, rowCount, "" /*patient.getBloodGroup()*/, getCellFormat2())); colCount++; sheet0.addCell( new Label( colCount, rowCount, simpleDateFormat.format(patient.getRegistrationDate()), getCellFormat2())); colCount++; // Patient Attribute Values for (PatientAttribute patientAttribute : patientAttributes) { query = "SELECT value from patientattributevalue WHERE patientid = " + patient.getId() + " AND patientattributeid = " + patientAttribute.getId(); SqlRowSet sqlResultSet1 = jdbcTemplate.queryForRowSet(query); if (sqlResultSet1 != null && sqlResultSet1.next()) { String value = sqlResultSet1.getString(1); if (value != null && !value.trim().equalsIgnoreCase("")) { sheet0.addCell(new Label(colCount, rowCount, value, getCellFormat2())); } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2())); } } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2())); } colCount++; } // Program Enrollment Details sheet0.addCell( new Label( colCount, rowCount, simpleDateFormat.format(dateOfIncident), getCellFormat2())); colCount++; sheet0.addCell( new Label( colCount, rowCount, simpleDateFormat.format(dateOfEnrollment), getCellFormat2())); colCount++; // ProgramStage Values for (ProgramStage programStage : programStages) { query = "SELECT programstageinstanceid,duedate,executiondate from programstageinstance " + " WHERE programinstanceid = " + programInstanceId + " AND programstageid = " + programStage.getId(); SqlRowSet sqlResultSet2 = jdbcTemplate.queryForRowSet(query); Integer programStageInstanceId = 0; if (sqlResultSet2 != null && sqlResultSet2.next()) { programStageInstanceId = sqlResultSet2.getInt(1); // ProgramStage DueDate and Execution Date Date dueDate = sqlResultSet2.getDate(2); Date exeDate = sqlResultSet2.getDate(3); if (dueDate != null) { String dueDateStr = simpleDateFormat.format(dueDate); sheet0.addCell(new Label(colCount, rowCount, dueDateStr, getCellFormat3())); } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat3())); } colCount++; if (exeDate != null) { String exeDateStr = simpleDateFormat.format(exeDate); sheet0.addCell(new Label(colCount, rowCount, exeDateStr, getCellFormat3())); } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat3())); } colCount++; } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat3())); colCount++; sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat3())); colCount++; } for (DataElement dataElement : programStageDataElementMap.get(programStage)) { query = "SELECT value from patientdatavalue WHERE programstageinstanceid = " + programStageInstanceId + " AND dataelementid = " + dataElement.getId(); // " AND organisationunitid = " + orgUnit.getId(); SqlRowSet sqlResultSet3 = jdbcTemplate.queryForRowSet(query); if (sqlResultSet3 != null && sqlResultSet3.next()) { String value = sqlResultSet3.getString(1); if (dataElement.getType().equalsIgnoreCase(DataElement.VALUE_TYPE_BOOL)) { if (value.equalsIgnoreCase("false")) value = "No"; else value = "Yes"; } if (value != null && !value.trim().equalsIgnoreCase("")) { sheet0.addCell(new Label(colCount, rowCount, value, getCellFormat2())); } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2())); } } else { sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2())); } colCount++; } } rowCount++; } } } } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); } outputReportWorkbook.write(); outputReportWorkbook.close(); fileName = selProgram.getName() + ".xls"; File outputReportFile = new File(outputReportPath); inputStream = new BufferedInputStream(new FileInputStream(outputReportFile)); outputReportFile.deleteOnExit(); }