diff --git a/src/core_modules/capture-core/components/WidgetProfile/DataEntry/FormFoundation/DataElement.tsx b/src/core_modules/capture-core/components/WidgetProfile/DataEntry/FormFoundation/DataElement.tsx index d536f9e699..6e3c81eafd 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/DataEntry/FormFoundation/DataElement.tsx +++ b/src/core_modules/capture-core/components/WidgetProfile/DataEntry/FormFoundation/DataElement.tsx @@ -350,6 +350,10 @@ export const buildDataElement = ( return null; } + if (trackedEntityAttribute.access?.read === false) { + return null; + } + return trackedEntityAttribute.valueType === dataElementTypes.DATE ? buildDateDataElement(optionSets, programTrackedEntityAttribute, trackedEntityAttribute, querySingleResource) : buildBaseDataElement( diff --git a/src/core_modules/capture-core/components/WidgetProfile/DataEntry/FormFoundation/types.ts b/src/core_modules/capture-core/components/WidgetProfile/DataEntry/FormFoundation/types.ts index 5ad6c320b0..8d12506b09 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/DataEntry/FormFoundation/types.ts +++ b/src/core_modules/capture-core/components/WidgetProfile/DataEntry/FormFoundation/types.ts @@ -56,6 +56,9 @@ export type TrackedEntityAttribute = { unique?: boolean | null; orgunitScope?: boolean | null; pattern?: string | null; + access?: { + read?: boolean | null; + } | null; }; export type ProgramTrackedEntityAttribute = { diff --git a/src/core_modules/capture-core/components/WidgetProfile/hooks/hooks.types.ts b/src/core_modules/capture-core/components/WidgetProfile/hooks/hooks.types.ts index 47a7595bdb..21b7da4784 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/hooks/hooks.types.ts +++ b/src/core_modules/capture-core/components/WidgetProfile/hooks/hooks.types.ts @@ -31,6 +31,9 @@ export type InputProgramData = { }; valueType: string; unique: boolean; + access?: { + read?: boolean | null; + } | null; }; displayInList: boolean; }>; diff --git a/src/core_modules/capture-core/components/WidgetProfile/hooks/useApiProgram.ts b/src/core_modules/capture-core/components/WidgetProfile/hooks/useApiProgram.ts index ada6c9dde0..08d1e1affd 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/hooks/useApiProgram.ts +++ b/src/core_modules/capture-core/components/WidgetProfile/hooks/useApiProgram.ts @@ -21,7 +21,7 @@ const fields = 'options[id,displayName,code,style, translations]]]]],' + 'programTrackedEntityAttributes[trackedEntityAttribute[id,displayName,displayShortName,displayFormName,' + 'displayDescription,valueType,optionSetValue,unique,orgunitScope,pattern,translations[property,locale,value],' + - 'optionSet[id,displayName,version,valueType,options[id,displayName,name,code,style,translations]]],' + + 'optionSet[id,displayName,version,valueType,options[id,displayName,name,code,style,translations]],access[read]],' + 'displayInList,searchable,mandatory,renderOptionsAsRadio,allowFutureDate],' + 'trackedEntityType[id,access,displayName,allowAuditLog,minAttributesRequiredToSearch,featureType,' + 'trackedEntityTypeAttributes[trackedEntityAttribute[id],displayInList,mandatory,searchable],' + diff --git a/src/core_modules/capture-core/components/WidgetProfile/hooks/useClientAttributesWithSubvalues.ts b/src/core_modules/capture-core/components/WidgetProfile/hooks/useClientAttributesWithSubvalues.ts index 9253d935b4..c4317b860f 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/hooks/useClientAttributesWithSubvalues.ts +++ b/src/core_modules/capture-core/components/WidgetProfile/hooks/useClientAttributesWithSubvalues.ts @@ -31,8 +31,12 @@ export const useClientAttributesWithSubvalues = ( async (promisedAcc: Promise, currentTEA) => { const { displayInList, - trackedEntityAttribute: { id, optionSet, valueType, unique, displayFormName }, + trackedEntityAttribute: { id, optionSet, valueType, unique, displayFormName, access }, } = currentTEA; + const acc = await promisedAcc; + if (access?.read === false) { + return acc; + } const foundAttribute = trackedEntityInstanceAttributes?.find(item => item.attribute === id); let value; if (foundAttribute) { @@ -52,8 +56,6 @@ export const useClientAttributesWithSubvalues = ( } } - const acc = await promisedAcc; - if (isMultiTextWithoutOptionset(valueType, optionSet)) { log.error(errorCreator(MULIT_TEXT_WITH_NO_OPTIONS_SET)({ optionSet })); return acc;