Aidbox / Issues

Issue tracker for Aidbox FHIR backend by Health Samurai
7 stars 0 forks source link

[BUG] Unable to parse HL7v2 RAS017 message #564

Closed pavlushkin closed 9 months ago

pavlushkin commented 9 months ago

Describe the bug Receiving RAS017 message from Epic -> parsing error

Epic documentation: https://open.epic.com/Tech/TechSpec?spec=staged%2FOutgoing%20Medication%20Administration%20Notification%20Interface%20Technical%20Specification.pdf

Severity Moderate

Steps to reproduce the behavior:

Hl7v2Config:

resourceType: Hl7v2Config
id: example
mapping:
  id: example
  resourceType: Mapping
isStrict: false

Error:

config:
  id: example
  resourceType: Hl7v2Config
type: RAS
outcome:
  - error
  - >-
    Rule :administration [RXA+ RXR observation*] at RXR expected  [RXR] got
    [RXE] segment position 4
ts: '2023-09-19T18:30:51.083228Z'
event: O17
status: error

Expected behavior The message is parsed

Versions:

mput commented 9 months ago

Looks like Epic produces invalid RAS017 messages according to HLv2 2.7 😞

Screenshot 2023-09-21 at 12 36 07

Anyway, loosened rules for RXE segment, looks like it's quite safe.

@pavlushkin fix should be available on :EDGE pretty soon, does it work for you?

mput commented 9 months ago

Fix is available on edge. by spec timing_encoded part and RXR segment are required, I've set them to optional:

RAS_O17:
  patient: [PID, 'PD1?', NTE*, AL1*, 'patient_visit?']
- encoding: [RXE, timing_encoded+, RXR+, RXC*]
+ encoding: [RXE, timing_encoded*, RXR*, RXC*]
  order_detail_supplement: [NTE+, RXR+, components*]
  patient_visit: [PV1, 'PV2?']
  observation: [OBX, NTE*]
  msg: [MSH, SFT*, NTE*, 'patient?', order+]
  components: [RXC, NTE*]
  order_detail: [RXO, 'order_detail_supplement?']
  timing: [TQ1, TQ2*]
  order: [ORC, timing*, 'order_detail?', 'encoding?', administration+, CTI*]
  administration: [RXA+, RXR, observation*]
  timing_encoded: [TQ1, TQ2*]

Also, it's required to describe custom ZXE segment with config extension:

#### simplest mapping

PUT http://localhost:8765/Mapping/example
Authorization: Basic cm9vdDpzZWNyZXQ=
Content-Type: application/json

{
  "resourceType" : "Mapping",
  "id" : "example",
  "body" : {
    "resourceType" : "Bundle",
    "type" : "transaction",
    "entry" : [ {
      "resource" : {
        "resourceType" : "Patient",
        "name" : [ {
          "given" : [ "$ msg.PID.name.0.given" ],
          "family" : "$ msg.PID.name.0.family.surname"
        } ]
      },
      "request" : {
        "method" : "POST",
        "url" : "/fhir/Patient"
      }
    } ]
  }
}

#### Config with Additional ZXE segment

PUT http://localhost:8765/Hl7v2Config/example
Authorization: Basic cm9vdDpzZWNyZXQ=
Content-Type: application/json

{
  "resourceType" : "Hl7v2Config",
  "isStrict" : false,
  "mapping" : {
    "resourceType" : "Mapping",
    "id" : "example"
  },
  "extensions" : [ {
    "msh" : "RAS_O17:encoding",
    "segment" : "ZXE",
    "fields" : [ {
      "key" : "ZXE1",
      "name" : "ZXE.1",
      "type" : "ST"
    }, {
      "key" : "ZXE2",
      "name" : "ZXE.2",
      "type" : "ST"
    }, {
      "key" : "ZXE3",
      "name" : "ZXE.3",
      "type" : "ST"
    }, {
      "key" : "ZXE4",
      "name" : "ZXE.4",
      "type" : "ST"
    }, {
      "key" : "ZXE5",
      "name" : "ZXE.5",
      "type" : "ST"
    }, {
      "key" : "ZXE6",
      "name" : "ZXE.6",
      "type" : "ST"
    }, {
      "key" : "ZXE7",
      "name" : "ZXE.7",
      "type" : "ST"
    }, {
      "key" : "ZXE8",
      "name" : "ZXE.8",
      "type" : "ST"
    }, {
      "key" : "ZXE9",
      "name" : "ZXE.9",
      "type" : "ST"
    }, {
      "key" : "ZXE10",
      "name" : "ZXE.10",
      "type" : "ST"
    }, {
      "key" : "ZXE11",
      "name" : "ZXE.11",
      "type" : "ST"
    }, {
      "key" : "ZXE12",
      "name" : "ZXE.12",
      "type" : "ST"
    }, {
      "key" : "ZXE13",
      "name" : "ZXE.13",
      "type" : "ST"
    }, {
      "key" : "ZXE14",
      "name" : "ZXE.14",
      "type" : "ST"
    }, {
      "key" : "ZXE15",
      "name" : "ZXE.15",
      "type" : "ST"
    }, {
      "key" : "order_pharmaceutical_class",
      "name" : "ZXE.16",
      "type" : "ST"
    }, {
      "key" : "order_therapeutic_class",
      "name" : "ZXE.17",
      "type" : "ST"
    } ]
  } ],
  "id" : "example"
}

as a result, fields order_pharmaceutical_class & order_therapeutic_class will be available in outcome:

      encoding:
        RXE:
          give_code:
            code: 00409-7983-09
            system: NDC
            display: 0.9% NaCl (volume based) infusion 1,000 mL 1,000 mL total volume
          give_units:
            code: mL
            display: mL
          give_dosage_form:
            code: '127'
          give_amount_minimum: '1000'
        ZXE:
          order_therapeutic_class: '1038'
          order_pharmaceutical_class: '127'
pavlushkin commented 9 months ago

Thank you for the explanation and fix. Checking...

pavlushkin commented 9 months ago

@mput @VarvaraSemenova The error is fixed, but new one has come up:

type: RAS
outcome:
  - error
  - 'Extra input [ZXC] pos: 8'
ts: '2023-09-21T15:23:48.056689Z'
event: O17
status: error

The message is same.

mput commented 9 months ago

The error is fixed, but new one has come up Looks like the field isStrict is set to true in Hl7v2Config.

Set it to false. Another option is to add extensions for ZXC and ZTA

pavlushkin commented 9 months ago

Thanks, isStrict=false works.

mput commented 9 months ago

Thanks, isStrict=false works. Superb. If you need help with extensions definition syntax - let me know.