Skip to content

Commit

Permalink
added tests and fixed issue phatboyg#41
Browse files Browse the repository at this point in the history
  • Loading branch information
ahives committed Dec 11, 2017
1 parent e428e01 commit 7bb370b
Show file tree
Hide file tree
Showing 16 changed files with 389 additions and 63 deletions.
88 changes: 88 additions & 0 deletions src/Machete.HL7.Tests/FieldsPropertyTests.cs
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());
}
}
}
2 changes: 0 additions & 2 deletions src/Machete.HL7.Tests/Format_Specs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Machete.HL7.Tests
{
using System.Threading.Tasks;
using Machete.Formatters;
using NUnit.Framework;
using Segments;
using Testing;
Expand All @@ -14,7 +13,6 @@ public class Formatting_an_HL7_segment :
[Test, Explicit]
public async Task Should_return_the_same_as_the_input()
{
// const string message = @"MSH|^~\&|MACHETELAB||UBERMED||201701131234|||K113|P|";
const string message = @"MSH|^~\&|MACHETELAB||UBERMED||201701131234|||K113|P";

ParseResult<HL7Entity> entityResult = Parser.Parse(message);
Expand Down
47 changes: 47 additions & 0 deletions src/Machete.HL7.Tests/HasValueTests.cs
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);
}
}
}
97 changes: 97 additions & 0 deletions src/Machete.HL7.Tests/IsPresentTests.cs
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);
}
}
}
8 changes: 3 additions & 5 deletions src/Machete.HL7.Tests/LayoutFormattingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,16 @@ public void Should_be_able_to_format_layout()

EntityResult<HL7Entity> parse = Parser.Parse(message);

ILayoutParserFactory<ORM_O01, HL7Entity> layout;
Assert.IsTrue(Schema.TryGetLayout(out layout));
Assert.IsTrue(Schema.TryGetLayout(out ILayoutParserFactory<ORM_O01, HL7Entity> layout));

IParser<HL7Entity, ORM_O01> query = parse.CreateQuery(q => layout.CreateParser(LayoutParserOptions.None, q));
Result<Cursor<HL7Entity>, ORM_O01> result = parse.Query(query);

Assert.That(result.HasResult, Is.True);

LayoutList<ORM_O01_ORDER> orders = result.Select(x => x.Order);

ILayoutFormatter<ORM_O01_ORDER> formatter;
Assert.That(Schema.TryGetLayoutFormatter(out formatter), Is.True);

Assert.That(Schema.TryGetLayoutFormatter(out ILayoutFormatter<ORM_O01_ORDER> formatter), Is.True);

var context = new StringBuilderFormatContext();

Expand Down
2 changes: 1 addition & 1 deletion src/Machete.HL7.Tests/Machete.HL7.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<DebugType>portable</DebugType>
<LangVersion>7.1</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
Expand Down
6 changes: 2 additions & 4 deletions src/Machete.HL7.Tests/SegmentListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public void Should_be_able_to_query_order_tests_segment_list()

EntityResult<HL7Entity> parse = Parser.Parse(message);

ILayoutParserFactory<OrderLayout, HL7Entity> layout;
Assert.IsTrue(Schema.TryGetLayout(out layout));
Assert.IsTrue(Schema.TryGetLayout(out ILayoutParserFactory<OrderLayout, HL7Entity> layout));

IParser<HL7Entity, OrderLayout> query = parse.CreateQuery(q => layout.CreateParser(LayoutParserOptions.None, q));

Expand Down Expand Up @@ -54,8 +53,7 @@ public void Should_be_able_to_count_SegmentList()

EntityResult<HL7Entity> parse = Parser.Parse(message);

ILayoutParserFactory<OrderLayout, HL7Entity> layout;
Assert.IsTrue(Schema.TryGetLayout(out layout));
Assert.IsTrue(Schema.TryGetLayout(out ILayoutParserFactory<OrderLayout, HL7Entity> layout));

