Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [DHIS2-15888] multi text element in program rules #3482

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('Post process rules effects', () => {
{ type: 'HIDEPROGRAMSTAGE', id: 'PUZaKR0Jh2k' },
{ id: 'SWfdBhglX0fk', type: 'HIDESECTION' },
{ id: 'w75KJ2mc4zz', type: 'ASSIGN', value: 'value1' },
{ id: 'wasdJ2mc4zz', type: 'ASSIGN', value: 'true' },
{ id: 'wasdJ2mc4zz', type: 'ASSIGN', value: 32 },
{ id: 'pjsdJ2mc4zz', type: 'ASSIGN', value: 'value1,value2' },
{ id: 'ky6dJ2mc4zz', type: 'ASSIGN', value: 'value1,value2' },
{
Expand Down Expand Up @@ -186,7 +186,7 @@ test('Post process rules effects', () => {
{
id: 'wasdJ2mc4zz',
type: 'ASSIGN',
value: null,
value: 32,
},
{
id: 'pjsdJ2mc4zz',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,7 @@ describe('Assign effects', () => {
fgrr9Dvnyt5: { id: 'fgrr9Dvnyt5', valueType: 'IMAGE' },
oZ3fhkd9taw: { id: 'oZ3fhkd9taw', valueType: 'UNKNOWN' },
hyur9Dvnyt5: { id: 'hyur9Dvnyt5', valueType: 'MULTI_TEXT', optionSetId: 'pC3N9N77UmT' },
ght5r9Dnyt5: { id: 'ght5r9Dnyt5', valueType: 'MULTI_TEXT', optionSetId: 'pC3N9N77UmT' },
};
const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' };
const optionSets = {
Expand Down Expand Up @@ -2729,6 +2730,12 @@ describe('Assign effects', () => {
dataElementId: 'hyur9Dvnyt5',
programRuleActionType: 'ASSIGN',
},
{
id: 'gty5r9Dvnyt5',
data: "'Female,Male,Female'",
dataElementId: 'ght5r9Dnyt5',
programRuleActionType: 'ASSIGN',
},
{
id: 'lopr9Dvnyt5',
data: 'username',
Expand Down Expand Up @@ -2884,6 +2891,12 @@ describe('Assign effects', () => {
type: 'ASSIGN',
value: 'Male,Female',
},
{
id: 'ght5r9Dnyt5',
targetDataType: 'dataElement',
type: 'ASSIGN',
value: 'Female,Male',
},
{
id: 'plor9Dvnyt5',
targetDataType: 'dataElement',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const dateMomentFormat = 'YYYY-MM-DD';

export const outputConverter: IConvertOutputRulesEffectsValue = {
convertText: (value: string): string => value,
convertMultiText: (value: string): string => value,
convertMultiText: (value: string): string => [...new Set(value.split(','))].join(','),
superskip marked this conversation as resolved.
Show resolved Hide resolved
convertLongText: (value: string): string => value,
convertLetter: (value: string): string => value,
convertPhoneNumber: (value: string): string => value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { OutputEffect, HideOutputEffect, AssignOutputEffect, OutputEffects
import { type RenderFoundation, dataElementTypes } from '../metaData';

const isValidOptionSet = (optionSets, effectValue) => {
superskip marked this conversation as resolved.
Show resolved Hide resolved
if (!optionSets || !optionSets.options || effectValue === null || effectValue === '') {
if (!optionSets.options || effectValue === null || effectValue === '') {
return false;
}
// Using == because effect.value is always a string whereas option.value can be a number
Expand Down Expand Up @@ -44,7 +44,7 @@ const postProcessAssignEffects = ({

// If a value gets assigned to an option set it must match one of its available options
assignValueEffects.map((effect) => {
if (!isValidOptionSet(optionSets[effect.id], effect.value)) {
if (optionSets[effect.id] && !isValidOptionSet(optionSets[effect.id], effect.value)) {
effect.value = null;
}
return effect;
Expand Down
Loading