Search in sources :

Example 36 with ProgramStage

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

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

the class ActivityReportingServiceImpl method enrollProgram.

@Override
public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient enrollProgram(String enrollInfo, List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> mobileProgramStageList, Date incidentDate) throws NotAllowedException {
    String[] enrollProgramInfo = enrollInfo.split("-");
    int patientId = Integer.parseInt(enrollProgramInfo[0]);
    int programId = Integer.parseInt(enrollProgramInfo[1]);
    TrackedEntityInstance patient = entityInstanceService.getTrackedEntityInstance(patientId);
    Program program = programService.getProgram(programId);
    ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(patient, program, new Date(), incidentDate, patient.getOrganisationUnit());
    Iterator<ProgramStage> programStagesIterator = program.getProgramStages().iterator();
    for (int i = 0; i < program.getProgramStages().size(); i++) {
        ProgramStage programStage = programStagesIterator.next();
        if (programStage.getAutoGenerateEvent()) {
            ProgramStageInstance programStageInstance = programStageInstanceService.createProgramStageInstance(programInstance, programStage, new Date(), incidentDate, patient.getOrganisationUnit());
            int programStageInstanceId = programStageInstance.getId();
            // Inject Datavalue avaiable on-the-fly
            if (mobileProgramStageList != null && mobileProgramStageList.size() > 0) {
                org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage mobileProgramStage = mobileProgramStageList.get(i);
                if (mobileProgramStage != null && mobileProgramStage.getDataElements().size() > 0) {
                    mobileProgramStage.setId(programStageInstanceId);
                    if (mobileProgramStage.isSingleEvent()) {
                        this.saveProgramStage(mobileProgramStage, patientId, patient.getOrganisationUnit().getId());
                    } else {
                        this.saveProgramStage(mobileProgramStage, patientId, 0);
                    }
                }
            }
            programInstance.getProgramStageInstances().add(programStageInstance);
        }
    }
    programInstanceService.updateProgramInstance(programInstance);
    patient.getProgramInstances().add(programInstance);
    entityInstanceService.updateTrackedEntityInstance(patient);
    patient = entityInstanceService.getTrackedEntityInstance(patientId);
    return getPatientModel(patient);
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 38 with ProgramStage

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

Example 39 with ProgramStage

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

the class DhisConvenienceTest method createProgram.

public static Program createProgram(char uniqueCharacter, Set<ProgramStage> programStages, Set<TrackedEntityAttribute> attributes, Set<OrganisationUnit> organisationUnits, DataElementCategoryCombo categoryCombo) {
    Program program = new Program();
    program.setAutoFields();
    program.setName("Program" + uniqueCharacter);
    program.setCode("ProgramCode" + uniqueCharacter);
    program.setShortName("ProgramShort" + uniqueCharacter);
    program.setDescription("Description" + uniqueCharacter);
    program.setEnrollmentDateLabel("DateOfEnrollmentDescription");
    program.setIncidentDateLabel("DateOfIncidentDescription");
    program.setProgramType(ProgramType.WITH_REGISTRATION);
    if (programStages != null) {
        for (ProgramStage programStage : programStages) {
            programStage.setProgram(program);
            program.getProgramStages().add(programStage);
        }
    }
    if (attributes != null) {
        for (TrackedEntityAttribute attribute : attributes) {
            ProgramTrackedEntityAttribute ptea = new ProgramTrackedEntityAttribute(program, attribute, false, false);
            ptea.setAutoFields();
            program.getProgramAttributes().add(ptea);
        }
    }
    if (organisationUnits != null) {
        program.getOrganisationUnits().addAll(organisationUnits);
    }
    if (categoryCombo != null) {
        program.setCategoryCombo(categoryCombo);
    } else if (categoryService != null) {
        program.setCategoryCombo(categoryService.getDefaultDataElementCategoryCombo());
    }
    return program;
}
Also used : Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 40 with ProgramStage

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

the class DhisConvenienceTest method createProgramStage.

public static ProgramStage createProgramStage(char uniqueCharacter, Set<DataElement> dataElements) {
    ProgramStage programStage = createProgramStage(uniqueCharacter, 0);
    if (dataElements != null) {
        int sortOrder = 1;
        for (DataElement dataElement : dataElements) {
            ProgramStageDataElement psd = createProgramStageDataElement(programStage, dataElement, sortOrder);
            psd.setAutoFields();
            programStage.getProgramStageDataElements().add(psd);
        }
    }
    return programStage;
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStage(org.hisp.dhis.program.ProgramStage)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)40 Program (org.hisp.dhis.program.Program)24 DataElement (org.hisp.dhis.dataelement.DataElement)13 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)10 ArrayList (java.util.ArrayList)7 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 PeriodType (org.hisp.dhis.period.PeriodType)6 Date (java.util.Date)5 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)5 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)5 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 List (java.util.List)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)3 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3