<?xml version="1.0" encoding="UTF-8"?>

<OperationDefinition xmlns="http://hl7.org/fhir">
  <id value="PlanDefinition-apply"/>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml">
      <p class="res-header-id">
        <b>Generated Narrative: OperationDefinition PlanDefinition-apply</b>
      </p>
      <a name="PlanDefinition-apply"> </a>
      <a name="hcPlanDefinition-apply"> </a>
      <p>URL: [base]/PlanDefinition/$apply</p>
      <p>URL: [base]/PlanDefinition/[id]/$apply</p>
      <h3>Parameters</h3>
      <table class="grid">
        <tr>
          <td>
            <b>Use</b>
          </td>
          <td>
            <b>Name</b>
          </td>
          <td>
            <b>Scope</b>
          </td>
          <td>
            <b>Cardinality</b>
          </td>
          <td>
            <b>Type</b>
          </td>
          <td>
            <b>Binding</b>
          </td>
          <td>
            <b>Documentation</b>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>planDefinition</td>
          <td>type</td>
          <td>0..1</td>
          <td>
            <a href="plandefinition.html">PlanDefinition</a>
          </td>
          <td/>
          <td>
            <div>
              <p>The plan definition to be applied. If the operation is invoked at the instance level, this parameter is not allowed; if the operation is invoked at the type level, this parameter is required, or a url (and optionally version) must be supplied</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>url</td>
          <td>type</td>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#canonical">canonical</a> (
            <a href="plandefinition.html" title="http://hl7.org/fhir/StructureDefinition/PlanDefinition">PlanDefinition</a>)
          </td>
          <td/>
          <td>
            <div>
              <p>The url of the plan definition to be applied. If the operation is invoked at the instance level, this parameter is not allowed; if the operation is invoked at the type level, this parameter (and optionally the version), or the planDefinition parameter must be supplied</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>version</td>
          <td>type</td>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#string">string</a>
          </td>
          <td/>
          <td>
            <div>
              <p>The version of the plan definition to be applied. If the operation is invoked at the instance level, this parameter is not allowed; if the operation is invoked at the type level, this parameter may only be used if the url parameter is supplied.</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>subject</td>
          <td/>
          <td>1..*</td>
          <td>
            <a href="datatypes.html#string">string</a>
            <br/>(
            <a href="search.html#reference">reference</a>)
          </td>
          <td/>
          <td>
            <div>
              <p>The subject(s) that is/are the target of the plan to be applied. The subject may be a Patient, Practitioner, Organization, Location, Device, or Group. Subjects provided in this parameter will be resolved as the subject of the PlanDefinition based on the type of the subject. If multiple subjects of the same type are provided, the behavior is implementation-defined</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>encounter</td>
          <td/>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#string">string</a>
            <br/>(
            <a href="search.html#reference">reference</a>)
          </td>
          <td/>
          <td>
            <div>
              <p>The encounter in context, if any</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>practitioner</td>
          <td/>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#string">string</a>
            <br/>(
            <a href="search.html#reference">reference</a>)
          </td>
          <td/>
          <td>
            <div>
              <p>The practitioner applying the plan definition</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>organization</td>
          <td/>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#string">string</a>
            <br/>(
            <a href="search.html#reference">reference</a>)
          </td>
          <td/>
          <td>
            <div>
              <p>The organization applying the plan definition</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>userType</td>
          <td/>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#CodeableConcept">CodeableConcept</a>
          </td>
          <td/>
          <td>
            <div>
              <p>The type of user initiating the request, e.g. patient, healthcare provider, or specific type of healthcare provider (physician, nurse, etc.)</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>userLanguage</td>
          <td/>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#CodeableConcept">CodeableConcept</a>
          </td>
          <td/>
          <td>
            <div>
              <p>Preferred language of the person using the system</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>userTaskContext</td>
          <td/>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#CodeableConcept">CodeableConcept</a>
          </td>
          <td/>
          <td>
            <div>
              <p>The task the system user is performing, e.g. laboratory results review, medication list review, etc. This information can be used to tailor decision support outputs, such as recommended information resources</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>setting</td>
          <td/>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#CodeableConcept">CodeableConcept</a>
          </td>
          <td/>
          <td>
            <div>
              <p>The current setting of the request (inpatient, outpatient, etc.)</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>IN</td>
          <td>settingContext</td>
          <td/>
          <td>0..1</td>
          <td>
            <a href="datatypes.html#CodeableConcept">CodeableConcept</a>
          </td>
          <td/>
          <td>
            <div>
              <p>Additional detail about the setting of the request, if any</p>

            </div>
          </td>
        </tr>
        <tr>
          <td>OUT</td>
          <td>return</td>
          <td/>
          <td>0..*</td>
          <td>
            <a href="bundle.html">Bundle</a>
          </td>
          <td/>
          <td>
            <div>
              <p>A Bundle for each input subject that is the result of applying the plan definition to that subject. Note that even though there is a single parameter named return of type Bundle, it is a multi-cardinality parameter, and so will still be returned using a Parameters resource, as described in the general operations framework (https://hl7.org/fhir/R4/operations.html#response).</p>

            </div>
          </td>
        </tr>
      </table>
      <div>
        <p>The result of this operation is a Bundle for each subject, where the Bundle contains Request resources that are the direct result of applying the PlanDefinition to that subject. The Bundle will have entries for each of the applicable actions in the PlanDefinition based on evaluating the applicability condition in context, and producing Request resources based on the definition element for each applicable action.</p>

        <p>For each applicable action, the definition is applied as described in the $apply operation of the ActivityDefinition resource, and the resulting resource is added as an entry to the Bundle. The resulting Bundle may be any combination of Request resources, including CarePlan, RequestOrchestration, and individual Request resources such as ServiceRequest and MedicationRequest.</p>

        <p>Note that to preserve the structure of the PlanDefinition, systems may choose to return the results in a RequestOrchestration. In this case, the individual request resources will have an intent of 
          <code>option</code>, meaning the their intent is governed by the RequestOrchestraiont.
        </p>

        <p>If the ActivityDefinition includes library references, those libraries will be available to the evaluated expressions. If those libraries have parameters, those parameters will be bound by name to the parameters given to the operation. In addition, parameters to the $apply operation are available within dynamicValue expressions as context variables, accessible by the name of the parameter, prefixed with a percent (%) symbol.</p>

        <p>For a more detailed description, refer to the PlanDefinition and ActivityDefinition resource documentation. Note that result of this operation is transient (i.e. none of the resources created by the operation are persisted in the server, they are all returned as entries in the result Bundle(s)). The result effectively represents a proposed set of activities, and it is up to the caller to determine whether and how those activities are actually carried out and/or persisted.</p>

      </div>
    </div>
  </text>
  <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm">
    <valueInteger value="3"/>
  </extension>
  <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status">
    <valueCode value="normative"/>
  </extension>
  <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-wg">
    <valueCode value="cds"/>
  </extension>
  <url value="http://hl7.org/fhir/OperationDefinition/PlanDefinition-apply"/>
  <version value="6.0.0-ballot3"/>
  <name value="Apply"/>
  <title value="Apply"/>
  <status value="active"/>
  <kind value="operation"/>
  <experimental value="false"/>
  <date value="2025-11-27T15:05:37+00:00"/>
  <publisher value="HL7 International / Clinical Decision Support"/>
  <contact>
    <telecom>
      <system value="url"/>
      <value value="http://hl7.org/fhir"/>
    </telecom>
    <telecom>
      <system value="email"/>
      <value value="fhir@lists.hl7.org"/>
    </telecom>
  </contact>
  <contact>
    <telecom>
      <system value="url"/>
      <value value="http://www.hl7.org/Special/committees/dss"/>
    </telecom>
  </contact>
  <description value="The apply operation applies a PlanDefinition to a given subject or group of subjects, instantiating applicable actions and returning the results as bundles of request resources."/>
  <jurisdiction>
    <coding>
      <system value="http://unstats.un.org/unsd/methods/m49/m49.htm"/>
      <code value="001"/>
      <display value="World"/>
    </coding>
  </jurisdiction>
  <affectsState value="false"/>
  <code value="apply"/>
  <comment value="The result of this operation is a Bundle for each subject, where the Bundle contains Request resources that are the direct result of applying the PlanDefinition to that subject. The Bundle will have entries for each of the applicable actions in the PlanDefinition based on evaluating the applicability condition in context, and producing Request resources based on the definition element for each applicable action.&#xA;&#xA;For each applicable action, the definition is applied as described in the $apply operation of the ActivityDefinition resource, and the resulting resource is added as an entry to the Bundle. The resulting Bundle may be any combination of Request resources, including CarePlan, RequestOrchestration, and individual Request resources such as ServiceRequest and MedicationRequest.&#xA;&#xA;Note that to preserve the structure of the PlanDefinition, systems may choose to return the results in a RequestOrchestration. In this case, the individual request resources will have an intent of `option`, meaning the their intent is governed by the RequestOrchestraiont.&#xA;&#xA;If the ActivityDefinition includes library references, those libraries will be available to the evaluated expressions. If those libraries have parameters, those parameters will be bound by name to the parameters given to the operation. In addition, parameters to the $apply operation are available within dynamicValue expressions as context variables, accessible by the name of the parameter, prefixed with a percent (%) symbol.&#xA;&#xA;For a more detailed description, refer to the PlanDefinition and ActivityDefinition resource documentation. Note that result of this operation is transient (i.e. none of the resources created by the operation are persisted in the server, they are all returned as entries in the result Bundle(s)). The result effectively represents a proposed set of activities, and it is up to the caller to determine whether and how those activities are actually carried out and/or persisted."/>
  <resource value="PlanDefinition"/>
  <system value="false"/>
  <type value="true"/>
  <instance value="true"/>
  <parameter>
    <name value="planDefinition"/>
    <use value="in"/>
    <scope value="type"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The plan definition to be applied. If the operation is invoked at the instance level, this parameter is not allowed; if the operation is invoked at the type level, this parameter is required, or a url (and optionally version) must be supplied"/>
    <type value="PlanDefinition"/>
  </parameter>
  <parameter>
    <name value="url"/>
    <use value="in"/>
    <scope value="type"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The url of the plan definition to be applied. If the operation is invoked at the instance level, this parameter is not allowed; if the operation is invoked at the type level, this parameter (and optionally the version), or the planDefinition parameter must be supplied"/>
    <type value="canonical"/>
    <targetProfile value="http://hl7.org/fhir/StructureDefinition/PlanDefinition"/>
  </parameter>
  <parameter>
    <name value="version"/>
    <use value="in"/>
    <scope value="type"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The version of the plan definition to be applied. If the operation is invoked at the instance level, this parameter is not allowed; if the operation is invoked at the type level, this parameter may only be used if the url parameter is supplied."/>
    <type value="string"/>
  </parameter>
  <parameter>
    <name value="subject"/>
    <use value="in"/>
    <min value="1"/>
    <max value="*"/>
    <documentation value="The subject(s) that is/are the target of the plan to be applied. The subject may be a Patient, Practitioner, Organization, Location, Device, or Group. Subjects provided in this parameter will be resolved as the subject of the PlanDefinition based on the type of the subject. If multiple subjects of the same type are provided, the behavior is implementation-defined"/>
    <type value="string"/>
    <searchType value="reference"/>
  </parameter>
  <parameter>
    <name value="encounter"/>
    <use value="in"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The encounter in context, if any"/>
    <type value="string"/>
    <searchType value="reference"/>
  </parameter>
  <parameter>
    <name value="practitioner"/>
    <use value="in"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The practitioner applying the plan definition"/>
    <type value="string"/>
    <searchType value="reference"/>
  </parameter>
  <parameter>
    <name value="organization"/>
    <use value="in"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The organization applying the plan definition"/>
    <type value="string"/>
    <searchType value="reference"/>
  </parameter>
  <parameter>
    <name value="userType"/>
    <use value="in"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The type of user initiating the request, e.g. patient, healthcare provider, or specific type of healthcare provider (physician, nurse, etc.)"/>
    <type value="CodeableConcept"/>
  </parameter>
  <parameter>
    <name value="userLanguage"/>
    <use value="in"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="Preferred language of the person using the system"/>
    <type value="CodeableConcept"/>
  </parameter>
  <parameter>
    <name value="userTaskContext"/>
    <use value="in"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The task the system user is performing, e.g. laboratory results review, medication list review, etc. This information can be used to tailor decision support outputs, such as recommended information resources"/>
    <type value="CodeableConcept"/>
  </parameter>
  <parameter>
    <name value="setting"/>
    <use value="in"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="The current setting of the request (inpatient, outpatient, etc.)"/>
    <type value="CodeableConcept"/>
  </parameter>
  <parameter>
    <name value="settingContext"/>
    <use value="in"/>
    <min value="0"/>
    <max value="1"/>
    <documentation value="Additional detail about the setting of the request, if any"/>
    <type value="CodeableConcept"/>
  </parameter>
  <parameter>
    <name value="return"/>
    <use value="out"/>
    <min value="0"/>
    <max value="*"/>
    <documentation value="A Bundle for each input subject that is the result of applying the plan definition to that subject. Note that even though there is a single parameter named return of type Bundle, it is a multi-cardinality parameter, and so will still be returned using a Parameters resource, as described in the general operations framework (https://hl7.org/fhir/R4/operations.html#response)."/>
    <type value="Bundle"/>
  </parameter>
</OperationDefinition>