Skip to content

Commit

Permalink
Merge pull request #7 from rmngrc/accepting-multiple-definitions-of-o…
Browse files Browse the repository at this point in the history
…ne-kind

Supporting many definitions of one kind
  • Loading branch information
rimiti authored Feb 15, 2019
2 parents 44b0b61 + 570b9a1 commit b4bf0e0
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 18 deletions.
58 changes: 40 additions & 18 deletions src/class/hl7-2.4/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,57 @@ export default class hl7 {
this._config = config
}

getSegmentsByType(type) {
return this._message.segments.filter((item) => {
return item.name === type
})
}

/**
* @description Convert from config mapping file hl7 to object
* @return {{}}
*/
process() {
let obj = {}
for (let segment in this._config.mapping) {
let s = (segment.toUpperCase() === 'MSH') ? this._message.header : this._message.getSegment(segment.toUpperCase())
for (let value of this._config.mapping[segment].values) {
if (value.field && s instanceof Object) {
let index1 = value.component[0]
let index2 = value.component[1]

if (s.getField(index1).includes('~')) {
let split = s.getField(index1).split('~')
let array = []
for (let v of split) {
array.push(v.split('^'))
}
let segmentType = segment.toUpperCase()
let segmentsOfType = (segmentType === 'MSH')
? [this._message.header]
: this.getSegmentsByType(segment.toUpperCase())

obj[segment] = []

for (let s of segmentsOfType) {
let tmpObj = {}

let output = []
for (let v in array) {
(array[v][value.component[1] - 1]) ? output.push(array[v][value.component[1] - 1]) : output.push('')
for (let value of this._config.mapping[segment].values) {
if (value.field && s instanceof Object) {
let index1 = value.component[0]
let index2 = value.component[1]

if (s.getField(index1).includes('~')) {
let split = s.getField(index1).split('~')
let array = []
for (let v of split) {
array.push(v.split('^'))
}

let output = []
for (let v in array) {
(array[v][value.component[1] - 1]) ? output.push(array[v][value.component[1] - 1]) : output.push('')
}
this._generateObject(tmpObj, value.field, output)
} else {
this._generateObject(tmpObj, value.field, s.getComponent(index1, index2))
}
this._generateObject(obj, value.field, output)
} else {
this._generateObject(obj, value.field, s.getComponent(index1, index2))
}
}

if (segmentsOfType.length > 1) {
obj[segment].push(tmpObj[segment])
} else {
obj[segment] = tmpObj[segment]
}
}
}
return obj
Expand Down
73 changes: 73 additions & 0 deletions test/oru/config/r01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"format": "hl7-2.4",
"adapter": "default",
"mapping": {
"msh": {
"values": [
{ "field": "msh.message_datetime", "component": [5,1] },
{ "field": "msh.message_type", "component": [7,1] },
{ "field": "msh.message_type_ref", "component": [7,2] },
{ "field": "msh.message_control_id", "component": [8,1] }
]
},
"pid": {
"values": [
{ "field": "pid.id", "component": [3,1] },
{ "field": "pid.origin", "component": [3,4] },
{ "field": "pid.first_name", "component": [5,2] },
{ "field": "pid.last_name", "component": [5,1] },
{ "field": "pid.birthdate", "component": [7,1] },
{ "field": "pid.gender", "component": [8,1] },
{ "field": "pid.street_name", "component": [11,1] },
{ "field": "pid.city", "component": [11,3] },
{ "field": "pid.zip_code", "component": [11,5] },
{ "field": "pid.phone", "component": [13,1] },
{ "field": "pid.email", "component": [13,4] }
]
},
"orc": {
"values": [
{ "field": "orc.order_control", "component": [1,1] },
{ "field": "orc.order_number", "component": [2,1] },
{ "field": "orc.order_status", "component": [5,1] },
{ "field": "orc.response_flag", "component": [6,1] },
{ "field": "orc.timestamp", "component": [9,1] },
{ "field": "orc.entered_by", "component": [10,8] },
{ "field": "orc.ordering_provider", "component": [12,8] },
{ "field": "orc.enterers_location", "component": [13,1] }
]
},
"obr": {
"values": [
{ "field": "obr.id", "component": [1,1] },
{ "field": "obr.order_id", "component": [2,1] },
{ "field": "obr.file_number", "component": [3,1] },
{ "field": "obr.universal_service_id", "component": [4,1] },
{ "field": "obr.priority", "component": [5,1] },
{ "field": "obr.timestamp", "component": [7,1] },
{ "field": "obr.collector_id", "component": [10,1] }
]
},
"obx": {
"values": [
{ "field": "obx.id", "component": [1,1] },
{ "field": "obx.type", "component": [2,1] },
{ "field": "obx.observation_id", "component": [3,1] },
{ "field": "obx.text", "component": [3,2] },
{ "field": "obx.value", "component": [5,1] },
{ "field": "obx.unit", "component": [6,1] },
{ "field": "obx.ranges", "component": [7,1] },
{ "field": "obx.status", "component": [11,1] },
{ "field": "obx.timestamp", "component": [14,1] },
{ "field": "obx.laboratory", "component": [15,1] }
]
},
"nte": {
"values": [
{ "field": "nte.id", "component": [1,1] },
{ "field": "nte.source", "component": [2,1] },
{ "field": "nte.comment", "component": [3,1] }
]
}
}
}
39 changes: 39 additions & 0 deletions test/oru/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import test from 'ava'
import {decode} from '../../src/lib/parser'
import r01Mapping from './config/r01.json'

test(`ORU - Notification of new observation result`, t => {
const r01 = `MSH|^~\&|LCS|LCA|LIS|TEST9999|199807311532||ORU^R01|3629|P|2.2\rPID|2|2161348462|20809880170|1614614|20809880170^TESTPAT||19760924|M|||^^^^\r00000-0000|||||||86427531^^^03|SSN# HERE\rORC|NW|8642753100012^LIS|20809880170^LCS||||||19980727000000|||HAVILAND\rOBR|1|8642753100012^LIS|20809880170^LCS|008342^UPPER RESPIRATORY\rCULTURE^L|||19980727175800||||||SS#634748641 CH14885 SRC:THROA\rSRC:PENI|19980727000000||||||20809880170||19980730041800||BN|F\rOBX|1|ST|008342^UPPER RESPIRATORY CULTURE^L||FINALREPORT|||||N|F||| 19980729160500|BN\rORC|NW|8642753100012^LIS|20809880170^LCS||||||19980727000000|||HAVILAND\rOBR|2|8642753100012^LIS|20809880170^LCS|997602^.^L|||19980727175800||||G|||\r19980727000000||||||20809880170||19980730041800|||F|997602|||008342\rOBX|2|CE|997231^RESULT 1^L||M415|||||N|F|||19980729160500|BN\rNTE|1|L|MORAXELLA (BRANHAMELLA) CATARRHALIS\rNTE|2|L| HEAVY GROWTH\rNTE|3|L| BETA LACTAMASE POSITIVE\rOBX|3|CE|997232^RESULT 2^L||MR105|||||N|F|||19980729160500|BN\rNTE|1|L|ROUTINE RESPIRATORY FLORA`
const obj = decode(r01, r01Mapping)
t.is(obj.msh.message_datetime, '199807311532')
t.is(obj.msh.message_type, 'ORU')
t.is(obj.msh.message_type_ref, 'R01')
t.is(obj.msh.message_control_id, '3629')
t.is(obj.pid.id, '20809880170')
t.is(obj.pid.origin, '')
t.is(obj.pid.first_name, 'TESTPAT')
t.is(obj.pid.last_name, '20809880170')
t.is(obj.pid.birthdate, '19760924')
t.is(obj.pid.gender, 'M')
t.is(obj.pid.street_name, '')
t.is(obj.pid.city, '')
t.is(obj.pid.zip_code, '')
t.is(obj.pid.phone, '')
t.is(obj.pid.email, '')
t.is(obj.nte.length, 4)
t.is(obj.nte[0].id, '1')
t.is(obj.nte[0].source, 'L')
t.is(obj.nte[0].comment, 'MORAXELLA (BRANHAMELLA) CATARRHALIS')
t.is(obj.nte[1].id, '2')
t.is(obj.nte[1].source, 'L')
t.is(obj.nte[1].comment, ' HEAVY GROWTH')
t.is(obj.nte[2].id, '3')
t.is(obj.nte[2].source, 'L')
t.is(obj.nte[2].comment, ' BETA LACTAMASE POSITIVE')
t.is(obj.nte[3].id, '1')
t.is(obj.nte[3].source, 'L')
t.is(obj.nte[3].comment, 'ROUTINE RESPIRATORY FLORA')
t.is(obj.orc.length, 2)
t.is(obj.obr.length, 2)
t.is(obj.obx.length, 3)
})

0 comments on commit b4bf0e0

Please sign in to comment.