Created
May 29, 2024 20:19
-
-
Save ppazos/d44e0fda4e480bc4d60b03ec053efa28 to your computer and use it in GitHub Desktop.
Encode and decode strings for HL7 v2.x messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatHL7String(str) | |
{ | |
var hl7String = str.replace(/\\/g, '\\E\\'); | |
hl7String = hl7String.replace(/\|/g, '\\F\\'); | |
hl7String = hl7String.replace(/\^/g, '\\S\\'); | |
hl7String = hl7String.replace(/~/g, '\\R\\'); | |
hl7String = hl7String.replace(/&/g, '\\T\\'); | |
return hl7String; | |
} | |
console.log(" \\ | ^ ~ & "); | |
console.log(formatHL7String(" \\ | ^ ~ & ")); | |
function parseHL7String(hl7String) | |
{ | |
var parsedString = hl7String.replace(/\\F\\/g, '\|'); | |
parsedString = parsedString.replace(/\\S\\/g, '^'); | |
parsedString = parsedString.replace(/\\R\\/g, '~'); | |
parsedString = parsedString.replace(/\\T\\/g, '&'); | |
parsedString = parsedString.replace(/\\E\\/g, '\\'); | |
return parsedString; | |
} | |
console.log(parseHL7String(formatHL7String(" \\ | ^ ~ & "))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output should be: