use of org.hisp.dhis.program.comparator.ProgramStageInstanceVisitDateComparator in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method generateRepeatableEvent.
@Override
public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient generateRepeatableEvent(int orgUnitId, String eventInfo) throws NotAllowedException {
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(orgUnitId);
String[] keys = eventInfo.split("_");
ProgramStage programStage = programStageService.getProgramStage(Integer.parseInt(keys[4]));
int mobileProgramStageId = Integer.parseInt(keys[3]);
String nextDueDate = keys[2];
Program program = programService.getProgram(Integer.parseInt(keys[1]));
TrackedEntityInstance trackedEntityInstance = entityInstanceService.getTrackedEntityInstance(Integer.parseInt(keys[0]));
ProgramInstance programInstance = null;
ProgramStageInstance newProgramStageInstance = null;
if (mobileProgramStageId != 0) {
ProgramStageInstance oldProgramStageIntance = programStageInstanceService.getProgramStageInstance(mobileProgramStageId);
programInstance = oldProgramStageIntance.getProgramInstance();
newProgramStageInstance = new ProgramStageInstance(programInstance, oldProgramStageIntance.getProgramStage());
newProgramStageInstance.setDueDate(DateUtils.getMediumDate(nextDueDate));
} else {
programInstance = programInstanceService.getProgramInstances(new ProgramInstanceQueryParams().setTrackedEntityInstance(trackedEntityInstance).setProgram(program).setOrganisationUnitMode(OrganisationUnitSelectionMode.ALL)).iterator().next();
newProgramStageInstance = new ProgramStageInstance();
newProgramStageInstance.setProgramInstance(programInstance);
newProgramStageInstance.setProgramStage(programStage);
newProgramStageInstance.setDueDate(DateUtils.getMediumDate(nextDueDate));
newProgramStageInstance.setExecutionDate(DateUtils.getMediumDate(nextDueDate));
}
newProgramStageInstance.setOrganisationUnit(orgUnit);
programInstance.getProgramStageInstances().add(newProgramStageInstance);
List<ProgramStageInstance> proStageInstanceList = new ArrayList<>(programInstance.getProgramStageInstances());
Collections.sort(proStageInstanceList, new ProgramStageInstanceVisitDateComparator());
programInstance.getProgramStageInstances().removeAll(proStageInstanceList);
programInstance.getProgramStageInstances().addAll(proStageInstanceList);
programStageInstanceService.addProgramStageInstance(newProgramStageInstance);
programInstanceService.updateProgramInstance(programInstance);
TrackedEntityInstance tei = entityInstanceService.getTrackedEntityInstance(programInstance.getEntityInstance().getId());
org.hisp.dhis.api.mobile.model.LWUITmodel.Patient mobilePatient = getPatientModel(tei);
return mobilePatient;
}
use of org.hisp.dhis.program.comparator.ProgramStageInstanceVisitDateComparator in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method getMobileProgramStages.
private List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> getMobileProgramStages(ProgramInstance programInstance) {
List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> mobileProgramStages = new ArrayList<>();
List<ProgramStageInstance> proStageInstanceList = new ArrayList<>(programInstance.getProgramStageInstances());
Collections.sort(proStageInstanceList, new ProgramStageInstanceVisitDateComparator());
for (ProgramStageInstance eachProgramStageInstance : proStageInstanceList) {
// instance. This condition should be removed in the future
if (eachProgramStageInstance != null) {
ProgramStage programStage = eachProgramStageInstance.getProgramStage();
org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage mobileProgramStage = new org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage();
List<org.hisp.dhis.api.mobile.model.LWUITmodel.Section> mobileSections = new ArrayList<>();
mobileProgramStage.setId(eachProgramStageInstance.getId());
/* mobileProgramStage.setName( eachProgramStage.getName() ); */
mobileProgramStage.setName(programStage.getName());
// get report date
if (eachProgramStageInstance.getExecutionDate() != null) {
mobileProgramStage.setReportDate(DateUtils.getMediumDateString(eachProgramStageInstance.getExecutionDate()));
} else {
mobileProgramStage.setReportDate("");
}
if (programStage.getExecutionDateLabel() == null) {
mobileProgramStage.setReportDateDescription("Report Date");
} else {
mobileProgramStage.setReportDateDescription(programStage.getExecutionDateLabel());
}
// get due date
if (eachProgramStageInstance.getDueDate() != null) {
mobileProgramStage.setDueDate(DateUtils.getMediumDateString(eachProgramStageInstance.getDueDate()));
} else {
mobileProgramStage.setDueDate("");
}
// is repeatable
mobileProgramStage.setRepeatable(programStage.getRepeatable());
if (programStage.getStandardInterval() == null) {
mobileProgramStage.setStandardInterval(0);
} else {
mobileProgramStage.setStandardInterval(programStage.getStandardInterval());
}
// is completed
/*
* mobileProgramStage.setCompleted(
* checkIfProgramStageCompleted( patient,
* programInstance.getProgram(), programStage ) );
*/
mobileProgramStage.setCompleted(eachProgramStageInstance.isCompleted());
// is single event
mobileProgramStage.setSingleEvent(programInstance.getProgram().isWithoutRegistration());
// Set all data elements
mobileProgramStage.setDataElements(getDataElementsForMobile(programStage, eachProgramStageInstance));
// Set all program sections
if (programStage.getProgramStageSections().size() > 0) {
for (ProgramStageSection eachSection : programStage.getProgramStageSections()) {
org.hisp.dhis.api.mobile.model.LWUITmodel.Section mobileSection = new org.hisp.dhis.api.mobile.model.LWUITmodel.Section();
mobileSection.setId(eachSection.getId());
mobileSection.setName(eachSection.getName());
// Set all data elements' id, then we could have full
// from
// data element list of program stage
List<Integer> dataElementIds = new ArrayList<>();
for (DataElement dataElement : eachSection.getDataElements()) {
dataElementIds.add(dataElement.getId());
}
mobileSection.setDataElementIds(dataElementIds);
mobileSections.add(mobileSection);
}
}
mobileProgramStage.setSections(mobileSections);
mobileProgramStages.add(mobileProgramStage);
}
}
return mobileProgramStages;
}
Aggregations