DirectProject.DotNet.Context 1.1.1-preview010

This is a prerelease version of DirectProject.DotNet.Context.
dotnet add package DirectProject.DotNet.Context --version 1.1.1-preview010
NuGet\Install-Package DirectProject.DotNet.Context -Version 1.1.1-preview010
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DirectProject.DotNet.Context" Version="1.1.1-preview010" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DirectProject.DotNet.Context --version 1.1.1-preview010
#r "nuget: DirectProject.DotNet.Context, 1.1.1-preview010"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DirectProject.DotNet.Context as a Cake Addin
#addin nuget:?package=DirectProject.DotNet.Context&version=1.1.1-preview010&prerelease

// Install DirectProject.DotNet.Context as a Cake Tool
#tool nuget:?package=DirectProject.DotNet.Context&version=1.1.1-preview010&prerelease

Health.Direct.Context

License: MIT Twitter

badge

What is Direct.Health.Context

This is a Microsoft .NET Core reference implementation library for Expressing Context in Direct Messaging. The implementation guide is maintained at www.directproject.org.

Design of Context

The Context library uses the excellent MimeKit library as the base for creating and parsing mime messages. The current implementation is targeted for Direct Context version 1.1 compliance and recent ADT Notification requirements. If you find any issues, please create and issue and/or email me directly. I created this project in 2017 when I was very intimate with the details. Recently I revisited this project to bring it from 1.0 to 1.1 with respect to the Direct Context Guide, in addition making it compatible with ADT Notifications.

Originally Direct Context was intended to evolve as various versions bound to a specification version. For example, an application hosting multiple versions of the parser would decide which parser to load based on the version header value in the Context part. To this point I don't believe any context other than 1.1 has ever been put into production. ADT Notifications violate the code version binding to a Direct Context specification. I imagine the spec will catch up at some point. My hope is the concept of DirectContext could make way for completely different contexts, that allow for other interesting workflows. Senders and receivers would need to understand the two contexts, but they could be anything such as carrying patient consent requests and answers. In such a workflow we would just create a new DirectContext but the version would be something completely different such as pc-1.0 which would load the appropriate context object and leading to specific workflow actions.

Direct Context is an excellent answer to the alternative solutions of using ad-hoc mime headers to transport context. Just say no to ad-hoc headers.

License Information

Copyright (c) 2010-2017, Direct Project All rights reserved.

Authors: Joseph Shook Joseph.Shook@Surescripts.com

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of The Direct Project (directproject.org) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Installing via NuGet

The easiest way to install DirectProject.DotNet.Context is via NuGet.

In Visual Studio's Package Manager Console, simply enter the following command:

Install-Package DirectProject.DotNet.Context

Building Context

Creating a MimeMessage with Context

```csharp

// // Context // var contextBuilder = new ContextBuilder();

contextBuilder .WithContentId(MimeUtils.GenerateMessageId()) .WithDisposition("metadata.txt") .WithTransferEncoding(ContentEncoding.Base64) .WithVersion("1.0") .WithId(MimeUtils.GenerateMessageId()) .WithPatientId( new PatientInstance { PidContext = "2.16.840.1.113883.19.999999", LocalPatientId = "123456" }.ToList() ) .WithType(ContextStandard.Type.CategoryRadiology, ContextStandard.Type.ActionReport) .WithPurpose(ContextStandard.Purpose.PurposeResearch) .WithPatient( new Patient { GivenName = "John", SurName = "Doe", MiddleName = "Jacob", DateOfBirth = "1961-12-31", Gender = "M", PostalCode = "12345" } );

var context = contextBuilder.Build();

// // Mime message and simple body // var message = new MimeMessage(); message.From.Add(new MailboxAddress("HoboJoe", "hobojoe@hsm.DirectInt.lab")); message.To.Add(new MailboxAddress("Toby", "toby@redmond.hsgincubator.com")); message.Subject = "Sample message with pdf and context attached"; message.Headers.Add(MailStandard.Headers.DirectContext, context.ContentId);

var body = new TextPart("plain") { Text = @"Simple Body" };

// // Represent PDF attachment // var pdf = new MimePart("application/pdf") { ContentDisposition = new ContentDisposition(ContentDisposition.Attachment), FileName = "report.pdf", ContentTransferEncoding = ContentEncoding.Base64 };

var byteArray = Encoding.UTF8.GetBytes("Fake PDF (invalid)"); var stream = new MemoryStream(byteArray); pdf.Content = new MimeContent(stream);

// // Multi part construction // var multiPart = new Multipart("mixed") { body, contextBuilder.BuildMimePart(), pdf };

message.Body = multiPart;
```

