use of org.hisp.dhis.program.ProgramTrackedEntityAttribute in project dhis2-core by dhis2.
the class ProgramTrackedEntityAttributeGroupDocumentation method testAddAndRemoveMember.
@Test
public void testAddAndRemoveMember() throws Exception {
MockHttpSession session = getSession("ALL");
ProgramTrackedEntityAttribute attrA = createProgramTrackedEntityAttribute('A');
manager.save(attrA);
ProgramTrackedEntityAttributeGroup group = createProgramTrackedEntityAttributeGroup('A');
manager.save(group);
attrA.addGroup(group);
mvc.perform(post(schema.getRelativeApiEndpoint() + "/" + group.getUid() + "/attributes/" + attrA.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isNoContent());
mvc.perform(get(schema.getRelativeApiEndpoint() + "/{id}", group.getUid()).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.attributes.length()").value(1));
mvc.perform(delete(schema.getRelativeApiEndpoint() + "/" + group.getUid() + "/attributes/" + attrA.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isNoContent());
mvc.perform(get(schema.getRelativeApiEndpoint() + "/{id}", group.getUid()).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.attributes.length()").value(0));
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttribute in project dhis2-core by dhis2.
the class UpdateProgramAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
displayProvidedOtherFacility = (displayProvidedOtherFacility == null) ? false : displayProvidedOtherFacility;
displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
generateBydEnrollmentDate = (generateBydEnrollmentDate == null) ? false : generateBydEnrollmentDate;
ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
blockEntryForm = (blockEntryForm == null) ? false : blockEntryForm;
remindCompleted = (remindCompleted == null) ? false : remindCompleted;
selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
Program program = programService.getProgram(id);
program.setName(StringUtils.trimToNull(name));
program.setShortName(StringUtils.trimToNull(shortName));
program.setDescription(StringUtils.trimToNull(description));
program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
program.setProgramType(programType);
program.setDisplayIncidentDate(displayIncidentDate);
program.setOnlyEnrollOnce(onlyEnrollOnce);
program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
program.setSkipOffline(skipOffline);
program.setDisplayFrontPageList(displayFrontPageList);
program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
program.setCaptureCoordinates(captureCoordinates);
program.setExpiryDays(expiryDays);
program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
if (program.isRegistration()) {
program.setIgnoreOverdueEvents(ignoreOverdueEvents);
} else {
program.setIgnoreOverdueEvents(false);
}
periodTypeName = StringUtils.trimToNull(periodTypeName);
if (periodTypeName != null) {
PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
} else {
program.setExpiryPeriodType(null);
}
if (relationshipTypeId != null) {
RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
program.setRelationshipType(relationshipType);
program.setRelationshipFromA(relationshipFromA);
program.setRelationshipText(relationshipText);
Program relatedProgram = programService.getProgram(relatedProgramId);
program.setRelatedProgram(relatedProgram);
} else {
program.setRelationshipType(null);
program.setRelationshipFromA(null);
program.setRelationshipText(null);
program.setRelatedProgram(null);
}
if (trackedEntityId != null) {
TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
program.setTrackedEntity(trackedEntity);
} else if (program.getTrackedEntity() != null) {
program.setTrackedEntity(null);
}
if (program.getProgramAttributes() != null) {
program.getProgramAttributes().clear();
}
int index = 0;
for (String selectedPropertyId : selectedPropertyIds) {
String[] ids = selectedPropertyId.split("_");
if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
programAttribute.setAutoFields();
program.getProgramAttributes().add(programAttribute);
}
index++;
}
//TODO make more fine-grained
program.increaseVersion();
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(program, jsonAttributeValues);
}
if (categoryComboId != null) {
program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
}
if (workflowId != null && workflowId > 0) {
program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
} else {
program.setWorkflow(null);
}
programService.updateProgram(program);
return SUCCESS;
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttribute in project dhis2-core by dhis2.
the class AddProgramAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
onlyEnrollOnce = (onlyEnrollOnce == null) ? false : onlyEnrollOnce;
selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
Program program = new Program();
program.setName(StringUtils.trimToNull(name));
program.setShortName(StringUtils.trimToNull(shortName));
program.setDescription(StringUtils.trimToNull(description));
program.setVersion(1);
program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
program.setProgramType(programType);
program.setDisplayIncidentDate(displayIncidentDate);
program.setOnlyEnrollOnce(onlyEnrollOnce);
program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
program.setSkipOffline(skipOffline);
program.setDisplayFrontPageList(displayFrontPageList);
program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
program.setCaptureCoordinates(captureCoordinates);
program.setExpiryDays(expiryDays);
program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
if (programType == ProgramType.WITH_REGISTRATION) {
program.setIgnoreOverdueEvents(ignoreOverdueEvents);
} else {
program.setIgnoreOverdueEvents(false);
}
periodTypeName = StringUtils.trimToNull(periodTypeName);
if (periodTypeName != null) {
PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
} else {
program.setExpiryPeriodType(null);
}
if (relationshipTypeId != null) {
RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
program.setRelationshipType(relationshipType);
program.setRelationshipFromA(relationshipFromA);
program.setRelationshipText(relationshipText);
Program relatedProgram = programService.getProgram(relatedProgramId);
program.setRelatedProgram(relatedProgram);
} else {
program.setRelationshipType(null);
program.setRelationshipFromA(null);
program.setRelationshipText(null);
program.setRelatedProgram(null);
}
if (trackedEntityId != null) {
TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
program.setTrackedEntity(trackedEntity);
}
if (categoryComboId != null) {
program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
}
if (workflowId != null && workflowId > 0) {
program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
}
programService.addProgram(program);
int index = 0;
for (String selectedPropertyId : selectedPropertyIds) {
String[] ids = selectedPropertyId.split("_");
if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
programAttribute.setAutoFields();
program.getProgramAttributes().add(programAttribute);
}
index++;
}
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(program, jsonAttributeValues);
}
programService.updateProgram(program);
if (program.isWithoutRegistration()) {
ProgramStage programStage = new ProgramStage();
programStage.setName(name);
programStage.setDescription(description);
programStage.setProgram(program);
programStage.setMinDaysFromStart(0);
programStage.setAutoGenerateEvent(true);
programStage.setExecutionDateLabel(REPORT_DATE_DESCRIPTION);
programStageService.saveProgramStage(programStage);
}
if (program.isWithoutRegistration()) {
// Add a new program-instance
ProgramInstance programInstance = new ProgramInstance();
programInstance.setEnrollmentDate(new Date());
programInstance.setIncidentDate(new Date());
programInstance.setProgram(program);
programInstance.setStatus(ProgramStatus.ACTIVE);
programInstanceService.addProgramInstance(programInstance);
}
return SUCCESS;
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttribute in project dhis2-core by dhis2.
the class DefaultProgramService method getPatientAttributeForMobile.
private org.hisp.dhis.api.mobile.model.PatientAttribute getPatientAttributeForMobile(ProgramTrackedEntityAttribute ppa) {
TrackedEntityAttribute pa = ppa.getAttribute();
org.hisp.dhis.api.mobile.model.PatientAttribute mobileAttribute = new org.hisp.dhis.api.mobile.model.PatientAttribute();
mobileAttribute.setName(pa.getName());
mobileAttribute.setType(pa.getValueType());
mobileAttribute.setValue("");
if (ppa.isDisplayInList()) {
mobileAttribute.setDisplayedInList(true);
} else {
mobileAttribute.setDisplayedInList(false);
}
mobileAttribute.setMandatory(ppa.isMandatory());
if (pa.hasOptionSet()) {
OptionSet optionSet = new OptionSet();
if (pa.getOptionSet() != null) {
optionSet.setId(pa.getOptionSet().getId());
optionSet.setName(pa.getOptionSet().getName());
optionSet.setOptions(pa.getOptionSet().getOptionValues());
mobileAttribute.setOptionSet(optionSet);
}
}
return mobileAttribute;
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttribute 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;
}
Aggregations