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);
}
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);
}
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;
}
Aggregations