Search in sources :

Example 1 with ProgramStage

use of org.hisp.dhis.api.mobile.model.ProgramStage in project dhis2-core by dhis2.

the class DefaultProgramService method getProgram.

@Override
public Program getProgram(int programId, String localeString) {
    org.hisp.dhis.program.Program program = programService.getProgram(programId);
    Program pr = new Program();
    pr.setId(program.getId());
    pr.setName(program.getName());
    pr.setVersion(program.getVersion());
    List<ProgramStage> prStgs = new ArrayList<>();
    for (org.hisp.dhis.program.ProgramStage programStage : program.getProgramStages()) {
        ProgramStage prStg = new ProgramStage();
        prStg.setId(programStage.getId());
        prStg.setName(programStage.getName());
        List<DataElement> des = new ArrayList<>();
        Set<ProgramStageDataElement> programStageDataElements = programStage.getProgramStageDataElements();
        for (ProgramStageDataElement programStagedataElement : programStageDataElements) {
            org.hisp.dhis.dataelement.DataElement dataElement = programStagedataElement.getDataElement();
            DataElement de = ModelMapping.getDataElement(dataElement);
            de.setCompulsory(programStagedataElement.isCompulsory());
            des.add(de);
        }
        prStg.setDataElements(des);
        prStgs.add(prStg);
    }
    pr.setProgramStages(prStgs);
    return pr;
}
Also used : Program(org.hisp.dhis.api.mobile.model.Program) ArrayList(java.util.ArrayList) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.api.mobile.model.DataElement) ProgramStage(org.hisp.dhis.api.mobile.model.ProgramStage)

Example 2 with ProgramStage

use of org.hisp.dhis.api.mobile.model.ProgramStage 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)

Aggregations

ArrayList (java.util.ArrayList)2 Program (org.hisp.dhis.api.mobile.model.Program)2 ProgramStage (org.hisp.dhis.api.mobile.model.ProgramStage)2 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)2 DataElement (org.hisp.dhis.api.mobile.model.DataElement)1 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)1 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)1