use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method getDataElementsForMobile.
private List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> getDataElementsForMobile(ProgramStage programStage, ProgramStageInstance programStageInstance) {
List<ProgramStageDataElement> programStageDataElements = new ArrayList<>(programStage.getProgramStageDataElements());
List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> mobileDataElements = new ArrayList<>();
for (ProgramStageDataElement programStageDataElement : programStageDataElements) {
org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement mobileDataElement = new org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement();
mobileDataElement.setId(programStageDataElement.getDataElement().getId());
String dataElementName;
if (programStageDataElement.getDataElement().getFormName() != null && !programStageDataElement.getDataElement().getFormName().trim().equals("")) {
dataElementName = programStageDataElement.getDataElement().getFormName();
} else {
dataElementName = programStageDataElement.getDataElement().getName();
}
mobileDataElement.setName(dataElementName);
mobileDataElement.setType(programStageDataElement.getDataElement().getValueType());
// problem
mobileDataElement.setCompulsory(programStageDataElement.isCompulsory());
// mobileDataElement.setNumberType(
// programStageDataElement.getDataElement().getNumberType() );
// Value
TrackedEntityDataValue patientDataValue = dataValueService.getTrackedEntityDataValue(programStageInstance, programStageDataElement.getDataElement());
if (patientDataValue != null) {
// Convert to standard date format before send to client
if (ValueType.DATE == programStageDataElement.getDataElement().getValueType()) {
mobileDataElement.setValue(PeriodUtil.convertDateFormat(patientDataValue.getValue()));
} else {
mobileDataElement.setValue(patientDataValue.getValue());
}
} else {
mobileDataElement.setValue(null);
}
// Option set
if (programStageDataElement.getDataElement().getOptionSet() != null) {
mobileDataElement.setOptionSet(ModelMapping.getOptionSet(programStageDataElement.getDataElement()));
} else {
mobileDataElement.setOptionSet(null);
}
// Category Option Combo
if (programStageDataElement.getDataElement().getCategoryCombos() != null) {
mobileDataElement.setCategoryOptionCombos(ModelMapping.getCategoryOptionCombos(programStageDataElement.getDataElement()));
} else {
mobileDataElement.setCategoryOptionCombos(null);
}
mobileDataElements.add(mobileDataElement);
}
return mobileDataElements;
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class DefaultProgramService method getProgram.
@Override
public Program getProgram(int programId, String localeString) {
org.hisp.dhis.program.Program program = programService.getProgram(programId);
Program pr = new Program();
pr.setId(program.getId());
pr.setName(program.getName());
pr.setVersion(program.getVersion());
List<ProgramStage> prStgs = new ArrayList<>();
for (org.hisp.dhis.program.ProgramStage programStage : program.getProgramStages()) {
ProgramStage prStg = new ProgramStage();
prStg.setId(programStage.getId());
prStg.setName(programStage.getName());
List<DataElement> des = new ArrayList<>();
Set<ProgramStageDataElement> programStageDataElements = programStage.getProgramStageDataElements();
for (ProgramStageDataElement programStagedataElement : programStageDataElements) {
org.hisp.dhis.dataelement.DataElement dataElement = programStagedataElement.getDataElement();
DataElement de = ModelMapping.getDataElement(dataElement);
de.setCompulsory(programStagedataElement.isCompulsory());
des.add(de);
}
prStg.setDataElements(des);
prStgs.add(prStg);
}
pr.setProgramStages(prStgs);
return pr;
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class DefaultProgramService method getProgramLWUIT.
@Override
public org.hisp.dhis.api.mobile.model.LWUITmodel.Program getProgramLWUIT(int programId) {
org.hisp.dhis.program.Program program = programService.getProgram(programId);
org.hisp.dhis.api.mobile.model.LWUITmodel.Program pr = new org.hisp.dhis.api.mobile.model.LWUITmodel.Program();
pr.setId(program.getId());
pr.setName(program.getName());
pr.setType(program.getProgramType().getValue());
pr.setVersion(program.getVersion());
pr.setDateOfEnrollmentDescription(program.getEnrollmentDateLabel());
pr.setDateOfIncidentDescription(program.getIncidentDateLabel());
if (program.getTrackedEntity() != null && program.getTrackedEntity().getName() != null) {
pr.setTrackedEntityName(program.getTrackedEntity().getName());
}
List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> prStgs = new ArrayList<>();
for (org.hisp.dhis.program.ProgramStage programStage : program.getProgramStages()) {
org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage prStg = new org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage();
// add report date
prStg.setReportDate("");
prStg.setReportDateDescription(programStage.getExecutionDateLabel());
prStg.setDueDate("");
prStg.setId(programStage.getId());
prStg.setName(programStage.getName());
prStg.setRepeatable(programStage.getRepeatable());
if (programStage.getStandardInterval() == null) {
prStg.setStandardInterval(0);
} else {
prStg.setStandardInterval(programStage.getStandardInterval());
}
prStg.setCompleted(false);
prStg.setSingleEvent(program.isWithoutRegistration());
List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> des = new ArrayList<>();
Set<ProgramStageDataElement> programStageDataElements = programStage.getProgramStageDataElements();
for (ProgramStageDataElement programStageDataElement : programStageDataElements) {
org.hisp.dhis.dataelement.DataElement dataElement = programStageDataElement.getDataElement();
org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement de = ModelMapping.getDataElementLWUIT(dataElement);
de.setCompulsory(programStageDataElement.isCompulsory());
de.setNumberType(null);
des.add(de);
}
prStg.setDataElements(des);
// Set all program sections
List<org.hisp.dhis.api.mobile.model.LWUITmodel.Section> mobileSections = new ArrayList<>();
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 (org.hisp.dhis.dataelement.DataElement element : eachSection.getDataElements()) {
dataElementIds.add(element.getId());
}
mobileSection.setDataElementIds(dataElementIds);
mobileSections.add(mobileSection);
}
}
prStg.setSections(mobileSections);
prStgs.add(prStg);
}
pr.setProgramStages(prStgs);
List<ProgramTrackedEntityAttribute> programPatientAttributes = new ArrayList<>(program.getProgramAttributes());
for (ProgramTrackedEntityAttribute ppa : programPatientAttributes) {
pr.getProgramAttributes().add(this.getPatientAttributeForMobile(ppa));
}
if (program.getRelatedProgram() != null) {
pr.setRelationshipText(program.getRelationshipText());
pr.setRelatedProgramId(program.getRelatedProgram().getId());
pr.setRelationshipType(program.getRelationshipType().getId());
}
return pr;
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class NamebasedUtilsImpl method transformDataElementsToMobileModel.
@Override
public List<org.hisp.dhis.api.mobile.model.DataElement> transformDataElementsToMobileModel(List<ProgramStageDataElement> programStageDataElements) {
List<org.hisp.dhis.api.mobile.model.DataElement> des = new ArrayList<>();
for (ProgramStageDataElement programStagedataElement : programStageDataElements) {
DataElement dataElement = programStagedataElement.getDataElement();
org.hisp.dhis.api.mobile.model.DataElement de = ModelMapping.getDataElement(dataElement);
de.setCompulsory(programStagedataElement.isCompulsory());
des.add(de);
}
return des;
}
use of org.hisp.dhis.program.ProgramStageDataElement 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;
}
Aggregations