Search in sources :

Example 11 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection 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)

Example 12 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.

the class DefaultProgramService method getProgramLWUIT.

@Override
public org.hisp.dhis.api.mobile.model.LWUITmodel.Program getProgramLWUIT(int programId) {
    org.hisp.dhis.program.Program program = programService.getProgram(programId);
    org.hisp.dhis.api.mobile.model.LWUITmodel.Program pr = new org.hisp.dhis.api.mobile.model.LWUITmodel.Program();
    pr.setId(program.getId());
    pr.setName(program.getName());
    pr.setType(program.getProgramType().getValue());
    pr.setVersion(program.getVersion());
    pr.setDateOfEnrollmentDescription(program.getEnrollmentDateLabel());
    pr.setDateOfIncidentDescription(program.getIncidentDateLabel());
    if (program.getTrackedEntity() != null && program.getTrackedEntity().getName() != null) {
        pr.setTrackedEntityName(program.getTrackedEntity().getName());
    }
    List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> prStgs = new ArrayList<>();
    for (org.hisp.dhis.program.ProgramStage programStage : program.getProgramStages()) {
        org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage prStg = new org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage();
        // add report date
        prStg.setReportDate("");
        prStg.setReportDateDescription(programStage.getExecutionDateLabel());
        prStg.setDueDate("");
        prStg.setId(programStage.getId());
        prStg.setName(programStage.getName());
        prStg.setRepeatable(programStage.getRepeatable());
        if (programStage.getStandardInterval() == null) {
            prStg.setStandardInterval(0);
        } else {
            prStg.setStandardInterval(programStage.getStandardInterval());
        }
        prStg.setCompleted(false);
        prStg.setSingleEvent(program.isWithoutRegistration());
        List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> des = new ArrayList<>();
        Set<ProgramStageDataElement> programStageDataElements = programStage.getProgramStageDataElements();
        for (ProgramStageDataElement programStageDataElement : programStageDataElements) {
            org.hisp.dhis.dataelement.DataElement dataElement = programStageDataElement.getDataElement();
            org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement de = ModelMapping.getDataElementLWUIT(dataElement);
            de.setCompulsory(programStageDataElement.isCompulsory());
            de.setNumberType(null);
            des.add(de);
        }
        prStg.setDataElements(des);
        // Set all program sections
        List<org.hisp.dhis.api.mobile.model.LWUITmodel.Section> mobileSections = new ArrayList<>();
        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 (org.hisp.dhis.dataelement.DataElement element : eachSection.getDataElements()) {
                    dataElementIds.add(element.getId());
                }
                mobileSection.setDataElementIds(dataElementIds);
                mobileSections.add(mobileSection);
            }
        }
        prStg.setSections(mobileSections);
        prStgs.add(prStg);
    }
    pr.setProgramStages(prStgs);
    List<ProgramTrackedEntityAttribute> programPatientAttributes = new ArrayList<>(program.getProgramAttributes());
    for (ProgramTrackedEntityAttribute ppa : programPatientAttributes) {
        pr.getProgramAttributes().add(this.getPatientAttributeForMobile(ppa));
    }
    if (program.getRelatedProgram() != null) {
        pr.setRelationshipText(program.getRelationshipText());
        pr.setRelatedProgramId(program.getRelatedProgram().getId());
        pr.setRelationshipType(program.getRelationshipType().getId());
    }
    return pr;
}
Also used : ArrayList(java.util.ArrayList) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) Program(org.hisp.dhis.api.mobile.model.Program) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramStage(org.hisp.dhis.api.mobile.model.ProgramStage)

Example 13 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.

the class DhisConvenienceTest method createProgramStageSection.

public static ProgramStageSection createProgramStageSection(char uniqueCharacter, Integer sortOrder) {
    ProgramStageSection section = new ProgramStageSection();
    section.setAutoFields();
    section.setName("ProgramStageSection" + uniqueCharacter);
    section.setSortOrder(sortOrder);
    return section;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection)

Aggregations

ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)13 DataElement (org.hisp.dhis.dataelement.DataElement)6 ArrayList (java.util.ArrayList)5 ProgramStage (org.hisp.dhis.program.ProgramStage)5 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)5 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)2 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 DataValue (org.hisp.dhis.api.mobile.model.DataValue)1 Program (org.hisp.dhis.api.mobile.model.Program)1 ProgramStage (org.hisp.dhis.api.mobile.model.ProgramStage)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 DataSet (org.hisp.dhis.dataset.DataSet)1 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 PeriodType (org.hisp.dhis.period.PeriodType)1 Program (org.hisp.dhis.program.Program)1