@prefix fhir: <http://hl7.org/fhir/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# - resource -------------------------------------------------------------------

<http://ehealth.sundhed.dk/fhir/OperationDefinition/-s-assigned-material-count> a fhir:OperationDefinition ;
  fhir:nodeRole fhir:treeRoot ;
  fhir:Resource.id [ fhir:value "-s-assigned-material-count"] ;
  fhir:DomainResource.text [
     fhir:Narrative.status [ fhir:value "generated" ] ;
     fhir:Narrative.div "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p class=\"res-header-id\"><b>Generated Narrative: OperationDefinition -s-assigned-material-count</b></p><a name=\"-s-assigned-material-count\"> </a><a name=\"hc-s-assigned-material-count\"> </a><p>URL: [base]/$assigned-material-count</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>ehealth-documentReference</td><td/><td>1..1</td><td><a href=\"http://hl7.org/fhir/R4/references.html#Reference\">Reference</a></td><td/><td><div><p>Mandatory reference for general-material <code>ehealth-documentReference</code> from the Plan service.</p>\n</div></td></tr><tr><td>IN</td><td>group-by-careTeam</td><td/><td>0..1</td><td><a href=\"http://hl7.org/fhir/R4/datatypes.html#boolean\">boolean</a></td><td/><td><div><p>group the count by CareTeams present in the <code>Communication.participant.actor</code> references</p>\n</div></td></tr><tr><td>IN</td><td>date</td><td/><td>0..1</td><td><a href=\"http://hl7.org/fhir/R4/datatypes.html#dateTime\">dateTime</a></td><td/><td><div><p>Only count <code>ehealth-material-communications</code> where the <code>Communication.period</code> contains the date</p>\n</div></td></tr><tr><td>IN</td><td>status</td><td/><td>1..*</td><td><a href=\"http://hl7.org/fhir/R4/datatypes.html#string\">string</a></td><td/><td><div><p>Only count <code>ehealth-material-communications</code> with one of the given statuses</p>\n</div></td></tr></table></div>"
  ] ;
  fhir:OperationDefinition.url [ fhir:value "http://ehealth.sundhed.dk/fhir/OperationDefinition/-s-assigned-material-count"] ;
  fhir:OperationDefinition.version [ fhir:value "10.0.0"] ;
  fhir:OperationDefinition.name [ fhir:value "assigned-material-count"] ;
  fhir:OperationDefinition.title [ fhir:value "Retrieve count of assignments for material"] ;
  fhir:OperationDefinition.status [ fhir:value "active"] ;
  fhir:OperationDefinition.kind [ fhir:value "operation"] ;
  fhir:OperationDefinition.date [ fhir:value "2026-08-06T13:29:38+00:00"^^xsd:dateTime] ;
  fhir:OperationDefinition.publisher [ fhir:value "Den telemedicinske infrastruktur (eHealth Infrastructure)"] ;
  fhir:OperationDefinition.contact [
     fhir:index 0 ;
     fhir:ContactDetail.name [ fhir:value "Den telemedicinske infrastruktur (eHealth Infrastructure)" ] ;
     fhir:ContactDetail.telecom [
       fhir:index 0 ;
       fhir:ContactPoint.system [ fhir:value "url" ] ;
       fhir:ContactPoint.value [ fhir:value "http://ehealth.sundhed.dk" ]
     ]
  ] ;
  fhir:OperationDefinition.description [ fhir:value "This operation counts the number of material assignments (``ehealth-material-communication resources``) for a given ``ehealth-documentreference`` from the Plan service. This is done by performing an internal search using the given ehealth-documentReference, date and status parameters. Regardless of the given parameters, only ``ehealth-material-communication`` resources referring to an active ``ehealth-episodeofcare`` are counted. The group-by-careteam parameter determines whether a simple '_summary=count' search is performed or if all results should be fetched to extract and count based on participant CareTeam references.\r\n\r\n## Input\r\nThe operation has two mandatory input parameters:\r\n - An EHealthDocumentReference reference\r\n - One or more status codes\r\n\r\nAdditionally, there are two optional input parameters:\r\n - A boolean indicating whether to group the result by participant CareTeam references\r\n - A date parameter\r\n\r\n### EHealthDocumentReference reference\r\nA mandatory reference to an EHealthDocumentReference (general-material) in the plan service. Only ``ehealth-material-communication`` resources with the given reference in ``Communication.payload.content`` are counted.\r\n\r\n### Group-by-careTeam boolean\r\nThe group-by-careTeam parameter is optional. When not supplied by the user, it is assumed false. When it is set to true, the operation returns a count per CareTeam referenced as a participant in the matching ehealth-material-communication resources.\r\n\r\n### Date\r\nThe date parameter is optional, however, the count is always filtered by a date. If one is not given by the user, the date of execution is used instead. Only ``ehealth-material-communication`` resources whose ``Communication.period`` contains the used date are counted.\r\n\r\n### Status code list\r\nAt least one ``status`` code must be supplied by the user. Only ``ehealth-material-communications`` with one of the supplied status codes in ``Communication.status`` will be counted.\r\n\r\n## Output\r\nWhen supplied with valid inputs, the operation will return a Bundle resource with a single Parameters resource in its ``Bundle.entry`` list. The Parameters resource format depends on whether the group-by-careTeam parameter was true.\r\n\r\n### Output Parameters\r\nIf group-by-careTeam was false or not present. The Parameters resource will only contain a single parameter, named ``total`` with the value being the count of the ``ehealth-material-communication`` resources found to satisfy the given parameters.\r\n\r\nExample of output with group-by-careTeam as false or not present:\r\n```\r\n\"resource\": {\r\n    \"resourceType\": \"Parameters\",\r\n    \"parameter\": [{\r\n            \"name\": \"total\",\r\n            \"valueInteger\": 42\r\n            }]\r\n    }]\r\n}\r\n```\r\n\r\nIf group-by-careTeam was true, the Parameters resource will contain a parameter for each CareTeam that is referenced in ``Communication.participant.actor`` in any of the matching ``ehealth-material-communication`` resources. The name of each parameter will be the reference value (CareTeam/[id]) of the CareTeam and the value will be the count of matching ``ehealth-material-communication`` resources that reference that CareTeam. It is worth noting that if an ``ehealth-material-communication`` has two (or more) distinct participant CareTeams, this will add to the count of each of them.\r\n\r\nExample of output with group-by-careTeam as true:\r\n```\r\n\"resource\": {\r\n    \"resourceType\": \"Parameters\",\r\n    \"parameter\": [{\r\n            \"name\": \"CareTeam/123\",\r\n            \"valueInteger\": 5\r\n            },\r\n            {\r\n            \"name\": \"CareTeam/456\",\r\n            \"valueInteger\": 7\r\n            }]\r\n    }]\r\n}\r\n```\r\n"] ;
  fhir:OperationDefinition.jurisdiction [
     fhir:index 0 ;
     fhir:CodeableConcept.coding [
       fhir:index 0 ;
       fhir:Coding.system [ fhir:value "urn:iso:std:iso:3166" ] ;
       fhir:Coding.code [ fhir:value "DK" ] ;
       fhir:Coding.display [ fhir:value "Denmark" ]
     ]
  ] ;
  fhir:OperationDefinition.affectsState [ fhir:value "false"^^xsd:boolean] ;
  fhir:OperationDefinition.code [ fhir:value "assigned-material-count"] ;
  fhir:OperationDefinition.system [ fhir:value "true"^^xsd:boolean] ;
  fhir:OperationDefinition.type [ fhir:value "false"^^xsd:boolean] ;
  fhir:OperationDefinition.instance [ fhir:value "false"^^xsd:boolean] ;
  fhir:OperationDefinition.parameter [
     fhir:index 0 ;
     fhir:OperationDefinition.parameter.name [ fhir:value "ehealth-documentReference" ] ;
     fhir:OperationDefinition.parameter.use [ fhir:value "in" ] ;
     fhir:OperationDefinition.parameter.min [ fhir:value "1"^^xsd:integer ] ;
     fhir:OperationDefinition.parameter.max [ fhir:value "1" ] ;
     fhir:OperationDefinition.parameter.documentation [ fhir:value "Mandatory reference for general-material ``ehealth-documentReference`` from the Plan service." ] ;
     fhir:OperationDefinition.parameter.type [ fhir:value "Reference" ]
  ], [
     fhir:index 1 ;
     fhir:OperationDefinition.parameter.name [ fhir:value "group-by-careTeam" ] ;
     fhir:OperationDefinition.parameter.use [ fhir:value "in" ] ;
     fhir:OperationDefinition.parameter.min [ fhir:value "0"^^xsd:integer ] ;
     fhir:OperationDefinition.parameter.max [ fhir:value "1" ] ;
     fhir:OperationDefinition.parameter.documentation [ fhir:value "group the count by CareTeams present in the ``Communication.participant.actor`` references" ] ;
     fhir:OperationDefinition.parameter.type [ fhir:value "boolean" ]
  ], [
     fhir:index 2 ;
     fhir:OperationDefinition.parameter.name [ fhir:value "date" ] ;
     fhir:OperationDefinition.parameter.use [ fhir:value "in" ] ;
     fhir:OperationDefinition.parameter.min [ fhir:value "0"^^xsd:integer ] ;
     fhir:OperationDefinition.parameter.max [ fhir:value "1" ] ;
     fhir:OperationDefinition.parameter.documentation [ fhir:value "Only count ``ehealth-material-communications`` where the ``Communication.period`` contains the date" ] ;
     fhir:OperationDefinition.parameter.type [ fhir:value "dateTime" ]
  ], [
     fhir:index 3 ;
     fhir:OperationDefinition.parameter.name [ fhir:value "status" ] ;
     fhir:OperationDefinition.parameter.use [ fhir:value "in" ] ;
     fhir:OperationDefinition.parameter.min [ fhir:value "1"^^xsd:integer ] ;
     fhir:OperationDefinition.parameter.max [ fhir:value "*" ] ;
     fhir:OperationDefinition.parameter.documentation [ fhir:value "Only count ``ehealth-material-communications`` with one of the given statuses" ] ;
     fhir:OperationDefinition.parameter.type [ fhir:value "string" ]
  ] .

# - ontology header ------------------------------------------------------------

<http://ehealth.sundhed.dk/fhir/OperationDefinition/-s-assigned-material-count.ttl> a owl:Ontology ;
  owl:imports fhir:fhir.ttl .

# -------------------------------------------------------------------------------------

