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

Alternative to JUTE $if derective proposal #2

Closed
ruscoder opened this issue Sep 5, 2023 · 6 comments
Closed

Alternative to JUTE $if derective proposal #2

ruscoder opened this issue Sep 5, 2023 · 6 comments
Assignees

Comments

@ruscoder
Copy link
Member

ruscoder commented Sep 5, 2023

It's not relevant for primitive types (str, number), because it might be expressed using FHIRpath iif().
For complex structures, I can suggest something like switch:

{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [{
        "request": {
            "url": "/Observation",
            "method": "POST"
        },
        "resource": {
            "code": {
                "{{ QuestionnaireResponse.repeat(item).where(linkId='my-id').exists() }}": {
                     "display": "Branch then"
                 },
                // ...another branches might be here...
                "{{ QuestionnaireResponse.repeat(item).where(linkId='my-id').exists().not() }}": {
                     "display": "Branch else"
                 }
            }
        }
    }]
}

For implementation, it means if an object contains expression-keys and all of them are evaluated to boolean (array of one boolean element), then it should be handled as the switch.

It differs from #1, because all expressions must return booleans. Of course, there's an edge case, when #1 should map array of booleans, but it's not the case of usage.

@ir4y
Copy link
Member

ir4y commented Sep 6, 2023

{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [{
        "request": {
            "url": "/Observation",
            "method": "POST"
        },
        "resource": {
            "code": {
                "{% if QuestionnaireResponse.repeat(item).where(linkId='my-id') = '1' %}": {
                     "display": "Branch then"
                 },
                "{% elsif QuestionnaireResponse.repeat(item).where(linkId='my-id').exists() = '2' %}": {
                     "display": "Branch two"
                 },
                "{% else %}": {
                    "display": "Branch else"
                }
            }
        }
    }]
}

@ir4y
Copy link
Member

ir4y commented Sep 6, 2023

{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [{
        "request": {
            "url": "/Observation",
            "method": "POST"
        },
        "resource": {
            "code": {
                "{% case QuestionnaireResponse.repeat(item).where(linkId='my-id') %}": {
                    "{% when '2' %}": { // '1' is a FHIRPath expression
                         "display": "Branch then"
                     },
                    "{% when '2' %}": { // '2' is a FHIRPath expression
                         "display": "Branch two"
                     },
                    "{% else %}": {
                        "display": "Branch else"
                    }
                }
            }
        }
    }]
}

@ir4y
Copy link
Member

ir4y commented Sep 6, 2023

Ordering issue for multiple elsif and when for case.
The possible solution is rid of elsif and allow one constants for case

@ir4y
Copy link
Member

ir4y commented Nov 1, 2023

Check if it is possible to use an extension to implement if and/or case logic (Check #4 for more details).

@ruscoder
Copy link
Member Author

I added support for if and else, the examples are available in tests

describe('If block', () => {

If/else block should not contain user-defined keys because it's fully replaced with if or else branch blocks.
In case else is missing for the false condition, the null will be returned.

The condition must be a single element with true or false, otherwise, an exception will be triggered. I think it's more obvious behavior than just returning else branch all the time. But it's not a final decision. So, let's think about it

@ruscoder
Copy link
Member Author

I've decided to adhere to fhirpath's iif behavior by using implicitly iif(expr, true, false) under the hood.

4809e3d

So, it works consistently with fhirpath conditions.

ruscoder added a commit that referenced this issue May 28, 2024
feat: add support for if, for, assign and merge

Closes #1 #2 #3 #7 #8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants