Structured Data Capture
3.0.0 - STU 3 International flag

Structured Data Capture, published by HL7 International / FHIR Infrastructure. This guide is not an authorized publication; it is the continuous build for version 3.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/sdc/ and changes regularly. See the Directory of published versions

: SDC Map population StructureMap example - JSON Representation

Page standards status: Informative

Raw json | Download


{
  "resourceType" : "StructureMap",
  "id" : "questionnaire-population-transform",
  "text" : {
    "status" : "generated",
    "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><pre class=\"fml\">\r\n<b>map</b><span style=\"color: navy\"> &quot;</span>http://hl7.org/fhir/uv/sdc/StructureMap/questionnaire-population-transform<span style=\"color: navy\">&quot; = &quot;</span>QuestionnairePopulationTransform<span style=\"color: navy\">&quot;\r\n\r\n</span><span style=\"color: navy\">// </span><span style=\"color: green\">Sample structure map showing process for auto-populating a QuestionnaireResponse from a query bundle</span>\r\n\r\n<b>uses</b><span style=\"color: navy\"> &quot;</span><a href=\"http://hl7.org/fhir/R4/bundle.html\" title=\"Bundle\">http://hl7.org/fhir/StructureDefinition/Bundle</a><span style=\"color: navy\">&quot; </span><b>as </b><b>source</b>\r\n<b>uses</b><span style=\"color: navy\"> &quot;</span><a href=\"http://hl7.org/fhir/R4/questionnaireresponse.html\" title=\"QuestionnaireResponse\">http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse</a><span style=\"color: navy\">&quot; </span><b>as </b><b>target</b>\r\n\r\n<b>group </b>main<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">src</span><span style=\"color: navy\"> : </span>Bundle, <b>target</b> <span style=\"color: maroon\">qr</span><span style=\"color: navy\"> : </span>QuestionnaireResponse<span style=\"color: navy\">)</span><span style=\"color: navy\"> {\r\n</span>  src<span style=\"color: navy\"><b> -&gt; </b></span>qr.questionnaire = <span style=\"color: blue\">'http://hl7.org/fhir/uv/sdc/Questionnaire/questionnaire-sdc-test-fhirpath-prepop-source-query'</span> <i>&quot;questionnaire&quot;</i><span style=\"color: navy\">;</span>\r\n  src<span style=\"color: navy\"><b> -&gt; </b></span>qr.status = <span style=\"color: blue\">'in-progress'</span> <i>&quot;status&quot;</i><span style=\"color: navy\">;</span>\r\n  src<span style=\"color: navy\"><b> -&gt; </b></span>qr.authored = <span style=\"color: navy\">(</span>now()<span style=\"color: navy\">)</span> <i>&quot;authored&quot;</i><span style=\"color: navy\">;</span>\r\n  src.entry first<b> as </b><span style=\"color: maroon\">patient</span><span style=\"color: navy\"><b> -&gt; </b></span> qr.subject<b> as </b><span style=\"color: maroon\">subject</span><span style=\"color: navy\">, </span> subject.reference = <span style=\"color: navy\">(</span>patient.resource.entry.fullUrl<span style=\"color: navy\">)</span> <i>&quot;subject&quot;</i><span style=\"color: navy\">;</span>\r\n  src<span style=\"color: navy\"><b> -&gt; </b></span> qr.item<b> as </b><span style=\"color: maroon\">grp</span><span style=\"color: navy\">, </span> grp.linkId = <span style=\"color: blue\">'grp'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    src<span style=\"color: navy\"><b> -&gt; </b></span> grp.item<b> as </b><span style=\"color: maroon\">partDetails</span><span style=\"color: navy\">, </span> partDetails.linkId = <span style=\"color: blue\">'part-details'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      src.entry first<b> as </b><span style=\"color: maroon\">patient</span><span style=\"color: navy\"><b> -&gt; </b></span><span style=\"color: maroon\">partDetails</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        patient.resource<b> as </b><span style=\"color: maroon\">patientRes</span><span style=\"color: navy\"><b> -&gt; </b></span> partDetails.item<b> as </b><span style=\"color: maroon\">participantId</span><span style=\"color: navy\">, </span> participantId.linkId = <span style=\"color: blue\">'participant-id'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          patientRes.entry<b> as </b><span style=\"color: maroon\">patientResEntry</span><span style=\"color: navy\"><b> -&gt; </b></span> participantId.answer<b> as </b><span style=\"color: maroon\">participantIdAnswer</span><span style=\"color: navy\">, </span> participantIdAnswer.value = <span style=\"color: navy\">(</span>patientResEntry.resource.id<span style=\"color: navy\">)</span> <i>&quot;participantIdValue&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;participantId&quot;</i><span style=\"color: navy\">;</span>\r\n        patient.resource<b> as </b><span style=\"color: maroon\">patientRes</span><span style=\"color: navy\"><b> -&gt; </b></span> partDetails.item<b> as </b><span style=\"color: maroon\">familyName</span><span style=\"color: navy\">, </span> familyName.linkId = <span style=\"color: blue\">'family-name'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          patientRes.entry<b> as </b><span style=\"color: maroon\">patientResEntry</span><span style=\"color: navy\"><b> -&gt; </b></span> familyName.answer<b> as </b><span style=\"color: maroon\">familyNameAnswer</span><span style=\"color: navy\">, </span> familyNameAnswer.value = <span style=\"color: navy\">(</span>patientResEntry.resource.name.first().family<span style=\"color: navy\">)</span> <i>&quot;familyNameValue&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;familyName&quot;</i><span style=\"color: navy\">;</span>\r\n        patient.resource<b> as </b><span style=\"color: maroon\">patientRes</span><span style=\"color: navy\"><b> -&gt; </b></span> partDetails.item<b> as </b><span style=\"color: maroon\">givenName</span><span style=\"color: navy\">, </span> givenName.linkId = <span style=\"color: blue\">'given-name'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          patientRes.entry<b> as </b><span style=\"color: maroon\">patientResEntry</span><span style=\"color: navy\"><b> -&gt; </b></span> givenName.answer<b> as </b><span style=\"color: maroon\">givenNameAnswer</span><span style=\"color: navy\">, </span> givenNameAnswer.value = <span style=\"color: navy\">(</span>patientResEntry.resource.name.first().given.aggregate(iif($total.empty(), $this, $total &amp; ' ' &amp; $this))<span style=\"color: navy\">)</span> <i>&quot;givenNameValue&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;givenName&quot;</i><span style=\"color: navy\">;</span>\r\n        patient.resource<b> as </b><span style=\"color: maroon\">patientRes</span><span style=\"color: navy\"><b> -&gt; </b></span> partDetails.item<b> as </b><span style=\"color: maroon\">dob</span><span style=\"color: navy\">, </span> dob.linkId = <span style=\"color: blue\">'dob'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          patientRes.entry<b> as </b><span style=\"color: maroon\">patientResEntry</span><span style=\"color: navy\"><b> -&gt; </b></span> dob.answer<b> as </b><span style=\"color: maroon\">dobAnswer</span><span style=\"color: navy\">, </span> dobAnswer.value = <span style=\"color: navy\">(</span>patientResEntry.resource.birthDate<span style=\"color: navy\">)</span> <i>&quot;dobValue&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;dob&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;patientDetails&quot;</i><span style=\"color: navy\">;</span>\r\n      src.entry<b> as </b><span style=\"color: maroon\">conditions</span><b> where </b>(resource.link.url.contains('/Condition?'))<span style=\"color: navy\"><b> -&gt; </b></span> partDetails.item<b> as </b><span style=\"color: maroon\">conditionItem</span><span style=\"color: navy\">, </span> conditionItem.linkId = <span style=\"color: blue\">'condition-count'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        conditions<span style=\"color: navy\"><b> -&gt; </b></span> conditionItem.answer<b> as </b><span style=\"color: maroon\">conditionCountAnswer</span><span style=\"color: navy\">, </span> conditionCountAnswer.value = <span style=\"color: navy\">(</span>conditions.resource.entry.count()<span style=\"color: navy\">)</span> <i>&quot;conditionCountAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;condition-count&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;part-details&quot;</i><span style=\"color: navy\">;</span>\r\n    src.entry<b> as </b><span style=\"color: maroon\">medications</span><b> where </b>(resource.link.url.contains('/MedicationStatement?'))<span style=\"color: navy\"><b> -&gt; </b></span><span style=\"color: maroon\">grp</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      medications.resource<b> as </b><span style=\"color: maroon\">medRes</span><span style=\"color: navy\"><b> -&gt; </b></span><span style=\"color: maroon\">grp</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        medRes.entry<b> as </b><span style=\"color: maroon\">med</span><b> where </b>(resource is MedicationStatement)<span style=\"color: navy\"><b> -&gt; </b></span> grp.item<b> as </b><span style=\"color: maroon\">medsItem</span><span style=\"color: navy\">, </span> medsItem.linkId = <span style=\"color: blue\">'meds'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          med.resource<b> as </b><span style=\"color: maroon\">medResource</span><span style=\"color: navy\"><b> -&gt; </b></span> medsItem.item<b> as </b><span style=\"color: maroon\">medsName</span><span style=\"color: navy\">, </span> medsName.linkId = <span style=\"color: blue\">'meds-name'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>            medResource.medication<b> as </b><span style=\"color: maroon\">medMedication</span><span style=\"color: navy\"><b> -&gt; </b></span> medsName.answer<b> as </b><span style=\"color: maroon\">medsNameAnswer</span><span style=\"color: navy\">, </span> medsNameAnswer.value = <span style=\"color: navy\">(</span>medMedication.select(iif(text, text, coding.display.first()))<span style=\"color: navy\">)</span> <i>&quot;medsNameAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;medsName&quot;</i><span style=\"color: navy\">;</span>\r\n          med.resource<b> as </b><span style=\"color: maroon\">medResource</span><span style=\"color: navy\"><b> -&gt; </b></span> medsItem.item<b> as </b><span style=\"color: maroon\">medsStatus</span><span style=\"color: navy\">, </span> medsStatus.linkId = <span style=\"color: blue\">'med-status'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>            medResource.medication<b> as </b><span style=\"color: maroon\">medsMedication</span><span style=\"color: navy\"><b> -&gt; </b></span> medsStatus.answer<b> as </b><span style=\"color: maroon\">medsStatusAnswer</span><span style=\"color: navy\">, </span> medsStatusAnswer.value = <span style=\"color: navy\">(</span>medResource.status<span style=\"color: navy\">)</span> <i>&quot;medsStatusAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;medsStatus&quot;</i><span style=\"color: navy\">;</span>\r\n          med.resource<b> as </b><span style=\"color: maroon\">medResource</span><b> where </b>(category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').exists())<span style=\"color: navy\"><b> -&gt; </b></span> medsItem.item<b> as </b><span style=\"color: maroon\">medsCategory</span><span style=\"color: navy\">, </span> medsCategory.linkId = <span style=\"color: blue\">'meds-category'</span><b> then</b><span style=\"color: navy\"> {\r\n</span>            medResource<span style=\"color: navy\"><b> -&gt; </b></span> medsCategory.answer<b> as </b><span style=\"color: maroon\">medsCategoryAnswer</span><span style=\"color: navy\">, </span> medsCategoryAnswer.value = <span style=\"color: navy\">(</span>medResource.category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').code.aggregate(iif($total.empty(), $this, $total &amp; ' ' &amp; $this))<span style=\"color: navy\">)</span> <i>&quot;medsCategoryAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;medsCategory&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;medItem&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;medEntry&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;meds&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;grp&quot;</i><span style=\"color: navy\">;</span>\r\n<span style=\"color: navy\">}\r\n\r\n</span></pre></div>"
  },
  "extension" : [
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg",
      "valueCode" : "fhir"
    }
  ],
  "url" : "http://hl7.org/fhir/uv/sdc/StructureMap/questionnaire-population-transform",
  "version" : "3.0.0",
  "name" : "QuestionnairePopulationTransform",
  "title" : "Questionnaire Population Transform",
  "status" : "draft",
  "experimental" : true,
  "date" : "2023-12-07T23:07:45+00:00",
  "publisher" : "HL7 International / FHIR Infrastructure",
  "contact" : [
    {
      "name" : "HL7 International / FHIR Infrastructure",
      "telecom" : [
        {
          "system" : "url",
          "value" : "http://www.hl7.org/Special/committees/fiwg"
        }
      ]
    },
    {
      "telecom" : [
        {
          "system" : "url",
          "value" : "http://www.hl7.org/Special/committees/fiwg"
        }
      ]
    }
  ],
  "description" : "Sample structure map showing process for auto-populating a QuestionnaireResponse from a query bundle",
  "jurisdiction" : [
    {
      "coding" : [
        {
          "system" : "http://unstats.un.org/unsd/methods/m49/m49.htm",
          "code" : "001",
          "display" : "World"
        }
      ]
    }
  ],
  "structure" : [
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Bundle",
      "mode" : "source"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse",
      "mode" : "target"
    }
  ],
  "group" : [
    {
      "name" : "main",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "src",
          "type" : "Bundle",
          "mode" : "source"
        },
        {
          "name" : "qr",
          "type" : "QuestionnaireResponse",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "questionnaire",
          "source" : [
            {
              "context" : "src"
            }
          ],
          "target" : [
            {
              "context" : "qr",
              "contextType" : "variable",
              "element" : "questionnaire",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "http://hl7.org/fhir/uv/sdc/Questionnaire/questionnaire-sdc-test-fhirpath-prepop-source-query"
                }
              ]
            }
          ]
        },
        {
          "name" : "status",
          "source" : [
            {
              "context" : "src"
            }
          ],
          "target" : [
            {
              "context" : "qr",
              "contextType" : "variable",
              "element" : "status",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "in-progress"
                }
              ]
            }
          ]
        },
        {
          "name" : "authored",
          "source" : [
            {
              "context" : "src"
            }
          ],
          "target" : [
            {
              "context" : "qr",
              "contextType" : "variable",
              "element" : "authored",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "now()"
                }
              ]
            }
          ]
        },
        {
          "name" : "subject",
          "source" : [
            {
              "context" : "src",
              "element" : "entry",
              "listMode" : "first",
              "variable" : "patient"
            }
          ],
          "target" : [
            {
              "context" : "qr",
              "contextType" : "variable",
              "element" : "subject",
              "variable" : "subject"
            },
            {
              "context" : "subject",
              "contextType" : "variable",
              "element" : "reference",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "patient.resource.entry.fullUrl"
                }
              ]
            }
          ]
        },
        {
          "name" : "grp",
          "source" : [
            {
              "context" : "src"
            }
          ],
          "target" : [
            {
              "context" : "qr",
              "contextType" : "variable",
              "element" : "item",
              "variable" : "grp"
            },
            {
              "context" : "grp",
              "contextType" : "variable",
              "element" : "linkId",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "grp"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "part-details",
              "source" : [
                {
                  "context" : "src"
                }
              ],
              "target" : [
                {
                  "context" : "grp",
                  "contextType" : "variable",
                  "element" : "item",
                  "variable" : "partDetails"
                },
                {
                  "context" : "partDetails",
                  "contextType" : "variable",
                  "element" : "linkId",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "part-details"
                    }
                  ]
                }
              ],
              "rule" : [
                {
                  "name" : "patientDetails",
                  "source" : [
                    {
                      "context" : "src",
                      "element" : "entry",
                      "listMode" : "first",
                      "variable" : "patient"
                    }
                  ],
                  "target" : [
                    {
                      "contextType" : "variable",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "partDetails"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "participantId",
                      "source" : [
                        {
                          "context" : "patient",
                          "element" : "resource",
                          "variable" : "patientRes"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "partDetails",
                          "contextType" : "variable",
                          "element" : "item",
                          "variable" : "participantId"
                        },
                        {
                          "context" : "participantId",
                          "contextType" : "variable",
                          "element" : "linkId",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueString" : "participant-id"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "participantIdValue",
                          "source" : [
                            {
                              "context" : "patientRes",
                              "element" : "entry",
                              "variable" : "patientResEntry"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "participantId",
                              "contextType" : "variable",
                              "element" : "answer",
                              "variable" : "participantIdAnswer"
                            },
                            {
                              "context" : "participantIdAnswer",
                              "contextType" : "variable",
                              "element" : "value",
                              "transform" : "evaluate",
                              "parameter" : [
                                {
                                  "valueString" : "patientResEntry.resource.id"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name" : "familyName",
                      "source" : [
                        {
                          "context" : "patient",
                          "element" : "resource",
                          "variable" : "patientRes"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "partDetails",
                          "contextType" : "variable",
                          "element" : "item",
                          "variable" : "familyName"
                        },
                        {
                          "context" : "familyName",
                          "contextType" : "variable",
                          "element" : "linkId",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueString" : "family-name"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "familyNameValue",
                          "source" : [
                            {
                              "context" : "patientRes",
                              "element" : "entry",
                              "variable" : "patientResEntry"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "familyName",
                              "contextType" : "variable",
                              "element" : "answer",
                              "variable" : "familyNameAnswer"
                            },
                            {
                              "context" : "familyNameAnswer",
                              "contextType" : "variable",
                              "element" : "value",
                              "transform" : "evaluate",
                              "parameter" : [
                                {
                                  "valueString" : "patientResEntry.resource.name.first().family"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name" : "givenName",
                      "source" : [
                        {
                          "context" : "patient",
                          "element" : "resource",
                          "variable" : "patientRes"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "partDetails",
                          "contextType" : "variable",
                          "element" : "item",
                          "variable" : "givenName"
                        },
                        {
                          "context" : "givenName",
                          "contextType" : "variable",
                          "element" : "linkId",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueString" : "given-name"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "givenNameValue",
                          "source" : [
                            {
                              "context" : "patientRes",
                              "element" : "entry",
                              "variable" : "patientResEntry"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "givenName",
                              "contextType" : "variable",
                              "element" : "answer",
                              "variable" : "givenNameAnswer"
                            },
                            {
                              "context" : "givenNameAnswer",
                              "contextType" : "variable",
                              "element" : "value",
                              "transform" : "evaluate",
                              "parameter" : [
                                {
                                  "valueString" : "patientResEntry.resource.name.first().given.aggregate(iif($total.empty(), $this, $total & ' ' & $this))"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name" : "dob",
                      "source" : [
                        {
                          "context" : "patient",
                          "element" : "resource",
                          "variable" : "patientRes"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "partDetails",
                          "contextType" : "variable",
                          "element" : "item",
                          "variable" : "dob"
                        },
                        {
                          "context" : "dob",
                          "contextType" : "variable",
                          "element" : "linkId",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueString" : "dob"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "dobValue",
                          "source" : [
                            {
                              "context" : "patientRes",
                              "element" : "entry",
                              "variable" : "patientResEntry"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "dob",
                              "contextType" : "variable",
                              "element" : "answer",
                              "variable" : "dobAnswer"
                            },
                            {
                              "context" : "dobAnswer",
                              "contextType" : "variable",
                              "element" : "value",
                              "transform" : "evaluate",
                              "parameter" : [
                                {
                                  "valueString" : "patientResEntry.resource.birthDate"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "condition-count",
                  "source" : [
                    {
                      "context" : "src",
                      "element" : "entry",
                      "variable" : "conditions",
                      "condition" : "(resource.link.url.contains('/Condition?'))"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "partDetails",
                      "contextType" : "variable",
                      "element" : "item",
                      "variable" : "conditionItem"
                    },
                    {
                      "context" : "conditionItem",
                      "contextType" : "variable",
                      "element" : "linkId",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "condition-count"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "conditionCountAnswer",
                      "source" : [
                        {
                          "context" : "conditions"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "conditionItem",
                          "contextType" : "variable",
                          "element" : "answer",
                          "variable" : "conditionCountAnswer"
                        },
                        {
                          "context" : "conditionCountAnswer",
                          "contextType" : "variable",
                          "element" : "value",
                          "transform" : "evaluate",
                          "parameter" : [
                            {
                              "valueString" : "conditions.resource.entry.count()"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "meds",
              "source" : [
                {
                  "context" : "src",
                  "element" : "entry",
                  "variable" : "medications",
                  "condition" : "(resource.link.url.contains('/MedicationStatement?'))"
                }
              ],
              "target" : [
                {
                  "contextType" : "variable",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "grp"
                    }
                  ]
                }
              ],
              "rule" : [
                {
                  "name" : "medEntry",
                  "source" : [
                    {
                      "context" : "medications",
                      "element" : "resource",
                      "variable" : "medRes"
                    }
                  ],
                  "target" : [
                    {
                      "contextType" : "variable",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "grp"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "medItem",
                      "source" : [
                        {
                          "context" : "medRes",
                          "element" : "entry",
                          "variable" : "med",
                          "condition" : "(resource is MedicationStatement)"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "grp",
                          "contextType" : "variable",
                          "element" : "item",
                          "variable" : "medsItem"
                        },
                        {
                          "context" : "medsItem",
                          "contextType" : "variable",
                          "element" : "linkId",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueString" : "meds"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "medsName",
                          "source" : [
                            {
                              "context" : "med",
                              "element" : "resource",
                              "variable" : "medResource"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "medsItem",
                              "contextType" : "variable",
                              "element" : "item",
                              "variable" : "medsName"
                            },
                            {
                              "context" : "medsName",
                              "contextType" : "variable",
                              "element" : "linkId",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueString" : "meds-name"
                                }
                              ]
                            }
                          ],
                          "rule" : [
                            {
                              "name" : "medsNameAnswer",
                              "source" : [
                                {
                                  "context" : "medResource",
                                  "element" : "medication",
                                  "variable" : "medMedication"
                                }
                              ],
                              "target" : [
                                {
                                  "context" : "medsName",
                                  "contextType" : "variable",
                                  "element" : "answer",
                                  "variable" : "medsNameAnswer"
                                },
                                {
                                  "context" : "medsNameAnswer",
                                  "contextType" : "variable",
                                  "element" : "value",
                                  "transform" : "evaluate",
                                  "parameter" : [
                                    {
                                      "valueString" : "medMedication.select(iif(text, text, coding.display.first()))"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name" : "medsStatus",
                          "source" : [
                            {
                              "context" : "med",
                              "element" : "resource",
                              "variable" : "medResource"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "medsItem",
                              "contextType" : "variable",
                              "element" : "item",
                              "variable" : "medsStatus"
                            },
                            {
                              "context" : "medsStatus",
                              "contextType" : "variable",
                              "element" : "linkId",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueString" : "med-status"
                                }
                              ]
                            }
                          ],
                          "rule" : [
                            {
                              "name" : "medsStatusAnswer",
                              "source" : [
                                {
                                  "context" : "medResource",
                                  "element" : "medication",
                                  "variable" : "medsMedication"
                                }
                              ],
                              "target" : [
                                {
                                  "context" : "medsStatus",
                                  "contextType" : "variable",
                                  "element" : "answer",
                                  "variable" : "medsStatusAnswer"
                                },
                                {
                                  "context" : "medsStatusAnswer",
                                  "contextType" : "variable",
                                  "element" : "value",
                                  "transform" : "evaluate",
                                  "parameter" : [
                                    {
                                      "valueString" : "medResource.status"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name" : "medsCategory",
                          "source" : [
                            {
                              "context" : "med",
                              "element" : "resource",
                              "variable" : "medResource",
                              "condition" : "(category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').exists())"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "medsItem",
                              "contextType" : "variable",
                              "element" : "item",
                              "variable" : "medsCategory"
                            },
                            {
                              "context" : "medsCategory",
                              "contextType" : "variable",
                              "element" : "linkId",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueString" : "meds-category"
                                }
                              ]
                            }
                          ],
                          "rule" : [
                            {
                              "name" : "medsCategoryAnswer",
                              "source" : [
                                {
                                  "context" : "medResource"
                                }
                              ],
                              "target" : [
                                {
                                  "context" : "medsCategory",
                                  "contextType" : "variable",
                                  "element" : "answer",
                                  "variable" : "medsCategoryAnswer"
                                },
                                {
                                  "context" : "medsCategoryAnswer",
                                  "contextType" : "variable",
                                  "element" : "value",
                                  "transform" : "evaluate",
                                  "parameter" : [
                                    {
                                      "valueString" : "medResource.category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').code.aggregate(iif($total.empty(), $this, $total & ' ' & $this))"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}