Skip to content

Question - Switch syntax support #31

Description

@ruscoder

If we need to map one value to another, I think we need an explicit structure, like:

display:
  "{% switch %myCoding.code %}":
    code1: Another Display 1
    code2: Another Display 2
    code3: Another Display 3
    code4: Another Display 4
    "{% default %}": Other

Currently, there are three workarounds to do it.

  1. Using fhirpath iif --- too difficult to read (wrong formatting to make it readable!)
iif(%myCoding.code = 'code1', 'Another Display 1',
  iif(%myCoding.code = 'code2', 'Another Display 2',
    iif(%myCoding.code = 'code3', 'Another Display 3',
       iif(%myCoding.code = 'code4', 'Another Display 4', 'Other')
    )
  )  
)
  1. Using FPML if/else --- looks not good and similar to option 1. The keys order might lost when formatted.
display:
  "{% if %myCoding.code = ''code1'' %}": Another Display 1
  "{% else %}":
    "{% if %myCoding.code = ''code2'' %}": Another Display 2
    "{% else %}":
      "{% if %myCoding.code = ''code3'' %}": Another Display 3
      "{% else %}":
        "{% if %myCoding.code = ''code4'' %}": Another Display 4
  1. Using if and first value --- the most readable option, but looks like a hack
"{% assign %}":
  displayValue:
    - "{% if %myCoding.code = 'code1' %}": "Another Display 1"
    - "{% if %myCoding.code = 'code2' %}": "Another Display 2"
    - "{% if %myCoding.code = 'code3' %}": "Another Display 3"
    - "{% if %myCoding.code = 'code4' %}": "Another Display 4"
    - Other
display: "{{ %displayValue }}"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions