Search in sources :

Example 16 with ProgramStageInstance

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

the class AbstractEventService method updateEventForEventDate.

@Override
public void updateEventForEventDate(Event event) {
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getEvent());
    if (programStageInstance == null) {
        return;
    }
    Date executionDate = new Date();
    if (event.getEventDate() != null) {
        executionDate = DateUtils.parseDate(event.getEventDate());
    }
    if (event.getStatus() == EventStatus.COMPLETED) {
        programStageInstance.setStatus(EventStatus.COMPLETED);
    } else {
        programStageInstance.setStatus(EventStatus.VISITED);
    }
    ImportOptions importOptions = new ImportOptions();
    OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), event.getOrgUnit());
    if (organisationUnit == null) {
        organisationUnit = programStageInstance.getOrganisationUnit();
    }
    programStageInstance.setOrganisationUnit(organisationUnit);
    programStageInstance.setExecutionDate(executionDate);
    programStageInstanceService.updateProgramStageInstance(programStageInstance);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Date(java.util.Date) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 17 with ProgramStageInstance

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

the class AbstractEventService method updateEventForNote.

@Override
public void updateEventForNote(Event event) {
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getEvent());
    if (programStageInstance == null) {
        return;
    }
    saveTrackedEntityComment(programStageInstance, event, getStoredBy(event, null, currentUserService.getCurrentUser()));
}
Also used : ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 18 with ProgramStageInstance

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

the class PdfDataEntryFormImportUtil method addNewProgramStageInstance.

private int addNewProgramStageInstance(int programStageId, int organisationUnitId, Date executionDate) throws Exception {
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    if (organisationUnit == null) {
        throw new Exception("Invalid organisation unit identifier: " + organisationUnitId);
    }
    ProgramStage programStage = programStageService.getProgramStage(programStageId);
    Program program = programStage.getProgram();
    ProgramInstance programInstance = programInstanceService.getProgramInstances(program).iterator().next();
    ProgramStageInstance programStageInstance = new ProgramStageInstance();
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setProgramStage(programStage);
    programStageInstance.setDueDate(executionDate);
    programStageInstance.setExecutionDate(executionDate);
    programStageInstance.setOrganisationUnit(organisationUnit);
    return programStageInstanceService.addProgramStageInstance(programStageInstance);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 19 with ProgramStageInstance

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

the class ActivityReportingServiceImpl method getAllActivityPlan.

@Override
public ActivityPlan getAllActivityPlan(OrganisationUnit unit, String localeString) {
    List<Activity> items = new ArrayList<>();
    TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams();
    param.addOrganisationUnit(unit);
    Grid trackedEntityDrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
    List<List<Object>> entityInstanceList = trackedEntityDrid.getRows();
    for (List<Object> entityInstance : entityInstanceList) {
        TrackedEntityInstance trackedEntityInstance = entityInstanceService.getTrackedEntityInstance(entityInstance.get(0).toString());
        for (ProgramStageInstance programStageInstance : programStageInstanceService.getProgramStageInstances(trackedEntityInstance, EventStatus.ACTIVE)) {
            items.add(getActivity(programStageInstance, false));
        }
    }
    if (items.isEmpty()) {
        return null;
    }
    Collections.sort(items, activityComparator);
    return new ActivityPlan(items);
}
Also used : Grid(org.hisp.dhis.common.Grid) ActivityPlan(org.hisp.dhis.api.mobile.model.ActivityPlan) ArrayList(java.util.ArrayList) Activity(org.hisp.dhis.api.mobile.model.Activity) List(java.util.List) PatientList(org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList) ArrayList(java.util.ArrayList) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 20 with ProgramStageInstance

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

ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)23 ArrayList (java.util.ArrayList)10 ProgramInstance (org.hisp.dhis.program.ProgramInstance)9 Date (java.util.Date)8 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 ProgramStage (org.hisp.dhis.program.ProgramStage)7 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)7 Program (org.hisp.dhis.program.Program)6 DataElement (org.hisp.dhis.dataelement.DataElement)5 TrackedEntityDataValue (org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue)5 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)4 HashSet (java.util.HashSet)3 List (java.util.List)3 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)3 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)2 Activity (org.hisp.dhis.api.mobile.model.Activity)2 ActivityPlan (org.hisp.dhis.api.mobile.model.ActivityPlan)2