forked from phatboyg/Machete
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests and fixed issue phatboyg#41
- Loading branch information
Showing
16 changed files
with
389 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
namespace Machete.HL7.Tests | ||
{ | ||
using HL7Schema.V26; | ||
using NUnit.Framework; | ||
using Testing; | ||
|
||
|
||
[TestFixture] | ||
public class FieldsPropertyTests : | ||
HL7MacheteTestHarness<MSH, HL7Entity> | ||
{ | ||
[Test] | ||
public void Should_be_able_get_all_entity_fields() | ||
{ | ||
const string message = @"MSH|^~\&|MACHETELAB|^DOSC|MACHETE|18779|20130405125146269||ORM^O01|1999077678|P|2.3|||AL|AL | ||
PID|1|000000000026|60043^^^MACHETE^MRN||MACHETE^JOE||19890909|F|||123 SEASAME STREET^^Oakland^CA^94600||5101234567|5101234567||||||||||||||||N"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.Fields)); | ||
Assert.IsTrue(result.Select(x => x.Fields).IsPresent); | ||
Assert.AreEqual(15, result.Select(x => x.Fields).Count()); | ||
} | ||
|
||
[Test] | ||
public void Should_be_able_to_access_entity_fields() | ||
{ | ||
const string message = @"MSH|^~\&|MACHETELAB|^DOSC|MACHETE|18779|20130405125146269||ORM^O01|1999077678|P|2.3|||AL|AL | ||
PID|1|000000000026|60043^^^MACHETE^MRN||MACHETE^JOE||19890909|F|||123 SEASAME STREET^^Oakland^CA^94600||5101234567|5101234567||||||||||||||||N"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.Fields)); | ||
Assert.IsTrue(result.Select(x => x.Fields).IsPresent); | ||
Assert.IsTrue(result.Select(x => x.Fields).TryGetValue(7, out var field)); | ||
Assert.AreEqual("ORM^O01", field.ValueOrDefault()); | ||
} | ||
|
||
[Test] | ||
public void Should_be_able_to_get_fields() | ||
{ | ||
const string message = @"MSH|^~\&|MACHETELAB|^DOSC|MACHETE|18779|20130405125146269||ORM^O01|1999077678|P|2.3|||AL|AL | ||
PID|1|000000000026|60043^^^MACHETE^MRN~60044^^^MACHETE^MRN||MACHETE^JOE||19890909|F|||123 SEASAME STREET^^Oakland^CA^94600||5101234567|5101234567||||||||||||||||N"; | ||
|
||
ParseResult<HL7Entity> parse = Parser.Parse(message); | ||
|
||
var result = parse.Query(q => from msh in q.Select<MSH>() | ||
from pid in q.Select<PID>() | ||
select pid); | ||
|
||
string patientIdentifierList = result.Select(x => x.Fields)[2].ValueOrDefault(); | ||
|
||
Assert.AreEqual("60043^^^MACHETE^MRN~60044^^^MACHETE^MRN", patientIdentifierList); | ||
} | ||
|
||
[Test] | ||
public void Should_be_able_return_no_fields_on_empty_entity() | ||
{ | ||
const string message = @"MSH|^~\&|MACHETELAB|^DOSC|MACHETE|18779|20130405125146269||ORM^O01|1999077678|P|2.3|||AL|AL | ||
PID"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
from pid in q.Select<PID>() | ||
select pid); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.Fields)); | ||
Assert.IsTrue(result.Select(x => x.Fields).IsPresent); | ||
Assert.AreEqual(0, result.Select(x => x.Fields).Count()); | ||
} | ||
} | ||
} |
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,47 @@ | ||
namespace Machete.HL7.Tests | ||
{ | ||
using HL7Schema.V26; | ||
using NUnit.Framework; | ||
using Testing; | ||
|
||
|
||
[TestFixture] | ||
public class HasValueTests : | ||
HL7MacheteTestHarness<MSH, HL7Entity> | ||
{ | ||
[Test] | ||
public void Should_detect_field_has_no_value() | ||
{ | ||
const string message = @"MSH|^~\&|LIFTLAB||UBERMED||201701131234|||K113|P|"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.MessageType)); | ||
Assert.IsTrue(result.Select(x => x.MessageType).HasValue); | ||
} | ||
|
||
[Test] | ||
public void Should_detect_component_field_has_no_value() | ||
{ | ||
const string message = @"MSH|^~\&|LIFTLAB||UBERMED||201701131234||^R01|K113|P|"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.MessageType)); | ||
Assert.IsTrue(result.Select(x => x.MessageType).HasValue); | ||
Assert.IsFalse(result.Select(x => x.MessageType).Select(x => x.MessageCode).HasValue); | ||
} | ||
} | ||
} |
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,97 @@ | ||
namespace Machete.HL7.Tests | ||
{ | ||
using HL7Schema.V26; | ||
using NUnit.Framework; | ||
using Testing; | ||
|
||
|
||
[TestFixture] | ||
public class IsPresentTests : | ||
HL7MacheteTestHarness<MSH, HL7Entity> | ||
{ | ||
[Test] | ||
public void Should_detect_data_is_present_in_complex_field() | ||
{ | ||
const string message = @"MSH|^~\&|LIFTLAB||UBERMED||201701131234|||K113|P|"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.MessageType)); | ||
Assert.IsTrue(result.Select(x => x.MessageType).IsPresent); | ||
} | ||
|
||
[Test] | ||
public void Should_detect_data_is_not_present_in_complex_field() | ||
{ | ||
const string message = @"MSH|^~\&|LIFTLAB||UBERMED||201701131234"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.MessageType)); | ||
Assert.IsFalse(result.Select(x => x.MessageType).IsPresent); | ||
} | ||
|
||
[Test] | ||
public void Should_detect_data_is_present_with_field_of_whitespace() | ||
{ | ||
const string message = @"MSH|^~\&|LIFTLAB||UBERMED||201701131234|| |K113|P|"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.MessageType)); | ||
Assert.IsTrue(result.Select(x => x.MessageType).IsPresent); | ||
} | ||
|
||
[Test] | ||
public void Should_detect_data_is_present_in_simple_field() | ||
{ | ||
const string message = @"MSH|^~\&|LIFTLAB||UBERMED||201701131234|SECURE1"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.Security)); | ||
Assert.IsTrue(result.Select(x => x.Security).IsPresent); | ||
} | ||
|
||
[Test] | ||
public void Should_detect_data_is_not_present_in_simple_field() | ||
{ | ||
const string message = @"MSH|^~\&|LIFTLAB||UBERMED"; | ||
|
||
EntityResult<HL7Entity> entityResult = Parser.Parse(message); | ||
|
||
var query = entityResult.CreateQuery(q => | ||
from msh in q.Select<MSH>() | ||
select msh); | ||
|
||
var result = entityResult.Query(query); | ||
|
||
Assert.IsNotNull(result.Select(x => x.Security)); | ||
Assert.IsFalse(result.Select(x => x.Security).IsPresent); | ||
} | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.