Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/main/java/org/hisp/dhis/api/ApiFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,26 @@ public class ApiFields {
authorities,organisationUnits[%2$s],dataViewOrganisationUnits[%2$s]""",
ID_EXT_FIELDS, ORG_UNIT_FIELDS);

/** Object style fields. */
public static final String OBJECT_STYLE_FIELDS = "color,icon";

/** Program stage data element fields. */
public static final String PROGRAM_STAGE_DATA_ELEMENT_FIELDS =
String.format(
"""
%1$s,programStage[%2$s],dataElement[%3$s],\
compulsory,displayInReports,skipSynchronization,skipAnalytics,sortOrder""",
compulsory,displayInReports,skipSynchronization,skipAnalytics,\
allowFutureDate,sortOrder""",
NAME_EXT_FIELDS, NAME_FIELDS, DATA_ELEMENT_FIELDS);

/** Tracked entity attribute fields. */
public static final String TRACKED_ENTITY_ATTRIBUTE_FIELDS =
String.format("%s,valueType,aggregationType,confidential,unique", NAME_FIELDS);
String.format("%s,valueType,aggregationType,confidential,unique,orgunitScope", NAME_FIELDS);

/** Tracked entity attribute extended fields. */
public static final String TRACKED_ENTITY_ATTRIBUTE_EXT_FIELDS =
String.format("%s,valueType,aggregationType,confidential,unique", NAME_EXT_FIELDS);
String.format(
"%s,valueType,aggregationType,confidential,unique,orgunitScope", NAME_EXT_FIELDS);

