Search in sources :

Example 21 with ProgramStageInstance

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

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

the class SingleEventListener method registerEvent.

// -------------------------------------------------------------------------
// Supportive Methods
// -------------------------------------------------------------------------
private void registerEvent(Map<String, String> commandValuePairs, SMSCommand smsCommand, IncomingSms sms) {
    OrganisationUnit orgUnit = getOrganisationUnits(sms).iterator().next();
    List<ProgramInstance> programInstances = new ArrayList<>(programInstanceService.getProgramInstances(smsCommand.getProgram(), ProgramStatus.ACTIVE));
    if (programInstances.isEmpty()) {
        ProgramInstance pi = new ProgramInstance();
        pi.setEnrollmentDate(new Date());
        pi.setIncidentDate(new Date());
        pi.setProgram(smsCommand.getProgram());
        pi.setStatus(ProgramStatus.ACTIVE);
        programInstanceService.addProgramInstance(pi);
        programInstances.add(pi);
    } else if (programInstances.size() > 1) {
        update(sms, SmsMessageStatus.FAILED, false);
        sendFeedback("Multiple active program instances exists for program: " + smsCommand.getProgram().getUid(), sms.getOriginator(), ERROR);
        return;
    }
    ProgramInstance programInstance = null;
    programInstance = programInstances.get(0);
    ProgramStageInstance programStageInstance = new ProgramStageInstance();
    programStageInstance.setOrganisationUnit(orgUnit);
    programStageInstance.setProgramStage(smsCommand.getProgramStage());
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setExecutionDate(sms.getSentDate());
    programStageInstance.setDueDate(sms.getSentDate());
    programStageInstance.setAttributeOptionCombo(dataElementCategoryService.getDefaultDataElementCategoryOptionCombo());
    programStageInstance.setCompletedBy("DHIS 2");
    programStageInstanceService.addProgramStageInstance(programStageInstance);
    for (SMSCode smsCode : smsCommand.getCodes()) {
        TrackedEntityDataValue dataValue = new TrackedEntityDataValue();
        dataValue.setAutoFields();
        dataValue.setDataElement(smsCode.getDataElement());
        dataValue.setProgramStageInstance(programStageInstance);
        dataValue.setValue(commandValuePairs.get(smsCode.getCode()));
        trackedEntityDataValueService.saveTrackedEntityDataValue(dataValue);
    }
    update(sms, SmsMessageStatus.PROCESSED, true);
    sendFeedback(StringUtils.defaultIfEmpty(smsCommand.getSuccessMessage(), EVENT_REGISTERED), sms.getOriginator(), INFO);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ArrayList(java.util.ArrayList) TrackedEntityDataValue(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue) SMSCode(org.hisp.dhis.sms.command.code.SMSCode) Date(java.util.Date) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 23 with ProgramStageInstance

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

the class AuditController method getTrackedEntityDataValueAudit.

@RequestMapping(value = "trackedEntityDataValue", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> psi, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<DataElement> dataElements = getDataElements(de);
    List<ProgramStageInstance> programStageInstances = getProgramStageInstances(psi);
    List<TrackedEntityDataValueAudit> dataValueAudits;
    Pager pager = null;
    if (skipPaging) {
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
    } else {
        int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
        pager = new Pager(page, total, pageSize);
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityDataValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.filter(TrackedEntityDataValueAudit.class, dataValueAudits, fields).getChildren());
    return rootNode;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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