<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="pcm-organization-parent" />
  <url value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-parent" />
  <version value="0.4.2" />
  <name value="PCMOrganizationParent" />
  <title value="PCM Parent Organization" />
  <status value="active" />
  <description value="Root organization in PCM representing the onboarded parent legal entity. Created and identified by PCM during manual onboarding. Parent identity and active state are controlled by MoH/PCM; the organization may update contact details only." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Organization" />
  <baseDefinition value="http://fhir.health.gov.il/StructureDefinition/il-core-organization" />
  <derivation value="constraint" />
  <differential>
    <element id="Organization">
      <path value="Organization" />
      <constraint>
        <key value="pcm-parent-active-moh-identifier" />
        <severity value="error" />
        <human value="An active Parent Organization requires exactly one applicable MoH institution-symbol or approved paying-entity identifier." />
        <expression value="active = false or (identifier.where(system = 'http://institutions.health.gov.il/Institutions').count() + identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh').count() = 1)" />
        <source value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-parent" />
      </constraint>
      <constraint>
        <key value="pcm-parent-payer-identifier" />
        <severity value="error" />
        <human value="A Parent paying-entity identifier must be one of the approved unique organization codes; generic code 400 is not accepted." />
        <expression value="identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh').value.all($this = '101' or $this = '102' or $this = '103' or $this = '104' or $this = '406' or $this = '401' or $this = '405' or $this = '402' or $this = '300')" />
        <source value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-parent" />
      </constraint>
      <constraint>
        <key value="pcm-parent-hmo-identifier" />
        <severity value="error" />
        <human value="An HMO Parent uses one of the four unique HMO paying-entity codes and not an institution symbol; those four codes are valid only for an HMO Parent." />
        <expression value="(type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and code = '73').exists() implies (identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh' and (value = '101' or value = '102' or value = '103' or value = '104')).count() = 1 and identifier.where(system = 'http://institutions.health.gov.il/Institutions').empty())) and (identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh' and (value = '101' or value = '102' or value = '103' or value = '104')).exists() implies type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and code = '73').exists())" />
        <source value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-parent" />
      </constraint>
      <constraint>
        <key value="pcm-parent-institution-identifier" />
        <severity value="error" />
        <human value="A general-hospital or geriatric-medical-center Parent uses an institution symbol and not a paying-entity identifier." />
        <expression value="type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and (code = '1' or code = '22')).exists() implies (identifier.where(system = 'http://institutions.health.gov.il/Institutions').count() = 1 and identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh').empty())" />
        <source value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-parent" />
      </constraint>
      <constraint>
        <key value="pcm-parent-public-entity-identifier" />
        <severity value="error" />
        <human value="Structurally distinguishable public-entity Parent types use their decided paying-entity code, and those codes are limited to their matching institution type." />
        <expression value="(type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and code = '71').exists() implies identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh' and value = '406').count() = 1) and (type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and code = '75').exists() implies identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh' and value = '401').count() = 1) and (type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and code = '87').exists() implies identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh' and value = '405').count() = 1) and (identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh' and value = '406').exists() implies type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and code = '71').exists()) and (identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh' and value = '401').exists() implies type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and code = '75').exists()) and (identifier.where(system = 'http://fhir.health.gov.il/cs/paying-entity-moh' and value = '405').exists() implies type.coding.where(system = 'http://fhir.health.gov.il/cs/institution-type-moh' and code = '87').exists())" />
        <source value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-parent" />
      </constraint>
    </element>
    <element id="Organization.id">
      <path value="Organization.id" />
      <min value="1" />
    </element>
    <element id="Organization.meta">
      <path value="Organization.meta" />
      <min value="1" />
    </element>
    <element id="Organization.meta.lastUpdated">
      <path value="Organization.meta.lastUpdated" />
      <comment value="Server-managed timestamp of the most recent authoritative resource change." />
      <min value="1" />
    </element>
    <element id="Organization.meta.profile">
      <path value="Organization.meta.profile" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <comment value="PCM includes the applicable server-return profile URL; additional compatible profile URLs are allowed." />
      <min value="1" />
    </element>
    <element id="Organization.meta.profile:pcmProfile">
      <path value="Organization.meta.profile" />
      <sliceName value="pcmProfile" />
      <min value="1" />
      <max value="1" />
      <fixedCanonical value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-parent" />
    </element>
    <element id="Organization.identifier">
      <path value="Organization.identifier" />
      <comment value="PCM-managed identifiers. Every Parent has one PCM Organization business identifier and, where the type-specific mapping is resolved, the applicable MoH identifier. Organization-facing writes cannot add, replace, or remove these values." />
      <min value="1" />
    </element>
    <element id="Organization.identifier:moh-inst-symbol">
      <path value="Organization.identifier" />
      <sliceName value="moh-inst-symbol" />
      <comment value="PCM records this identifier for hospitals and other institution-registry participants where the approved type mapping requires it." />
    </element>
    <element id="Organization.identifier:moe-inst">
      <path value="Organization.identifier" />
      <sliceName value="moe-inst" />
      <max value="0" />
    </element>
    <element id="Organization.identifier:moh-hospital-department">
      <path value="Organization.identifier" />
      <sliceName value="moh-hospital-department" />
      <max value="0" />
    </element>
    <element id="Organization.identifier:paying-entity-moh">
      <path value="Organization.identifier" />
      <sliceName value="paying-entity-moh" />
      <comment value="PCM records the approved paying-entity identifier only for organization types with a specific unique code. Generic code 400 is not a unique organization identifier." />
    </element>
    <element id="Organization.identifier:pcmOrganizationId">
      <path value="Organization.identifier" />
      <sliceName value="pcmOrganizationId" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Organization.identifier:pcmOrganizationId.use">
      <path value="Organization.identifier.use" />
      <min value="1" />
      <fixedCode value="official" />
    </element>
    <element id="Organization.identifier:pcmOrganizationId.system">
      <path value="Organization.identifier.system" />
      <fixedUri value="http://pcm.fhir.health.gov.il/identifier/pcm-organization-id" />
    </element>
    <element id="Organization.active">
      <path value="Organization.active" />
      <comment value="MoH/PCM-controlled participation state. Organizations cannot set this through the client FHIR API. An inactive Parent prevents operational use of its children without rewriting each child's independently MoH/PCM-controlled active value." />
      <min value="1" />
    </element>
    <element id="Organization.type">
      <path value="Organization.type" />
      <comment value="Parent organization classification is MoH/PCM-controlled and not writable by organizations through the client FHIR API." />
      <min value="2" />
    </element>
    <element id="Organization.type:pcmOrgType">
      <path value="Organization.type" />
      <sliceName value="pcmOrgType" />
      <comment value="Marks this Organization as a PCM Parent Organization." />
      <min value="1" />
      <max value="1" />
      <patternCodeableConcept>
        <coding>
          <system value="http://pcm.fhir.health.gov.il/cs/pcm-org-type" />
          <code value="parent-org" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="Organization.type:pcmOrgType.coding">
      <path value="Organization.type.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Organization.type:pcmOrgType.coding.system">
      <path value="Organization.type.coding.system" />
      <min value="1" />
      <fixedUri value="http://pcm.fhir.health.gov.il/cs/pcm-org-type" />
    </element>
    <element id="Organization.type:pcmOrgType.coding.code">
      <path value="Organization.type.coding.code" />
      <min value="1" />
      <fixedCode value="parent-org" />
    </element>
    <element id="Organization.name">
      <path value="Organization.name" />
      <comment value="Parent organization name is MoH/PCM-controlled and not writable by organizations through the client FHIR API." />
    </element>
    <element id="Organization.alias">
      <path value="Organization.alias" />
      <max value="0" />
    </element>
    <element id="Organization.telecom">
      <path value="Organization.telecom" />
      <comment value="Parent organization telecom is MoH/PCM-controlled; organization-managed operational contacts are represented in contact." />
    </element>
    <element id="Organization.address">
      <path value="Organization.address" />
      <comment value="Parent organization address is MoH/PCM-controlled and not writable by organizations through the client FHIR API." />
    </element>
    <element id="Organization.partOf">
      <path value="Organization.partOf" />
      <max value="0" />
    </element>
    <element id="Organization.contact">
      <path value="Organization.contact" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="purpose.coding.code" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <comment value="The organization SHOULD supply ADMIN, PATINF, and SEC contacts. Additional purpose-coded contacts are allowed. Parent contacts are the fallback for a child that does not override the same purpose." />
    </element>
    <element id="Organization.contact.purpose">
      <path value="Organization.contact.purpose" />
      <min value="1" />
      <binding>
        <strength value="extensible" />
        <valueSet value="http://pcm.fhir.health.gov.il/ValueSet/pcm-contactentity-type" />
      </binding>
    </element>
    <element id="Organization.contact:admin">
      <path value="Organization.contact" />
      <sliceName value="admin" />
      <comment value="Administrative enquiries contact." />
      <min value="0" />
      <max value="1" />
    </element>
    <element id="Organization.contact:admin.purpose.coding">
      <path value="Organization.contact.purpose.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Organization.contact:admin.purpose.coding.system">
      <path value="Organization.contact.purpose.coding.system" />
      <min value="1" />
      <fixedUri value="http://terminology.hl7.org/CodeSystem/contactentity-type" />
    </element>
    <element id="Organization.contact:admin.purpose.coding.code">
      <path value="Organization.contact.purpose.coding.code" />
      <min value="1" />
      <fixedCode value="ADMIN" />
    </element>
    <element id="Organization.contact:patientInfo">
      <path value="Organization.contact" />
      <sliceName value="patientInfo" />
      <comment value="Patient information / patient-facing enquiries contact." />
      <min value="0" />
      <max value="1" />
    </element>
    <element id="Organization.contact:patientInfo.purpose.coding">
      <path value="Organization.contact.purpose.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Organization.contact:patientInfo.purpose.coding.system">
      <path value="Organization.contact.purpose.coding.system" />
      <min value="1" />
      <fixedUri value="http://terminology.hl7.org/CodeSystem/contactentity-type" />
    </element>
    <element id="Organization.contact:patientInfo.purpose.coding.code">
      <path value="Organization.contact.purpose.coding.code" />
      <min value="1" />
      <fixedCode value="PATINF" />
    </element>
    <element id="Organization.contact:security">
      <path value="Organization.contact" />
      <sliceName value="security" />
      <comment value="Security / InfoSec / incident response contact." />
      <min value="0" />
      <max value="1" />
    </element>
    <element id="Organization.contact:security.purpose.coding">
      <path value="Organization.contact.purpose.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Organization.contact:security.purpose.coding.system">
      <path value="Organization.contact.purpose.coding.system" />
      <min value="1" />
      <fixedUri value="http://pcm.fhir.health.gov.il/cs/pcm-contactentity-type" />
    </element>
    <element id="Organization.contact:security.purpose.coding.code">
      <path value="Organization.contact.purpose.coding.code" />
      <min value="1" />
      <fixedCode value="SEC" />
    </element>
    <element id="Organization.endpoint">
      <path value="Organization.endpoint" />
      <max value="0" />
    </element>
  </differential>
</StructureDefinition>