Search in sources :

Example 1 with ProgramStageInstanceVisitDateComparator

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Patient(org.hisp.dhis.api.mobile.model.LWUITmodel.Patient) ArrayList(java.util.ArrayList) ProgramStageInstanceVisitDateComparator(org.hisp.dhis.program.comparator.ProgramStageInstanceVisitDateComparator) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams)

Example 2 with ProgramStageInstanceVisitDateComparator

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;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ArrayList(java.util.ArrayList) ProgramStageInstanceVisitDateComparator(org.hisp.dhis.program.comparator.ProgramStageInstanceVisitDateComparator) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Aggregations

ArrayList (java.util.ArrayList)2 ProgramStage (org.hisp.dhis.program.ProgramStage)2 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 ProgramStageInstanceVisitDateComparator (org.hisp.dhis.program.comparator.ProgramStageInstanceVisitDateComparator)2 Patient (org.hisp.dhis.api.mobile.model.LWUITmodel.Patient)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.program.Program)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 ProgramInstanceQueryParams (org.hisp.dhis.program.ProgramInstanceQueryParams)1 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)1 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1