Search in sources :

Example 16 with ProgramStageDataElement

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

the class ActivityReportingServiceImpl method getDataElementsForMobile.

private List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> getDataElementsForMobile(ProgramStage programStage, ProgramStageInstance programStageInstance) {
    List<ProgramStageDataElement> programStageDataElements = new ArrayList<>(programStage.getProgramStageDataElements());
    List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> mobileDataElements = new ArrayList<>();
    for (ProgramStageDataElement programStageDataElement : programStageDataElements) {
        org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement mobileDataElement = new org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement();
        mobileDataElement.setId(programStageDataElement.getDataElement().getId());
        String dataElementName;
        if (programStageDataElement.getDataElement().getFormName() != null && !programStageDataElement.getDataElement().getFormName().trim().equals("")) {
            dataElementName = programStageDataElement.getDataElement().getFormName();
        } else {
            dataElementName = programStageDataElement.getDataElement().getName();
        }
        mobileDataElement.setName(dataElementName);
        mobileDataElement.setType(programStageDataElement.getDataElement().getValueType());
        // problem
        mobileDataElement.setCompulsory(programStageDataElement.isCompulsory());
        // mobileDataElement.setNumberType(
        // programStageDataElement.getDataElement().getNumberType() );
        // Value
        TrackedEntityDataValue patientDataValue = dataValueService.getTrackedEntityDataValue(programStageInstance, programStageDataElement.getDataElement());
        if (patientDataValue != null) {
            // Convert to standard date format before send to client
            if (ValueType.DATE == programStageDataElement.getDataElement().getValueType()) {
                mobileDataElement.setValue(PeriodUtil.convertDateFormat(patientDataValue.getValue()));
            } else {
                mobileDataElement.setValue(patientDataValue.getValue());
            }
        } else {
            mobileDataElement.setValue(null);
        }
        // Option set
        if (programStageDataElement.getDataElement().getOptionSet() != null) {
            mobileDataElement.setOptionSet(ModelMapping.getOptionSet(programStageDataElement.getDataElement()));
        } else {
            mobileDataElement.setOptionSet(null);
        }
        // Category Option Combo
        if (programStageDataElement.getDataElement().getCategoryCombos() != null) {
            mobileDataElement.setCategoryOptionCombos(ModelMapping.getCategoryOptionCombos(programStageDataElement.getDataElement()));
        } else {
            mobileDataElement.setCategoryOptionCombos(null);
        }
        mobileDataElements.add(mobileDataElement);
    }
    return mobileDataElements;
}
Also used : ArrayList(java.util.ArrayList) TrackedEntityDataValue(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement)

Example 17 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement 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 18 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement 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 19 with ProgramStageDataElement

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

the class NamebasedUtilsImpl method transformDataElementsToMobileModel.

@Override
public List<org.hisp.dhis.api.mobile.model.DataElement> transformDataElementsToMobileModel(List<ProgramStageDataElement> programStageDataElements) {
    List<org.hisp.dhis.api.mobile.model.DataElement> des = new ArrayList<>();
    for (ProgramStageDataElement programStagedataElement : programStageDataElements) {
        DataElement dataElement = programStagedataElement.getDataElement();
        org.hisp.dhis.api.mobile.model.DataElement de = ModelMapping.getDataElement(dataElement);
        de.setCompulsory(programStagedataElement.isCompulsory());
        des.add(de);
    }
    return des;
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList)

Example 20 with ProgramStageDataElement

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

the class NamebasedUtilsImpl method transformDataElementsToMobileModel.

@Override
public List<org.hisp.dhis.api.mobile.model.DataElement> transformDataElementsToMobileModel(Integer programStageId) {
    ProgramStage programStage = programStageService.getProgramStage(programStageId);
    List<org.hisp.dhis.api.mobile.model.DataElement> des = new ArrayList<>();
    List<ProgramStageDataElement> programStageDataElements = new ArrayList<>(programStage.getProgramStageDataElements());
    des = transformDataElementsToMobileModel(programStageDataElements);
    return des;
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage)

Aggregations

ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)43 DataElement (org.hisp.dhis.dataelement.DataElement)21 ProgramStage (org.hisp.dhis.program.ProgramStage)15 HashSet (java.util.HashSet)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)7 User (org.hisp.dhis.user.User)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Program (org.hisp.dhis.program.Program)6 Test (org.junit.jupiter.api.Test)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 List (java.util.List)4 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)4 Event (org.hisp.dhis.tracker.domain.Event)4 HashMap (java.util.HashMap)3 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 PeriodType (org.hisp.dhis.period.PeriodType)3