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