forked from wokket/rust-hl7
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* WIP: starting on an escape sequence decoder * feat wokket#22: WIP on escape sequence handling, not as easy as I'd hoped because of HL7's full on spec. This will prob come in stages. * feat wokket#22: Good progress on simple delimiter escape sequences * feat wokket#22: Ensure highlighted text sequences (\N\, \H\)are ignored * perf: better than halved the perf of the 'No escape sequence' benchmark using a regex(!) rather than a simple str.find() * feat: Added support for ignoring custom (\Zdd\) escape sequences * chore: docs pass, moved decoder into better module/location * perf: Moved to the regex for all searching ops, about a 15% improvement in the benchmark * docs * docs: Added demo example for info on how to use the library * docs: Docs pass * feat: Added support for \X..\ escape sequences * docs: Updated docs for \X\ sequences.
- Loading branch information
Showing
8 changed files
with
478 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rusthl7::{escape_sequence::*, separators::Separators}; | ||
|
||
// Note that we;re calkling decode on a whole message here, although it would normally be on an individual field... | ||
// this is just to make it work a bit harder on a larger dataset, not because it makes sense in a HL7 sense | ||
|
||
fn no_sequences(c: &mut Criterion) { | ||
c.bench_function("No Escape Sequences", |b| { | ||
let delims = Separators::default(); | ||
let decoder = EscapeSequence::new(delims); | ||
|
||
b.iter(|| { | ||
let _ = decoder.decode(get_sample_message_no_sequence()); | ||
}) | ||
}); | ||
} | ||
|
||
// We expect creation to be a little slower, as we init the regexes to make decode() calls faster | ||
// Amortizing this cost across multiple calls makes sense if we're caching the struct | ||
fn create_struct(c: &mut Criterion) { | ||
c.bench_function("Create struct", |b| { | ||
let delims = Separators::default(); | ||
|
||
b.iter(|| { | ||
let _ = EscapeSequence::new(delims); | ||
}) | ||
}); | ||
} | ||
|
||
fn no_sequences_but_backslash(c: &mut Criterion) { | ||
c.bench_function("No Escape Sequences But Backslash", |b| { | ||
let delims = Separators::default(); | ||
let decoder = EscapeSequence::new(delims); | ||
|
||
b.iter(|| { | ||
let _ = decoder.decode(get_sample_message_with_backslash()); | ||
}) | ||
}); | ||
} | ||
|
||
fn has_escape_sequences(c: &mut Criterion) { | ||
c.bench_function("Has Escape Sequences", |b| { | ||
let delims = Separators::default(); | ||
let decoder = EscapeSequence::new(delims); | ||
|
||
b.iter(|| { | ||
let _ = decoder.decode(get_sample_message_with_escape_sequences()); | ||
}) | ||
}); | ||
} | ||
|
||
fn get_sample_message_no_sequence() -> &'static str { | ||
// note we've stripped the backslash from the MSH | ||
"MSH|^~*&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4\rPID|||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\rOBR|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\rOBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|70_105|H|||F" | ||
} | ||
|
||
fn get_sample_message_with_backslash() -> &'static str { | ||
//there's a backslash down at char 487! | ||
"MSH|^~\\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4\rPID|||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\rOBR|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\rOBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|\\70_105|H|||F" | ||
} | ||
|
||
fn get_sample_message_with_escape_sequences() -> &'static str { | ||
//there's a backslash down at char 487! | ||
"MSH|^~\\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4\rPID|||\\F\\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\rOBR|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\rOBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|\\70_105|H|||F" | ||
} | ||
|
||
criterion_group!( | ||
decoder, | ||
create_struct, | ||
no_sequences, | ||
no_sequences_but_backslash, | ||
has_escape_sequences | ||
); | ||
criterion_main!(decoder); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*! | ||
A short example demonstrating one way to use this library for HL7 processing. | ||
*/ | ||
|
||
use std::{convert::TryFrom, error::Error}; | ||
use rusthl7::{escape_sequence::EscapeSequence, message::Message}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
|
||
// Normally message would come over the wire from a remote service etc. | ||
// Consider using the hl7-mllp-code crate or similar to make building those network services easier. | ||
let hl7_string = get_sample_message(); | ||
|
||
// Parse the string into a structured entity | ||
let message = Message::try_from(hl7_string)?; | ||
|
||
// We can deep query message fields using the `query` functionality | ||
let postcode = message.query("PID.F11.C5"); // Field 11, Component 5 | ||
assert_eq!(postcode, "35292"); | ||
|
||
// If you have the potential for escape sequences in your data you can process those using `EscapeSequence` | ||
let charge_to_practice = message.query("OBR.F23"); | ||
assert_eq!(charge_to_practice, r#"Joes Obs \T\ Gynae"#); | ||
|
||
let decoder = EscapeSequence::new(message.get_separators()); | ||
let charge_to_practice = decoder.decode(charge_to_practice); // Handle the escape sequences | ||
assert_eq!(charge_to_practice, "Joes Obs & Gynae"); // converted the \T\ sequence to an ampersand | ||
|
||
Ok(()) | ||
} | ||
|
||
fn get_sample_message() -> &'static str { | ||
"MSH|^~\\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4\rPID|||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\rOBR|1|845439^GHH OE|1045813^GHH LAB|15545^GLUCOSE|||200202150730|||||||||555-55-5555^PRIMARY^PATRICIA P^^^^MD^^|||||||Joes Obs \\T\\ Gynae||F||||||444-44-4444^HIPPOCRATES^HOWARD H^^^^MD\rOBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|70_105|H|||F" | ||
} |
This file contains 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
Oops, something went wrong.