{
  "resourceType": "StructureDefinition",
  "url": "https://cgm.com/fhir/his/medico/r4/sd/pip/QuestionnaireResponse_PiPQuestionnaireResponse_1",
  "name": "QuestionnaireResponse_PiPQuestionnaireResponse_1",
  "status": "draft",
  "description": "This profile describes the QuestionnaireResponse related data to be exchanged with Patient Portal.",
  "fhirVersion": "4.0.1",
  "kind": "resource",
  "abstract": false,
  "type": "QuestionnaireResponse",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "QuestionnaireResponse.id",
        "path": "QuestionnaireResponse.id",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.meta",
        "path": "QuestionnaireResponse.meta",
        "min": 1
      },
      {
        "id": "QuestionnaireResponse.meta.lastUpdated",
        "path": "QuestionnaireResponse.meta.lastUpdated",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.meta.profile",
        "path": "QuestionnaireResponse.meta.profile",
        "min": 1,
        "max": "1",
        "fixedCanonical": "https://cgm.com/fhir/his/medico/r4/sd/pip/QuestionnaireResponse_PiPQuestionnaireResponse_1"
      },
      {
        "id": "QuestionnaireResponse.contained",
        "path": "QuestionnaireResponse.contained",
        "short": "A structured set of questions",
        "definition": "A structured set of questions intended to guide the collection of answers from end-users. Questionnaires provide detailed control over order, presentation, phraseology and grouping to allow coherent, consistent data collection.",
        "alias": [
          "inline resources",
          "anonymous resources",
          "contained resources",
          "Form",
          "CRF",
          "Survey"
        ],
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Resource",
            "profile": [
              "https://cgm.com/fhir/his/medico/r4/sd/pip/Questionnaire_PiPQuestionnaire_1"
            ]
          }
        ],
        "constraint": [
          {
            "key": "dom-2",
            "severity": "error",
            "human": "If the resource is contained in another resource, it SHALL NOT contain nested Resources",
            "expression": "contained.contained.empty()",
            "xpath": "not(parent::f:contained and f:contained)",
            "source": "http://hl7.org/fhir/StructureDefinition/DomainResource"
          },
          {
            "key": "dom-4",
            "severity": "error",
            "human": "If a resource is contained in another resource, it SHALL NOT have a meta.versionId or a meta.lastUpdated",
            "expression": "contained.meta.versionId.empty() and contained.meta.lastUpdated.empty()",
            "xpath": "not(exists(f:contained/*/f:meta/f:versionId)) and not(exists(f:contained/*/f:meta/f:lastUpdated))",
            "source": "http://hl7.org/fhir/StructureDefinition/DomainResource"
          },
          {
            "key": "dom-3",
            "severity": "error",
            "human": "If the resource is contained in another resource, it SHALL be referred to from elsewhere in the resource or SHALL refer to the containing resource",
            "expression": "contained.where((('#'+id in (%resource.descendants().reference | %resource.descendants().as(canonical) | %resource.descendants().as(uri) | %resource.descendants().as(url))) or descendants().where(reference = '#').exists() or descendants().where(as(canonical) = '#').exists() or descendants().where(as(canonical) = '#').exists()).not()).trace('unmatched', id).empty()",
            "xpath": "not(exists(for $id in f:contained/*/f:id/@value return $contained[not(parent::*/descendant::f:reference/@value=concat('#', $contained/*/id/@value) or descendant::f:reference[@value='#'])]))",
            "source": "http://hl7.org/fhir/StructureDefinition/DomainResource"
          },
          {
            "key": "dom-6",
            "severity": "warning",
            "human": "A resource should have narrative for robust management",
            "expression": "text.`div`.exists()",
            "xpath": "exists(f:text/h:div)",
            "source": "http://hl7.org/fhir/StructureDefinition/DomainResource"
          },
          {
            "key": "dom-5",
            "severity": "error",
            "human": "If a resource is contained in another resource, it SHALL NOT have a security label",
            "expression": "contained.meta.security.empty()",
            "xpath": "not(exists(f:contained/*/f:meta/f:security))",
            "source": "http://hl7.org/fhir/StructureDefinition/DomainResource"
          },
          {
            "key": "que-2",
            "severity": "error",
            "human": "The link ids for groups and questions must be unique within the questionnaire",
            "expression": "descendants().linkId.isDistinct()",
            "xpath": "count(descendant::f:linkId/@value)=count(distinct-values(descendant::f:linkId/@value))",
            "source": "http://hl7.org/fhir/StructureDefinition/Questionnaire"
          },
          {
            "key": "que-0",
            "severity": "warning",
            "human": "Name should be usable as an identifier for the module by machine processing applications such as code generation",
            "expression": "name.matches('[A-Z]([A-Za-z0-9_]){0,254}')",
            "xpath": "not(exists(f:name/@value)) or matches(f:name/@value, '[A-Z]([A-Za-z0-9_]){0,254}')",
            "source": "http://hl7.org/fhir/StructureDefinition/Questionnaire"
          }
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "rim",
            "map": "Entity. Role, or Act"
          },
          {
            "identity": "rim",
            "map": "N/A"
          },
          {
            "identity": "workflow",
            "map": "Definition"
          },
          {
            "identity": "rim",
            "map": "Observation[moodCode=DEF]"
          }
        ]
      },
      {
        "id": "QuestionnaireResponse.identifier",
        "path": "QuestionnaireResponse.identifier",
        "min": 1
      },
      {
        "id": "QuestionnaireResponse.identifier.system",
        "path": "QuestionnaireResponse.identifier.system",
        "min": 1
      },
      {
        "id": "QuestionnaireResponse.identifier.value",
        "path": "QuestionnaireResponse.identifier.value",
        "min": 1
      },
      {
        "id": "QuestionnaireResponse.questionnaire",
        "path": "QuestionnaireResponse.questionnaire",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.subject",
        "path": "QuestionnaireResponse.subject",
        "min": 1
      },
      {
        "id": "QuestionnaireResponse.subject.reference",
        "path": "QuestionnaireResponse.subject.reference",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.encounter",
        "path": "QuestionnaireResponse.encounter",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.encounter.reference",
        "path": "QuestionnaireResponse.encounter.reference",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.authored",
        "path": "QuestionnaireResponse.authored",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.author",
        "path": "QuestionnaireResponse.author",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Practitioner",
              "http://hl7.org/fhir/StructureDefinition/Patient",
              "http://hl7.org/fhir/StructureDefinition/Organization"
            ]
          }
        ]
      },
      {
        "id": "QuestionnaireResponse.item",
        "path": "QuestionnaireResponse.item",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.item.text",
        "path": "QuestionnaireResponse.item.text",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.item.answer",
        "path": "QuestionnaireResponse.item.answer",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.item.answer.item",
        "path": "QuestionnaireResponse.item.answer.item",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.item.item",
        "path": "QuestionnaireResponse.item.item",
        "mustSupport": true
      }
    ]
  }
}