/** Tracked entity type fields. */
public static final String TRACKED_ENTITY_TYPE_FIELDS =
Expand Down Expand Up @@ -410,6 +415,7 @@ public class ApiFields {
programStages[%6$s],\
programTrackedEntityAttributes[%7$s],\
programRuleVariables[%8$s],\
style[%10$s],\
%9$s""",
NAME_EXT_FIELDS,
NAME_FIELDS,
Expand All @@ -419,7 +425,8 @@ public class ApiFields {
PROGRAM_STAGE_FIELDS,
PROGRAM_TRACKED_ENTITY_ATTRIBUTES_FIELDS,
PROGRAM_RULE_VARIABLE_FIELDS,
PROGRAM_SIMPLE_FIELDS);
PROGRAM_SIMPLE_FIELDS,
OBJECT_STYLE_FIELDS);

/** Program standard fields. */
public static final String PROGRAM_STD_FIELDS =
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/org/hisp/dhis/model/ObjectStyle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2004-2025, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class ObjectStyle implements Serializable {
@JsonProperty private String color;

@JsonProperty private String icon;
}
2 changes: 2 additions & 0 deletions src/main/java/org/hisp/dhis/model/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public class Program extends NameableObject {

@JsonProperty private FeatureType featureType;

@JsonProperty private ObjectStyle style;

public Program(String id, String name) {
this.id = id;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ public class ProgramStageDataElement extends NameableObject {

@JsonProperty private Boolean skipAnalytics;

@JsonProperty private Boolean allowFutureDate = false;

@JsonProperty private Integer sortOrder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class TrackedEntityAttribute extends NameableObject {

@JsonProperty private Boolean unique = false;

@JsonProperty private Boolean orgunitScope = false;

@JsonIgnore
public boolean isConfidentialNullSafe() {
return confidential != null && confidential;
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/hisp/dhis/ApiFieldsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void testProgramStageFields() {
legendSets[id,code,name,created,lastUpdated,\
attributeValues,shortName,description],\
optionSet[id,code,name,created,lastUpdated,attributeValues,translations,sharing,access,valueType,version]],\
compulsory,displayInReports,skipSynchronization,skipAnalytics,sortOrder],\
compulsory,displayInReports,skipSynchronization,skipAnalytics,allowFutureDate,sortOrder],\
programStageSections[id,code,name,created,lastUpdated,attributeValues,translations,sharing,access,\
shortName,description,formName,programStage[id,code,name,created,lastUpdated,\
attributeValues,shortName,description],sortOrder,\
Expand All @@ -71,7 +71,7 @@ void testProgramExtFields() {
trackedEntityType[id,code,name,created,lastUpdated,attributeValues,translations,sharing,access,shortName,description,formName,\
trackedEntityTypeAttributes[id,\
trackedEntityAttribute[id,code,name,created,lastUpdated,attributeValues,shortName,description,valueType,\
aggregationType,confidential,unique],displayInList,mandatory,searchable]],\
aggregationType,confidential,unique,orgunitScope],displayInList,mandatory,searchable]],\
categoryCombo[id,code,name,created,lastUpdated,attributeValues,shortName,description,\
categories[id,code,name,created,lastUpdated,attributeValues,translations,sharing,access,shortName,description,formName,dataDimensionType,dataDimension,\
categoryOptions[id,code,name,created,lastUpdated,attributeValues],\
Expand All @@ -88,7 +88,7 @@ void testProgramExtFields() {
aggregationType,valueType,domainType,url,categoryCombo[id,code,name,created,lastUpdated,attributeValues,shortName,description],\
legendSets[id,code,name,created,lastUpdated,attributeValues,shortName,description],\
optionSet[id,code,name,created,lastUpdated,attributeValues,translations,sharing,access,valueType,version]],\
compulsory,displayInReports,skipSynchronization,skipAnalytics,sortOrder],\
compulsory,displayInReports,skipSynchronization,skipAnalytics,allowFutureDate,sortOrder],\
programStageSections[id,code,name,created,lastUpdated,attributeValues,translations,sharing,access,\
shortName,description,formName,programStage[id,code,name,created,lastUpdated,attributeValues,shortName,description],\
sortOrder,dataElements[id,code,name,created,lastUpdated,attributeValues,shortName,description],\
Expand All @@ -100,15 +100,15 @@ void testProgramExtFields() {
programTrackedEntityAttributes[id,code,name,program[id,code,name,created,lastUpdated,\
attributeValues,shortName,description],\
trackedEntityAttribute[id,code,name,created,lastUpdated,attributeValues,shortName,\
description,valueType,aggregationType,confidential,unique],\
description,valueType,aggregationType,confidential,unique,orgunitScope],\
sortOrder,displayInList,mandatory,allowFutureDate,searchable],\
programRuleVariables[id,code,name,created,lastUpdated,attributeValues,translations,\
sharing,access,program[id,code,name,created,lastUpdated,attributeValues],\
programRuleVariableSourceType,valueType,programStage[id,code,name,created,\
lastUpdated,attributeValues],trackedEntityAttribute[id,code,name,created,\
lastUpdated,attributeValues],useCodeForOptionSet,\
dataElement[id,code,name,created,lastUpdated,attributeValues]],\
programType,\
style[color,icon],programType,\
enrollmentDateLabel,incidentDateLabel,enrollmentLabel,followUpLabel,\
orgUnitLabel,relationshipLabel,noteLabel,trackedEntityAttributeLabel,\
programStageLabel,eventLabel,\
Expand All @@ -132,7 +132,7 @@ void testProgramMinFields() {
programTrackedEntityAttributes[id,code,name,\
program[id,code,name,created,lastUpdated,attributeValues,shortName,description],\
trackedEntityAttribute[id,code,name,created,lastUpdated,attributeValues,shortName,\
description,valueType,aggregationType,confidential,unique],\
description,valueType,aggregationType,confidential,unique,orgunitScope],\
sortOrder,displayInList,mandatory,allowFutureDate,searchable],\
programType,\
enrollmentDateLabel,incidentDateLabel,enrollmentLabel,followUpLabel,\
Expand Down
18 changes: 16 additions & 2 deletions src/test/java/org/hisp/dhis/ProgramApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.function.Predicate;
import org.hisp.dhis.model.DataElement;
import org.hisp.dhis.model.FeatureType;
import org.hisp.dhis.model.ObjectStyle;
import org.hisp.dhis.model.OrgUnit;
import org.hisp.dhis.model.Program;
import org.hisp.dhis.model.ProgramAccessLevel;
Expand Down Expand Up @@ -93,6 +95,18 @@ void testSaveUpdateRemoveProgramObjects() {
assertEquals("dIFNZrYGcOB", saved.getId());
assertEquals("Address Book", saved.getName());

assertNotNull(saved.getStyle());
ObjectStyle objectStyle = saved.getStyle();
assertEquals("#64b5f6", objectStyle.getColor());
assertEquals("Address_Book", objectStyle.getIcon());

assertNotNull(saved.getProgramStages());
assertTrue(
saved.getProgramStages().stream()
.flatMap(ps -> ps.getProgramStageDataElements().stream())
.map(ProgramStageDataElement::getAllowFutureDate)
.allMatch(Predicate.isEqual(true)));

pr.setName("Yellow Pages");

ObjectsResponse updateResponse = dhis2.saveProgram(objects);
Expand Down Expand Up @@ -292,7 +306,7 @@ void testGetProgramExtChildProgramme() {
assertNotNull(pr.getCreated());
assertNotNull(pr.getLastUpdated());
assertEquals(ProgramType.WITH_REGISTRATION, pr.getProgramType());
assertEquals(ProgramAccessLevel.OPEN, pr.getAccessLevel());
assertNotNull(pr.getAccessLevel());
assertEquals(FeatureType.POINT, pr.getFeatureType());
assertNotNull(pr.getCategoryCombo());
assertNotEmpty(pr.getOrganisationUnits());
Expand Down Expand Up @@ -406,7 +420,7 @@ void testGetProgramStdChildProgramme() {
assertNotNull(pr.getCreated());
assertNotNull(pr.getLastUpdated());
assertEquals(ProgramType.WITH_REGISTRATION, pr.getProgramType());
assertEquals(ProgramAccessLevel.OPEN, pr.getAccessLevel());
assertNotNull(pr.getAccessLevel());
assertEquals(FeatureType.POINT, pr.getFeatureType());
assertNotNull(pr.getCategoryCombo());
assertEmpty(pr.getOrganisationUnits());
Expand Down
30 changes: 13 additions & 17 deletions src/test/java/org/hisp/dhis/TrackedEntityAttributeApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.List;
import org.hisp.dhis.model.AggregationType;
import org.hisp.dhis.model.ValueType;
import org.hisp.dhis.model.metadata.Metadata;
import org.hisp.dhis.model.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.query.Query;
import org.hisp.dhis.response.HttpStatus;
import org.hisp.dhis.response.Status;
import org.hisp.dhis.response.object.ObjectResponse;
import org.hisp.dhis.support.JsonClassPathFile;
import org.hisp.dhis.support.TestTags;
import org.hisp.dhis.util.UidUtils;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag(TestTags.INTEGRATION)
class TrackedEntityAttributeApiTest {
private static final String TEA_PRODUCT_NAME_FILE =
"metadata/tracked-entity-attribute-product-name.json";

@Test
void testGetTrackedEntityAttribute() {
Expand Down Expand Up @@ -79,21 +80,14 @@ void testGetTrackedEntityAttributes() {
void testCreateUpdateDeleteTrackedEntityAttributes() {
Dhis2 dhis2 = new Dhis2(TestFixture.DEFAULT_CONFIG);

String uidA = UidUtils.generateUid();
String uidB = UidUtils.generateUid();

TrackedEntityAttribute tea = new TrackedEntityAttribute();
tea.setName(uidA);
tea.setDescription(uidA);
tea.setCode(uidA);
tea.setShortName(uidA);
tea.setFormName(uidA);
tea.setValueType(ValueType.TEXT);
tea.setAggregationType(AggregationType.COUNT);
TrackedEntityAttribute productName =
JsonClassPathFile.fromJson(TEA_PRODUCT_NAME_FILE, TrackedEntityAttribute.class);

// Create

ObjectResponse createResp = dhis2.saveTrackedEntityAttribute(tea);
ObjectResponse createResp = dhis2.saveTrackedEntityAttribute(productName);

assertEquals(201, createResp.getHttpStatusCode().intValue(), createResp.toString());
assertEquals(HttpStatus.CREATED, createResp.getHttpStatus(), createResp.toString());
Expand All @@ -107,10 +101,12 @@ void testCreateUpdateDeleteTrackedEntityAttributes() {

TrackedEntityAttribute retrieved = dhis2.getTrackedEntityAttribute(teaId);

assertNotNull(tea);
assertNotNull(productName);
assertEquals(teaId, retrieved.getId());
assertEquals(tea.getFormName(), retrieved.getFormName());
assertEquals(tea.getShortName(), retrieved.getDescription());
assertEquals(productName.getFormName(), retrieved.getFormName());
assertEquals(productName.getShortName(), retrieved.getShortName());
assertEquals(productName.getDescription(), retrieved.getDescription());
assertEquals(productName.getOrgunitScope(), retrieved.getOrgunitScope());

retrieved.setName(uidB);

Expand All @@ -125,8 +121,8 @@ void testCreateUpdateDeleteTrackedEntityAttributes() {

// Get updated

tea = dhis2.getTrackedEntityAttribute(teaId);
assertNotNull(tea);
retrieved = dhis2.getTrackedEntityAttribute(teaId);
assertNotNull(retrieved);
assertEquals(teaId, retrieved.getId());
assertEquals(uidB, retrieved.getName());
assertNotNull(retrieved.getDescription());
Expand Down
8 changes: 7 additions & 1 deletion src/test/resources/metadata/program-address-book.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"trackedEntityType": {
"id": "nEenWmSyUEp"
},
"style": {
"color": "#64b5f6",
"icon": "Address_Book"
},
"programTrackedEntityAttributes": [
{
"id": "NkvU4urhVNv",
Expand Down Expand Up @@ -163,7 +167,8 @@
"compulsory": true,
"displayInReports": true,
"skipSynchronization": false,
"skipAnalytics": false
"allowFutureDate": true,
"skipAnalytics": false
},
{
"id": "Fnz6H9q2rKk",
Expand All @@ -176,6 +181,7 @@
"compulsory": true,
"displayInReports": true,
"skipSynchronization": false,
"allowFutureDate": true,
"skipAnalytics": false
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"id": "Y2UamzuFBVD",
"code": "PRODUCT_NAME",
"name": "Product Name",
"shortName": "Product Name",
"description": "Product Name Description",
"formName": "Product Name",
"aggregationType": "COUNT",
"valueType": "TEXT",
"unique": true,
"sharing": {
"external": false,
"users": {},
"userGroups": {},
"public": "r-------"
},
"orgunitScope": true,
"translations": [
{
"locale": "fr",
"property": "NAME",
"value": "Nom du produit"
},
{
"locale": "fr",
"property": "FORM_NAME",
"value": "Nom du produit"
},
{
"locale": "fr",
"property": "SHORT_NAME",
"value": "Nom du produit"
}
]
}
Loading