FhirEx.Resources.MessageHeader (fhir_ex v0.2.0)

Copy Markdown View Source

FHIR R5 MessageHeader resource.

The header of a FHIR message. In a message Bundle this must be the first entry. It identifies what event the message represents, who sent it, and where responses should go.

https://www.hl7.org/fhir/R5/messageheader.html

Polymorphic event[x]

The event is stored as a tagged tuple:

{:coding, %Coding{system: "http://example.org/events", code: "admin-notify"}}
{:canonical, "http://example.org/MessageDefinition/patient-link"}

Source and destination endpoint[x]

Both source and each destination carry a required endpoint field, also polymorphic:

%{endpoint: {:url, "https://receiver.example.org/fhir"}}
%{endpoint: {:reference, %Reference{reference: "Device/device-001"}}}

Example

alias FhirEx.Resources.MessageHeader
alias FhirEx.Types.{Coding, Reference, ContactPoint}

header = %MessageHeader{
  id: "mh-001",
  event: {:coding, %Coding{
    system: "http://example.org/fhir/message-events",
    code: "patient-link"
  }},
  source: %{
    name: "LabSystem",
    software: "LabApp",
    version: "3.1.45.AABB",
    contact: %ContactPoint{system: "phone", value: "+1-800-LAB-HELP"},
    endpoint: {:url, "https://lab.example.org/fhir/messaging"}
  },
  destination: [
    %{
      name: "HIS",
      endpoint: {:url, "https://his.example.org/fhir"},
      receiver: %Reference{reference: "Organization/org-001"}
    }
  ],
  author: %Reference{reference: "Practitioner/prac-001"},
  focus: [%Reference{reference: "Patient/patient-001"}]
}

Message Bundle

Wrap a MessageHeader as the first entry of a message Bundle:

bundle = FhirEx.Resources.Bundle.new(
  type: "message",
  entry: [
    FhirEx.Resources.Bundle.entry(header),
    FhirEx.Resources.Bundle.entry(patient)
  ]
)

Summary

Functions

Builds the struct from a string-keyed map (e.g., from decoded FHIR JSON).

Builds a new struct from a map or keyword list of field values.

Returns the FHIR resource type name string.

Converts the struct to a string-keyed map for use with FhirEx.JSON.

Types

destination()

@type destination() :: %{
  name: String.t() | nil,
  target: FhirEx.Types.Reference.t() | nil,
  endpoint: endpoint_type(),
  receiver: FhirEx.Types.Reference.t() | nil
}

endpoint_type()

@type endpoint_type() :: {:url, String.t()} | {:reference, FhirEx.Types.Reference.t()}

event_type()

@type event_type() :: {:coding, FhirEx.Types.Coding.t()} | {:canonical, String.t()}

response()

@type response() :: %{
  identifier: FhirEx.Types.Identifier.t(),
  code: String.t(),
  details: FhirEx.Types.Reference.t() | nil
}

source()

@type source() :: %{
  name: String.t() | nil,
  software: String.t() | nil,
  version: String.t() | nil,
  contact: FhirEx.Types.ContactPoint.t() | nil,
  endpoint: endpoint_type()
}

t()

@type t() :: %FhirEx.Resources.MessageHeader{
  author: FhirEx.Types.Reference.t() | nil,
  definition: String.t() | nil,
  destination: [destination()] | nil,
  event: event_type(),
  extension: [FhirEx.Types.Extension.t()] | nil,
  focus: [FhirEx.Types.Reference.t()] | nil,
  id: String.t() | nil,
  meta: FhirEx.Types.Meta.t() | nil,
  reason: FhirEx.Types.CodeableConcept.t() | nil,
  response: response() | nil,
  responsible: FhirEx.Types.Reference.t() | nil,
  sender: FhirEx.Types.Reference.t() | nil,
  source: source(),
  text: FhirEx.Types.Narrative.t() | nil
}

Functions

from_map(map)

@spec from_map(map()) :: t()

Builds the struct from a string-keyed map (e.g., from decoded FHIR JSON).

new(attrs \\ %{})

@spec new(map() | keyword()) :: t()

Builds a new struct from a map or keyword list of field values.

resource_type()

@spec resource_type() :: String.t()

Returns the FHIR resource type name string.

to_map(mh)

@spec to_map(t()) :: map()

Converts the struct to a string-keyed map for use with FhirEx.JSON.