コード例 #1
0
        public void Should_be_able_to_format_layout()
        {
            const string message = @"MSH|^~\&|MACHETELAB|^DOSC|MACHETE|18779|20130405125146269||ORM^O01|1999077678|P|2.3|||AL|AL
NTE|1||KOPASD
NTE|2||A3RJ
NTE|3||7ADS
NTE|4||G46DG
PID|1|000000000026|60043^^^MACHETE^MRN||MACHETE^JOE||19890909|F|||123 SEASAME STREET^^Oakland^CA^94600||5101234567|5101234567||||||||||||||||N
PD1|M|F|N||||F|
NTE|1||IN42
PV1|1|O|||||92383^Machete^Janice||||||||||||12345|||||||||||||||||||||||||201304051104
PV2||||||||20150615|20150616|1||||||||||||||||||||||||||N
IN1|1|||MACHETE INC|1234 Fruitvale ave^^Oakland^CA^94601^USA||5101234567^^^^^510^1234567|074394|||||||A1|MACHETE^JOE||19890909|123 SEASAME STREET^^Oakland^CA^94600||||||||||||N|||||666889999|0||||||F||||T||60043^^^MACHETE^MRN
GT1|1|60043^^^MACHETE^MRN|MACHETE^JOE||123 SEASAME STREET^^Oakland^CA^94600|5416666666|5418888888|19890909|F|P
AL1|1|FA|^pollen allergy|SV|jalubu daggu||
ORC|NW|PRO2350||XO934N|||^^^^^R||20130405125144|91238^Machete^Joe||92383^Machete^Janice
OBR|1|PRO2350||11636^Urinalysis, with Culture if Indicated^L|||20130405135133||||N|||||92383^Machete^Janice|||||||||||^^^^^R
DG1|1|I9|788.64^URINARY HESITANCY^I9|URINARY HESITANCY
OBX|1||URST^Urine Specimen Type^^^||URN
NTE|1||abc
NTE|2||dsa
ORC|NW|PRO2351||XO934N|||^^^^^R||20130405125144|91238^Machete^Joe||92383^Machete^Janice
OBR|1|PRO2350||11637^Urinalysis, with Culture if Indicated^L|||20130405135133||||N|||||92383^Machete^Janice|||||||||||^^^^^R
DG1|1|I9|788.64^URINARY HESITANCY^I9|URINARY HESITANCY
OBX|1||URST^Urine Specimen Type^^^||URN
NTE|1||abc
NTE|2||dsa
ORC|NW|PRO2352||XO934N|||^^^^^R||20130405125144|91238^Machete^Joe||92383^Machete^Janice
OBR|1|PRO2350||11638^Urinalysis, with Culture if Indicated^L|||20130405135133||||N|||||92383^Machete^Janice|||||||||||^^^^^R
DG1|1|I9|788.64^URINARY HESITANCY^I9|URINARY HESITANCY
OBX|1||URST^Urine Specimen Type^^^||URN
NTE|1||abc
NTE|2||dsa";

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

            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);

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

            var context = new StringBuilderFormatContext();

            formatter.Format(context, orders[0].Value);

            Assert.That(context.ToString(), Is.EqualTo(message));
        }
コード例 #2
0
        public async Task <FormatResult <TSchema> > FormatAsync(Stream output, EntityResult <TSchema> input)
        {
            using (var writer = new StreamWriter(output))
            {
                for (int i = 0;; i++)
                {
                    TSchema entity;
                    if (!input.TryGetEntity(i, out entity))
                    {
                        break;
                    }

                    HL7Segment segment = entity as HL7Segment;
                    if (segment == null)
                    {
                        throw new MacheteSchemaException($"The entity is not an HL7 segment: {TypeCache.GetShortName(entity.GetType())}");
                    }

                    if (i > 0)
                    {
                        await writer.WriteAsync(_settings.SegmentSeparator);
                    }

                    IEntityFormatter entityFormatter;
                    if (_schema.TryGetEntityFormatter(entity, out entityFormatter))
                    {
                        var context = new StringBuilderFormatContext();
                        context.AddSettings(_settings);

                        entityFormatter.Format(context, entity);

                        await writer.WriteAsync(context.ToString()).ConfigureAwait(false);
                    }
                    else
                    {
                        throw new MacheteSchemaException($"The entity type was not found: {TypeCache.GetShortName(entity.GetType())}");
                    }
                }
            }

            return(new HL7FormatResult <TSchema>());
        }
コード例 #3
0
        public void Should_simply_format_using_entity_formatter()
        {
            const string message = @"MSH|^~\&|MACHETELAB||UBERMED||201701131234|||K113|P";

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

            MSHSegment entity;

            Assert.That(entityResult.TryGetEntity(0, out entity), Is.True);

            IEntityFormatter <MSHSegment> formatter;

            Assert.That(Schema.TryGetEntityFormatter(out formatter), Is.True);

            var context = new StringBuilderFormatContext();

            formatter.Format(context, entity);

            Assert.That(context.ToString(), Is.EqualTo(message));
        }
コード例 #4
0
        public async Task <FormatResult <TSchema> > FormatAsync(Stream output, EntityCollection <TSchema> input)
        {
            using (var writer = new StreamWriter(output))
            {
                for (var i = 0;; i++)
                {
                    if (!input.TryGetEntity(i, out TSchema entity))
                    {
                        break;
                    }

                    if (!(entity is HL7Segment))
                    {
                        throw new MacheteSchemaException($"The entity is not an HL7 segment: {TypeCache.GetShortName(entity.GetType())}");
                    }

                    if (i > 0)
                    {
                        await writer.WriteAsync(_settings.SegmentSeparator).ConfigureAwait(false);
                    }

                    if (!_schema.TryGetEntityFormatter(entity, out var entityFormatter))
                    {
                        throw new MacheteSchemaException($"An entity formatter for the entity was not found: {TypeCache.GetShortName(entity.GetType())}");
                    }

                    var context = new StringBuilderFormatContext();
                    context.AddSettings(_settings);

                    entityFormatter.Format(context, entity);

                    if (context.Position > 0)
                    {
                        await writer.WriteAsync(context.ToString()).ConfigureAwait(false);
                    }
                }
            }

            return(new HL7FormatResult <TSchema>());
        }