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