<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="Mxx-HealthHub-ObservationFreeText" />
  <url value="https://fhir.medatixx.de/HealthHub/StructureDefinition/Mxx_HealthHub_ObservationFreeText" />
  <version value="1.5.0" />
  <name value="Mxx_HealthHub_ObservationFreeText" />
  <status value="active" />
  <publisher value="medatixx GmbH &amp; Co. KG" />
  <description value="Observation profile for free-text record entries proposed via POST /Observation/$propose. Derives directly from the FHIR R4 base Observation (not from Mxx_HealthHub_Observation, which targets the read path for laboratory and vital-signs values and carries incompatible max:0 constraints on performer and derivedFrom). Supports text content via valueString, optional attachments via contained DocumentReference resources referenced from derivedFrom, and practitioner/organisation attribution via performer slices. A mandatory mxxPartnerReference extension (Mxx_HealthHub_PartnerReference) identifies the submitting partner system. The optional mxxRecordCategory extension steers the target category in the practice record; the optional mxxEntryCallUri extension carries a deep-link back to the originating partner application." />
  <copyright value="medatixx GmbH &amp; Co. KG" />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Observation" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Observation" />
  <derivation value="constraint" />
  <differential>
    <element id="Observation">
      <path value="Observation" />
      <short value="Free-text record entry" />
      <definition value="A free-text record entry proposed by a partner system. The entry is either processed automatically or must be confirmed by a user; which case applies is a configuration detail and not part of this contract." />
      <constraint>
        <key value="mxx-obsft-att-contained" />
        <severity value="error" />
        <human value="Every attachment referenced from derivedFrom must be a contained resource (local '#' reference); external references are not allowed." />
        <expression value="derivedFrom.all(reference.exists() and reference.startsWith('#'))" />
      </constraint>
      <constraint>
        <key value="mxx-obsft-att-contenttype" />
        <severity value="error" />
        <human value="Each contained attachment's content type must be a code from Mxx_HealthHub_VS_HealthRecordContentTypes." />
        <expression value="contained.ofType(DocumentReference).content.attachment.contentType.all(memberOf('https://fhir.medatixx.de/HealthHub/ValueSet/Mxx_HealthHub_VS_HealthRecordContentTypes'))" />
      </constraint>
      <constraint>
        <key value="mxx-obsft-att-inline" />
        <severity value="error" />
        <human value="Contained attachments must carry their content inline in attachment.data; attachment.url is not allowed and DocumentReference.status must be 'current'." />
        <expression value="contained.ofType(DocumentReference).all(status = 'current' and content.attachment.url.empty())" />
      </constraint>
    </element>
    <element id="Observation.extension">
      <path value="Observation.extension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="Observation.extension:mxxRecordCategory">
      <path value="Observation.extension" />
      <sliceName value="mxxRecordCategory" />
      <short value="Practice-specific record category" />
      <definition value="Steers the filing category in the practice software record. Carries the instance-local record category ID (string) obtained from $getRecordCategories; the ID is only meaningful within a single PVS instance." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="https://fhir.medatixx.de/HealthHub/StructureDefinition/Mxx_HealthHub_RecordCategory" />
      </type>
    </element>
    <element id="Observation.extension:mxxEntryCallUri">
      <path value="Observation.extension" />
      <sliceName value="mxxEntryCallUri" />
      <short value="Deep-link back to the partner system" />
      <definition value="Optional deep-link back to the originating view in the partner application. Sub-extensions: Uri (1..1), Label (0..1), OpenInBrowser (0..1)." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="https://fhir.medatixx.de/HealthHub/StructureDefinition/Mxx_HealthHub_EntryCallUri" />
      </type>
    </element>
    <element id="Observation.extension:mxxPartnerReference">
      <path value="Observation.extension" />
      <sliceName value="mxxPartnerReference" />
      <short value="Submitting partner system" />
      <definition value="The partner system submitting the entry to the practice software for recording. Mandatory. Uses the Mxx_HealthHub_PartnerReference extension (valueReference to Mxx_HealthHub_PartnerSystem), consistent with Mxx_HealthHub_Appointment. Observation.performer cannot carry this reference because base FHIR does not allow a Device target on Observation.performer." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="https://fhir.medatixx.de/HealthHub/StructureDefinition/Mxx_HealthHub_PartnerReference" />
      </type>
    </element>
    <element id="Observation.modifierExtension">
      <path value="Observation.modifierExtension" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). This profile defines no modifier extensions; per FHIR a modifier extension must not be ignored, so none are permitted here." />
      <max value="0" />
    </element>
    <element id="Observation.identifier">
      <path value="Observation.identifier" />
      <max value="0" />
    </element>
    <element id="Observation.basedOn">
      <path value="Observation.basedOn" />
      <max value="0" />
    </element>
    <element id="Observation.partOf">
      <path value="Observation.partOf" />
      <max value="0" />
    </element>
    <element id="Observation.status">
      <path value="Observation.status" />
      <short value="preliminary (fixed)" />
      <definition value="The status is always 'preliminary'. The entry is submitted as a proposal; the practice software sets the status after processing." />
      <fixedCode value="preliminary" />
    </element>
    <element id="Observation.category">
      <path value="Observation.category" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). The FHIR observation-category classification does not steer the PVS filing; filing is driven solely by the mxxRecordCategory extension (record category ID) or the partner-system default. Consistent with DocumentReference.category in the HealthRecordEntry profile." />
      <max value="0" />
    </element>
    <element id="Observation.code">
      <path value="Observation.code" />
      <short value="Fixed marker: free-text record entry" />
      <definition value="Fixed classifier for this profile. code.coding is not used (max 0); code.text is fixed to 'Free-text record entry'. code carries no per-entry classification - the filing category is the mxxRecordCategory extension and the entry name derives from that record category. Present only because base FHIR requires Observation.code (1..1); the partner always sends the same constant." />
      <min value="1" />
    </element>
    <element id="Observation.code.coding">
      <path value="Observation.code.coding" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). code carries no coded classification; the record category is the single source of truth (mxxRecordCategory extension)." />
      <max value="0" />
    </element>
    <element id="Observation.code.text">
      <path value="Observation.code.text" />
      <short value="Fixed sentinel text" />
      <definition value="Fixed to 'Free-text record entry'. Constant marker so code imposes no per-entry decision on the partner." />
      <min value="1" />
      <fixedString value="Free-text record entry" />
    </element>
    <element id="Observation.subject">
      <path value="Observation.subject" />
      <short value="Patient" />
      <definition value="Reference to the patient to whom the entry is to be assigned. Must be a patient known in the practice system." />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.medatixx.de/HealthHub/StructureDefinition/Mxx_HealthHub_Patient" />
      </type>
    </element>
    <element id="Observation.focus">
      <path value="Observation.focus" />
      <max value="0" />
    </element>
    <element id="Observation.encounter">
      <path value="Observation.encounter" />
      <max value="0" />
    </element>
    <element id="Observation.effective[x]">
      <path value="Observation.effective[x]" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). The practice record keeps a single entry date, which is taken from Observation.issued. A separate clinical timestamp has no target field in the practice record." />
      <max value="0" />
    </element>
    <element id="Observation.issued">
      <path value="Observation.issued" />
      <short value="Creation timestamp (mandatory)" />
      <definition value="The point in time the entry was created / made available (instant). Mandatory; corresponds to the entry date in the practice record." />
      <min value="1" />
    </element>
    <element id="Observation.performer">
      <path value="Observation.performer" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="type" />
        </discriminator>
        <rules value="closed" />
      </slicing>
      <short value="Practitioner, organisation and user (all mandatory)" />
      <min value="3" />
      <max value="3" />
    </element>
    <element id="Observation.performer:practitioner">
      <path value="Observation.performer" />
      <sliceName value="practitioner" />
      <short value="Practitioner" />
      <definition value="The practitioner to whom the entry is to be attributed in the practice software. Mandatory. Analogous to author:practitioner in Mxx_HealthHub_HealthRecordEntry." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.medatixx.de/HealthHub/StructureDefinition/Mxx_HealthHub_Practitioner" />
      </type>
    </element>
    <element id="Observation.performer:practitioner.reference">
      <path value="Observation.performer.reference" />
      <min value="1" />
    </element>
    <element id="Observation.performer:practitioner.type">
      <path value="Observation.performer.type" />
      <min value="1" />
      <fixedUri value="Mxx_HealthHub_Practitioner" />
    </element>
    <element id="Observation.performer:practitioner.identifier">
      <path value="Observation.performer.identifier" />
      <max value="0" />
    </element>
    <element id="Observation.performer:practitioner.display">
      <path value="Observation.performer.display" />
      <max value="0" />
    </element>
    <element id="Observation.performer:organization">
      <path value="Observation.performer" />
      <sliceName value="organization" />
      <short value="Organisation" />
      <definition value="The organisation / practice site to which the entry is to be attributed in the practice software. Mandatory. Analogous to custodian in Mxx_HealthHub_HealthRecordEntry." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.medatixx.de/HealthHub/StructureDefinition/Mxx_HealthHub_Organization" />
      </type>
    </element>
    <element id="Observation.performer:organization.reference">
      <path value="Observation.performer.reference" />
      <min value="1" />
    </element>
    <element id="Observation.performer:organization.type">
      <path value="Observation.performer.type" />
      <min value="1" />
      <fixedUri value="Mxx_HealthHub_Organization" />
    </element>
    <element id="Observation.performer:organization.identifier">
      <path value="Observation.performer.identifier" />
      <max value="0" />
    </element>
    <element id="Observation.performer:organization.display">
      <path value="Observation.performer.display" />
      <max value="0" />
    </element>
    <element id="Observation.performer:user">
      <path value="Observation.performer" />
      <sliceName value="user" />
      <short value="User" />
      <definition value="The practice-software user to whom the entry is to be attributed. Mandatory. Analogous to author:user in Mxx_HealthHub_HealthRecordEntry." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.medatixx.de/HealthHub/StructureDefinition/Mxx_HealthHub_User" />
      </type>
    </element>
    <element id="Observation.performer:user.reference">
      <path value="Observation.performer.reference" />
      <min value="1" />
    </element>
    <element id="Observation.performer:user.type">
      <path value="Observation.performer.type" />
      <min value="1" />
      <fixedUri value="Mxx_HealthHub_User" />
    </element>
    <element id="Observation.performer:user.identifier">
      <path value="Observation.performer.identifier" />
      <max value="0" />
    </element>
    <element id="Observation.performer:user.display">
      <path value="Observation.performer.display" />
      <max value="0" />
    </element>
    <element id="Observation.value[x]">
      <path value="Observation.value[x]" />
      <short value="Free-text content (mandatory)" />
      <definition value="The primary free-text body of the record entry. Mandatory. valueString is the single authoritative content field, giving one clearly defined mapping path. code.text is a fixed marker (not a per-entry label), note is not used (max 0), and text inside a contained attachment belongs to that attachment, not the entry body." />
      <comment value="The HTTP request body stays UTF-8 encoded; only the character repertoire that can be stored is limited. Free text is stored in the PVS record using the Windows-1252 character set: ASCII and the characters contained in Windows-1252 (e.g. ä, ö, ü, ß, é, à, the euro sign €) are preserved; characters outside this set (e.g. emoji or other Unicode symbols) are not supported and are stored as '?'. Partner systems - especially web applications with free character input - should restrict or sanitise input accordingly. See Grundlagen &gt; Anforderungen an Partnersysteme (P-11-001)." />
      <min value="1" />
      <type>
        <code value="string" />
      </type>
    </element>
    <element id="Observation.dataAbsentReason">
      <path value="Observation.dataAbsentReason" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). A free-text entry always carries its content in valueString." />
      <max value="0" />
    </element>
    <element id="Observation.interpretation">
      <path value="Observation.interpretation" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). Interpretation flags apply to quantitative results, not to free-text entries." />
      <max value="0" />
    </element>
    <element id="Observation.note">
      <path value="Observation.note" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). Supplementary annotations have no target field in the practice record; the entry body is carried in valueString." />
      <max value="0" />
    </element>
    <element id="Observation.bodySite">
      <path value="Observation.bodySite" />
      <max value="0" />
    </element>
    <element id="Observation.method">
      <path value="Observation.method" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). The measurement method applies to quantitative results, not to free-text entries." />
      <max value="0" />
    </element>
    <element id="Observation.specimen">
      <path value="Observation.specimen" />
      <max value="0" />
    </element>
    <element id="Observation.device">
      <path value="Observation.device" />
      <max value="0" />
    </element>
    <element id="Observation.referenceRange">
      <path value="Observation.referenceRange" />
      <short value="Not used" />
      <definition value="Not used in this profile (max 0). Reference ranges apply to quantitative results, not to free-text entries." />
      <max value="0" />
    </element>
    <element id="Observation.hasMember">
      <path value="Observation.hasMember" />
      <max value="0" />
    </element>
    <element id="Observation.derivedFrom">
      <path value="Observation.derivedFrom" />
      <short value="Attachments (contained DocumentReference)" />
      <definition value="References to file attachments. Each attachment is a contained DocumentReference resource within the same Observation object (e.g. '#attachment-1'). The DocumentReference carries the binary content as Base64 in content[0].attachment.data; the content type must be a code from Mxx_HealthHub_VS_HealthRecordContentTypes. The total size of all attachments must not exceed 20 MB." />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/DocumentReference" />
      </type>
    </element>
    <element id="Observation.component">
      <path value="Observation.component" />
      <max value="0" />
    </element>
  </differential>
</StructureDefinition>