Parsing Context

Parsing context is very simple from a file or from a stream. Using the message from the previous example the following code shows most examples of accessing context and the metadata.

```csharp

// // Assert context can be serialized and parsed. // var messageParsed = MimeMessage.Load(message.ToString().ToStream()); Assert.True(messageParsed.ContainsDirectContext()); Assert.Equal(context.ContentId, messageParsed.DirectContextId()); var contextParsed = message.DirectContext(); Assert.NotNull(contextParsed);

// // Headers // Assert.Equal("text", contextParsed.ContentType.MediaType); Assert.Equal("plain", contextParsed.ContentType.MediaSubtype); Assert.Equal("attachment", contextParsed.ContentDisposition.Disposition); Assert.Equal("metadata.txt", contextParsed.ContentDisposition.FileName); Assert.Equal(context.ContentId, contextParsed.ContentId);

// // Metadata // Assert.Equal("1.0", contextParsed.Metadata.Version); Assert.Equal(context.Metadata.Id, contextParsed.Metadata.Id);

// // Metatdata PatientId // Assert.Equal("2.16.840.1.113883.19.999999:123456", contextParsed.Metadata.PatientId); Assert.Equal(1, contextParsed.Metadata.PatientIdentifier.Count()); var patientIdentifiers = Enumerable.ToList(contextParsed.Metadata.PatientIdentifier); Assert.Equal("2.16.840.1.113883.19.999999", patientIdentifiers[0].PidContext); Assert.Equal("123456", patientIdentifiers[0].LocalPatientId);

// // Metatdata Type // Assert.Equal("radiology/report", contextParsed.Metadata.Type.ToString()); Assert.Equal("radiology", contextParsed.Metadata.Type.Category); Assert.Equal("report", contextParsed.Metadata.Type.Action);

// // Metatdata Purpose // Assert.Equal("research", contextParsed.Metadata.Purpose);

// // Metadata Patient // Assert.Equal("givenName=John; surname=Doe; middleName=Jacob; dateOfBirth=1961-12-31; gender=M; postalCode=12345", contextParsed.Metadata.Patient.ToString());

Assert.Equal("John", contextParsed.Metadata.Patient.GivenName); Assert.Equal("Doe", contextParsed.Metadata.Patient.SurName); Assert.Equal("1961-12-31", contextParsed.Metadata.Patient.DateOfBirth); ```

The above code can also be ran from the context.tests project.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1-preview010 159 2/20/2022
1.1.1-preview008 152 8/6/2021
1.1.1-preview007 261 7/2/2021
1.1.1-preview006 276 7/2/2021
1.1.1-preview005 196 6/25/2021
1.1.1-preview004 188 6/25/2021
1.1.1-preview003 178 4/28/2021
1.1.1-preview002 170 4/28/2021
1.1.1-preview001 183 4/22/2021
1.1.0-preview010 177 4/22/2021
1.1.0-preview009 163 4/14/2021
1.1.0-preview008 168 4/14/2021
1.1.0-preview007 169 4/14/2021
1.1.0-preview006 187 4/14/2021
1.0.0.4-beta 692 10/19/2017
1.0.0.3-beta 676 10/19/2017
1.0.0.2-beta 647 10/9/2017

V1.1 Parser+ Compatible with CMS ADT Notifications