IParser<HL7Entity, OrderLayout> query = parse.CreateQuery(q => layout.CreateParser(LayoutParserOptions.None, q));

Expand Down
29 changes: 0 additions & 29 deletions src/Machete.HL7.Tests/SegmentTests.cs

This file was deleted.

9 changes: 3 additions & 6 deletions src/Machete.HL7.Tests/Template_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public void Should_be_possible()

EntityResult<HL7Entity> entityResult = Parser.Parse(message);

ILayoutParserFactory<MessageLayout, HL7Entity> layout;
Assert.That(Schema.TryGetLayout(out layout), Is.True);
Assert.That(Schema.TryGetLayout(out ILayoutParserFactory<MessageLayout, HL7Entity> layout), Is.True);

IParser<HL7Entity, MessageLayout> query = entityResult.CreateQuery(layout);

Expand All @@ -39,8 +38,7 @@ public void Should_pull_the_optional_segments_without_a_glitch()

EntityResult<HL7Entity> entityResult = Parser.Parse(message);

ILayoutParserFactory<MessageLayout, HL7Entity> layout;
Assert.That(Schema.TryGetLayout(out layout), Is.True);
Assert.That(Schema.TryGetLayout(out ILayoutParserFactory<MessageLayout, HL7Entity> layout), Is.True);

IParser<HL7Entity, MessageLayout> query = entityResult.CreateQuery(q => layout.CreateParser(LayoutParserOptions.None, q));

Expand Down Expand Up @@ -89,8 +87,7 @@ public void Should_be_able_to_query_order_tests()

EntityResult<HL7Entity> parse = Parser.Parse(message);

ILayoutParserFactory<OrderLayout, HL7Entity> layout;
Assert.IsTrue(Schema.TryGetLayout(out layout));
Assert.IsTrue(Schema.TryGetLayout(out ILayoutParserFactory<OrderLayout, HL7Entity> layout));

IParser<HL7Entity, OrderLayout> query = parse.CreateQuery(q => layout.CreateParser(LayoutParserOptions.None, q));

Expand Down
10 changes: 3 additions & 7 deletions src/Machete.HL7.Tests/Translate_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ from msh in q.Select<MSHSegment>()

var translateResult = await translator.Translate(entityResult, result);

MSHSegment translated;
Assert.IsTrue(translateResult.TryGetEntity(0, out translated));
Assert.IsTrue(translateResult.TryGetEntity(0, out MSHSegment translated));
Assert.That(translated.SendingApplication, Is.Not.Null);
Assert.IsTrue(translated.SendingApplication.HasValue);
Assert.That(translated.SendingApplication.ValueOrDefault(), Is.EqualTo("MACHETELAB"));
Assert.IsTrue(translated.ReceivingApplication.HasValue);
Assert.That(translated.ReceivingApplication.ValueOrDefault(), Is.EqualTo("MACHETELAB"));
Assert.AreEqual(
translated.ReceivingApplication.ValueOrDefault(),
translated.SendingApplication.ValueOrDefault());
Assert.AreEqual(translated.ReceivingApplication.ValueOrDefault(), translated.SendingApplication.ValueOrDefault());
}

[Test]
Expand All @@ -66,8 +63,7 @@ from pid in q.Select<PIDSegment>()

var translateResult = await translator.Translate(entityResult, result);

PIDSegment translated;
Assert.IsTrue(translateResult.TryGetEntity(0, out translated));
Assert.IsTrue(translateResult.TryGetEntity(0, out PIDSegment translated));
Assert.That(translated.PatientIdentifierList.HasValue, Is.True);
Assert.That(translated.PatientIdentifierList[0].HasValue, Is.True);
Assert.IsTrue(translated.PatientIdentifierList[0].Select(x => x.IdNumber).HasValue);
Expand Down
Loading

0 comments on commit 7bb370b

Please sign in to comment.