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 $map directive proposal #1

Closed
ir4y opened this issue Sep 5, 2023 · 4 comments
Closed

Alternative to JUTE $map directive proposal #1

ir4y opened this issue Sep 5, 2023 · 4 comments
Assignees

Comments

@ir4y
Copy link
Member

ir4y commented Sep 5, 2023

Use FHIRPath as a key for array:

{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [{
        "request": {
            "url": "{{ '/Patient/' + QuestionnaireResponse.repeat(item).where(linkId='patientId').answer.valueString }}",
            "method": "PATCH"
        },
        "resource": {
            "telecom": {
                "{{ QuestionnaireResponse.repeat(item).where(linkId='phone-group') }}": { //<-<-<-<-<-<-<-<-
                    "system": "phone",
                    "use": "{{ item.where(linkId='phone-type').answer.valueString }}",
                    "value": "{{ item.where(linkId='phone-number').answer.valueString }}"
                }
            }
        }
    }]
}

https://github.com/beda-software/FHIRPathMappingLanguage/blob/main/examples/repeatable/fhirpathmap.json#L11

@ruscoder
Copy link
Member

ruscoder commented Sep 5, 2023

How to deal with mapping values from multiple QR fields into one array attribute, let's say I want to populatetelecom field with multiple emails (linkId=email-group) and multiple phone number (linkId=phone-group)?

I can suggest, something like:

{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [{
        "request": {
            "url": "{{ '/Patient/' + QuestionnaireResponse.repeat(item).where(linkId='patientId').answer.valueString }}",
            "method": "PATCH"
        },
        "resource": {
            "telecom": [
                {
                    "{{ QuestionnaireResponse.repeat(item).where(linkId='phone-group') }}": { //<-<-<-<-<-<-<-<-
                        "system": "phone",
                        "use": "{{ item.where(linkId='phone-type').answer.valueString }}",
                        "value": "{{ item.where(linkId='phone-number').answer.valueString }}"
                    }
                },
                {
                    "{{ QuestionnaireResponse.repeat(item).where(linkId='email-group') }}": { //<-<-<-<-<-<-<-<-
                        "system": "email",
                        "use": "{{ item.where(linkId='email-type').answer.valueString }}",
                        "value": "{{ item.where(linkId='email').answer.valueString }}"
                    }
                },
            ]
        }
    }]
}

For one hardcoded telecom:

{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [{
        "request": {
            "url": "{{ '/Patient/' + QuestionnaireResponse.repeat(item).where(linkId='patientId').answer.valueString }}",
            "method": "PATCH"
        },
        "resource": {
            "telecom": [
                {
                    "system": "phone",
                    "use": "{{ QuestionnaireResponse.repeat(item).where(linkId='phone-group').where(linkId='phone-type').answer.valueString }}",
                    "value": "{{ QuestionnaireResponse.repeat(item).where(linkId='phone-group').where(linkId='phone-number').answer.valueString }}"
                },
            ]
        }
    }]
}

So, if the key contains expression, it should be mapped to array of objects.

@ir4y
Copy link
Member Author

ir4y commented Sep 6, 2023

Another possible approach that leverages https://shopify.github.io/liquid/tags/iteration/#for
An array element could be a JSON object with a single key. The key is a liquid tag that describes the iteration logic.
All resulting elements will be added to the parenting array:

{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [{
        "request": {
            "url": "{{ '/Patient/' + QuestionnaireResponse.repeat(item).where(linkId='patientId').answer.valueString }}",
            "method": "PATCH"
        },
        "resource": {
            "telecom": [{
                "{% for item in QuestionnaireResponse.repeat(item).where(linkId='phone-group') %}": { 
                    "system": "phone",
                    "use": "{{ %item.where(linkId='phone-type').answer.valueString }}",
                    "value": "{{ %item.where(linkId='phone-number').answer.valueString }}"
                }
            },
           {
                "{% for item in QuestionnaireResponse.repeat(item).where(linkId='email-group') %}": { 
                    "system": "email",
                    "use": "{{ %item.where(linkId='email-type').answer.valueString }}",
                    "value": "{{ %item.where(linkId='email-number').answer.valueString }}"
                }
            },
           {
                "system": "other",
                "use": "icq",
                "value": "123321231"
           }]
        }
    }]
}

@ir4y
Copy link
Member Author

ir4y commented Nov 1, 2023

As an alternative approach we can use an extension, please check #4 for more details.

@ruscoder
Copy link
Member

I've added an additional explicit iteration logic using the for block, the tests are available here

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

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