{
  "resourceType": "OperationDefinition",
  "url": "http://electronichealth.se/fhir/OperationDefinition/NLLGetLatestDispense",
  "version": "1.0.0",
  "name": "NLLGetLatestDispense",
  "title": "latestdispense",
  "status": "draft",
  "kind": "query",
  "date": "2026-01-11T23:00:00+00:00",
  "publisher": "The Swedish eHealth Agency",
  "description": "An operation implemented as a named query that retrieves prescriptions for a patient or for a specified set of prescriptions, returning only the most recent dispense associated with each prescription. The operation also supports the optional inclusion of associated provenance resources.\r\n",
  "purpose": "Simplify the consumption of prescription data by identifying and returning only the most recent dispense for each prescription on the server side, with the option to include related events.",
  "affectsState": false,
  "code": "latest-dispense",
  "comment": "The query always returns the prescription (MedicationRequest) together with its most recent dispense (MedicationDispense).\n\nClients may optionally request the inclusion of Provenance related to both the prescription and the dispense. The server may obtain these related resources using FHIR Search reverse‑include expressions, such as _revinclude=Provenance:target:MedicationRequest to include prescribing Provenance, and _revinclude:iterate=Provenance:target:MedicationDispense to include dispense‑related Provenance. These expressions illustrate one possible retrieval approach and are not formal operation parameters.\r\n\r\nExample:\r\n```\r\n_revinclude=Provenance:target:MedicationRequest\n&_revinclude:iterate=Provenance:target:MedicationDispense\n```\r\n\r\nThis named query is invoked as:\nGET [base]/MedicationRequest?_query=latest-dispense\r\n",
  "resource": [
    "MedicationRequest"
  ],
  "system": false,
  "type": false,
  "instance": false,
  "parameter": [
    {
      "name": "patient._id",
      "use": "in",
      "min": 0,
      "max": "1",
      "documentation": "The patient whose prescriptions are to be retrieved. Use of this parameter precludes the use of the _id parameter within the same request.",
      "type": "Reference"
    },
    {
      "name": "_id",
      "use": "in",
      "min": 0,
      "max": "*",
      "documentation": "A comma‑separated list of one or more prescription identifiers (MedicationRequest IDs).",
      "type": "string"
    },
    {
      "name": "status",
      "use": "in",
      "min": 0,
      "max": "*",
      "documentation": "A comma‑separated list of prescription status values that may be used in combination with a patient reference.",
      "type": "ValueSet",
      "binding": {
        "strength": "required",
        "valueSet": "http://electronichealth.se/fhir/ValueSet/medication-request-status"
      }
    },
    {
      "name": "authoredon",
      "use": "in",
      "min": 0,
      "max": "1",
      "documentation": "Specifies the authoredOn date used for date‑based filtering of prescriptions. When provided, it defines the earliest date from which prescriptions shall be included. The parameter may be supplied on its own to indicate a start date, or together with an upper bound to express a date interval.\n\nExample: ?authoredon=ge2023-01-01&authoredon=le2024-01-01",
      "type": "Range"
    },
    {
      "name": "result",
      "use": "out",
      "min": 1,
      "max": "1",
      "documentation": "A Bundle containing prescriptions (MedicationRequest), the most recent dispense (MedicationDispense) for each prescription, and, when requested, Provenance resources associated specifically with the prescriptions.",
      "type": "Bundle"
    }
  ]
}