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WAAa,EAAW,gBAAgB,KAE1C,EAAkB,QAChB,UAAY,EAAW,gBAAgB,MAI7C,EAAU,EAAK,QAAQ,KAAK,EAC9B,MAKwB,IAAvB,EAAK,OAAO,QACZ,EAAK,OAAO,GAAG,eAAe,gBAC9B,EAAK,OAAO,GAAG,eAAe,iBACjC,EAAU,EAAK,QAAU,EAAK,OAAO,GAAG,YACxC,EAAU,EAAK,OAAS,YACtB,EAAK,OAAO,GAAc,aAEhC,IAGG,CACT,CACE,MAAM,IAAI,MAAM,iCAAmC,EAEvD,CAWA,SAAS,0BAA0B,EAAuB,GACxD,GAAoB,OAAhB,EACF,OAAO,qBAAqB,EAAuB,EAAa,CAAC,EAIrE,CAt3BA,aAAa,CACX,iBACA,gBACA,kBACA,eACA,6BAm3Ba,CACb,gBAAiB,gBACjB,kBAAmB,kBACnB,wBAAyB,wBACzB,0BAA2B","file":"/npm/surveyjs-fhir@0.2.0/src/index.mjs","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/surveyjs-fhir@0.2.0/src/index.mjs\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*\n * SurveyJS-FHIR\n * (c) 2020 Duke Crucible\n * MIT license\n *\n * Converts JSON between SurveyJS and FHIR formats.\n */\n\n// We need survey-library from SurveyJS, but it doesn't matter which\n// way we get it.\nimport requireOneOf from 'require-one-of';\n\nrequireOneOf([\n  'survey-angular',\n  'survey-jquery',\n  'survey-knockout',\n  'survey-react',\n  'survey-vue']);\n\n/**\n * Convert a SurveyJS Questionnaire to a FHIR Questionnaire.\n *\n * @param {json} survey JSON representing a SurveyJS survey.\n * @param {string} fhirVersion The FHIR version of the result Questionnaire.\n *\n * @return {json} JSON representing an equivalent FHIR Questionnaire.\n */\nfunction toQuestionnaire(survey, fhirVersion) {\n  if (fhirVersion === 'R4') {\n    const questionnaireJson = {\n      'resourceType': 'Questionnaire',\n      'status': 'unknown',\n      'item': [],\n    };\n\n    // TODO:  visibleIf <-> FHIR.enableWhen and FHIR.enableBehavior need to be\n    //        done in a separate pass. This is because we won't know all of the\n    //        type mappings for the elements, which will require a first pass.\n    //        We will need to maintain a dict of the mappings between element\n    //        names and types. Further, we can only support simple clauses like\n    //        (question operand value) and all must be linked by only one of\n    //        \"and\" and \"or\" because of limitations of FHIR.\n    //        The right way to parse this is likely going to be through\n    //        SurveyJS's own conditionsParser:\n    //        https://github.com/surveyjs/survey-library/blob/master/src/conditionsParser.ts\n\n    if (survey.hasOwnProperty('pages')) {\n      survey.pages.forEach((page, pageIndex) => {\n        if (page.hasOwnProperty('name')) {\n          const childItems = [];\n\n          if (page.hasOwnProperty('elements')) {\n            page.elements.forEach((element, elementIndex) => {\n              if (element.hasOwnProperty('name') &&\n                  element.hasOwnProperty('type')) {\n                const childItem = {\n                  'linkId': element.name,\n                };\n\n                if (element.hasOwnProperty('title')) {\n                  childItem.text = element.title;\n                }\n\n                if (element.hasOwnProperty('readOnly')) {\n                  childItem.readOnly = element.readOnly;\n                }\n\n                if (element.hasOwnProperty('maxLength')) {\n                  childItem.maxLength = element.maxLength;\n                }\n\n                if (element.hasOwnProperty('isRequired')) {\n                  childItem.required = element.isRequired;\n                }\n\n                if (element.hasOwnProperty('visibleIf')) {\n                  throw new Error(\n                      'visibleIf is not yet supported: ' + element.name);\n                }\n\n                switch (element.type) {\n                  case 'text':\n                    if (element.hasOwnProperty('inputType')) {\n                      switch (element.inputType) {\n                        case 'number':\n                          childItem.type = 'decimal';\n\n                          if (element.hasOwnProperty('defaultValue')) {\n                            childItem.initial = [{\n                              'valueDecimal': element.defaultValue,\n                            }];\n                          }\n\n                          childItems.push(childItem);\n                          break;\n                        case 'date':\n                          childItem.type = 'date';\n\n                          if (element.hasOwnProperty('defaultValue')) {\n                            childItem.initial = [{\n                              'valueDate': element.defaultValue,\n                            }];\n                          }\n\n                          childItems.push(childItem);\n                          break;\n                        case 'datetime':\n                          childItem.type = 'dateTime';\n\n                          if (element.hasOwnProperty('defaultValue')) {\n                            childItem.initial = [{\n                              'valueDateTime': element.defaultValue,\n                            }];\n                          }\n\n                          childItems.push(childItem);\n                          break;\n                        case 'time':\n                          childItem.type = 'time';\n\n                          if (element.hasOwnProperty('defaultValue')) {\n                            childItem.initial = [{\n                              'valueTime': element.defaultValue,\n                            }];\n                          }\n\n                          childItems.push(childItem);\n                          break;\n                        case 'url':\n                          childItem.type = 'url';\n\n                          if (element.hasOwnProperty('defaultValue')) {\n                            childItem.initial = [{\n                              'valueUri': element.defaultValue,\n                            }];\n                          }\n\n                          childItems.push(childItem);\n                          break;\n                        default:\n                          throw new Error(\n                              'Unsupported string input type: ' +\n                              element.inputType);\n                          break;\n                      }\n                    } else {\n                      childItem.type = 'string';\n\n                      if (element.hasOwnProperty('defaultValue')) {\n                        childItem.initial = [{\n                          'valueString': element.defaultValue,\n                        }];\n                      }\n\n                      childItems.push(childItem);\n                    }\n                    break;\n                  case 'boolean':\n                    childItem.type = 'boolean';\n\n                    if (element.hasOwnProperty('defaultValue')) {\n                      childItem.initial = [{\n                        'valueBoolean': element.defaultValue,\n                      }];\n                    }\n\n                    childItems.push(childItem);\n                    break;\n                  case 'comment':\n                    childItem.type = 'text';\n\n                    if (element.hasOwnProperty('defaultValue')) {\n                      childItem.initial = [{\n                        'valueString': element.defaultValue,\n                      }];\n                    }\n\n                    childItems.push(childItem);\n                    break;\n                  case 'url':\n                    childItem.type = 'url';\n\n                    if (element.hasOwnProperty('defaultValue')) {\n                      childItem.initial = [{\n                        'valueUri': element.defaultValue,\n                      }];\n                    }\n\n                    childItems.push(childItem);\n                    break;\n                  case 'dropdown':\n                    if (element.hasOwnProperty('hasOther') &&\n                        element.hasOther) {\n                      childItem.type = 'open-choice';\n                    } else {\n                      childItem.type = 'choice';\n                    }\n\n                    const answerOptions = [];\n\n                    if (element.hasOwnProperty('choices')) {\n                      element.choices.forEach((option, optionIndex) => {\n                        const answerOption = {\n                          'valueCoding': {},\n                        };\n\n                        if (option.hasOwnProperty('value')) {\n                          answerOption.valueCoding.code = option.value;\n\n                          if (element.hasOwnProperty('defaultValue')) {\n                            if (option.value === element.defaultValue) {\n                              answerOption.initialSelected = true;\n                            }\n                          }\n                        }\n\n                        if (option.hasOwnProperty('text')) {\n                          answerOption.valueCoding.display = (\n                            option.text);\n                        }\n\n                        answerOptions.push(answerOption);\n                      });\n                    }\n\n                    childItem.answerOption = answerOptions;\n\n                    childItems.push(childItem);\n                    break;\n                  case 'file':\n                    childItem.type = 'attachment';\n\n                    childItems.push(childItem);\n                    break;\n                  default:\n                    throw new Error(\n                        'Unsupported survey element type: ' + element.type);\n                    break;\n                }\n              } else {\n                throw new Error(\n                    'Survey elements found missing a name or type.');\n              }\n            });\n          }\n\n          if (childItems.length > 0) {\n            const itemGroup = {\n              'linkId': page.name,\n              'type': 'group',\n              'item': childItems,\n            };\n\n            if (page.hasOwnProperty('title')) {\n              itemGroup.text = page.title;\n            }\n\n            questionnaireJson.item.push(itemGroup);\n          } else {\n            throw new Error('A page was found with no elements.');\n          }\n        } else {\n          throw new Error('A survey page had no name.');\n        }\n      });\n    } else {\n      console.warn(\n          'Survey in toQuestionnaire had no pages in it.  ' +\n          'Returning a blank FHIR questionnaire.');\n    }\n\n    return questionnaireJson;\n  } else {\n    throw new Error('FHIR version not implemented: ' + fhirVersion);\n  }\n}\n\n/**\n * Recursively convert a FHIR questionnaire or its child item into\n * a SurveyJS survey.\n *\n * @param {json} questionnaire JSON representing a FHIR\n *     Questionnaire or one of its child items.\n * @param {string} fhirVersion The FHIR version of the questionnaie.\n * @param {string} defaultTitle The default title to use for a SurveyJS\n *     page created if a suitable one is not found.\n *\n * @return {json} JSON representing an equivalent SurveyJS Questionnaire.\n */\nfunction unpackItemsRecursive(questionnaire, fhirVersion, defaultTitle=null) {\n  if (fhirVersion === 'R4') {\n    let pages = [];\n\n    if (questionnaire.hasOwnProperty('item')) {\n      const page = {};\n\n      // Get basic data for this page.\n      let title = defaultTitle;\n\n      // Root questionnaire\n      if (questionnaire.hasOwnProperty('title')) {\n        title = questionnaire.title;\n      }\n\n      // Child item-groups\n      if (questionnaire.hasOwnProperty('text')) {\n        title = questionnaire.text;\n      }\n\n      if (title) {\n        page.title = title;\n      }\n\n      if (questionnaire.hasOwnProperty('name')) {\n        page.name = questionnaire.name;\n      }\n\n      if (questionnaire.hasOwnProperty('linkId')) {\n        page.name = questionnaire.linkId;\n      }\n\n      const elements = [];\n      questionnaire.item.forEach((item, itemIndex) => {\n        if (item.hasOwnProperty('item')) {\n          // This is a group.  Unpack it using our current defaults.\n          pages = pages.concat(unpackItemsRecursive(\n              item, fhirVersion, title));\n        } else {\n          // This is an element.\n          const element = {};\n\n          // Get basic, universal information for this item.\n          // Root questionnaire\n          if (item.hasOwnProperty('name')) {\n            element.name = item.name;\n          }\n\n          // Child item-groups\n          if (item.hasOwnProperty('linkId')) {\n            element.name = item.linkId;\n          }\n\n          // Root questionnarie\n          if (item.hasOwnProperty('title')) {\n            element.title = item.title;\n          }\n\n          // Child item-groups\n          if (item.hasOwnProperty('text')) {\n            element.title = item.text;\n          }\n\n          if (item.hasOwnProperty('required')) {\n            element.isRequired = item.required;\n          }\n\n          if (item.hasOwnProperty('maxLength')) {\n            element.maxLength = item.maxLength;\n          }\n\n          if (item.hasOwnProperty('readOnly')) {\n            element.readOnly = item.readOnly;\n          }\n\n          // TODO:  Support FHIR enableWhen/enableBehavior.\n          // Going from FHIR to SurveyJS in this case should be much easier\n          // than from SurveyJS to FHIR.\n\n          switch (item.type) {\n            case 'decimal':\n              if (item.hasOwnProperty('initial') &&\n                  item.initial.length === 1 &&\n                  item.initial[0].hasOwnProperty('valueDecimal')) {\n                element.defaultValue = item.initial[0].valueDecimal;\n              }\n\n              element.type = 'text';\n              element.inputType = 'number';\n              elements.push(element);\n              break;\n            case 'date':\n              if (item.hasOwnProperty('initial') &&\n                  item.initial.length === 1 &&\n                  item.initial[0].hasOwnProperty('valueDate')) {\n                element.defaultValue = item.initial[0].valueDate;\n              }\n\n              element.type = 'text';\n              element.inputType = 'date';\n              elements.push(element);\n              break;\n            case 'dateTime':\n              if (item.hasOwnProperty('initial') &&\n                  item.initial.length === 1 &&\n                  item.initial[0].hasOwnProperty('valueDateTime')) {\n                element.defaultValue = item.initial[0].valueDateTime;\n              }\n\n              element.type = 'text';\n              element.inputType = 'datetime';\n              elements.push(element);\n              break;\n            case 'time':\n              if (item.hasOwnProperty('initial') &&\n                  item.initial.length === 1 &&\n                  item.initial[0].hasOwnProperty('valueTime')) {\n                element.defaultValue = item.initial[0].valueTime;\n              }\n\n              element.type = 'text';\n              element.inputType = 'time';\n              elements.push(element);\n              break;\n            case 'url':\n              if (item.hasOwnProperty('initial') &&\n                  item.initial.length === 1 &&\n                  item.initial[0].hasOwnProperty('valueUri')) {\n                element.defaultValue = item.initial[0].valueUri;\n              }\n\n              element.type = 'text';\n              element.inputType = 'url';\n              elements.push(element);\n              break;\n            case 'string':\n              if (item.hasOwnProperty('initial') &&\n                  item.initial.length === 1 &&\n                  item.initial[0].hasOwnProperty('valueString')) {\n                element.defaultValue = item.initial[0].valueString;\n              }\n\n              element.type = 'text';\n              elements.push(element);\n              break;\n            case 'boolean':\n              if (item.hasOwnProperty('initial') &&\n                  item.initial.length === 1 &&\n                  item.initial[0].hasOwnProperty('valueBoolean')) {\n                element.defaultValue = item.initial[0].valueBoolean;\n              }\n\n              element.type = 'boolean';\n              elements.push(element);\n              break;\n            case 'text':\n              if (item.hasOwnProperty('initial') &&\n                  item.initial.length === 1 &&\n                  item.initial[0].hasOwnProperty('valueString')) {\n                element.defaultValue = item.initial[0].valueString;\n              }\n\n              element.type = 'comment';\n              elements.push(element);\n              break;\n            case 'attachment':\n              element.type = 'file';\n              // Required, but no clear place to store this in FHIR.\n              element.maxSize = 0;\n              elements.push(element);\n              break;\n            case 'open-choice':\n              element.hasOther = true;\n            case 'choice':\n              element.type = 'dropdown';\n              let defaultValue = null;\n              const choices = [];\n\n              if (item.hasOwnProperty('answerOption')) {\n                item.answerOption.forEach((option, optionIndex) => {\n                  const choice = {};\n\n                  if (option.hasOwnProperty('valueInteger')) {\n                    choice.value = String(option.valueInteger);\n                    choice.text = String(option.valueInteger);\n                  }\n\n                  if (option.hasOwnProperty('valueDate')) {\n                    choice.value = String(option.valueDate);\n                    choice.text = String(option.valueDate);\n                  }\n\n                  if (option.hasOwnProperty('valueTime')) {\n                    choice.value = String(option.valueTime);\n                    choice.text = String(option.valueTime);\n                  }\n\n                  if (option.hasOwnProperty('valueString')) {\n                    choice.value = String(option.valueString);\n                    choice.text = String(option.valueString);\n                  }\n\n                  if (option.hasOwnProperty('valueCoding')) {\n                    if (option.valueCoding.hasOwnProperty('code')) {\n                      choice.value = option.valueCoding.code;\n                      choice.text = option.valueCoding.code;\n                    }\n\n                    if (option.valueCoding.hasOwnProperty('display')) {\n                      choice.text = option.valueCoding.display;\n\n                      if (!(choice.hasOwnProperty('value'))) {\n                        choice.value = option.valueCoding.display;\n                      }\n                    }\n                  }\n\n                  if (choice.hasOwnProperty('value')) {\n                    if (option.hasOwnProperty('initialSelected')) {\n                      if (option.initialSelected) {\n                        defaultValue = choice.value;\n                      }\n                    }\n                    choices.push(choice);\n                  } else {\n                    throw new Error(\n                        'Questionnaire dropdowns had invalid options.');\n                  }\n                });\n\n                element.choices = choices;\n              }\n\n              if (defaultValue) {\n                element.defaultValue = defaultValue;\n              }\n              elements.push(element);\n              break;\n            default:\n              throw new Error(\n                  'Unsupported questionnaire item type: ' + item.type);\n              break;\n          }\n        }\n      });\n\n      // Decline to add empty pages.\n      if (elements.length > 0) {\n        page.elements = elements;\n        pages.push(page);\n      }\n    }\n\n    return pages;\n  } else {\n    throw new Error('FHIR version not implemented: ' + fhirVersion);\n  }\n}\n\n/**\n * Convert a FHIR Questionnaire to a SurveyJS Questionnaire\n *\n * @param {json} questionnaire JSON representing a FHIR\n *     Questionnaire.\n * @param {string} fhirVersion The FHIR version of the questionnaie.\n *\n * @return {json} JSON representing an equivalent SurveyJS Questionnaire.\n */\nfunction fromQuestionnaire(questionnaire, fhirVersion) {\n  const pages = unpackItemsRecursive(questionnaire, fhirVersion);\n\n  return {\n    'pages': pages,\n  };\n}\n\n/**\n * Recursively check a FHIR Questionnaire for slots that would match\n * a SurveyJS JSON Response, and create a corresponding FHIR\n * QuestionnaireResponse.\n *\n * @param {json} questionnaire JSON representing a FHIR\n *     Questionnaire being filled out, or a child item.\n * @param {json} surveyResponse JSON representing a SurveyJS response.\n * @param {string} fhirVersion The FHIR version of the questionnaie.\n *\n * @return {json} a FHIR QuestionnaireResponse or child item corresponding\n *     to the questionnaire argument filled out with the surveyResponse\n *     argument data.\n */\nfunction packSurveyResponse(questionnaire, surveyResponse, fhirVersion) {\n  if (fhirVersion === 'R4') {\n    // We will traverse the questionnaire's items, matching them to a survey\n    // response as possible.\n    const items = [];\n\n    // The response item's structure largely mimics that of the questionnaire\n    // itself.  Thus, we will copy it and add the answers whenever applicable.\n    if (questionnaire.hasOwnProperty('item')) {\n      questionnaire.item.forEach((item, itemIndex) => {\n        const currentItem = {};\n\n        if (item.hasOwnProperty('linkId')) {\n          currentItem.linkId = item.linkId;\n\n          // Check the survey response for this linkId.\n          if (surveyResponse.hasOwnProperty(item.linkId) &&\n              item.hasOwnProperty('type')) {\n            switch (item.type) {\n              case 'decimal':\n                currentItem.answer = [\n                  {'valueDecimal': surveyResponse[item.linkId]}];\n                break;\n              case 'date':\n                currentItem.answer = [\n                  {'valueDate': surveyResponse[item.linkId]}];\n                break;\n              case 'dateTime':\n                currentItem.answer = [\n                  {'valueDateTime': surveyResponse[item.linkId]}];\n                break;\n              case 'time':\n                currentItem.answer = [\n                  {'valueTime': surveyResponse[item.linkId]}];\n                break;\n              case 'url':\n                currentItem.answer = [\n                  {'valueUri': surveyResponse[item.linkId]}];\n                break;\n              case 'string':\n                currentItem.answer = [\n                  {'valueString': surveyResponse[item.linkId]}];\n                break;\n              case 'boolean':\n                currentItem.answer = [\n                  {'valueBoolean': surveyResponse[item.linkId]}];\n                break;\n              case 'text':\n                currentItem.answer = [\n                  {'valueString': surveyResponse[item.linkId]}];\n                break;\n              case 'attachment':\n                currentItem.answer = [];\n\n                surveyResponse[item.linkId].forEach(\n                    (surveyAttachment, surveyAttachmentIndex) => {\n                      const attachment = {};\n\n                      if (surveyAttachment.hasOwnProperty('type')) {\n                        attachment.contentType = surveyAttachment.type;\n                      }\n\n                      if (surveyAttachment.hasOwnProperty('name')) {\n                        attachment.title = surveyAttachment.name;\n                      }\n\n                      if (surveyAttachment.hasOwnProperty('content')) {\n                        // SurveyJS includes a prefix.\n                        // We should take everything after the comma.\n                        const commaPosition = (\n                          surveyAttachment.content.indexOf(','));\n                        attachment.data = (\n                          surveyAttachment.content.substring(\n                              commaPosition + 1));\n                      }\n\n                      currentItem.answer.push(\n                          {'valueAttachment': attachment});\n                    });\n                break;\n              case 'choice':\n                currentItem.answer = [\n                  {'valueString': surveyResponse[item.linkId]}];\n                break;\n              case 'open-choice':\n                currentItem.answer = [\n                  {'valueString': surveyResponse[item.linkId]}];\n\n                if (surveyResponse\n                    .hasOwnProperty(item.linkId + '-Comment')) {\n                  currentItem.answer.push(\n                      {'valueString':\n                           surveyResponse[item.linkId + '-Comment']});\n                }\n                break;\n              default:\n                throw new Error(\n                    'Unsupported questionnaire item type: ' + item.type);\n                break;\n            }\n          }\n        }\n\n        if (item.hasOwnProperty('definition')) {\n          currentItem.definition = item.definition;\n        }\n\n        if (item.hasOwnProperty('text')) {\n          currentItem.text = item.text;\n        }\n\n        if (item.hasOwnProperty('item')) {\n          currentItem.item = (\n            packSurveyResponse(item, surveyResponse, fhirVersion));\n        }\n\n        items.push(currentItem);\n      });\n    }\n\n    return items;\n  } else {\n    throw new Error('FHIR version not implemented: ' + fhirVersion);\n  }\n}\n\n/**\n * Convert a SurveyJS JSON response to a FHIR QuestionnaireResponse.\n *\n * @param {json} questionnaire JSON representing a FHIR\n *     Questionnaire\n * @param {json} surveyResponse A SurveyJS JSON response\n * @param {string} fhirVersion The FHIR version of the questionnaireResponse.\n *\n * @return {json} The FHIR QuestionnaireResponse equivalent of the\n *     surveyResponse.\n */\nfunction toQuestionnaireResponse(questionnaire, surveyResponse, fhirVersion) {\n  if (fhirVersion === 'R4') {\n    // We will traverse the questionnaire's items,\n    // matching them to a survey response as possible.\n    const questionnaireResponseJson = {\n      'resourceType': 'QuestionnaireResponse',\n      'status': 'completed',\n    };\n\n    // The response item's structure largely mimics that of the questionnaire\n    // itself.  Thus, we will copy it and add the answers whenever applicable.\n    questionnaireResponseJson.item = packSurveyResponse(\n        questionnaire,\n        surveyResponse,\n        fhirVersion);\n\n    return questionnaireResponseJson;\n  } else {\n    throw new Error('FHIR version not implemented: ' + fhirVersion);\n  }\n}\n\n/**\n * Recursively check the items in a FHIR QuestionnaireResponse for survey\n * answers, then unpack them into a SurveyJS-style JSON survey response.\n *\n * @param {json} questionnaireResponse JSON representing a FHIR\n *     QuestionnaireResponse or one of its child items.\n * @param {string} fhirVersion The FHIR version of the questionnaireResponse.\n * @param {json} currentResult The unpacked result so far.\n *\n * @return {json} currentResult augmented with the survey response data\n *     from the questionnaireResponse argument.\n */\nfunction unpackSurveyResponse(\n    questionnaireResponse,\n    fhirVersion,\n    currentResult) {\n  if (fhirVersion === 'R4') {\n    let newResult = currentResult;\n\n    if (questionnaireResponse.hasOwnProperty('item')) {\n      questionnaireResponse.item.forEach((item, itemIndex) => {\n        if (item.hasOwnProperty('item')) {\n          newResult = unpackSurveyResponse(item, fhirVersion, newResult);\n        }\n\n        // Even without the questionnaire, we can largely infer the format\n        // of the result.  We will make a best-effort attempt to reconstitute\n        // it under the assumption that the answers match the prescription\n        // above.  This may not always be feasible and may eventually\n        // need the format of the base questionnaire.\n        if (item.hasOwnProperty('linkId') && item.hasOwnProperty('answer')) {\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueBoolean'))) {\n            newResult[item.linkId] = item.answer[0].valueBoolean;\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueDecimal'))) {\n            newResult[item.linkId] = item.answer[0].valueDecimal;\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueInteger'))) {\n            newResult[item.linkId] = item.answer[0].valueInteger;\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueDate'))) {\n            newResult[item.linkId] = item.answer[0].valueDate;\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueDateTime'))) {\n            newResult[item.linkId] = item.answer[0].valueDateTime;\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueTime'))) {\n            newResult[item.linkId] = item.answer[0].valueTime;\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueString'))) {\n            newResult[item.linkId] = item.answer[0].valueString;\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueUri'))) {\n            newResult[item.linkId] = item.answer[0].valueUri;\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueCoding'))) {\n            if (item.answer[0].valueCoding.hasOwnProperty('code')) {\n              newResult[item.linkId] = (\n                item.answer[0].valueCoding.code);\n            } else if (\n              item.answer[0].valueCoding.hasOwnProperty('display')) {\n              newResult[item.linkId] = (\n                item.answer[0].valueCoding.display);\n            }\n          }\n\n          if ((item.answer.length === 1) &&\n              (item.answer[0].hasOwnProperty('valueQuantity'))) {\n            if (item.answer[0].valueQuantity.hasOwnProperty('value')) {\n              newResult[item.linkId] = (\n                item.answer[0].valueQuantity.value);\n              if (item.answer[0].valueQuantity.hasOwnProperty('unit')) {\n                newResult[item.linkId] += (\n                  item.answer[0].valueQuantity.unit);\n              }\n            }\n          }\n\n          // Special case:  One or more file attachments.\n          if ((item.answer.length >= 1) &&\n              (item.answer[0].hasOwnProperty('valueAttachment'))) {\n            newResult[item.linkId] = [];\n            item.answer.forEach((attachment, attachmentIndex) => {\n              if (attachment.hasOwnProperty('valueAttachment')) {\n                const currentAttachment = {};\n\n                if (attachment.valueAttachment.hasOwnProperty('title')) {\n                  currentAttachment.name = (\n                    attachment.valueAttachment.title);\n                }\n\n                if (attachment.valueAttachment\n                    .hasOwnProperty('contentType')) {\n                  currentAttachment.type = (\n                    attachment.valueAttachment.contentType);\n\n                  if (attachment.valueAttachment.hasOwnProperty('data')) {\n                    currentAttachment.content = (\n                      'data:' + attachment.valueAttachment.contentType +\n                      ';base64,' + attachment.valueAttachment.data);\n                  } else {\n                    currentAttachment.content = (\n                      'base64,' + attachment.valueAttachment.data);\n                  }\n                }\n\n                newResult[item.linkId].push(currentAttachment);\n              }\n            });\n          }\n\n          // Special case:  Two strings.\n          if ((item.answer.length === 2) &&\n              (item.answer[0].hasOwnProperty('valueString')) &&\n              (item.answer[1].hasOwnProperty('valueString'))) {\n            newResult[item.linkId] = item.answer[0].valueString;\n            newResult[item.linkId + '-Comment'] = (\n              item.answer[1].valueString);\n          }\n        }\n      });\n    }\n    return newResult;\n  } else {\n    throw new Error('FHIR version not implemented: ' + fhirVersion);\n  }\n}\n\n/**\n * Convert a FHIR QuestionnaireResponse to SurveyJS JSON.\n *\n * @param {json} questionnaireResponse JSON representing a FHIR\n *     QuestionnaireResponse\n * @param {string} fhirVersion The FHIR version of the questionnaireResponse.\n *\n * @return {json} The SurveyJS JSON equivalent of the questionnaireResponse\n */\nfunction fromQuestionnaireResponse(questionnaireResponse, fhirVersion) {\n  if (fhirVersion === 'R4') {\n    return unpackSurveyResponse(questionnaireResponse, fhirVersion, {});\n  } else {\n\n  }\n}\n\nexport default {\n  toQuestionnaire: toQuestionnaire,\n  fromQuestionnaire: fromQuestionnaire,\n  toQuestionnaireResponse: toQuestionnaireResponse,\n  fromQuestionnaireResponse: fromQuestionnaireResponse,\n};\n"]}