├── lib ├── segments │ ├── NCK.txt │ ├── RDT.txt │ ├── DSC.txt │ ├── ERR.txt │ ├── ADD.txt │ ├── NPU.txt │ ├── QAK.txt │ ├── RDF.txt │ ├── BLG.txt │ ├── ODT.txt │ ├── ERQ.txt │ ├── OM6.txt │ ├── RGS.txt │ ├── CTI.txt │ ├── NTE.txt │ ├── CM1.txt │ ├── CSS.txt │ ├── EQL.txt │ ├── LCC.txt │ ├── ODS.txt │ ├── DSP.txt │ ├── SPR.txt │ ├── RXR.txt │ ├── CM2.txt │ ├── CSP.txt │ ├── VTQ.txt │ ├── OM5.txt │ ├── MFE.txt │ ├── EVN.txt │ ├── LCH.txt │ ├── RXC.txt │ ├── APR.txt │ ├── MSA.txt │ ├── ACC.txt │ ├── RQ1.txt │ ├── MFI.txt │ ├── VAR.txt │ ├── PTH.txt │ ├── AL1.txt │ ├── MFA.txt │ ├── LRL.txt │ ├── ROL.txt │ ├── CTD.txt │ ├── URD.txt │ ├── MRG.txt │ ├── NSC.txt │ ├── PRA.txt │ ├── LOC.txt │ ├── DB1.txt │ ├── DRG.txt │ ├── OM3.txt │ ├── RQD.txt │ ├── AIS.txt │ ├── PRD.txt │ ├── QRF.txt │ ├── LDP.txt │ ├── CM0.txt │ ├── RF1.txt │ ├── PD1.txt │ ├── URS.txt │ ├── AIL.txt │ ├── AIP.txt │ ├── AUT.txt │ ├── QRD.txt │ ├── OM2.txt │ ├── FAC.txt │ ├── PES.txt │ ├── CDM.txt │ ├── AIG.txt │ ├── PDC.txt │ ├── NST.txt │ ├── OM4.txt │ ├── PR1.txt │ ├── UB2.txt │ ├── PRC.txt │ ├── OBX.txt │ ├── PSH.txt │ ├── DG1.txt │ ├── CSR.txt │ ├── MSH.txt │ ├── IAM.txt │ ├── GOL.txt │ ├── RXG.txt │ ├── UB1.txt │ ├── RXA.txt │ ├── STF.txt │ ├── ARQ.txt │ ├── FT1.txt │ ├── TXA.txt │ ├── RXD.txt │ ├── PCR.txt │ ├── IN3.txt │ ├── RXO.txt │ ├── SCH.txt │ ├── PID.txt │ ├── PRB.txt │ ├── PEO.txt │ ├── RXE.txt │ ├── ORC.txt │ ├── NK1.txt │ ├── PV2.txt │ ├── OBR.txt │ ├── PV1.txt │ ├── IN1.txt │ ├── GT1.txt │ ├── OM1.txt │ └── IN2.txt ├── translate.js ├── serializer.js ├── segments.txt └── parser.js ├── .travis.yml ├── .gitignore ├── .jshintrc ├── index.js ├── scrub.js ├── test ├── fixtures │ ├── sample2.txt │ ├── sample.txt │ ├── sample6.txt │ ├── sample4.txt │ ├── sample3.txt │ ├── isabella_jones_lipid_panel.txt │ ├── sample5.txt │ ├── isabella_jones_multiple_tests.txt │ └── samples.txt └── test.js ├── .jsbeautifyrc ├── Jenkinsfile ├── RELEASENOTES.md ├── example.js ├── package.json ├── gruntfile.js ├── README.md └── LICENSE /lib/segments/NCK.txt: -------------------------------------------------------------------------------- 1 | NCK 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 0 TS O 1 System Date/Time 4 | -------------------------------------------------------------------------------- /lib/segments/RDT.txt: -------------------------------------------------------------------------------- 1 | RDT 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 0 VARIES R 1 Column Value 4 | -------------------------------------------------------------------------------- /lib/segments/DSC.txt: -------------------------------------------------------------------------------- 1 | DSC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 180 ST O 1 Continuation Pointer 4 | -------------------------------------------------------------------------------- /lib/segments/ERR.txt: -------------------------------------------------------------------------------- 1 | ERR 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 80 ELD R * Error Code and Location 4 | -------------------------------------------------------------------------------- /lib/segments/ADD.txt: -------------------------------------------------------------------------------- 1 | ADD 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 65536 ST O 1 Addendum Continuation Pointer 4 | -------------------------------------------------------------------------------- /lib/segments/NPU.txt: -------------------------------------------------------------------------------- 1 | NPU 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 80 PL R 1 Bed Location 4 | 2 1 IS O 1 Bed Status 5 | -------------------------------------------------------------------------------- /lib/segments/QAK.txt: -------------------------------------------------------------------------------- 1 | QAK 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 32 ST C 1 Query Tag 4 | 2 2 ID O 1 Query Response Status 5 | -------------------------------------------------------------------------------- /lib/segments/RDF.txt: -------------------------------------------------------------------------------- 1 | RDF 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 3 NM R 1 Number of Columns per Row 4 | 2 40 RCD R * Column Description 5 | -------------------------------------------------------------------------------- /lib/segments/BLG.txt: -------------------------------------------------------------------------------- 1 | BLG 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 40 CCD O 1 When to Charge 4 | 2 50 ID O 1 Charge Type 5 | 3 100 CX O 1 Account ID 6 | -------------------------------------------------------------------------------- /lib/segments/ODT.txt: -------------------------------------------------------------------------------- 1 | ODT 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE R 1 Tray Type 4 | 2 60 CE O 10 Service Period 5 | 3 80 ST O 1 Text Instruction 6 | -------------------------------------------------------------------------------- /lib/segments/ERQ.txt: -------------------------------------------------------------------------------- 1 | ERQ 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 32 ST O 1 Query Tag 4 | 2 60 CE R 1 Event Identifier 5 | 3 256 QIP O * Input Parameter List 6 | -------------------------------------------------------------------------------- /lib/segments/OM6.txt: -------------------------------------------------------------------------------- 1 | OM6 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM O 1 Sequence Number - Test/Observation Master File 4 | 2 10240 TX O 1 Derivation Rule 5 | -------------------------------------------------------------------------------- /lib/segments/RGS.txt: -------------------------------------------------------------------------------- 1 | RGS 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - RGS 4 | 2 3 ID C 1 Segment Action Code 5 | 3 200 CE O 1 Resource Group ID 6 | -------------------------------------------------------------------------------- /lib/segments/CTI.txt: -------------------------------------------------------------------------------- 1 | CTI 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 EI R 1 Sponsor Study ID 4 | 2 60 CE C 1 Study Phase Identifier 5 | 3 60 CE O 1 Study Scheduled Time Point 6 | -------------------------------------------------------------------------------- /lib/segments/NTE.txt: -------------------------------------------------------------------------------- 1 | NTE 2 | SEQ LEN DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O Set ID - NTE 4 | 2 8 ID O Source of Comment 5 | 3 64000 FT O R Comment FT 6 | 4 60 CE O Comment Type 7 | -------------------------------------------------------------------------------- /lib/segments/CM1.txt: -------------------------------------------------------------------------------- 1 | CM1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - CM1 4 | 2 60 CE R 1 Study Phase Identifier 5 | 3 300 ST R 1 Description of Study Phase 6 | -------------------------------------------------------------------------------- /lib/segments/CSS.txt: -------------------------------------------------------------------------------- 1 | CSS 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE R 1 Study Scheduled Time Point 4 | 2 26 TS O 1 Study Scheduled Patient Time Point 5 | 3 60 CE O 3 Study Quality Control Codes 6 | -------------------------------------------------------------------------------- /lib/segments/EQL.txt: -------------------------------------------------------------------------------- 1 | EQL 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 32 ST O 1 Query Tag 4 | 2 1 ID R 1 Query/ Response Format Code 5 | 3 60 CE R 1 EQL Query Name 6 | 4 4096 ST R 1 EQL Query Statement 7 | -------------------------------------------------------------------------------- /lib/segments/LCC.txt: -------------------------------------------------------------------------------- 1 | LCC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 PL R 1 Primary Key Value - LCC 4 | 2 10 IS R 1 Location Department 5 | 3 60 CE O * Accommodation Type 6 | 4 60 CE R * Charge Code 7 | -------------------------------------------------------------------------------- /lib/segments/ODS.txt: -------------------------------------------------------------------------------- 1 | ODS 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 1 ID R 1 Type 4 | 2 60 CE O 10 Service Period 5 | 3 60 CE R 20 Diet, Supplement, or Preference Code 6 | 4 80 ST O 2 Text Instruction 7 | -------------------------------------------------------------------------------- /lib/segments/DSP.txt: -------------------------------------------------------------------------------- 1 | DSP 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O 1 Set ID - DSP 4 | 2 4 SI O 1 Display Level 5 | 3 300 TX R 1 Data Line 6 | 4 2 ST O 1 Logical Break Point 7 | 5 20 TX O 1 Result ID 8 | -------------------------------------------------------------------------------- /lib/segments/SPR.txt: -------------------------------------------------------------------------------- 1 | SPR 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 32 ST O 1 Query Tag 4 | 2 1 ID R 1 Query/ Response Format Code 5 | 3 60 CE R 1 Stored Procedure Name 6 | 4 256 QIP O * Input Parameter Lisbt 7 | -------------------------------------------------------------------------------- /lib/segments/RXR.txt: -------------------------------------------------------------------------------- 1 | RXR 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE R 1 Route 4 | 2 60 CE O 1 Site 5 | 3 60 CE O 1 Administration Device 6 | 4 60 CE O 1 Administration Method 7 | 5 60 CE O 1 Routing Instruction 8 | -------------------------------------------------------------------------------- /lib/segments/CM2.txt: -------------------------------------------------------------------------------- 1 | CM2 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O 1 Set ID - CM2 4 | 2 60 CE R 1 Scheduled Time Point 5 | 3 300 ST O 1 Description of Time Point 6 | 4 60 CE R 200 Events Scheduled This Time Point 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "14.19.3" 4 | 5 | before_script: 6 | - npm install -g grunt-cli 7 | - npm install --quiet 8 | 9 | #services: 10 | # - mongodb 11 | 12 | script: 13 | - grunt 14 | -------------------------------------------------------------------------------- /lib/segments/CSP.txt: -------------------------------------------------------------------------------- 1 | CSP 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE R 1 Study Phase Identifier 4 | 2 26 TS R 1 Date/time Study Phase Began 5 | 3 26 TS O 1 Date/time Study Phase Ended 6 | 4 60 CE C 1 Study Phase Evaluability 7 | -------------------------------------------------------------------------------- /lib/segments/VTQ.txt: -------------------------------------------------------------------------------- 1 | VTQ 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 32 ST O 1 Query Tag 4 | 2 1 ID R 1 Query/ Response Format Code 5 | 3 60 CE R 1 VT Query Name 6 | 4 60 CE R 1 Virtual Table Name 7 | 5 256 QSC O * Selection Criteria 8 | -------------------------------------------------------------------------------- /lib/segments/OM5.txt: -------------------------------------------------------------------------------- 1 | OM5 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM O 1 Sequence Number - Test/Observation Master File 4 | 2 200 CE O * Test/Observations Included within an Ordered Test Battery 5 | 3 200 ST O 1 Observation ID Suffixes 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | .project 4 | .settings 5 | .vagrant 6 | .pem 7 | 8 | server/coverage 9 | client/coverage 10 | coverage 11 | .DS_Store 12 | 13 | */**/.DS_Store 14 | 15 | .rdb 16 | 17 | npm-debug.log 18 | 19 | .anvil 20 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "browser": false, // Standard browser globals e.g. `window`, `document`. 3 | "node": true, // Enable globals available when code is running inside of the NodeJS runtime environment. 4 | "indent": 2 // Specify indentation spacing 5 | } -------------------------------------------------------------------------------- /lib/segments/MFE.txt: -------------------------------------------------------------------------------- 1 | MFE 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 3 ID R 1 Record-Level Event Code 4 | 2 20 ST C 1 MFN Control ID 5 | 3 26 TS O 1 Effective Date/Time 6 | 4 200 VARIES R * Primary Key Value - MFE 7 | 5 3 ID R * Primary Key Value Type 8 | -------------------------------------------------------------------------------- /lib/segments/EVN.txt: -------------------------------------------------------------------------------- 1 | EVN 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 3 ID B 1 Event Type Code 4 | 2 26 TS R 1 Recorded Date/Time 5 | 3 26 TS O 1 Date/Time Planned Event 6 | 4 3 IS O 1 Event Reason Code 7 | 5 60 XCN O * Operator ID 8 | 6 26 TS O 1 Event Occurred 9 | -------------------------------------------------------------------------------- /lib/segments/LCH.txt: -------------------------------------------------------------------------------- 1 | LCH 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 PL R 1 Primary Key Value - LCH 4 | 2 3 ID O 1 Segment Action Code 5 | 3 80 EI O 1 Segment Unique Key 6 | 4 80 CE R 1 Location Characteristic ID 7 | 5 80 CE R 1 Location Characteristic Value 8 | -------------------------------------------------------------------------------- /lib/segments/RXC.txt: -------------------------------------------------------------------------------- 1 | RXC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 1 ID R 1 RX Component Type 4 | 2 100 CE R 1 Component Code 5 | 3 20 NM R 1 Component Amount 6 | 4 60 CE R 1 Component Units 7 | 5 20 NM O 1 Component Strength 8 | 6 60 CE O 1 Component Strength Units 9 | -------------------------------------------------------------------------------- /lib/segments/APR.txt: -------------------------------------------------------------------------------- 1 | APR 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 80 SCV O * Time Selection Criteria 4 | 2 80 SCV O * Resource Selection Criteria 5 | 3 80 SCV O * Location Selection Criteria 6 | 4 5 NM O 1 Slot Spacing Criteria 7 | 5 80 SCV O * Filler Override Criteria 8 | -------------------------------------------------------------------------------- /lib/segments/MSA.txt: -------------------------------------------------------------------------------- 1 | MSA 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 2 ID R 1 Acknowledgement Code 4 | 2 20 ST R 1 Message Control ID 5 | 3 80 ST O 1 Text Message 6 | 4 15 NM O 1 Expected Sequence Number 7 | 5 1 ID B 1 Delayed Acknowledgment Type 8 | 6 100 CE O 1 Error Condition 9 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //main module that exports all other sub modules 3 | 4 | exports.parseString = require('./lib/parser.js').parseString; 5 | exports.serializeJSON = require('./lib/serializer.js').serializeJSON; 6 | exports.translate = require('./lib/translate.js').translate; 7 | -------------------------------------------------------------------------------- /lib/segments/ACC.txt: -------------------------------------------------------------------------------- 1 | ACC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 26 TS O 1 Accident Date/Time 4 | 2 60 CE O 1 Accident Code 5 | 3 25 ST O 1 Accident Location 6 | 4 60 CE O 1 Auto Accident State 7 | 5 1 ID O 1 Accident Job Related Indicator 8 | 6 12 ID O 1 Accident Death Indicator 9 | -------------------------------------------------------------------------------- /lib/segments/RQ1.txt: -------------------------------------------------------------------------------- 1 | RQ1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 10 ST O 1 Anticipated Price 4 | 2 60 CE C 1 Manufacturer ID 5 | 3 16 ST C 1 Manufacturer s Catalog 6 | 4 60 CE C 1 Vendor ID 7 | 5 16 ST C 1 Vendor Catalog 8 | 6 1 ID O 1 Taxable 9 | 7 1 ID O 1 Substitute Allowed 10 | -------------------------------------------------------------------------------- /lib/segments/MFI.txt: -------------------------------------------------------------------------------- 1 | MFI 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE R 1 Master File Identifier 4 | 2 180 HD O 1 Master File Application Identifier 5 | 3 3 ID R 1 File-Level Event Code 6 | 4 26 TS O 1 Entered Date/Time 7 | 5 26 TS O 1 Effective Date/Time 8 | 6 2 ID R 1 Response Level Code 9 | -------------------------------------------------------------------------------- /lib/segments/VAR.txt: -------------------------------------------------------------------------------- 1 | VAR 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 EI R 1 Variance Instance ID 4 | 2 26 TS R 1 Documented Date/Time 5 | 3 26 TS O 1 Stated Variance Date/Time 6 | 4 80 XCN O * Variance Originator 7 | 5 60 CE O 1 Variance Classification 8 | 6 512 ST O * Variance Description 9 | -------------------------------------------------------------------------------- /lib/segments/PTH.txt: -------------------------------------------------------------------------------- 1 | PTH 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 2 ID R 1 Action Code 4 | 2 80 CE R 1 Pathway ID 5 | 3 60 EI R 1 Pathway Instance ID 6 | 4 26 TS R 1 Pathway Established Date/Time 7 | 5 80 CE O 1 Pathway Life Cycle Status 8 | 6 26 TS C 1 Change Pathway Life Cycle Status Date/Time 9 | -------------------------------------------------------------------------------- /lib/segments/AL1.txt: -------------------------------------------------------------------------------- 1 | AL1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - AL1 4 | 2 2 IS O 1 Allergy Type 5 | 3 60 CE R 1 Allergy Code/Mnemonic/Description 6 | 4 2 IS O 1 Allergy Severity 7 | 5 15 ST O * Allergy Reaction 8 | 6 8 DT O 1 Identification Date 9 | -------------------------------------------------------------------------------- /lib/segments/MFA.txt: -------------------------------------------------------------------------------- 1 | MFA 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 3 ID R 1 Record-Level Event Code 4 | 2 20 ST C 1 MFN Control ID 5 | 3 26 TS O 1 Event Completion Date/Time 6 | 4 60 CE R 1 MFN Record Level Error Return 7 | 5 60 CE R * Primary Key Value MFA 8 | 6 3 ID R * Primary Key Value Type - MFA 9 | -------------------------------------------------------------------------------- /lib/segments/LRL.txt: -------------------------------------------------------------------------------- 1 | LRL 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 PL R 1 Primary Key Value - LRL 4 | 2 3 ID O 1 Segment Action Code 5 | 3 80 EI O 1 Segment Unique Key 6 | 4 80 CE R 1 Location Relationship ID 7 | 5 80 XON C * Organizational Location Relationship Value 8 | 6 80 PL C 1 Patient Location Relationship Value 9 | -------------------------------------------------------------------------------- /lib/segments/ROL.txt: -------------------------------------------------------------------------------- 1 | ROL 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 EI R 1 Role Instance ID 4 | 2 2 ID R 1 Action Code 5 | 3 80 CE R 1 Role-ROL 6 | 4 80 XCN R * Role Person 7 | 5 26 TS O 1 Role Begin Date/Time 8 | 6 26 TS O 1 Role End Date/Time 9 | 7 80 CE O 1 Role Duration 10 | 8 80 CE O 1 Role Action Reason 11 | -------------------------------------------------------------------------------- /lib/segments/CTD.txt: -------------------------------------------------------------------------------- 1 | CTD 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 CE R * Contact Role 4 | 2 106 XPN O * Contact Name 5 | 3 200 XAD O * Contact Address 6 | 4 60 PL O 1 Contact Location 7 | 5 100 XTN O * Contact Communication Information 8 | 6 200 CE O 1 Preferred Method Of Contact 9 | 7 100 PI O * Contact Identifiers 10 | -------------------------------------------------------------------------------- /lib/segments/URD.txt: -------------------------------------------------------------------------------- 1 | URD 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 26 TS O 1 R/U Date/Time 4 | 2 1 ID O 1 Report Priority 5 | 3 60 XCN R * R/U Who Subject Definition 6 | 4 60 CE O * R/U What Subject Definition 7 | 5 60 CE O * R/U What Department Code 8 | 6 20 ST O * R/U Display/Print Locations 9 | 7 1 ID O 1 R/U Results Level 10 | -------------------------------------------------------------------------------- /lib/segments/MRG.txt: -------------------------------------------------------------------------------- 1 | MRG 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 20 CX R * Prior Patient Identifier List 4 | 2 20 CX O * Prior Alternate Patient ID 5 | 3 20 CX O 1 Prior Patient Account Number 6 | 4 20 CX O 1 Prior Patient ID 7 | 5 20 CX O 1 Prior Visit Number 8 | 6 20 CX O 1 Prior Alternate Visit ID 9 | 7 48 XPN O * Prior Patient Name 10 | -------------------------------------------------------------------------------- /lib/segments/NSC.txt: -------------------------------------------------------------------------------- 1 | NSC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 0 IS O 1 Network Change Type 4 | 2 0 ST O 1 Current CPU 5 | 3 0 ST O 1 Current Fileserver 6 | 4 0 ST O 1 Current Application 7 | 5 0 ST O 1 Current Facility 8 | 6 0 ST O 1 New CPU 9 | 7 0 ST O 1 New Fileserver 10 | 8 0 ST O 1 New Application 11 | 9 0 ST O 1 New Facility 12 | -------------------------------------------------------------------------------- /lib/segments/PRA.txt: -------------------------------------------------------------------------------- 1 | PRA 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE R 1 Primary Key Value - PRA 4 | 2 60 CE O * Practitioner Group 5 | 3 3 IS O * Practitioner Category 6 | 4 1 ID O 1 Provider Billing 7 | 5 100 SPD O * Specialty 8 | 6 100 PLN O * Practitioner ID Numbers 9 | 7 200 PIP O * Privileges 10 | 8 8 DT O 1 Date Entered Practice 11 | -------------------------------------------------------------------------------- /lib/segments/LOC.txt: -------------------------------------------------------------------------------- 1 | LOC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 PL R 1 Primary Key Value - LOC 4 | 2 48 ST O 1 Location Description 5 | 3 2 IS R * Location Type - LOC 6 | 4 90 XON O * Organization Name - LOC 7 | 5 106 XAD O * Location Address 8 | 6 40 XTN O * Location Phone 9 | 7 60 CE O * License Number 10 | 8 3 IS O * Location Equipment 11 | 12 | -------------------------------------------------------------------------------- /lib/segments/DB1.txt: -------------------------------------------------------------------------------- 1 | DB1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - DB1 4 | 2 2 IS O 1 Disabled Person Code 5 | 3 32 CX O * Disabled Person Identifier 6 | 4 1 ID O 1 Disabled Indicator 7 | 5 8 DT O 1 Disability Start Date 8 | 6 8 DT O 1 Disability End Date 9 | 7 8 DT O 1 Disability Return to Work Date 10 | 8 8 DT O 1 Disability Unable to Work Date 11 | -------------------------------------------------------------------------------- /scrub.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //scrubs line ends /r/n into /r 3 | 4 | var fs=require('fs'); 5 | 6 | if (process.argv.length!==3){ 7 | console.log("Usage: node scrub.js hl7_filename"); 8 | process.exit(); 9 | } 10 | 11 | var filename=process.argv[2]; 12 | 13 | var data = fs.readFileSync(filename).toString(); 14 | 15 | data = data.split('\n').join('\r'); 16 | 17 | fs.writeFileSync(filename, data); -------------------------------------------------------------------------------- /lib/segments/DRG.txt: -------------------------------------------------------------------------------- 1 | DRG 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE O 1 Diagnostic Related Group 4 | 2 26 TS O 1 DRG Assigned Date/Time 5 | 3 1 ID O 1 DRG Approval Indicator 6 | 4 2 IS O 1 DRG Grouper Review Code 7 | 5 60 CE O 1 Outlier Type 8 | 6 3 NM O 1 Outlier Days 9 | 7 12 CP O 1 Outlier Cost 10 | 8 1 IS O 1 DRG Payor 11 | 9 9 CP O 1 Outlier Reimbursement 12 | 10 1 ID O 1 Confidential Indicator 13 | -------------------------------------------------------------------------------- /lib/segments/OM3.txt: -------------------------------------------------------------------------------- 1 | OM3 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM O 1 Sequence Number - Test/Observation Master File 4 | 2 60 CE O 1 Preferred Coding System 5 | 3 60 CE O 1 Valid Coded Answers 6 | 4 200 CE O * Normal Text/Codes for Categorical Observations 7 | 5 200 CE O 1 Abnormal Text/Codes for Categorical Observations 8 | 6 200 CE O 1 Critical Text Codes for Categorical Observations 9 | 7 3 ID O 1 Value Type 10 | -------------------------------------------------------------------------------- /lib/segments/RQD.txt: -------------------------------------------------------------------------------- 1 | RQD 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O 1 Requisition Line Number 4 | 2 60 CE C 1 Item Code - Internal 5 | 3 60 CE C 1 Item Code - External 6 | 4 60 CE C 1 Hospital Item Code 7 | 5 6 NM O 1 Requisition Quantity 8 | 6 60 CE O 1 Requisition Unit of Measure 9 | 7 30 IS O 1 Dept. Cost Center 10 | 8 30 IS O 1 Item Natural Account Code 11 | 9 60 CE O 1 Deliver To ID 12 | 10 8 DT O 1 Date Needed 13 | -------------------------------------------------------------------------------- /lib/segments/AIS.txt: -------------------------------------------------------------------------------- 1 | AIS 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - AIS 4 | 2 3 ID C 1 Segment Action Code 5 | 3 200 CE R 1 Universal Service ID 6 | 4 26 TS C 1 Start Date/Time 7 | 5 20 NM C 1 Start Date/Time Offset 8 | 6 200 CE C 1 Start Date/Time Offset Units 9 | 7 20 NM O 1 Duration 10 | 8 200 CE O 1 Duration Units 11 | 9 10 IS C 1 Allow Substitution Code 12 | 10 200 CE C 1 Filler Status Code 13 | -------------------------------------------------------------------------------- /lib/segments/PRD.txt: -------------------------------------------------------------------------------- 1 | PRD 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 CE R * Provider Role 4 | 2 106 XPN O * Provider Name 5 | 3 60 XAD O * Provider Address 6 | 4 60 PL O 1 Provider Location 7 | 5 100 XTN O * Provider Communication Information 8 | 6 200 CE O 1 Preferred Method Of Contact 9 | 7 100 PI O * Provider Identifiers 10 | 8 26 TS O 1 Effective Start Date of Provider Role 11 | 9 26 TS O 1 Effective End Date of Provider Role 12 | -------------------------------------------------------------------------------- /test/fixtures/sample2.txt: -------------------------------------------------------------------------------- 1 | MSH|^~\&|EPIC|EPICADT|SMS|SMSADT|199912271408|CHARRIS|ADT^A04|1817457|D|2.5| PID||0493575^^^2^ID 1|454721||DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086| NK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC||||||||||||||||||||||||||| PV1||O|168 ~219~C~PMA^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||||||||||||||||||||199912271408||||||002376853 -------------------------------------------------------------------------------- /lib/segments/QRF.txt: -------------------------------------------------------------------------------- 1 | QRF 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 20 ST R * Where Subject Filter 4 | 2 26 TS O 1 When Data Start Date/Time 5 | 3 26 TS O 1 When Data End Date/Time 6 | 4 60 ST O * What User Qualifier 7 | 5 60 ST O * Other QRY Subject Filter 8 | 6 12 ID O * Which Date/Time Qualifier 9 | 7 12 ID O * Which Date/Time Status Qualifier 10 | 8 12 ID O * Date/Time Selection Qualifier 11 | 9 60 TQ O 1 When Quantity/Timing Qualifier 12 | -------------------------------------------------------------------------------- /lib/segments/LDP.txt: -------------------------------------------------------------------------------- 1 | LDP 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 PL R 1 Primary Key Value - LDP 4 | 2 10 IS R 1 Location Department 5 | 3 3 IS O * Location Service 6 | 4 60 CE O * Specialty Type 7 | 5 1 IS O * Valid Patient Classes 8 | 6 1 ID O 1 Active/Inactive Flag 9 | 7 26 TS O 1 Activation Date LDP 10 | 8 26 TS O 1 Inactivation Date - LDP 11 | 9 80 ST O 1 Inactivated Reason 12 | 10 80 VH O * Visiting Hours 13 | 11 40 XTN O 1 Contact Phone 14 | -------------------------------------------------------------------------------- /lib/segments/CM0.txt: -------------------------------------------------------------------------------- 1 | CM0 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O 1 Set ID - CM0 4 | 2 60 EI R 1 Sponsor Study ID 5 | 3 60 EI O 3 Alternate Study ID 6 | 4 300 ST R 1 Title of Study 7 | 5 60 XCN O * Chairman of Study 8 | 6 8 DT O 1 Last IRB Approval Date 9 | 7 8 NM O 1 Total Accrual to Date 10 | 8 8 DT O 1 Last Accrual Date 11 | 9 60 XCN O * Contact for Study 12 | 10 40 XTN O 1 Contact's Tel. Number 13 | 11 100 XAD O * Contact's Address 14 | -------------------------------------------------------------------------------- /lib/segments/RF1.txt: -------------------------------------------------------------------------------- 1 | RF1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 CE O 1 Referral Status 4 | 2 200 CE O 1 Referral Priority 5 | 3 200 CE O 1 Referral Type 6 | 4 200 CE O * Referral Disposition 7 | 5 200 CE O 1 Referral Category 8 | 6 30 EI R 1 Originating Referral Identifier 9 | 7 26 TS O 1 Effective Date 10 | 8 26 TS O 1 Expiration Date 11 | 9 26 TS O 1 Process Date 12 | 10 200 CE O * Referral Reason 13 | 11 30 EI O * External Referral Identifier 14 | -------------------------------------------------------------------------------- /lib/segments/PD1.txt: -------------------------------------------------------------------------------- 1 | PD1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 2 IS O * Living Dependency 4 | 2 2 IS O 1 Living Arrangement 5 | 3 90 XON O * Patient Primary Facility 6 | 4 90 XCN O * Patient Primary Care Provider Name & ID No. 7 | 5 2 IS O 1 Student Indicator 8 | 6 2 IS O 1 Handicap 9 | 7 2 IS O 1 Living Will 10 | 8 2 IS O 1 Organ Donor 11 | 9 1 ID O 1 Separate Bill 12 | 10 20 CX O * Duplicate Patient 13 | 11 80 CE O 1 Publicity Code 14 | 12 1 ID O 1 Protection Indicator 15 | -------------------------------------------------------------------------------- /lib/segments/URS.txt: -------------------------------------------------------------------------------- 1 | URS 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 20 ST R * R/U Where Subject Definition 4 | 2 26 TS O 1 R/U When Data Start Date/Time 5 | 3 26 TS O 1 R/U When Data End Date/Time 6 | 4 20 ST O * R/U What User Qualifier 7 | 5 20 ST O * R/U Other Results Subject Definition 8 | 6 12 ID O * R/U Which Date/Time Qualifier 9 | 7 12 ID O * R/U Which Date/Time Status Qualifier 10 | 8 12 ID O * R/U Date/Time Selection Qualifier 11 | 9 60 TQ O 1 R/U Quantity/Timing Qualifier 12 | -------------------------------------------------------------------------------- /test/fixtures/sample.txt: -------------------------------------------------------------------------------- 1 | MSH|^~\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4 PID|||555-44-4444||EVERYWOMAN^EVE^E^^^^L|JONES|19620320|F|||153 FERNWOOD DR.^^STATESVILLE^OH^35292||(206)3345232|(206)752-121||||AC555444444||67-A4335^OH^20030520 OBR|1|845439^GHH OE|1045813^GHH LAB|15545^GLUCOSE|||200202150730|||||||||555-55-5555^PRIMARY^PATRICIA P^^^^MD^^|||||||||F||||||444-44-4444^HIPPOCRATES^HOWARD H^^^^MD OBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|70_105|H|||F -------------------------------------------------------------------------------- /lib/segments/AIL.txt: -------------------------------------------------------------------------------- 1 | AIL 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - AIL 4 | 2 3 ID C 1 Segment Action Code 5 | 3 80 PL C 1 Location Resource ID 6 | 4 200 CE R 1 Location Type-AIL 7 | 5 200 CE O 1 Location Group 8 | 6 26 TS C 1 Start Date/Time 9 | 7 20 NM C 1 Start Date/Time Offset 10 | 8 200 CE C 1 Start Date/Time Offset Units 11 | 9 20 NM O 1 Duration 12 | 10 200 CE O 1 Duration Units 13 | 11 10 IS C 1 Allow Substitution Code 14 | 12 200 CE C 1 Filler Status Code 15 | -------------------------------------------------------------------------------- /lib/segments/AIP.txt: -------------------------------------------------------------------------------- 1 | AIP 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - AIP 4 | 2 3 ID C 1 Segment Action Code 5 | 3 80 XCN C * Personnel Resource ID 6 | 4 200 CE R 1 Resource Role 7 | 5 200 CE O 1 Resource Group 8 | 6 26 TS C 1 Start Date/Time 9 | 7 20 NM C 1 Start Date/Time Offset 10 | 8 200 CE C 1 Start Date/Time Offset Units 11 | 9 20 NM O 1 Duration 12 | 10 200 CE O 1 Duration Units 13 | 11 10 IS C 1 Allow Substitution Code 14 | 12 200 CE C 1 Filler Status Code 15 | -------------------------------------------------------------------------------- /.jsbeautifyrc: -------------------------------------------------------------------------------- 1 | { 2 | "indent_size": 2, 3 | "indent_char": " ", 4 | "indent_level": 0, 5 | "indent_with_tabs": false, 6 | "preserve_newlines": true, 7 | "max_preserve_newlines": 2, 8 | "jslint_happy": true, 9 | "brace_style": "collapse", 10 | "keep_array_indentation": false, 11 | "keep_function_indentation": false, 12 | "space_before_conditional": true, 13 | "break_chained_methods": false, 14 | "eval_code": false, 15 | "unescape_strings": false, 16 | "wrap_line_length": 0 17 | } -------------------------------------------------------------------------------- /lib/segments/AUT.txt: -------------------------------------------------------------------------------- 1 | AUT 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 CE O 1 Authorizing Payor, Plan ID 4 | 2 200 CE R 1 Authorizing Payor, Company ID 5 | 3 45 ST O 1 Authorizing Payor, Company Name 6 | 4 26 TS O 1 Authorization Effective Date 7 | 5 26 TS O 1 Authorization Expiration Date 8 | 6 30 EI C 1 Authorization Identifier 9 | 7 25 CP O 1 Reimbursement Limit 10 | 8 2 NM O 1 Requested Number of Treatments 11 | 9 2 NM O 1 Authorized Number of Treatments 12 | 10 26 TS O 1 Process Date 13 | -------------------------------------------------------------------------------- /lib/segments/QRD.txt: -------------------------------------------------------------------------------- 1 | QRD 2 | PSEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 26 TS R 1 Query Date/Time 4 | 2 1 ID R 1 Query Format Code 5 | 3 1 ID R 1 Query Priority 6 | 4 10 ST R 1 Query ID 7 | 5 1 ID O 1 Deferred Response Type 8 | 6 26 TS O 1 Deferred Response Date/Time 9 | 7 10 CQ R 1 Quantity Limited Request 10 | 8 60 XCN R * Who Subject Filter 11 | 9 60 CE R * What Subject Filter 12 | 10 60 CE R * What Department Data Code 13 | 11 20 VR O * What Data Code Value Qual. 14 | 12 1 ID O 1 Query Results Level 15 | -------------------------------------------------------------------------------- /lib/segments/OM2.txt: -------------------------------------------------------------------------------- 1 | OM2 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM O 1 Sequence Number - Test/Observation Master File 4 | 2 60 CE O 1 Units of Measure 5 | 3 10 NM O * Range of Decimal Precision 6 | 4 60 CE O 1 Corresponding SI Units of Measure 7 | 5 60 TX O 1 SI Conversion Factor 8 | 6 200 RFR O 1 Reference 9 | 7 200 NR O 1 Critical Range for Ordinal & Continuous Obs 10 | 8 200 RFR O 1 Absolute Range for Ordinal & Continuous Obs 11 | 9 200 DLT O * Delta Check Criteria 12 | 10 20 NM O 1 Minimum Meaningful Increments 13 | -------------------------------------------------------------------------------- /lib/segments/FAC.txt: -------------------------------------------------------------------------------- 1 | FAC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 20 EI R 1 Facility ID-FAC 4 | 2 1 ID O 1 Facility Type 5 | 3 200 XAD R * Facility Address 6 | 4 44 XTN R 1 Facility Telecommunication 7 | 5 60 XCN O * Contact Person 8 | 6 60 ST O * Contact Title 9 | 7 200 XAD O * Contact Address 10 | 8 44 XTN O * Contact Telecommunication 11 | 9 60 XCN R * Signature Authority 12 | 10 60 ST O 1 Signature Authority Title 13 | 11 200 XAD O * Signature Authority Address 14 | 12 44 XTN O 1 Signature Authority Telecommunication 15 | 16 | -------------------------------------------------------------------------------- /test/fixtures/sample6.txt: -------------------------------------------------------------------------------- 1 | MSH|^~\&|Sending 2 | 3 | test|Sending test facility|Receiving test|Receiving test facility|09542013500P|SECURITY|ORU^R01|12345||2.5.1||| 4 | PID|||||John Dow||64121968|M|||Every town, every street||(206)3345232||||||987654321|| 5 | OBR|1|845439^GHH OE|1045813^GHH LAB|15545^GLUCOSE|||101020114500|||||||||555-55-5555^PRIMARY^PATRICIA P^^^^MD^^|||||||||F|||||||444-44-4444^HIPPOCRATES^HOWARD H^^^^MD||||| 6 | OBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|70_105|H|||F|||||||||| 7 | -------------------------------------------------------------------------------- /lib/segments/PES.txt: -------------------------------------------------------------------------------- 1 | PES 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 80 XON O * Sender Organization Name 4 | 2 60 XCN O * Sender Individual Name 5 | 3 200 XAD O * Sender Address 6 | 4 44 XTN O * Sender Telephone 7 | 5 75 EI O 1 Sender Event Identifier 8 | 6 2 NM O 1 Sender Sequence Number 9 | 7 600 FT O * Sender Event Description 10 | 8 600 FT O 1 Sender Comment 11 | 9 26 TS O 1 Sender Aware Date/Time 12 | 10 26 TS R 1 Event Report Date 13 | 11 3 ID O 2 Event Report Timing/Type 14 | 12 1 ID O 1 Event Report Source 15 | 13 1 ID O * Event Reported To 16 | -------------------------------------------------------------------------------- /lib/segments/CDM.txt: -------------------------------------------------------------------------------- 1 | CDM 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 CE R 1 Primary Key Value - CDM 4 | 2 200 CE O * Charge Code Alias 5 | 3 20 ST R 1 Charge Description Short 6 | 4 250 ST O 1 Charge Description Long 7 | 5 1 IS O 1 Description Override Indicator 8 | 6 60 CE O * Exploding Charges 9 | 7 80 CE O * Procedure Code 10 | 8 1 ID O 1 Active/Inactive Flag 11 | 9 60 CE O * Inventory Number 12 | 10 12 NM O 1 Resource Load 13 | 11 200 CK O * Contract Number 14 | 12 200 XON O * Contract Organization 15 | 13 1 ID O 1 Room Fee Indicator 16 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { 3 | docker { 4 | image 'node:18.20.1-alpine3.19' 5 | } 6 | } 7 | stages { 8 | stage('Sanity Check') { 9 | steps { 10 | echo 'Node installation check...' 11 | sh 'node --version' 12 | } 13 | } 14 | stage('Build') { 15 | steps { 16 | echo 'Installing dependencies...' 17 | sh 'npm i' 18 | } 19 | } 20 | stage('Test') { 21 | steps { 22 | echo 'Testing...' 23 | sh 'npm run coverage' 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /lib/segments/AIG.txt: -------------------------------------------------------------------------------- 1 | AIG 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - AIG 4 | 2 3 ID C 1 Segment Action Code 5 | 3 200 CE C 1 Resource ID 6 | 4 200 CE R 1 Resource Type 7 | 5 200 CE O * Resource Group 8 | 6 5 NM O 1 Resource Quantity 9 | 7 200 CE O 1 Resource Quantity Units 10 | 8 26 TS C 1 Start Date/Time 11 | 9 20 NM C 1 Start Date/Time Offset 12 | 10 200 CE C 1 Start Date/Time Offset Units 13 | 11 20 NM O 1 Duration 14 | 12 200 CE O 1 Duration Units 15 | 13 10 IS C 1 Allow Substitution Code 16 | 14 200 CE C 1 Filler Status Code 17 | -------------------------------------------------------------------------------- /lib/segments/PDC.txt: -------------------------------------------------------------------------------- 1 | PDC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 80 XON R * Manufacturer/Distributor 4 | 2 60 CE R 1 Country 5 | 3 60 ST R 1 Brand Name 6 | 4 60 ST O 1 Device Family Name 7 | 5 60 CE O 1 Generic Name 8 | 6 60 ST O * Model Identifier 9 | 7 60 ST O 1 Catalogue Identifier 10 | 8 60 ST O * Other Identifier 11 | 9 60 CE O 1 Product Code 12 | 10 4 ID O 1 Marketing Basis 13 | 11 60 ST O 1 Marketing Approval ID 14 | 12 12 CQ O 1 Labeled Shelf Life 15 | 13 12 CQ O 1 Expected Shelf Life 16 | 14 26 TS O 1 Date First Marketed 17 | 15 26 TS O 1 Date Last Marketed 18 | -------------------------------------------------------------------------------- /lib/segments/NST.txt: -------------------------------------------------------------------------------- 1 | NST 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 0 ID O 1 Statistics Available 4 | 2 0 ST O 1 Source Identifier 5 | 3 0 ID O 1 Source Type 6 | 4 0 TS O 1 Statistics Start 7 | 5 0 TS O 1 Statistics End 8 | 6 0 NM O 1 Receive Character Count 9 | 7 0 NM O 1 Send Character Count 10 | 8 0 NM O 1 Messages Received 11 | 9 0 NM O 1 Messages Sent 12 | 10 0 NM O 1 Checksum Errors Received 13 | 11 0 NM O 1 Length Errors Received 14 | 12 0 NM O 1 Other Errors Received 15 | 13 0 NM O 1 Connect Timeouts 16 | 14 0 NM O 1 Receive Timeouts 17 | 15 0 NM O 1 Network Errors 18 | -------------------------------------------------------------------------------- /lib/segments/OM4.txt: -------------------------------------------------------------------------------- 1 | OM4 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM O 1 Sequence Number - Test/Observation Master File 4 | 2 1 ID O 1 Derived Specimen 5 | 3 60 TX O 1 Container Description 6 | 4 20 NM O 1 Container Volume 7 | 5 60 CE O 1 Container Units 8 | 6 60 CE O 1 Specimen 9 | 7 60 CE O 1 Additive 10 | 8 10240 TX O 1 Preparation 11 | 9 10240 TX O 1 Special Handling Requirements 12 | 10 20 CQ O 1 Normal Collection Volume 13 | 11 20 CQ O 1 Minimum Collection Volume 14 | 12 10240 TX O 1 Specimen Requirements 15 | 13 1 ID O * Specimen Priorities 16 | 14 20 CQ O 1 Specimen Retention Time 17 | -------------------------------------------------------------------------------- /test/fixtures/sample4.txt: -------------------------------------------------------------------------------- 1 | MSH|^~\&|EPIC|EPICADT|SMS|SMSADT|199912271408|CHARRIS|ADT^A04|1817457|D|2.5| 2 | PID||0493575^^^2^ID 1|454721||DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086|999-| 3 | NK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC||||||||||||||||||||||||||| 4 | NK1||DOE^JOHN ^^^^|SPO||(216)123-4567||EC||||||||||||||||||||||||||| 5 | NK1||DOE^ROBERT ^^^^|SPO||(216)123-4568||EC||||||||||||||||||||||||||| 6 | PV1||O|168 ~219~C~PMA^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||||||||||||||||||||199912271408||||||002376853 -------------------------------------------------------------------------------- /lib/segments/PR1.txt: -------------------------------------------------------------------------------- 1 | PR1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - PR1 4 | 2 2 IS B 1 Procedure Coding Method 5 | 3 80 CE R 1 Procedure Code 6 | 4 40 ST B 1 Procedure Description 7 | 5 26 TS R 1 rocedure Date/Time 8 | 6 2 IS R 1 Procedure Functional Type 9 | 7 4 NM O 1 Procedure Minutes 10 | 8 120 XCN B * Anesthesiologist 11 | 9 2 IS O 1 Anesthesia Code 12 | 10 4 NM O 1 Anesthesia Minutes 13 | 11 120 XCN B * Surgeon 14 | 12 230 XCN B * Procedure Practitioner 15 | 13 60 CE O 1 Consent Code 16 | 14 2 NM O 1 Procedure Priority 17 | 15 80 CE O 1 Associated Diagnosis Code 18 | 16 80 CE O * Procedure Code Modifier 19 | -------------------------------------------------------------------------------- /lib/segments/UB2.txt: -------------------------------------------------------------------------------- 1 | UB2 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O 1 Set ID - UB2 4 | 2 3 ST O 1 Co-Insurance Days 5 | 3 2 IS O 7 Condition Code 6 | 4 3 ST O 1 Covered Days 7 | 5 4 ST O 1 Non-Covered Days 8 | 6 11 UVC O 12 Value Amount & Code 9 | 7 11 OCD O 8 Occurrence Code & Date 10 | 8 28 OSP O 2 Occurrence Span Code/Dates 11 | 9 29 ST O 2 UB92 Locator 2 12 | 10 12 ST O 2 UB92 Locator 11 13 | 11 5 ST O 1 UB92 Locator 31 14 | 12 23 ST O 3 Document Control Number 15 | 13 4 ST O 23 UB92 Locator 49 16 | 14 14 ST O 5 UB92 Locator 56 17 | 15 27 ST O 1 UB92 Locator 57 18 | 16 2 ST O 2 UB92 Locator 78 19 | 17 3 NM O 1 Special Visit Count 20 | -------------------------------------------------------------------------------- /lib/segments/PRC.txt: -------------------------------------------------------------------------------- 1 | PRC 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 CE R 1 Primary Key Value - PRC 4 | 2 60 CE O * Facility ID - PRC 5 | 3 200 CE O * Department 6 | 4 1 IS O * Valid Patient Classes 7 | 5 12 CP C * Price 8 | 6 200 ST O * Formula 9 | 7 4 NM O 1 Minimum Quantity 10 | 8 4 NM O 1 Maximum Quantity 11 | 9 12 MO O 1 Minimum Price 12 | 10 12 MO O 1 Maximum Price 13 | 11 26 TS O 1 Effective Start Date 14 | 12 26 TS O 1 Effective End Date 15 | 13 1 IS O 1 Price Override Flag 16 | 14 60 CE O * Billing Category 17 | 15 1 ID O 1 Chargeable Flag 18 | 16 1 ID O 1 Active/Inactive Flag 19 | 17 12 MO O 1 Cost 20 | 18 1 IS O 1 Charge On Indicator 21 | -------------------------------------------------------------------------------- /lib/segments/OBX.txt: -------------------------------------------------------------------------------- 1 | OBX 2 | SEQ LEN DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O Set ID – Obx 4 | 2 2 ID R Value Type 5 | 3 590 CE R Observation Identifier 6 | 4 20 ST O Observation Sub-Id 7 | 5 65536 ST O Observation Value 8 | 6 60 CE O Units 9 | 7 10 ST O Reference Range 10 | 8 5 ID O Y/5 Abnormal Flags 11 | 9 5 NM O Probability 12 | 10 2 ID O Nature of Abnormal Test 13 | 11 1 ID R Observation Result Status 14 | 12 26 TS O Data Last Obs Normal Values 15 | 13 20 ST O User Defined Access Checks 16 | 14 26 TS O Date/Time of the Observation 17 | 15 60 CE O Producer’s Id 18 | 16 80 XCN O Responsible Observer 19 | 17 80 CE O Y Observation Method 20 | -------------------------------------------------------------------------------- /lib/segments/PSH.txt: -------------------------------------------------------------------------------- 1 | PSH 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 ST R 1 Report Type 4 | 2 60 ST O 1 Report Form Identifier 5 | 3 26 TS R 1 Report Date 6 | 4 26 TS O 1 Report Interval Start Date 7 | 5 26 TS O 1 Report Interval End Date 8 | 6 12 CQ O 1 Quantity Manufactured 9 | 7 12 CQ O 1 Quantity Distributed 10 | 8 1 ID O 1 Quantity Distributed Method 11 | 9 600 FT O 1 Quantity Distributed Comment 12 | 10 12 CQ O 1 Quantity in Use 13 | 11 1 ID O 1 Quantity in Use Method 14 | 12 600 FT O 1 Quantity in Use Comment 15 | 13 2 NM O 8 Number of Product Experience Reports Filed by Facility 16 | 14 2 NM O 8 Number of Product Experience Reports Filed by Distributor 17 | -------------------------------------------------------------------------------- /RELEASENOTES.md: -------------------------------------------------------------------------------- 1 | # HL7 Release Notes 2 | 3 | ## v1.1.2 - May 31, 2022 4 | 5 | ### Patch Update 6 | 7 | - GHSA-rm36-94g8-835r - Race Condition in Grunt 8 | 9 | ## v1.1.2 - April 13, 2022 10 | 11 | ### Patch Update 12 | 13 | - Upgraded dev dependencies 14 | - Switch to jest for testing and coverage 15 | 16 | ## v0.1.0 - December 12, 2014 17 | 18 | ### Initial release of the library 19 | 20 | - Supports ORU^R01 (Lab Results) HL7 v 2.3-2.5 messages. 21 | - Following segments are implemented MSH, PID, OBR, OBX, NTE 22 | - Parsing of HL7 v2 messages in JSON 23 | - Serializing JSON into HL7 24 | - Translating of JSON into more developer fiendly structure (named fields/elements) 25 | -------------------------------------------------------------------------------- /lib/segments/DG1.txt: -------------------------------------------------------------------------------- 1 | DG1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - DG1 4 | 2 2 ID B 1 Diagnosis Coding Method 5 | 3 60 CE O 1 Diagnosis Code - DG1 6 | 4 40 ST B 1 Diagnosis Description 7 | 5 26 TS O 1 Diagnosis Date/Time 8 | 6 2 IS R 1 Diagnosis Type 9 | 7 60 CE B 1 Major Diagnostic Category 10 | 8 60 CE B 1 Diagnostic Related Group 11 | 9 1 ID B 1 DRG Approval Indicator 12 | 10 2 IS B 1 DRG Grouper Review Code 13 | 11 60 CE B 1 Outlier Type 14 | 12 3 NM B 1 Outlier Days 15 | 13 12 CP B 1 Outlier Cost 16 | 14 4 ST B 1 Grouper Version And Type 17 | 15 2 ID O 1 Diagnosis Priority 18 | 16 60 XCN O * Diagnosing Clinician 19 | 17 3 IS O 1 Diagnosis Classification 20 | 18 1 ID O 1 Confidential Indicator 21 | 19 26 TS O 1 Attestation Date/Time 22 | -------------------------------------------------------------------------------- /lib/segments/CSR.txt: -------------------------------------------------------------------------------- 1 | CSR 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 EI R 1 Sponsor Study ID 4 | 2 60 EI O 1 Alternate Study ID 5 | 3 60 CE O 1 Institution Registering the Patient 6 | 4 30 CX R 1 Sponsor Patient ID 7 | 5 30 CX O 1 Alternate Patient ID - CSR 8 | 6 26 TS R 1 Date/Time Of Patient Study Registration 9 | 7 60 XCN O * Person Performing Study Registration 10 | 8 60 XCN R * Study Authorizing Provider 11 | 9 26 TS C 1 Date/time Patient Study Consent Signed 12 | 10 60 CE C 1 Patient Study Eligibility Status 13 | 11 26 TS O 3 Study Randomization Date/time 14 | 12 200 CE O 3 Randomized Study Arm 15 | 13 200 CE O 3 Stratum for Study Randomization 16 | 14 60 CE C 1 Patient Evaluability Status 17 | 15 26 TS C 1 Date/time Ended Study 18 | 16 60 CE C 1 Reason Ended Study 19 | -------------------------------------------------------------------------------- /lib/segments/MSH.txt: -------------------------------------------------------------------------------- 1 | MSH 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 1 ST R 1 Field Separator 4 | 2 4 ST R 1 Encoding Characters 5 | 3 180 HD O 1 Sending Application 6 | 4 180 HD O 1 Sending Facility 7 | 5 180 HD O 1 Receiving Application 8 | 6 180 HD O 1 Receiving Facility 9 | 7 26 TS O 1 Date/Time Of Message 10 | 8 40 ST O 1 Security 11 | 9 7 MSG R 1 Message Type 12 | 10 20 ST R 1 Message Control ID 13 | 11 3 PT R 1 Processing ID 14 | 12 60 VID R 1 Version ID 15 | 13 15 NM O 1 Sequence Number 16 | 14 180 ST O 1 Continuation Pointer 17 | 15 2 ID O 1 Accept Acknowledgment Type 18 | 16 2 ID O 1 Application Acknowledgment Type 19 | 17 2 ID O 1 Country Code 20 | 18 16 ID O * Character Set 21 | 19 60 CE O 1 Principal Language Of Message 22 | 20 20 ID O 1 Alternate Character Set Handling Scheme 23 | -------------------------------------------------------------------------------- /test/fixtures/sample3.txt: -------------------------------------------------------------------------------- 1 | MSH|^~\&|XXXX|C|PRIORITYHEALTH|PRIORITYHEALTH|20080511103530||ORU^R01|Q335939501T337311002|P|2.3||| PID|1||94000000000^^^Priority Health||LASTNAME^FIRSTNAME^INIT||19460101|M||||| PD1|1|||1234567890^PCPLAST^PCPFIRST^M^^^^^NPI| OBR|1||185L29839X64489JLPF~X64489^ACC_NUM|JLPF^Lipid Panel - C||||||||||||1694^DOCLAST^DOCFIRST^^MD||||||20080511103529||| OBX|1|NM|JHDL^HDL Cholesterol (CAD)|1|62|CD:289^mg/dL|>40^>40|""||""|F|||20080511103500|||^^^""| OBX|2|NM|JTRIG^Triglyceride (CAD)|1|72|CD:289^mg/dL|35-150^35^150|""||""|F|||20080511103500|||^^^""| OBX|3|NM|JVLDL^VLDL-C (calc - CAD)|1|14|CD:289^mg/dL||""||""|F|||20080511103500|||^^^""| OBX|4|NM|JLDL^LDL-C (calc - CAD)|1|134|CD:289^mg/dL|0-100^0^100|H||""|F|||20080511103500|||^^^""| OBX|5|NM|JCHO^Cholesterol (CAD)|1|210|CD:289^mg/dL|90-200^90^200|H||""|F|||20080511103500|||^^^""| -------------------------------------------------------------------------------- /lib/segments/IAM.txt: -------------------------------------------------------------------------------- 1 | IAM 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - IAM 4 | 2 250 CE O 1 Allergen Type Code 5 | 3 250 CE R 1 Allergen Code/Mnemonic/Description 6 | 4 250 CE O 1 Allergy Severity Code 7 | 5 15 ST O * Allergy Reaction Code 8 | 6 250 CNE R 1 Allergy Action Code 9 | 7 80 EI R 1 Allergy Unique Identifier 10 | 8 60 ST O 1 Action Reason 11 | 9 250 CE O 1 Sensitivity to Causative Agent Code 12 | 10 250 CE O 1 Allergen Group Code/Mnemonic/Description 13 | 11 8 DT O 1 Onset Date 14 | 12 60 ST O 1 Onset Date Text 15 | 13 8 TS O 1 Reported Date/Time 16 | 14 250 XPN O 1 Reported By 17 | 15 250 CE O 1 Relationship to Patient Code 18 | 16 250 CE O 1 Alert Device Code 19 | 17 250 CE O 1 Allergy Clinical Status Code 20 | 18 250 XCN O 1 Statused by Person 21 | 19 250 XON O 1 Statused by Organization 22 | 20 8 TS O 1 Statused at Date/Time 23 | -------------------------------------------------------------------------------- /lib/segments/GOL.txt: -------------------------------------------------------------------------------- 1 | GOL 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 2 ID R 1 Action Code 4 | 2 26 TS R 1 Action Date/Time 5 | 3 80 CE R 1 Goal ID 6 | 4 60 EI R 1 Goal Instance ID 7 | 5 60 EI O 1 Episode of Care ID 8 | 6 60 NM O 1 Goal List Priority 9 | 7 26 TS O 1 Goal Established Date/Time 10 | 8 26 TS O 1 Expected Goal Achieve Date/Time 11 | 9 80 CE O 1 Goal Classification 12 | 10 80 CE O 1 Goal Management Discipline 13 | 11 80 CE O 1 Current Goal Review Status 14 | 12 26 TS O 1 Current Goal Review Date/Time 15 | 13 26 TS O 1 Next Goal Review Date/Time 16 | 14 26 TS O 1 Previous Goal Review Date/Time 17 | 15 200 TQ O 1 Goal Review Interval 18 | 16 80 CE O 1 Goal Evaluation 19 | 17 300 ST O * Goal Evaluation Comment 20 | 18 80 CE O 1 Goal Life Cycle Status 21 | 19 26 TS O 1 Goal Life Cycle Status Date/Time 22 | 20 80 CE O * Goal Target Type 23 | 21 80 XPN O * Goal Target Name 24 | -------------------------------------------------------------------------------- /test/fixtures/isabella_jones_lipid_panel.txt: -------------------------------------------------------------------------------- 1 | MSH|^~\&|XXXX|C|SOMELAB|SOMELAB|20080511103530||ORU^R01|Q335939501T337311002|P|2.3||| 2 | PID|1||94000000000^^^Priority Health||JONES^ISABELLA^ISA||19750501|F|||||||||||123-456-7890| 3 | PD1|1|||1234567890^PCPLAST^PCPFIRST^M^^^^^NPI| 4 | OBR|1||185L29839X64489JLPF~X64489^ACC_NUM|JLPF^Lipid Panel - C||||||||||||1694^HOUSE^GREGORY^^MD||||||20080511103529||| 5 | OBX|1|NM|JHDL^HDL Cholesterol (CAD)|1|62|CD:289^mg/dL|>40^>40|""||""|F|||20080511103500|||^^^""| 6 | OBX|2|NM|JTRIG^Triglyceride (CAD)|1|72|CD:289^mg/dL|35-150^35^150|""||""|F|||20080511103500|||^^^""| 7 | OBX|3|NM|JVLDL^VLDL-C (calc - CAD)|1|14|CD:289^mg/dL||""||""|F|||20080511103500|||^^^""| 8 | OBX|4|NM|JLDL^LDL-C (calc - CAD)|1|134|CD:289^mg/dL|0-100^0^100|H||""|F|||20080511103500|||^^^""| 9 | OBX|5|NM|JCHO^Cholesterol (CAD)|1|210|CD:289^mg/dL|90-200^90^200|H||""|F|||20080511103500|||^^^""| -------------------------------------------------------------------------------- /lib/segments/RXG.txt: -------------------------------------------------------------------------------- 1 | RXG 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM R 1 Give Sub-ID Counter 4 | 2 4 NM O 1 Dispense Sub-ID Counter 5 | 3 200 TQ R 1 Quantity/Timing 6 | 4 100 CE R 1 Give Code 7 | 5 20 NM R 1 Give Amount - Minimum 8 | 6 20 NM O 1 Give Amount - Maximum 9 | 7 60 CE R 1 Give Units 10 | 8 60 CE O 1 Give Dosage Form 11 | 9 200 CE O * Administration Notes 12 | 10 1 ID O 1 Substitution Status 13 | 11 200 LA2 O 1 Dispense-To Location 14 | 12 1 ID O 1 Needs Human Review 15 | 13 200 CE O * Pharmacy/Treatment Supplier s Special Administration Instructions 16 | 14 20 ST C 1 Give Per 17 | 15 6 ST O 1 Give Rate Amount 18 | 16 60 CE O 1 Give Rate Units 19 | 17 20 NM O 1 Give Strength 20 | 18 60 CE O 1 Give Strength Units 21 | 19 20 ST O * Substance Lot Number 22 | 20 26 TS O * Substance Expiration Date 23 | 21 60 CE O * Substance Manufacturer Name 24 | 22 200 CE O * Indication 25 | -------------------------------------------------------------------------------- /lib/segments/UB1.txt: -------------------------------------------------------------------------------- 1 | UB1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O 1 Set ID - UB1 4 | 2 1 NM B 1 Blood Deductible 5 | 3 2 NM O 1 Blood Furnished-Pints Of 6 | 4 2 NM O 1 Blood Replaced-Pints 7 | 5 2 NM O 1 Blood Not Replaced-Pints 8 | 6 2 NM O 1 Co-Insurance Days 9 | 7 14 IS O 5 Condition Code 10 | 8 3 NM O 1 Covered Days - 11 | 9 3 NM O 1 Non Covered Days - 12 | 10 12 UVC O 8 Value Amount & Code 13 | 11 2 NM O 1 Number Of Grace Days 14 | 12 60 CE O 1 Special Program Indicator 15 | 13 60 CE O 1 PSRO/UR Approval Indicator 16 | 14 8 DT O 1 PSRO/UR Approved Stay-Fm 17 | 15 8 DT O 1 PSRO/UR Approved Stay-To 18 | 16 20 OCD O 5 Occurrence 19 | 17 60 CE O 1 Occurrence Span 20 | 18 8 DT O 1 Occur Span Start Date 21 | 19 8 DT O 1 Occur Span End Date 22 | 20 30 ST O 1 UB-82 Locator 2 23 | 21 7 ST O 1 UB-82 Locator 9 24 | 22 8 ST O 1 UB-82 Locator 27 25 | 23 17 ST O 1 UB-82 Locator 45 26 | -------------------------------------------------------------------------------- /lib/segments/RXA.txt: -------------------------------------------------------------------------------- 1 | RXA 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM R 1 Give Sub-ID Counter 4 | 2 4 NM R 1 Administration Sub-ID Counter 5 | 3 26 TS R 1 Date/Time Start of Administration 6 | 4 26 TS R 1 Date/Time End of Administration 7 | 5 100 CE R 1 Administered Code 8 | 6 20 NM R 1 Administered Amount 9 | 7 60 CE C 1 Administered Units 10 | 8 60 CE O 1 Administered Dosage Form 11 | 9 200 CE O * Administration Notes 12 | 10 200 XCN O * Administering Provider 13 | 11 200 LA2 C 1 Administered-at Location 14 | 12 20 ST C 1 Administered Per 15 | 13 20 NM O 1 Administered Strength 16 | 14 60 CE O 1 Administered Strength Units 17 | 15 20 ST O * Substance Lot Number 18 | 16 26 TS O * Substance Expiration Date 19 | 17 60 CE O * Substance Manufacturer Name 20 | 18 200 CE O * Substance Refusal Reason 21 | 19 200 CE O * Indication 22 | 20 2 ID O 1 Completion Status 23 | 21 2 ID O 1 Action Code-RXA 24 | 22 26 TS O 1 System Entry Date/Time 25 | -------------------------------------------------------------------------------- /lib/segments/STF.txt: -------------------------------------------------------------------------------- 1 | STF 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE R 1 Primary Key Value - STF 4 | 2 60 CX O * Staff ID Code 5 | 3 48 XPN O * Staff Name 6 | 4 2 IS O * Staff Type 7 | 5 1 IS O 1 Sex 8 | 6 26 TS O 1 Date/Time Of Birth 9 | 7 1 ID O 1 Active/Inactive Flag 10 | 8 200 CE O * Department 11 | 9 200 CE O * Hospital Service 12 | 10 40 XTN O * Phone 13 | 11 106 XAD O * Office/Home Address 14 | 12 26 DIN O * Institution Activation Date 15 | 13 26 DIN O * Institution Inactivation Date 16 | 14 60 CE O * Backup Person ID 17 | 15 40 ST O * E-Mail Address 18 | 16 200 CE O 1 Preferred Method Of Contact 19 | 17 80 CE O 1 Marital Status 20 | 18 20 ST O 1 Job Title 21 | 19 20 JCC O 1 Job Code/Class 22 | 20 2 IS O 1 Employment Status 23 | 21 1 ID O 1 Additional Insured on Auto 24 | 22 25 DLN O 1 Driver s License Number - Staff 25 | 23 1 ID O 1 Copy Auto Ins 26 | 24 8 DT O 1 Auto Ins. Expires 27 | 25 8 DT O 1 Date Last DMV Review 28 | 26 8 DT O 1 Date Next DMV Review 29 | -------------------------------------------------------------------------------- /lib/segments/ARQ.txt: -------------------------------------------------------------------------------- 1 | ARQ 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 75 EI R 1 Placer Appointment ID 4 | 2 75 EI C 1 Filler Appointment ID 5 | 3 5 NM C 1 Occurrence Number 6 | 4 22 EI O 1 Placer Group Number 7 | 5 200 CE O 1 Schedule ID 8 | 6 200 CE O 1 Request Event Reason 9 | 7 200 CE O 1 Appointment Reason 10 | 8 200 CE O 1 Appointment Type 11 | 9 20 NM O 1 Appointment Duration 12 | 10 200 CE O 1 Appointment Duration Units 13 | 11 53 DR O * Requested Start Date/Time Range 14 | 12 5 ST O 1 Priority-ARQ 15 | 13 100 RI O 1 Repeating Interval 16 | 14 5 ST O 1 Repeating Interval Duration 17 | 15 48 XCN R * Placer Contact Person 18 | 16 40 XTN O * Placer Contact Phone Number 19 | 17 106 XAD O * Placer Contact Address 20 | 18 80 PL O 1 Placer Contact Location 21 | 19 48 XCN R * Entered by Person 22 | 20 40 XTN O * Entered by Phone Number 23 | 21 80 PL O 1 Entered by Location 24 | 22 75 EI O 1 Parent Placer Appointment ID 25 | 23 75 EI O 1 Parent Filler Appointment ID 26 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs=require('fs'); 4 | var parser=require('./index.js'); 5 | var serializer=require('./index.js'); 6 | var translate=require('./lib/translate.js'); 7 | 8 | var data = fs.readFileSync('./test/fixtures/isabella_jones_lipid_panel.txt').toString().split("\n").join("\r"); 9 | 10 | console.log(data); 11 | 12 | var hl7=parser.parseString(data); 13 | 14 | //console.log(JSON.stringify(hl7,null,4)); 15 | 16 | //repeat-component-subcomponent 17 | //console.log(hl7[0]["MSH"]["MSH_3"][0][0]); 18 | //console.log(hl7[2]["NK1"]["NK1_2"][0][0]); 19 | //console.log(hl7[2]["NK1"]["NK1_3"][0][0]); 20 | 21 | 22 | console.log(hl7[1]); 23 | 24 | 25 | var text=serializer.serializeJSON(hl7); 26 | console.log(data.split("\r").join("\n")); 27 | console.log(); 28 | console.log(text.split("\r").join("\n")); 29 | console.log(); 30 | console.log(text==data); 31 | 32 | //console.log(JSON.stringify(hl7,null,4)); 33 | 34 | 35 | console.log(JSON.stringify(translate.translate(hl7),null,4)); 36 | -------------------------------------------------------------------------------- /lib/segments/FT1.txt: -------------------------------------------------------------------------------- 1 | FT1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O 1 Set ID - FT1 4 | 2 12 ST O 1 Transaction ID 5 | 3 10 ST O 1 Transaction Batch ID 6 | 4 26 TS R 1 Transaction Date 7 | 5 26 TS O 1 Transaction Posting Date 8 | 6 8 IS R 1 Transaction Type 9 | 7 80 CE R 1 Transaction Code 10 | 8 40 ST B 1 Transaction Description 11 | 9 40 ST B 1 Transaction Description - Alt 12 | 10 6 NM O 1 Transaction Quantity 13 | 11 12 CP O 1 Transaction Amount - Extended 14 | 12 12 CP O 1 Transaction Amount - Unit 15 | 13 60 CE O 1 Department Code 16 | 14 60 CE O 1 Insurance Plan ID 17 | 15 12 CP O 1 Insurance Amount 18 | 16 80 PL O 1 Assigned Patient Location 19 | 17 1 IS O 1 Fee Schedule 20 | 18 2 IS O 1 Patient Type 21 | 19 60 CE O * Diagnosis Code - FT1 22 | 20 120 XCN O * erformed By Code 23 | 21 120 XCN O * Ordered By Code 24 | 22 12 CP O 1 Unit Cost 25 | 23 22 EI O 1 Filler Order Number 26 | 24 120 XCN O * Entered By Code 27 | 25 80 CE O 1 Procedure Code 28 | 26 80 CE O * Procedure Code Modifier 29 | -------------------------------------------------------------------------------- /lib/segments/TXA.txt: -------------------------------------------------------------------------------- 1 | TXA 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - TXA 4 | 2 30 IS R 1 Document Type 5 | 3 2 ID C 1 Document Content Presentation 6 | 4 26 TS O 1 Activity Date/Time 7 | 5 60 XCN C * Primary Activity Provider Code/Name 8 | 6 26 TS O 1 Origination Date/Time 9 | 7 26 TS C 1 Transcription Date/Time 10 | 8 26 TS O * Edit Date/Time 11 | 9 60 XCN O * Originator Code/Name 12 | 10 60 XCN O * Assigned Document Authenticator 13 | 11 48 XCN C * Transcriptionist Code/Name 14 | 12 30 EI R 1 Unique Document Number 15 | 13 30 EI C 1 Parent Document Number 16 | 14 22 EI O * Placer Order Number 17 | 15 22 EI O 1 Filler Order Number 18 | 16 30 ST O 1 Unique Document File Name 19 | 17 2 ID R 1 Document Completion Status 20 | 18 2 ID O 1 Document Confidentiality Status 21 | 19 2 ID O 1 Document Availability Status 22 | 20 2 ID O 1 Document Storage Status 23 | 21 30 ST C 1 Document Change Reason 24 | 22 60 PPN C * Authentication Person, Time Stamp 25 | 23 60 XCN O * Distributed Copies 26 | -------------------------------------------------------------------------------- /lib/segments/RXD.txt: -------------------------------------------------------------------------------- 1 | RXD 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM R 1 Dispense Sub-ID Counter 4 | 2 100 CE R 1 Dispense/Give Code 5 | 3 26 TS R 1 Date/Time Dispensed 6 | 4 20 NM R 1 Actual Dispense Amount 7 | 5 60 CE C 1 Actual Dispense Units 8 | 6 60 CE O 1 Actual Dosage Form 9 | 7 20 ST R 1 Prescription Number 10 | 8 20 NM C 1 Number of Refills Remaining 11 | 9 200 ST O * Dispense Notes 12 | 10 200 XCN O * Dispensing Provider 13 | 11 1 ID O 1 Substitution Status 14 | 12 10 CQ O 1 Total Daily Dose 15 | 13 200 LA2 C 1 Dispense-To Location 16 | 14 1 ID O 1 Needs Human Review 17 | 15 200 CE O * Pharmacy/Treatment Supplier s Special Dispensing Instructions 18 | 16 20 NM O 1 Actual Strength 19 | 17 60 CE O 1 Actual Strength Unit 20 | 18 20 ST O * Substance Lot Number 21 | 19 26 TS O * Substance Expiration Date 22 | 20 60 CE O * Substance Manufacturer Name 23 | 21 200 CE O * Indication 24 | 22 20 NM O 1 Dispense Package Size 25 | 23 60 CE O 1 Dispense Package Size Unit 26 | 24 2 ID O 1 Dispense Package Method 27 | -------------------------------------------------------------------------------- /lib/segments/PCR.txt: -------------------------------------------------------------------------------- 1 | PCR 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE R 1 Implicated Product 4 | 2 1 IS O 1 Generic Product 5 | 3 60 CE O 1 Product Class 6 | 4 8 CQ O 1 Total Duration Of Therapy 7 | 5 26 TS O 1 Product Manufacture Date 8 | 6 26 TS O 1 Product Expiration Date 9 | 7 26 TS O 1 Product Implantation Date 10 | 8 26 TS O 1 Product Explantation Date 11 | 9 8 IS O 1 Single Use Device 12 | 10 60 CE O 1 Indication For Product Use 13 | 11 8 IS O 1 Product Problem 14 | 12 30 ST O 3 Product Serial/Lot Number 15 | 13 1 IS O 1 Product Available For Inspection 16 | 14 60 CE O 1 Product Evaluation Performed 17 | 15 60 CE O 1 Product Evaluation Status 18 | 16 60 CE O 1 Product Evaluation Results 19 | 17 8 ID O 1 Evaluated Product Source 20 | 18 26 TS O 1 Date Product Returned To Manufacturer 21 | 19 1 ID O 1 Device Operator Qualifications 22 | 20 1 ID O 1 Relatedness Assessment 23 | 21 2 ID O 6 Action Taken In Response To The Event 24 | 22 2 ID O 6 Event Causality Observations 25 | 23 1 ID O 3 Indirect Exposure Mechanism 26 | -------------------------------------------------------------------------------- /lib/segments/IN3.txt: -------------------------------------------------------------------------------- 1 | IN3 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - IN3 4 | 2 59 CX O 1 Certification Number 5 | 3 60 XCN O * Certified By 6 | 4 1 ID O 1 Certification Required 7 | 5 10 MOP O 1 Penalty 8 | 6 26 TS O 1 Certification Date/Time 9 | 7 26 TS O 1 Certification Modify Date/Time 10 | 8 60 XCN O * Operator 11 | 9 8 DT O 1 Certification Begin Date 12 | 10 8 DT O 1 Certification End Date 13 | 11 3 DTN O 1 Days 14 | 12 60 CE O 1 Non-Concur Code/Description 15 | 13 26 TS O 1 Non-Concur Effective Date/Time 16 | 14 60 XCN O * Physician Reviewer 17 | 15 48 ST O 1 Certification Contact 18 | 16 40 XTN O * Certification Contact Phone Number 19 | 17 60 CE O 1 Appeal Reason 20 | 18 60 CE O 1 Certification Agency 21 | 19 40 XTN O * Certification Agency Phone Number 22 | 20 40 PCF O * Pre-Certification Req/Window 23 | 21 48 ST O 1 Case Manager 24 | 22 8 DT O 1 Second Opinion Date 25 | 23 1 IS O 1 Second Opinion Status 26 | 24 1 IS O * Second Opinion Documentation Received 27 | 25 60 XCN O * Second Opinion Physician 28 | -------------------------------------------------------------------------------- /lib/segments/RXO.txt: -------------------------------------------------------------------------------- 1 | RXO 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 100 CE C 1 Requested Give Code 4 | 2 20 NM C 1 Requested Give Amount - Minimum 5 | 3 20 NM O 1 Requested Give Amount - Maximum 6 | 4 60 CE C 1 Requested Give Units 7 | 5 60 CE O 1 Requested Dosage Form 8 | 6 200 CE O * Provider s Pharmacy/Treatment Instructions 9 | 7 200 CE O * Provider s Administration Instructions 10 | 8 200 LA1 O 1 Deliver-to Location 11 | 9 1 ID O 1 Allow Substitutions 12 | 10 100 CE O 1 Requested Dispense Code 13 | 11 20 NM O 1 Requested Dispense Amount 14 | 12 60 CE O 1 Requested Dispense Units 15 | 13 3 NM O 1 Number Of Refills 16 | 14 60 XCN C * Ordering Provider s DEA Number 17 | 15 60 XCN C * Pharmacist/Treatment Supplier s Verifier ID 18 | 16 1 ID O 1 Needs Human Review 19 | 17 20 ST C 1 Requested Give Per 20 | 18 20 NM O 1 Requested Give Strength 21 | 19 60 CE O 1 Requested Give Strength Units 22 | 20 200 CE O * Indication 23 | 21 6 ST O 1 Requested Give Rate Amount 24 | 22 60 CE O 1 Requested Give Rate Units 25 | 23 10 CQ O 1 Total Daily Dose 26 | -------------------------------------------------------------------------------- /lib/segments/SCH.txt: -------------------------------------------------------------------------------- 1 | SCH 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 75 EI C 1 Placer Appointment ID 4 | 2 75 EI C 1 Filler Appointment ID 5 | 3 5 NM C 1 Occurrence Number 6 | 4 22 EI O 1 Placer Group Number 7 | 5 200 CE O 1 Schedule ID 8 | 6 200 CE R 1 Event Reason 9 | 7 200 CE O 1 Appointment Reason 10 | 8 200 CE O 1 Appointment Type 11 | 9 20 NM O 1 Appointment Duration 12 | 10 200 CE O 1 Appointment Duration Units 13 | 11 200 TQ R * Appointment Timing Quantity 14 | 12 48 XCN O * Placer Contact Person 15 | 13 40 XTN O 1 Placer Contact Phone Number 16 | 14 106 XAD O * Placer Contact Address 17 | 15 80 PL O 1 Placer Contact Location 18 | 16 38 XCN R * Filler Contact Person 19 | 17 40 XTN O 1 Filler Contact Phone Number 20 | 18 106 XAD O * Filler Contact Address 21 | 19 80 PL O 1 Filler Contact Location 22 | 20 48 XCN R * Entered by Person 23 | 21 40 XTN O * Entered by Phone Number 24 | 22 80 PL O 1 Entered by Location 25 | 23 75 EI O 1 Parent Placer Appointment ID 26 | 24 75 EI C 1 Parent Filler Appointment ID 27 | 25 200 CE O 1 Filler Status Code 28 | -------------------------------------------------------------------------------- /test/fixtures/sample5.txt: -------------------------------------------------------------------------------- 1 | MSH|^~\&|LCS|LCA|LIS|TEST9999|199807311532||ORU^R01|3629|P|2.2 2 | PID|2|2161348462|20809880170|1614614|20809880170^TESTPAT||19760924|M|||^^^^00000-0000|||||||86427531^^^03|SSN# HERE 3 | ORC|NW|8642753100012^LIS|20809880170^LCS||||||19980727000000|||HAVILAND 4 | OBR|1|8642753100012^LIS|20809880170^LCS|008342^UPPER RESPIRATORY 5 | CULTURE^L|||19980727175800||||||SS#634748641 CH14885 SRC:THROA SRC:PENI|19980727000000||||||20809880170||19980730041800||BN|F 6 | OBX|1|ST|008342^UPPER RESPIRATORY CULTURE^L||FINALREPORT|||||N|F||| 19980729160500|BN 7 | ORC|NW|8642753100012^LIS|20809880170^LCS||||||19980727000000|||HAVILAND 8 | OBR|2|8642753100012^LIS|20809880170^LCS|997602^.^L|||19980727175800||||G|||19980727000000||||||20809880170||19980730041800|||F|997602|||008342 9 | OBX|2|CE|997231^RESULT 1^L||M415|||||N|F|||19980729160500|BN 10 | NTE|1|L|MORAXELLA (BRANHAMELLA) CATARRHALIS 11 | NTE|2|L| HEAVY GROWTH 12 | NTE|3|L| BETA LACTAMASE POSITIVE 13 | OBX|3|CE|997232^RESULT 2^L||MR105|||||N|F|||19980729160500|BN 14 | NTE|1|L|ROUTINE RESPIRATORY FLORA -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@amida-tech/hl7", 3 | "version": "1.1.5", 4 | "description": "Parsing HL7 into JSON", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "grunt", 8 | "coverage": "grunt run:coverage" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/amida-tech/hl7.git" 13 | }, 14 | "keywords": [ 15 | "hl7", 16 | "json", 17 | "parser" 18 | ], 19 | "author": "Dmitry Kachaev (http://github.com/kachok)", 20 | "bugs": { 21 | "url": "https://github.com/amida-tech/hl7/issues" 22 | }, 23 | "homepage": "https://github.com/amida-tech/hl7", 24 | "license": "Apache-2.0", 25 | "devDependencies": { 26 | "grunt": "^1.6.1", 27 | "grunt-contrib-jshint": "^3.2.0", 28 | "grunt-contrib-watch": "^1.1.0", 29 | "grunt-jsbeautifier": "^0.2.13", 30 | "grunt-run": "^0.8.1", 31 | "jest": "^29.7.0" 32 | }, 33 | "engines": { 34 | "node": ">= 14.19.1" 35 | }, 36 | "directories": { 37 | "lib": "lib", 38 | "test": "test" 39 | } 40 | } -------------------------------------------------------------------------------- /lib/segments/PID.txt: -------------------------------------------------------------------------------- 1 | PID 2 | SEQ LEN DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O Set ID – Patient ID 4 | 2 20 CX O Patient ID (External ID) 5 | 3 20 CX R Y Patient ID (Internal ID) 6 | 4 20 CX O Y Alternate Patient ID – PID 7 | 5 48 XPN R Y Patient Name 8 | 6 48 XPN O Mother’s Maiden Name 9 | 7 26 TS O Date/Time of Birth 10 | 8 1 IS O Sex 11 | 9 48 XPN O Y Patient Alias 12 | 10 1 IS O Race 13 | 11 106 XAD O Y Patient Address 14 | 12 4 IS B Country Code 15 | 13 40 XTN O Y Phone Number – Home 16 | 14 40 XTN O Y Phone Number – Business 17 | 15 60 CE O Primary Language 18 | 16 1 IS O Marital Status 19 | 17 3 IS O Religion 20 | 18 20 CX O Patient Account Number 21 | 19 16 ST O SSN Number – Patient 22 | 20 25 DLN O Driver’s License Number - Patient 23 | 21 20 CX O Y Mother’s Identifier 24 | 22 3 IS O Ethnic Group 25 | 23 60 ST O Birth Place 26 | 24 2 ID O Multiple Birth Indicator 27 | 25 2 NM O Birth Order 28 | 26 4 IS O Y Citizenship 29 | 27 60 CE O Veterans Military Status 30 | 28 80 CE O Nationality 31 | 29 26 TS O Patient Death Date and Time 32 | 30 1 ID O Patient Death Indicator 33 | -------------------------------------------------------------------------------- /lib/segments/PRB.txt: -------------------------------------------------------------------------------- 1 | PRB 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 2 ID R 1 Action Code 4 | 2 26 TS R 1 Action Date/Time 5 | 3 80 CE R 1 Problem ID 6 | 4 60 EI R 1 Problem Instance ID 7 | 5 60 EI O 1 Episode of Care ID 8 | 6 60 NM O 1 Problem List Priority 9 | 7 26 TS O 1 Problem Established Date/Time 10 | 8 26 TS O 1 Anticipated Problem Resolution Date/Time 11 | 9 26 TS O 1 Actual Problem Resolution Date/Time 12 | 10 80 CE O 1 Problem Classification 13 | 11 80 CE O * Problem Management Discipline 14 | 12 80 CE O 1 Problem Persistence 15 | 13 80 CE O 1 Problem Confirmation Status 16 | 14 80 CE O 1 Problem Life Cycle Status 17 | 15 26 TS O 1 Problem Life Cycle Status Date/Time 18 | 16 26 TS O 1 Problem Date of Onset 19 | 17 80 ST O 1 Problem Onset Text 20 | 18 80 CE O 1 Problem Ranking 21 | 19 60 CE O 1 Certainty of Problem 22 | 20 5 NM O 1 Probability of Problem 23 | 21 80 CE O 1 Individual Awareness of Problem 24 | 22 80 CE O 1 Problem Prognosis 25 | 23 80 CE O 1 Individual Awareness of Prognosis 26 | 24 200 ST O 1 Family/Significant Other Awareness of Problem/Prognosis 27 | 25 80 CE O 1 Security/Sensitivity 28 | -------------------------------------------------------------------------------- /lib/segments/PEO.txt: -------------------------------------------------------------------------------- 1 | PEO 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 60 CE O * Event Identifiers Used 4 | 2 60 CE O * Event Symptom/Diagnosis Code 5 | 3 26 TS R 1 Event Onset Date/Time 6 | 4 26 TS O 1 Event Exacerbation Date/Time 7 | 5 26 TS O 1 Event Improved Date/Time 8 | 6 26 TS O 1 Event Ended Data/Time 9 | 7 106 XAD O * Event Location Occurred Address 10 | 8 1 ID O * Event Qualification 11 | 9 1 ID O 1 Event Serious 12 | 10 1 ID O 1 Event Expected 13 | 11 1 ID O * Event Outcome 14 | 12 1 ID O 1 Patient Outcome 15 | 13 600 FT O * Event Description From Others 16 | 14 600 FT O * Event From Original Reporter 17 | 15 600 FT O * Event Description From Patient 18 | 16 600 FT O * Event Description From Practitioner 19 | 17 600 FT O * Event Description From Autopsy 20 | 18 60 CE O * Cause Of Death 21 | 19 46 XPN O * Primary Observer Name 22 | 20 106 XAD O * Primary Observer Address 23 | 21 40 XTN O * Primary Observer Telephone 24 | 22 1 ID O 1 Primary Observer s Qualification 25 | 23 1 ID O 1 Confirmation Provided By 26 | 24 26 TS O 1 Primary Observer Aware Date/Time 27 | 25 1 ID O 1 Primary Observer s identity May Be Divulged 28 | -------------------------------------------------------------------------------- /lib/translate.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var path = require('path'); 3 | var fs = require('fs'); 4 | 5 | function translateSegment(segment) { 6 | 7 | try { 8 | var seg_name = segment[0]; 9 | //console.log("translating <" + seg_name + ">"); 10 | 11 | var format = fs.readFileSync(path.dirname(fs.realpathSync(__filename)) + "/segments/" + seg_name + ".txt").toString(); 12 | 13 | format = format.split("\n"); 14 | 15 | var data = {}; 16 | data["Segment"] = segment[0]; 17 | 18 | //console.log("segment.lengh", segment.length); 19 | //console.log("format.lengh", format.length); 20 | 21 | for (var i = 1; i < Math.min(segment.length, format.length - 1); i++) { 22 | var field_name = format[i + 1].split("\t")[5]; 23 | data[field_name] = segment[i]; 24 | } 25 | 26 | return data; 27 | } catch (ex) { 28 | //console.log(ex); //for debug 29 | } 30 | } 31 | 32 | function translate(data) { 33 | var tr = []; 34 | for (var seg in data) { 35 | tr.push(translateSegment(data[seg])); 36 | } 37 | 38 | return tr; 39 | } 40 | 41 | module.exports = { 42 | translate: translate, 43 | }; 44 | -------------------------------------------------------------------------------- /lib/segments/RXE.txt: -------------------------------------------------------------------------------- 1 | RXE 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 200 TQ R 1 Quantity/Timing 4 | 2 100 CE R 1 Give Code 5 | 3 20 NM R 1 Give Amount - Minimum 6 | 4 20 NM O 1 Give Amount - Maximum 7 | 5 60 CE R 1 Give Units 8 | 6 60 CE O 1 Give Dosage Form 9 | 7 200 CE O * Provider s Administration Instructions 10 | 8 200 LA1 C 1 Deliver-to Location 11 | 9 1 ID O 1 Substitution Status 12 | 10 20 NM C 1 Dispense Amount 13 | 11 60 CE C 1 Dispense Units 14 | 12 3 NM O 1 Number Of Refills 15 | 13 60 XCN C * Ordering Provider s DEA Number 16 | 14 60 XCN O * Pharmacist/Treatment Supplier s Verifier ID 17 | 15 20 ST C 1 Prescription Number 18 | 16 20 NM C 1 Number of Refills Remaining 19 | 17 20 NM C 1 Number of Refills/Doses Dispensed 20 | 18 26 TS C 1 D/T of Most Recent Refill or Dose Dispensed 21 | 19 10 CQ C 1 Total Daily Dose 22 | 20 1 ID O 1 Needs Human Review 23 | 21 200 CE O * Pharmacy/Treatment Supplier s Special Dispensing Instructions 24 | 22 20 ST C 1 Give Per 25 | 23 6 ST O 1 Give Rate Amount 26 | 24 60 CE O 1 Give Rate Units 27 | 25 20 NM O 1 Give Strength 28 | 26 60 CE O 1 Give Strength Units 29 | 27 200 CE O * Give Indication 30 | 28 20 NM O 1 Dispense Package Size 31 | 29 60 CE O 1 Dispense Package Size Unit 32 | 30 2 ID O 1 Dispense Package Method 33 | -------------------------------------------------------------------------------- /lib/segments/ORC.txt: -------------------------------------------------------------------------------- 1 | ORC 2 | SEQ LEN DT OPT RP/# ELEMENT NAME 3 | 1 2 ID R 1 Order Control 4 | 2 22 EI C 1 Placer Order Number 5 | 3 22 EI C 1 Filler Order Number 6 | 4 22 EI O 1 Placer Group Number 7 | 5 2 ID O 1 Order Status 8 | 6 1 ID O 1 Response Flag 9 | 7 200 TQ B * Quantity/Timing 10 | 8 200 EIP O 1 Parent Order 11 | 9 26 TS O 1 Date/Time of Transaction 12 | 10 250 XCN O * Entered By 13 | 11 250 XCN O * Verified By 14 | 12 250 XCN O * Ordering Provider 15 | 13 80 PL O 1 Enterer's Location 16 | 14 250 XTN O * Call Back Phone Number 17 | 15 26 TS O 1 Order Effective Date/Time 18 | 16 250 CE O 1 Order Control Code Reason 19 | 17 250 CE O 1 Entering Organization 20 | 18 250 CE O 1 Entering Device 21 | 19 250 XCN O * Action By 22 | 20 250 CE O 1 Advanced Beneficiary Notice Code 23 | 21 250 XON O * Ordering Facility Name 24 | 22 250 XAD O * Ordering Facility Address 25 | 23 250 XTN O * Ordering Facility Phone Number 26 | 24 250 XAD O * Ordering Provider Address 27 | 25 250 CWE O 1 Order Status Modifier 28 | 26 60 CWE C 1 Advanced Beneficiary Notice Override Reason 29 | 27 26 TS O 1 Filler's Expected Availability Date/Time 30 | 28 250 CWE O 1 Confidentiality Code 31 | 29 250 CWE O 1 Order Type 32 | 30 250 CNE O 1 Enterer Authorization Mode 33 | 31 250 CWE O 1 Parent Universal Service Identifier 34 | -------------------------------------------------------------------------------- /lib/segments/NK1.txt: -------------------------------------------------------------------------------- 1 | NK1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - NK1 4 | 2 48 XPN O * NK Name 5 | 3 60 CE O 1 Relationship 6 | 4 106 XAD O * Address 7 | 5 40 XTN O * Phone Number 8 | 6 40 XTN O * Business Phone Number 9 | 7 200 CE O 1 Contact Role 10 | 8 8 DT O 1 Start Date 11 | 9 8 DT O 1 End Date 12 | 10 60 ST O 1 Next of Kin / Associated Parties Job Title 13 | 11 20 JCC O 1 Next of Kin / Associated Parties Job Code/Class 14 | 12 20 CX O 1 Next of Kin / Associated Parties Employee Number 15 | 13 90 XON O * Organization Name - NK1 16 | 14 80 CE O 1 Marital Status 17 | 15 1 IS O 1 Sex 18 | 16 26 TS O 1 Date/Time Of Birth 19 | 17 2 IS O * Living Dependency 20 | 18 2 IS O * Ambulatory Status 21 | 19 80 CE O * Citizenship 22 | 20 60 CE O 1 Primary Language 23 | 21 2 IS O 1 Living Arrangement 24 | 22 80 CE O 1 Publicity Code 25 | 23 1 ID O 1 Protection Indicator 26 | 24 2 IS O 1 Student Indicator 27 | 25 80 CE O 1 Religion 28 | 26 48 XPN O * Mother s Maiden Name 29 | 27 80 CE O 1 Nationality 30 | 28 80 CE O * Ethnic Group 31 | 29 80 CE O * Contact Reason 32 | 30 48 XPN O * Contact Person s Name 33 | 31 40 XTN O * Contact Person s Telephone Number 34 | 32 106 XAD O * Contact Person s Address 35 | 33 32 CX O * Next of Kin/Associated Party s Identifiers 36 | 34 2 IS O 1 Job Status 37 | 35 80 CE O * Race 38 | 36 2 IS O 1 Handicap 39 | 37 16 ST O 1 Contact Person Social Security Number 40 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | // var expect = require('chai').expect; 2 | // var expect = require('chai').expect; 3 | 4 | var fs = require("fs"); 5 | 6 | var hl7 = require("../index.js"); 7 | 8 | describe('parse.js test', function () { 9 | var data = ""; 10 | var parsed; 11 | 12 | beforeAll(function () { 13 | data = fs.readFileSync('./test/fixtures/isabella_jones_lipid_panel.txt').toString().split("\n").join("\r"); 14 | parsed = hl7.parseString(data); 15 | }); 16 | 17 | it('should parse an HL7 string without error', function () { 18 | expect(parsed).not.toStrictEqual(undefined); 19 | }); 20 | 21 | it('parses fields with the correct mapping', function () { 22 | expect(parsed[1][5][0][0]).toEqual('JONES'); // parsed[SEGMENT][FIELD][FIELDREPEAT][COMPONENT] 23 | expect(parsed[1][5][0][1]).toEqual('ISABELLA'); 24 | }); 25 | 26 | it('translates HL7 sequence number to element name', function () { 27 | var tr = hl7.translate(parsed); 28 | 29 | expect(tr[1]["Segment"]).toEqual('PID'); 30 | expect(tr[1]['Patient Name'][0][0]).toEqual('JONES'); 31 | expect(tr[1]['Patient Name'][0][1]).toEqual('ISABELLA'); 32 | }); 33 | 34 | it('serializes parsed HL7 to a string', function () { 35 | var serialized = hl7.serializeJSON(parsed); 36 | 37 | expect(data).toEqual(serialized); 38 | }); 39 | 40 | it('correctly interprets the FIELDREPEAT character', function () { 41 | expect(parsed[3][3][0][0]).toEqual('185L29839X64489JLPF'); 42 | expect(parsed[3][3][1][0]).toEqual('X64489'); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /lib/segments/PV2.txt: -------------------------------------------------------------------------------- 1 | PV2 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 80 PL C 1 Prior Pending Location 4 | 2 60 CE O 1 Accommodation Code 5 | 3 60 CE O 1 Admit Reason 6 | 4 60 CE O 1 Transfer Reason 7 | 5 25 ST O * Patient Valuables 8 | 6 25 ST O 1 Patient Valuables Location 9 | 7 2 IS O 1 Visit User Code 10 | 8 26 TS O 1 Expected Admit Date/Time 11 | 9 26 TS O 1 Expected Discharge Date/Time 12 | 10 3 NM O 1 Estimated Length of Inpatient Stay 13 | 11 3 NM O 1 Actual Length of Inpatient Stay 14 | 12 50 ST O 1 Visit Description 15 | 13 90 XCN O * Referral Source Code 16 | 14 8 DT O 1 Previous Service Date 17 | 15 1 ID O 1 Employment Illness Related Indicator 18 | 16 1 IS O 1 Purge Status Code 19 | 17 8 DT O 1 Purge Status Date 20 | 18 2 IS O 1 Special Program Code 21 | 19 1 ID O 1 Retention Indicator 22 | 20 1 NM O 1 Expected Number of Insurance Plans 23 | 21 1 IS O 1 Visit Publicity Code 24 | 22 1 ID O 1 Visit Protection Indicator 25 | 23 90 XON O * Clinic Organization Name 26 | 24 2 IS O 1 Patient Status Code 27 | 25 1 IS O 1 Visit Priority Code 28 | 26 8 DT O 1 Previous Treatment Date 29 | 27 2 IS O 1 Expected Discharge Disposition 30 | 28 8 DT O 1 Signature on File Date 31 | 29 8 DT O 1 First Similar Illness Date 32 | 30 80 CE O 1 Patient Charge Adjustment Code 33 | 31 2 IS O 1 Recurring Service Code 34 | 32 1 ID O 1 Billing Media Code 35 | 33 26 TS O 1 Expected Surgery Date & Time 36 | 34 1 ID O 1 Military Partnership Code 37 | 35 1 ID O 1 Military Non-Availability Code 38 | 36 1 ID O 1 Newborn Baby Indicator 39 | 37 1 ID O 1 Baby Detained Indicator 40 | -------------------------------------------------------------------------------- /lib/serializer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var SEGMENT = '\r'; 4 | var FIELD = '|'; 5 | var COMPONENT = '^'; 6 | var FIELDREPEAT = '~'; 7 | var ESCAPE = '\\'; 8 | var SUBCOMPONENT = '&'; 9 | 10 | //Message[segment][field][repetition][component][sub-component] 11 | function serializeComponent(data) { 12 | if (typeof (data) === "string") { 13 | return data; 14 | } 15 | return data.join(SUBCOMPONENT); 16 | } 17 | 18 | function serializeRepeat(data) { 19 | if (typeof (data) === "string") { 20 | return data; 21 | } 22 | return data.map(serializeComponent).join(COMPONENT); 23 | } 24 | 25 | function serializeField(data) { 26 | if (typeof (data) === "string") { 27 | return data; 28 | } 29 | return data.map(serializeRepeat).join(FIELDREPEAT); 30 | } 31 | 32 | function serializeSegment(data) { 33 | if (typeof (data) === "string") { 34 | return data; 35 | } 36 | 37 | //handling header in special way... 38 | if (data[0] === "MSH") { 39 | //clone MSH array, since we are modifying it to remove separator elements 40 | var msh = JSON.parse(JSON.stringify(data)); 41 | msh.shift(); 42 | msh.shift(); 43 | return "MSH" + FIELD + msh.map(serializeField).join(FIELD); 44 | } 45 | 46 | return data.map(serializeField).join(FIELD); 47 | } 48 | 49 | function serialize(data) { 50 | return data.map(serializeSegment).join(SEGMENT); 51 | } 52 | 53 | function serializeJSON(data, options) { 54 | if (arguments.length === 1) { 55 | options = {}; 56 | } 57 | 58 | var result = serialize(data); 59 | 60 | return result; 61 | } 62 | 63 | module.exports = { 64 | serializeJSON: serializeJSON, 65 | }; 66 | -------------------------------------------------------------------------------- /lib/segments/OBR.txt: -------------------------------------------------------------------------------- 1 | OBR 2 | SEQ LEN DT OPT RP/# ELEMENT NAME 3 | 1 4 SI C Set ID - OBR 4 | 2 75 EI C Placer Order Number 5 | 3 75 EI C Filler Order Number 6 | 4 200 CE R Universal Service ID 7 | 5 2 ID B Priority 8 | 6 26 TS B Requested Date/time 9 | 7 26 TS C Observation Date/Time 10 | 8 26 TS O Observation End Date/Time 11 | 9 20 CQ O Collection Volume 12 | 10 60 XCN O Y Collector Identifier 13 | 11 1 ID O Specimen Action Code 14 | 12 60 CE O Danger Code 15 | 13 300 ST O Relevant Clinical Info. 16 | 14 26 TS C Specimen Received Date/Time 17 | 15 300 CM O Specimen Source 18 | 16 80 XCN O Y Ordering Provider 19 | 17 40 XTN O Y/2 Order Callback Phone Number 20 | 18 60 ST O Placer field 1 21 | 19 60 ST O Placer field 2 22 | 20 60 ST O Filler Field 1 23 | 21 60 ST O Filler Field 2 24 | 22 26 TS C Results Rpt/Status Chng - Date/Time 25 | 23 40 CM O Charge to Practice 26 | 24 10 ID O Diagnostic Serv Sect ID 27 | 25 1 ID C Result Status 28 | 26 400 CM O Parent Result 29 | 27 200 TQ O Y Quantity/Timing 30 | 28 150 XCN O Y/5 Result Copies To 31 | 29 150 CM O Parent 32 | 30 20 ID O Transportation Mode 33 | 31 300 CE O Y Reason for Study 34 | 32 200 CM O Principal Result Interpreter 35 | 33 200 CM O Y Assistant Result Interpreter 36 | 34 200 CM O Y Technician 37 | 35 200 CM O Y Transcriptionist 38 | 36 26 TS O Scheduled Date/Time 39 | 37 4 NM O Number of Sample Containers 40 | 38 60 CE O Y Transport Logistics of Collected Sample 41 | 39 200 CE O Y Collector’s Comment 42 | 40 60 CE O Transport Arrangement Responsibility 43 | 41 30 ID O Transport Arranged 44 | 42 1 ID O Escort Required 45 | 43 200 CE O Y Planned Patient Transport Comment 46 | -------------------------------------------------------------------------------- /gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | 3 | grunt.loadNpmTasks('grunt-run'); 4 | grunt.loadNpmTasks('grunt-contrib-jshint'); 5 | grunt.loadNpmTasks('grunt-contrib-watch'); 6 | grunt.loadNpmTasks('grunt-jsbeautifier'); 7 | 8 | grunt.registerTask('default', ['jshint', 'jsbeautifier', 'run']); 9 | 10 | // Print a timestamp (useful for when watching) 11 | grunt.registerTask('timestamp', function () { 12 | grunt.log.subhead(Date()); 13 | }); 14 | 15 | grunt.initConfig({ 16 | jshint: { 17 | files: ['./lib/*.js', './test/*.js', './test/**/*.js', 'gruntfile.js', 'package.json', 'index.js'], 18 | options: { 19 | browser: true, 20 | curly: true, 21 | eqeqeq: true, 22 | immed: true, 23 | latedef: true, 24 | newcap: true, 25 | noarg: true, 26 | sub: true, 27 | undef: false, 28 | boss: true, 29 | eqnull: true, 30 | node: true, 31 | expr: true, 32 | globals: { 33 | 'xit': true, 34 | 'xdescribe': true, 35 | 'it': true, 36 | 'describe': true, 37 | 'before': true, 38 | 'after': true, 39 | 'done': true 40 | } 41 | } 42 | }, 43 | jsbeautifier: { 44 | files: ['Gruntfile.js', 'index.js', 'lib/*.js', 'test/**/*.js'], 45 | options: { 46 | config: '.jsbeautifyrc' 47 | } 48 | }, 49 | watch: { 50 | all: { 51 | files: ['./lib/*.js', './test/*/*.js', 'index.js', 'gruntfile.js'], 52 | tasks: ['default'] 53 | } 54 | }, 55 | run: { 56 | test: { 57 | exec: 'npx jest', 58 | args: ['test'] 59 | }, 60 | coverage: { 61 | exec: 'npx jest --coverage', 62 | args: ['test'] 63 | } 64 | } 65 | }); 66 | }; 67 | -------------------------------------------------------------------------------- /lib/segments/PV1.txt: -------------------------------------------------------------------------------- 1 | PV1 2 | SEQ LEN DT OPT RP/# ELEMENT NAME 3 | 1 4 SI O Set ID – PV1 4 | 2 1 IS R Patient Class 5 | 3 80 PL O Assigned Patient Location 6 | 4 2 IS O Admission Type 7 | 5 250 CX O Preadmit Number 8 | 6 80 PL O Prior Patient Location 9 | 7 250 XCN O Y Attending Doctor 10 | 8 250 XCN O Y Referring Doctor 11 | 9 250 XCN B Y Consulting Doctor 12 | 10 3 IS O Hospital Service 13 | 11 80 PL O Temporary Location 14 | 12 2 IS O Preadmit Test Indicator 15 | 13 2 IS O Re admission Indicator 16 | 14 6 IS O Admit Source 17 | 15 2 IS O Y Ambulatory Status 18 | 16 2 IS O VIP Indicator 19 | 17 250 XCN O Y Admitting Doctor 20 | 18 2 IS O Patient Type 21 | 19 250 CX O Visit Number 22 | 20 50 FC O Y Financial Class 23 | 21 2 IS O Charge Price Indicator 24 | 22 2 IS O Courtesy Code 25 | 23 2 IS O Credit Rating 26 | 24 2 IS O Y Contract Code 27 | 25 8 DT O Y Contract Effective Date 28 | 26 12 NM O Y Contract Amount 29 | 27 3 NM O Y Contract Period 30 | 28 2 IS O Interest Code 31 | 29 4 IS O Transfer to Bad Debt Code 32 | 30 8 DT O Transfer to Bad Debt Date 33 | 31 10 IS O Bad Debt Agency Code 34 | 32 12 NM O Bad Debt Transfer Amount 35 | 33 12 NM O Bad Debt Recovery Amount 36 | 34 1 IS O Delete Account Indicator 37 | 35 8 DT O Delete Account Date 38 | 36 3 IS O Discharge Disposition 39 | 37 47 DLD O Discharged to Location 40 | 38 250 CE O Diet Type 41 | 39 2 IS O Servicing Facility 42 | 40 1 IS B Bed Status 43 | 41 2 IS O Account Status 44 | 42 80 PL O Pending Location 45 | 43 80 PL O Prior Temporary Location 46 | 44 26 TS O Admit Date/Time 47 | 45 26 TS O Y Discharge Date/Time 48 | 46 12 NM O Current Patient Balance 49 | 47 12 NM O Total Charges 50 | 48 12 NM O Total Adjustments 51 | 49 12 NM O Total Payments 52 | 50 250 CX O Alternate Visit ID 53 | 51 1 IS O Visit Indicator 54 | 52 250 XCN B Y Other Healthcare Provider 55 | -------------------------------------------------------------------------------- /lib/segments/IN1.txt: -------------------------------------------------------------------------------- 1 | IN1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - IN1 4 | 2 60 CE R 1 Insurance Plan ID 5 | 3 59 CX R * Insurance Company ID 6 | 4 130 XON O * Insurance Company Name 7 | 5 106 XAD O * Insurance Company Address 8 | 6 48 XPN O * Insurance Co Contact Person 9 | 7 40 XTN O * Insurance Co Phone Number 10 | 8 12 ST O 1 Group Number 11 | 9 130 XON O * Group Name 12 | 10 12 CX O * Insured s Group Emp ID 13 | 11 130 XON O * Insured s Group Emp Name 14 | 12 8 DT O 1 Plan Effective Date 15 | 13 8 DT O 1 Plan Expiration Date 16 | 14 55 AUI O 1 Authorization Information 17 | 15 3 IS O 1 Plan Type 18 | 16 48 XPN O * Name Of Insured 19 | 17 80 CE O 1 Insured s Relationship To Patient 20 | 18 26 TS O 1 Insured s Date Of Birth 21 | 19 106 XAD O * Insured s Address 22 | 20 2 IS O 1 Assignment Of Benefits 23 | 21 2 IS O 1 oordination Of Benefits 24 | 22 2 ST O 1 Coord Of Ben. Priority 25 | 23 1 ID O 1 Notice Of Admission Flag 26 | 24 8 DT O 1 Notice Of Admission Date 27 | 25 1 ID O 1 Report Of Eligibility Flag 28 | 26 8 DT O 1 Report Of Eligibility Date 29 | 27 2 IS O 1 Release Information Code 30 | 28 15 ST O 1 Pre-Admit Cert 31 | 29 26 TS O 1 Verification Date/Time 32 | 30 60 XCN O * Verification By 33 | 31 2 IS O 1 Type Of Agreement Code 34 | 32 2 IS O 1 Billing Status 35 | 33 4 NM O 1 Lifetime Reserve Days 36 | 34 4 NM O 1 Delay Before L.R. Day 37 | 35 8 IS O 1 Company Plan Code 38 | 36 15 ST O 1 Policy Number 39 | 37 12 CP O 1 Policy Deductible 40 | 38 12 CP B 1 Policy Limit - Amount 41 | 39 4 NM O 1 Policy Limit - Days 42 | 40 12 CP B 1 Room Rate - Semi-Private 43 | 41 12 CP B 1 Room Rate - Private 44 | 42 60 CE O 1 Insured s Employment Status 45 | 43 1 IS O 1 Insured s Sex 46 | 44 106 XAD O * Insured s Employer s Address 47 | 45 2 ST O 1 Verification Status 48 | 46 8 IS O 1 Prior Insurance Plan ID 49 | 47 3 IS O 1 Coverage Type 50 | 48 2 IS O 1 Handicap 51 | 49 12 CX O * Insured s ID Number 52 | -------------------------------------------------------------------------------- /lib/segments.txt: -------------------------------------------------------------------------------- 1 | MSH http://www.corepointhealth.com/resource-center/hl7-resources/hl7-msh-message-header 2 | SEQ LEN DT OPT RP/# ELEMENT NAME 3 | 1 1 ST R Field Separator 4 | 2 4 ST R Encoding Characters 5 | 3 180 HD O Sending Application 6 | 4 180 HD O Sending Facility 7 | 5 180 HD O Receiving Application 8 | 6 180 HD O Receiving Facility 9 | 7 26 TS O Date/Time of Message 10 | 8 40 ST O Security 11 | 9 7 CM_MSG R Message Type 12 | 10 20 ST R Message Control Id 13 | 11 3 PT R Processing Id 14 | 12 8 ID R Version Id 15 | 13 15 NM O Sequence Number 16 | 14 180 ST O Continuation Pointer 17 | 15 2 ID O Accept Acknowledgement Type 18 | 16 2 ID O Application Acknowledgement Type 19 | 17 2 ID O Country Code 20 | 18 6 ID O Character Set 21 | 19 3 CE O Principal Language of Message 22 | 23 | PID http://www.corepointhealth.com/resource-center/hl7-resources/hl7-pid-segment 24 | SEQ LEN DT OPT RP/# ELEMENT NAME 25 | 1 4 SI O Set ID – Patient ID 26 | 2 20 CX O Patient ID (External ID) 27 | 3 20 CX R Y Patient ID (Internal ID) 28 | 4 20 CX O Y Alternate Patient ID – PID 29 | 5 48 XPN R Y Patient Name 30 | 6 48 XPN O Mother’s Maiden Name 31 | 7 26 TS O Date/Time of Birth 32 | 8 1 IS O Sex 33 | 9 48 XPN O Y Patient Alias 34 | 10 1 IS O Race 35 | 11 106 XAD O Y Patient Address 36 | 12 4 IS B Country Code 37 | 13 40 XTN O Y Phone Number – Home 38 | 14 40 XTN O Y Phone Number – Business 39 | 15 60 CE O Primary Language 40 | 16 1 IS O Marital Status 41 | 17 3 IS O Religion 42 | 18 20 CX O Patient Account Number 43 | 19 16 ST O SSN Number – Patient 44 | 20 25 DLN O Driver’s License Number - Patient 45 | 21 20 CX O Y Mother’s Identifier 46 | 22 3 IS O Ethnic Group 47 | 23 60 ST O Birth Place 48 | 24 2 ID O Multiple Birth Indicator 49 | 25 2 NM O Birth Order 50 | 26 4 IS O Y Citizenship 51 | 27 60 CE O Veterans Military Status 52 | 28 80 CE O Nationality 53 | 29 26 TS O Patient Death Date and Time 54 | 30 1 ID O Patient Death Indicator -------------------------------------------------------------------------------- /lib/segments/GT1.txt: -------------------------------------------------------------------------------- 1 | GT1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 SI R 1 Set ID - GT1 4 | 2 59 CX O * Guarantor Number 5 | 3 48 XPN R * Guarantor Name 6 | 4 48 XPN O * Guarantor Spouse Name 7 | 5 106 XAD O * Guarantor Address 8 | 6 40 XTN O * Guarantor Ph Num-Home 9 | 7 40 XTN O * Guarantor Ph Num-Business 10 | 8 26 TS O 1 Guarantor Date/Time Of Birth 11 | 9 1 IS O 1 Guarantor Sex 12 | 10 2 IS O 1 Guarantor Type 13 | 11 80 CE O 1 Guarantor Relationship 14 | 12 11 ST O 1 Guarantor SSN 15 | 13 8 DT O 1 Guarantor Date - Begin 16 | 14 8 DT O 1 Guarantor Date - End 17 | 15 2 NM O 1 Guarantor Priority 18 | 16 130 XPN O * Guarantor Employer Name 19 | 17 106 XAD O * Guarantor Employer Address 20 | 18 40 XTN O * Guarantor Employer Phone Number 21 | 19 20 CX O * Guarantor Employee ID Number 22 | 20 2 IS O 1 Guarantor Employment Status 23 | 21 130 XON O * Guarantor Organization Name 24 | 22 1 ID O 1 Guarantor Billing Hold Flag 25 | 23 80 CE O 1 Guarantor Credit Rating Code 26 | 24 26 TS O 1 Guarantor Death Date And Time 27 | 25 1 ID O 1 Guarantor Death Flag 28 | 26 80 CE O 1 Guarantor Charge Adjustment Code 29 | 27 10 CP O 1 Guarantor Household Annual Income 30 | 28 3 NM O 1 Guarantor Household Size 31 | 29 20 CX O * Guarantor Employer ID Number 32 | 30 80 CE O 1 Guarantor Marital Status Code 33 | 31 8 DT O 1 Guarantor Hire Effective Date 34 | 32 8 DT O 1 Employment Stop Date 35 | 33 2 IS O 1 Living Dependency 36 | 34 2 IS O * Ambulatory Status 37 | 35 80 CE O * Citizenship 38 | 36 60 CE O 1 Primary Language 39 | 37 2 IS O 1 Living Arrangement 40 | 38 80 CE O 1 Publicity Code 41 | 39 1 ID O 1 Protection Indicator 42 | 40 2 IS O 1 Student Indicator 43 | 41 80 CE O 1 Religion 44 | 42 48 XPN O * Mother s Maiden Name 45 | 43 80 CE O 1 Nationality 46 | 44 80 CE O * Ethnic Group 47 | 45 48 XPN O * Contact Person s Name 48 | 46 40 XTN O * Contact Person s Telephone Number 49 | 47 80 CE O 1 Contact Reason 50 | 48 2 IS O 1 Contact Relationship 51 | 49 20 ST O 1 Job Title 52 | 50 20 JCC O 1 Job Code/Class 53 | 51 130 XON O * Guarantor Employer s Organization Name 54 | 52 2 IS O 1 Handicap 55 | 53 2 IS O 1 Job Status 56 | 54 50 FC O 1 Guarantor Financial Class 57 | 55 80 CE O * Guarantor Race 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HL7 2 | ========= 3 | 4 | HL7 v2 parser/serializer in JavaScript 5 | 6 | Currently supports ORU^R01 (Lab Results) HL7 v 2.3-2.5 messages. 7 | 8 | Following segments are implemented: 9 | 10 | * MSH - Message Header 11 | * PID - Patient Identification 12 | * OBR - Observation Request 13 | * OBX - Observation Result 14 | * NTE - Notes and Comments 15 | 16 | ## Example 17 | 18 | ``` 19 | MSH|^~\&|SOME LAB|LAB|HOSPITAL|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4 20 | PID|||555-44-4444||EVERYWOMAN^EVE^E^^^^L|JONES|19620320|F|||153 FERNWOOD DR.^^STATESVILLE^OH^35292||(206)3345232|(206)752-121||||AC555444444||67-A4335^OH^20030520 21 | OBR|1|845439^GHH OE|1045813^GHH LAB|15545^GLUCOSE|||200202150730|||||||||555-55-5555^PRIMARY^PATRICIA P^^^^MD^^|||||||||F||||||444-44-4444^HIPPOCRATES^HOWARD H^^^^MD 22 | OBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|70_105|H|||F 23 | ``` 24 | 25 | 26 | ```javascript 27 | [ 28 | ["MSH", 29 | "|", 30 | "^~\&", 31 | [["SOME LAB"]] 32 | ... 33 | ], 34 | ["PID", 35 | [[""]], 36 | [[""]], 37 | [["555-444-4444"]], 38 | ] 39 | ] 40 | ``` 41 | 42 | 43 | ## Quick up and running quide 44 | 45 | ### Prerequisites 46 | 47 | - Node.js (v14.19+) and NPM 48 | - Grunt.js 49 | 50 | ```sh 51 | # install dependencies and build 52 | 53 | npm i 54 | grunt 55 | ``` 56 | 57 | ## Additional message types 58 | Currently, Amida's Node-only HL7 library does not provide full HL7 coverage. For a more complete implementation built on the Java HAPI HL7 implementation, see https://github.com/MatthewVita/node-hl7-complete. Keep in mind that running this library requires the use of Java 7. 59 | 60 | The HAPI library exports two functions, `jsToHl7` and `hl7ToJs`. If you want to use the HAPI library as a drop-in for this library, replace `parseString(data)` with `hl7ToJs(data, callback)`, and replace `serializeJSON(data, options)` with `jsToHl7(dataType, data, callback)`. 61 | 62 | ## Contributing 63 | 64 | Contributors are welcome. See [issues](https://github.com/amida-tech/hl7/issues) 65 | 66 | ## Release Notes 67 | 68 | See release notes [here](./RELEASENOTES.md) 69 | 70 | ## License 71 | 72 | Licensed under [Apache 2.0](./LICENSE) 73 | -------------------------------------------------------------------------------- /lib/segments/OM1.txt: -------------------------------------------------------------------------------- 1 | OM1 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 4 NM R 1 Sequence Number - Test/Observation Master File 4 | 2 200 CE R 1 Producer's Test/Observation ID 5 | 3 12 ID O * Permitted Data Types 6 | 4 1 ID R 1 Specimen Required 7 | 5 200 CE R 1 Producer ID 8 | 6 200 TX O 1 Observation Description 9 | 7 200 CE O 1 Other Test/Observation IDs for the Observation 10 | 8 200 ST R * Other Names 11 | 9 30 ST O 1 Preferred Report Name for the Observation 12 | 10 8 ST O 1 Preferred Short Name or Mnemonic for Observation 13 | 11 200 ST O 1 Preferred Long Name for the Observation 14 | 12 1 ID O 1 Orderability 15 | 13 60 CE O * Identity of Instrument Used to Perform this Study 16 | 14 200 CE O * Coded Representation of Method 17 | 15 1 ID O 1 Portable 18 | 16 1 CE O * Observation Producing Department/Section 19 | 17 40 XTN O 1 Telephone Number of Section 20 | 18 1 IS R 1 Nature of Test/Observation 21 | 19 200 CE O 1 Report Subheader 22 | 20 20 ST O 1 Report Display Order 23 | 21 26 TS O 1 Date/Time Stamp for any change in Definition for the Observation 24 | 22 26 TS O 1 Effective Date/Time of Change 25 | 23 20 NM O 1 Typical Turn-Around Time 26 | 24 20 NM O 1 Processing Time 27 | 25 40 ID O * Processing Priority 28 | 26 5 ID O 1 Reporting Priority 29 | 27 200 CE O * Outside Site 30 | 28 1000 XAD O * Address of Outside Site 31 | 29 400 XTN O 1 Phone Number of Outside Site 32 | 30 1 IS O 1 Confidentiality Code 33 | 31 200 CE O 1 Observations Required to Interpret the Obs 34 | 32 65536 TX O 1 Interpretation of Observations 35 | 33 65536 CE O 1 Contraindications to Observations 36 | 34 200 CE O * Reflex Tests/Observations 37 | 35 80 TX O 1 Rules that Trigger Reflex Testing 38 | 36 65536 CE O 1 Fixed Canned Message 39 | 37 200 TX O 1 Patient Preparation 40 | 38 200 CE O 1 Procedure Medication 41 | 39 200 TX O 1 Factors that may Effect the Observation 42 | 40 60 ST O * Test/Observation Performance Schedule 43 | 41 65536 TX O 1 Description of Test Methods 44 | 42 60 CE O 1 Kind of Quantity Observed 45 | 43 60 CE O 1 Point Versus Interval 46 | 44 200 TX O 1 Challenge Information 47 | 45 200 CE O 1 Relationship Modifier 48 | 46 200 CE O 1 Target Anatomic Site Of Test 49 | 47 200 CE O 1 Modality Of Imaging Measurement 50 | -------------------------------------------------------------------------------- /lib/segments/IN2.txt: -------------------------------------------------------------------------------- 1 | IN2 2 | SEQ LENGTH DT OPT RP/# ELEMENT NAME 3 | 1 59 CX O * Insured s Employee ID 4 | 2 11 ST O 1 Insured s Social Security Number 5 | 3 130 XCN O * Insured s Employer s Name and ID 6 | 4 1 IS O 1 Employer Information Data 7 | 5 1 IS O * Mail Claim Party 8 | 6 15 ST O 1 Medicare Health Ins Card Number 9 | 7 48 XPN O * Medicaid Case Name 10 | 8 15 ST O 1 Medicaid Case Number 11 | 9 48 XPN O * Military Sponsor Name 12 | 10 20 ST O 1 Military ID Number 13 | 11 80 CE O 1 Dependent Of Military Recipient 14 | 12 25 ST O 1 Military Organization 15 | 13 25 ST O 1 Military Station 16 | 14 14 IS O 1 Military Service 17 | 15 2 IS O 1 Military Rank/Grade 18 | 16 3 IS O 1 Military Status 19 | 17 8 DT O 1 Military Retire Date 20 | 18 1 ID O 1 Military Non-Avail Cert On File 21 | 19 1 ID O 1 Baby Coverage 22 | 20 1 ID O 1 Combine Baby Bill 23 | 21 1 ST O 1 Blood Deductible 24 | 22 48 XPN O * Special Coverage Approval Name 25 | 23 30 ST O 1 Special Coverage Approval Title 26 | 24 8 IS O * Non-Covered Insurance Code 27 | 25 59 CX O * Payor ID 28 | 26 59 CX O * Payor Subscriber ID 29 | 27 1 IS O 1 Eligibility Source 30 | 28 25 RMC O * Room Coverage Type/Amount 31 | 29 25 PTA O * Policy Type/Amount 32 | 30 25 DDI O 1 Daily Deductible 33 | 31 2 IS O 1 Living Dependency 34 | 32 2 IS O * Ambulatory Status 35 | 33 80 CE O * Citizenship 36 | 34 60 CE O 1 Primary Language 37 | 35 2 IS O 1 Living Arrangement 38 | 36 80 CE O 1 Publicity Code 39 | 37 1 ID O 1 Protection Indicator 40 | 38 2 IS O 1 Student Indicator 41 | 39 80 CE O 1 Religion 42 | 40 48 XPN O * Mother s Maiden Name 43 | 41 80 CE O 1 Nationality 44 | 42 80 CE O * Ethnic Group 45 | 43 80 CE O * Marital Status 46 | 44 8 DT O 1 Insured s Employment Start Date 47 | 45 8 DT O 1 Employment Stop Date 48 | 46 20 ST O 1 Job Title 49 | 47 20 JCC O 1 Job Code/Class 50 | 48 2 IS O 1 Job Status 51 | 49 48 XPN O * Employer Contact Person Name 52 | 50 40 XTN O * Employer Contact Person Phone Number 53 | 51 2 IS O 1 Employer Contact Reason 54 | 52 48 XPN O * Insured s Contact Person s Name 55 | 53 40 XTN O * Insured s Contact Person Phone Number 56 | 54 2 IS O * Insured s Contact Person Reason 57 | 55 8 DT O 1 Relationship To The Patient Start Date 58 | 56 8 DT O * Relationship To The Patient Stop Date 59 | 57 2 IS O 1 Insurance Co. Contact Reason 60 | 58 40 XTN O 1 Insurance Co Contact Phone Number 61 | 59 2 IS O 1 Policy Scope 62 | 60 2 IS O 1 Policy Source 63 | 61 60 CX O 1 Patient Member Number 64 | 62 80 CE O 1 Guarantor s Relationship To Insured 65 | 63 40 XTN O * Insured s Phone Number - Home 66 | 64 40 XTN O * Insured s Employer Phone Number 67 | 65 60 CE O 1 Military Handicapped Program 68 | 66 1 ID O 1 Suspend Flag 69 | 67 1 ID O 1 Copay Limit Flag 70 | 68 1 ID O 1 Stoploss Limit Flag 71 | 69 130 XON O * Insured Organization Name And ID 72 | 70 130 XON O * Insured Employer Organization Name And ID 73 | 71 80 CE O * Race 74 | 72 60 CE O 1 HCFA Patient s Relationship to Insured 75 | -------------------------------------------------------------------------------- /test/fixtures/isabella_jones_multiple_tests.txt: -------------------------------------------------------------------------------- 1 | MSH|^~\&|XXXX|C|SOMELAB|SOMELAB|20080511103530||ORU^R01|Q335939501T337311002|P|2.3||| 2 | PID|1||94000000000^^^Priority Health||JONES^ISABELLA^ISA||19750501|F|||||||||||123-456-7890| 3 | OBR|1|13041|107478846|0009-1^LIPID SCREEN (CORONARY RISK I)||201005060000|201005060000|||||||201005061449||J9999^JOHN DOE^M.D.|(201)555-2277|||SOME LABORATORIES||201005060935|||F| 4 | OBX|1|NM|0058-8^Cholesterol^BRLI^2093-3^CHOLESTEROL^LOINC||120|mg/dl|< 200||||F|||201005060935| 5 | OBX|2|NM|0059-6^HDL CHOL.,DIRECT^BRLI^2085-9^CHOLESTEROL.IN HDL^LOINC||55|mg/dl|>50||||F|||201005060935| 6 | OBX|3|NM|0155-2^Triglycerides^BRLI^2571-8^TRIGLYCERIDE^LOINC||120|mg/dl|< 151||||F|||201005060935| 7 | OBX|4|NM|1764-0^HDL as % of Cholesterol^BRLI^2095-8^CHOLESTEROL.IN HDL/CHOLESTEROL.TOTAL^LOINC||46|%|||||F|||201005060935| 8 | OBX|5|NM|1421-7^Chol/HDL Ratio^BRLI^9830-1^CHOLESTEROL.TOTAL/CHOLESTEROL.IN HDL^LOINC||2.18||||||F|||201005060935| 9 | OBX|6|NM|0253-5^LDL/HDL Ratio^BRLI^11054-4^CHOLESTEROL.IN LDL/CHOLESTEROL.IN HDL^LOINC||0.75||0-3.55||||F|||201005060935| 10 | OBX|7|NM|0505-8^LDL Cholesterol^BRLI^2089-1^CHOLESTEROL.IN LDL^LOINC||41||< 100||||F|||201005060935| 11 | OBR|2|13041|107478846|3427-2^COMPREHENSIVE METABOLIC||201005060000|201005060000|||||||201005061449||J9999^JOHN DOE^M.D.|(201)555-2277|||SOME LABORATORIES||201005060935|||F| 12 | OBX|1|NM|0135-4^Total Protein^BRLI^2885-2^PROTEIN^LOINC||7.0|gm/dl|5.9-8.4||||F|||201005060935| 13 | OBX|2|NM|0033-1^Albumin^BRLI^1751-7^ALBUMIN^LOINC||4.8|gm/dl|3.2-5.2||||F|||201005060935| 14 | OBX|3|NM|1753-3^Globulin^BRLI^2336-6^GLOBULIN^LOINC||2.2|gm/dL|1.7-3.7||||F|||201005060935| 15 | OBX|4|NM|0641-1^A/G Ratio^BRLI^1759-0^ALBUMIN/GLOBULIN^LOINC||2.2||1.1-2.9||||F|||201005060935| 16 | OBX|5|NM|0148-7^Sodium^BRLI^2951-2^SODIUM^LOINC||141|mmol/L|133-145||||F|||201005060935| 17 | OBX|6|NM|0129-7^Potassium^BRLI^2823-3^POTASSIUM^LOINC||4.0|mmol/L|3.3-5.3||||F|||201005060935| 18 | OBX|7|NM|0057-0^Chloride^BRLI^2075-0^CHLORIDE^LOINC||99|mmol/L|96-108||||F|||201005060935| 19 | OBX|8|NM|0052-1^CO2^BRLI^2028-9^CARBON DIOXIDE^LOINC||25|mmol/L|21-29||||F|||201005060935| 20 | OBX|9|NM|0049-7^BUN^BRLI^3094-0^UREA NITROGEN^LOINC||20|mg/dl|7-25||||F|||201005060935| 21 | OBX|10|NM|0070-3^Creatinine^BRLI^2160-0^CREATININE^LOINC||1.0|mg/dl|0.6-1.3||||F|||201005060935| 22 | OBX|11|NM|090013-4^e-GFR^BRLI^^^LOINC||62||> 60 mL/min/1.73m2||||F|||201005060935| 23 | OBX|12|NM|1427-4^BUN/Creat Ratio^BRLI^3097-3^UREA NITROGEN/CREATININE^LOINC||20||10-28||||F|||201005060935| 24 | OBX|13|NM|0050-5^Calcium^BRLI^17861-6^CALCIUM^LOINC||9.0|mg/dl|8.4-10.4||||F|||201005060935| 25 | OBX|14|NM|0043-0^Bilirubin, Total^BRLI^1975-2^BILIRUBIN^LOINC||0.5|mg/dl|0.1-1.0||||F|||201005060935| 26 | OBX|15|NM|0185-9^Alk Phos^BRLI^6768-6^ALKALINE PHOSPHATASE^LOINC||55|u/l|39-120||||F|||201005060935| 27 | OBX|16|NM|0146-1^AST (SGOT)^BRLI^1920-8^ASPARTATE AMINOTRANSFERASE^LOINC||22|u/l|0-37||||F|||201005060935| 28 | OBX|17|NM|0147-9^ALT (SGPT)^BRLI^1742-6^ALANINE AMINOTRANSFERASE^LOINC||22|u/L|0-40||||F|||201005060935| 29 | OBX|18|NM|1976-0^Glucose^BRLI^2345-7^GLUCOSE^LOINC||80|mg/dL|70-99||||F|||201005060935| 30 | -------------------------------------------------------------------------------- /test/fixtures/samples.txt: -------------------------------------------------------------------------------- 1 | Sample lines example 1: 2 | MSH|^~\&|CERNER||PriorityHealth||||ORU^R01|Q479004375T431430612|P|2.3| 3 | PID|||001677980||SMITH^CURTIS||19680219|M||||||||||929645156318|123456789| 4 | PD1||||1234567890^LAST^FIRST^M^^^^^NPI| 5 | OBR|1|341856649^HNAM_ORDERID|000002006326002362|648088^Basic Metabolic Panel|||20061122151600|||||||||1620^Hooker^Robert^L||||||20061122154733|||F|||||||||||20061122140000| 6 | OBX|1|NM|GLU^Glucose Lvl|59|mg/dL|65-99^65^99|L|||F|||20061122154733| 7 | 8 | Sample lines example 2: 9 | MSH|^~\&|SOURCE|383018129|PRIORITY HEALTH|382715520|2007100914484648||ORU^R01|0129938170710091448|P|2.3| 10 | PID|1|1034157|012993817||LASTNAME^FIRSTNAME||19520101|M|||1234 MAIN^^DEARBORN HEIGHT^MI^48127|||||||| 11 | PID|1||94000000000^^^Priority Health||LASTNAME^FIRSTNAME||19400101|F| 12 | PD1|1|||1234567890^DOCLAST^DOCFIRST^M^^^^^NPI| 13 | OBR|1|||80061^LIPID PROFILE^CPT-4||20070911|||||||||| 14 | OBX|1|NM|13457-7^LDL (CALCULATED)^LOINC|49.000|MG/DL| 0.000 - 100.000|N|||F| 15 | OBX|2|NM|2093-3^CHOLESTEROL^LOINC|138.000|MG/DL|100.000 - 200.000|N|||F| 16 | OBX|3|NM|2086-7^HDL^LOINC|24.000|MG/DL|45.000 - 150.000|L|||F| 17 | OBX|4|NM|2571-8^TRIGLYCERIDES^LOINC|324.000|MG/DL| 0.000 - 150.000|H|||F| 18 | 19 | Sample lines example 3: 20 | MSH|^~\&|XXXX|C|PRIORITYHEALTH|PRIORITYHEALTH|20080511103530||ORU^R01|Q335939501T337311002|P|2.3||| 21 | PID|1||94000000000^^^Priority Health||LASTNAME^FIRSTNAME^INIT||19460101|M||||| 22 | PD1|1|||1234567890^PCPLAST^PCPFIRST^M^^^^^NPI| 23 | OBR|1||185L29839X64489JLPF~X64489^ACC_NUM|JLPF^Lipid Panel - C||||||||||||1694^DOCLAST^DOCFIRST^^MD||||||20080511103529||| 24 | OBX|1|NM|JHDL^HDL Cholesterol (CAD)|1|62|CD:289^mg/dL|>40^>40|""||""|F|||20080511103500|||^^^""| 25 | OBX|2|NM|JTRIG^Triglyceride (CAD)|1|72|CD:289^mg/dL|35-150^35^150|""||""|F|||20080511103500|||^^^""| 26 | OBX|3|NM|JVLDL^VLDL-C (calc - CAD)|1|14|CD:289^mg/dL||""||""|F|||20080511103500|||^^^""| 27 | OBX|4|NM|JLDL^LDL-C (calc - CAD)|1|134|CD:289^mg/dL|0-100^0^100|H||""|F|||20080511103500|||^^^""| 28 | OBX|5|NM|JCHO^Cholesterol (CAD)|1|210|CD:289^mg/dL|90-200^90^200|H||""|F|||20080511103500|||^^^""| 29 | 30 | - See more at: http://www.priorityhealth.com/provider/manual/office-mgmt/data-exchange/hl7/hl7-samples#sthash.TEEHCodq.dpuf 31 | 32 | MSH|^~\&|EPIC|EPICADT|SMS|SMSADT|199912271408|CHARRIS|ADT^A04|1817457|D|2.5| 33 | PID||0493575^^^2^ID 1|454721||DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086| 34 | NK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC||||||||||||||||||||||||||| 35 | PV1||O|168 ~219~C~PMA^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||||||||||||||||||||199912271408||||||002376853 36 | 37 | 38 | MSH|^~\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4 39 | PID|||555-44-4444||EVERYWOMAN^EVE^E^^^^L|JONES|19620320|F|||153 FERNWOOD DR.^ 40 | ^STATESVILLE^OH^35292||(206)3345232|(206)752-121||||AC555444444||67-A4335^OH^20030520 41 | OBR|1|845439^GHH OE|1045813^GHH LAB|15545^GLUCOSE|||200202150730||||||||| 42 | 555-55-5555^PRIMARY^PATRICIA P^^^^MD^^|||||||||F||||||444-44-4444^HIPPOCRATES^HOWARD H^^^^MD 43 | OBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|70_105|H|||F -------------------------------------------------------------------------------- /lib/parser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | //http://python-hl7.readthedocs.org/en/latest/accessors.html 4 | 5 | var SEGMENT = '\r'; 6 | var FIELD = '|'; 7 | var COMPONENT = '^'; 8 | var FIELDREPEAT = '~'; 9 | var ESCAPE = '\\'; 10 | var SUBCOMPONENT = '&'; 11 | 12 | //Message[segment][field][repetition][component][sub-component] 13 | function parseComponent(data) { 14 | var result = []; 15 | var subcomponents = data.split(SUBCOMPONENT); 16 | 17 | var s; 18 | if (subcomponents.length === 1) { 19 | s = subcomponents[0]; 20 | result = s; 21 | 22 | } else { 23 | 24 | for (var i = 0; i < subcomponents.length; i++) { 25 | s = subcomponents[i]; 26 | result.push(s); 27 | } 28 | } 29 | 30 | return result; 31 | } 32 | 33 | function parseRepeat(data) { 34 | var result = []; 35 | var components = data.split(COMPONENT); 36 | var c; 37 | 38 | for (var i = 0; i < components.length; i++) { 39 | c = parseComponent(components[i]); 40 | result.push(c); 41 | } 42 | 43 | return result; 44 | } 45 | 46 | function parseField(data) { 47 | var result = []; 48 | var repeats = data.split(FIELDREPEAT); 49 | 50 | for (var i = 0; i < repeats.length; i++) { 51 | var r = parseRepeat(repeats[i]); 52 | result.push(r); 53 | } 54 | 55 | return result; 56 | } 57 | 58 | function parseSegment(data) { 59 | var result = {}; 60 | var fields = data.split(FIELD); 61 | 62 | //var seg_name = fields[0]; 63 | 64 | result = []; 65 | var start = 0; 66 | 67 | //adjusting header segment, inserting | as first field 68 | if (fields[0] === "MSH") { 69 | fields[0] = FIELD; 70 | fields = ["MSH"].concat(fields); 71 | 72 | //ignore MSH1 and MSH2 73 | start = 3; 74 | 75 | result.push("MSH"); //segment name 76 | result.push(FIELD); //pipe 77 | result.push(fields[2]); //separators 78 | } else { 79 | result.push(fields[0]); //segment name 80 | 81 | start = 1; 82 | } 83 | 84 | for (var i = start; i < fields.length; i++) { 85 | //skip empty fields 86 | //if (fields[i] === "") continue; 87 | 88 | var f = parseField(fields[i]); 89 | result.push(f); 90 | } 91 | 92 | return result; 93 | } 94 | 95 | function parse(data) { 96 | //MSH check 97 | if (data.substr(0, 3) !== 'MSH') { 98 | //TODO: throw a proper error here 99 | return null; 100 | } 101 | 102 | //define field separator from MSH header 103 | FIELD = data[3]; 104 | 105 | //define all other separators from MSH header 106 | COMPONENT = data[4]; 107 | FIELDREPEAT = data[5]; 108 | ESCAPE = data[6]; 109 | SUBCOMPONENT = data[7]; 110 | 111 | //parse into result object 112 | var result = []; 113 | 114 | var segments = data.split(SEGMENT); 115 | for (var i = 0; i < segments.length; i++) { 116 | if (segments[i] === "") { 117 | continue; 118 | } 119 | var seg = parseSegment(segments[i]); 120 | 121 | result.push(seg); 122 | } 123 | 124 | return result; 125 | 126 | } 127 | 128 | function parseString(data, options) { 129 | //data must be a string 130 | if (!data || typeof (data) !== "string") { 131 | //TODO: throw a proper error here 132 | return null; 133 | } 134 | 135 | if (arguments.length === 1) { 136 | options = {}; 137 | } 138 | 139 | data = parse(data); 140 | 141 | return data; 142 | } 143 | 144 | module.exports = { 145 | parseString: parseString, 146 | }; 147 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 Amida Technology Solutions (http://amida-tech.com) 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------