@Override public String execute() throws Exception { DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay(); ProgramInstance programInstance = programInstanceService.getProgramInstance(programInstanceId); ProgramStage programStage = programStageService.getProgramStage(programStageId); patientId = programInstance.getPatient().getId(); programId = programInstance.getProgram().getId(); ProgramStageInstance programStageInstance = new ProgramStageInstance(); try { programStageInstance.setDueDate(sdf.parseDateTime(nextDueDate).toDate()); } catch (Exception e) { e.printStackTrace(); } programStageInstance.setProgramInstance(programInstance); programStageInstance.setProgramStage(programStage); programStageInstanceService.addProgramStageInstance(programStageInstance); return SUCCESS; }
@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; }