fhir api for .net programmers by mirjam baltus

25
© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. FHIR API for .Net programmers Mirjam Baltus FHIR Developer Days November 24, 2014

Upload: fhir-developer-days-2014

Post on 12-Jul-2015

357 views

Category:

Healthcare


10 download

TRANSCRIPT

Page 1: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

FHIR APIfor .Net programmers

Mirjam Baltus

FHIR Developer Days

November 24, 2014

Page 2: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Who am I?

Name: Mirjam Baltus-Bakker

Company: Furore, Amsterdam

Background:

ICT trainer

Furore FHIR team

Contact:

[email protected]

Page 3: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

HL7.FHIR SUPPORT APIUsing the Reference Implementations

Page 4: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Hl7.Fhir

- Core contents

- Model – classes generated from the spec

- Parsers and Serializers

- REST functionality – FhirClient

- Validation

- Specification

NuGet “FHIR”, or GitHub “fhir-net-api”

Page 5: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

A FHIR Resource

Page 6: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

A FHIR Resource in C#

public partial class Observation : Hl7.Fhir.Model.Resource

{

// Codes that provides reliability information about an observation

public enum ObservationReliability {Ok, Ongoing, …}

// Codes identifying interpretations of observations

public enum ObservationInterpretation {N, A, L, H }

public partial class ObservationReferenceRangeComponent : Hl7.Fhir.Model.Element

{ … }

public CodeableConcept Name { get; set; }

public List<ObservationReferenceRangeComponent> ReferenceRange { get; set;}

public List<ResourceReference> Performer { get; set; }

}

Page 7: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Primitives are not really primitive…

Page 8: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Primitives are not really primitive…

Page 9: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Resource example

using Hl7.Fhir.Model;

var pat = new Patient();

pat.Name = new List<HumanName>();pat.Name.Add(HumanName.ForFamily("Baltus")

.WithGiven("Mirjam"));

pat.MaritalStatus = newCodeableConcept("http://acme.org/MStat", "M");

pat.BirthDate = "1974-01-20";

Page 10: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Choice elements [x]

public

Hl7.Fhir.Model.CodeableConcept

MaritalStatus { set; get; }

public Hl7.Fhir.Model.Element

Deceased { set; get; }

pat.Deceased =new FhirBoolean(true);

pat.Deceased = newFhirDateTime("2012-01-30");

Page 11: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Hl7.Fhir Core

Model – Resources and Datatypes in the API

Parsers and Serializers

REST functionality – FhirClient

Validation

Page 12: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Parsing example

using Hl7.Fhir.Serialization;

// Suppose we have a JSON string

string str = "{\"resourceType\":\"Patient\",\"name\":" +

"[{\"family\":[\"Baltus\"],\"given\":[\"Mirjam\"]}]}";

// Parse the Patient from the string

var pat = (Patient)FhirParser.ParseResourceFromJson(str);

Page 13: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Parsing example 2

// Create a file-based reader for Xml

XmlReader xr = XmlReader.Create(

new StreamReader(@"publish\observation-example.xml"));

// Parse the Observation from the stream

var obs = (Observation)FhirParser.ParseResource(xr);

Page 14: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Serializing example

// Here’s our Observation again

var obs = (Observation)FhirParser.ParseResource(xr);

// Modify some fields of the observation

obs.Status = Observation.ObservationStatus.Amended;

obs.Value = new Quantity() { Value = 40, Units = "g" };

// Serialize the in-memory observation to Json

var jsonText = FhirSerializer.SerializeResourceToJson(obs);

Page 15: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Hl7.Fhir Core

Model – Resources and Datatypes in the API

Parsers and Serializers

REST functionality – FhirClient

Validation

Page 16: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

REST functionality

REST operations done with FhirClient

using Hl7.Fhir.Rest;

var client = new FhirClient( new Uri("http://acme.org/fhir"));

Operations throw a FhirOperationException

Outcome property with OperationOutcome

Page 17: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Using the FhirClient

var patEntry = client.Read<Patient>("Patient/1");

var pat = patEntry.Resource;var restId = patEntry.Id;var tags = patEntry.Tags;

pat.Name.Add(HumanName.ForFamily("Kramer").WithGiven("Ewout"));

client.Update<Patient>(patEntry);

var myId = ResourceIdentity.Build("Patient","31");

Page 18: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Using the FhirClient

var pat = new Patient() { /* set up data */ };

var patEntry = client.Create(pat);var restId = patEntry.Id;

var newEntry = client.Refresh(patEntry);

client.Delete(patEntry);var location =

new Uri("http://acme.org/fhir/Patient/34");client.Delete(location);

Page 19: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Bundles in C#

Abstraction on top of Atom parser

Bundle = feed, BundleEntry = entry.

Bundle result = new Bundle() { Title = "Demo bundle" };

result.Entries.Add(new ResourceEntry<Patient>()

{ LastUpdated=DateTimeOffset.Now, Resource = new Patient() });

result.Entries.Add(new DeletedEntry()

{ Id = new Uri("http://..."), When = DateTime.Now });

var bundleXml = FhirSerializer.SerializeBundleToXml(result);

Page 20: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Search

var criteria = new string[] { "family=Eve" };Bundle result = client.Search<Patient>(criteria);

while (result != null){

// Do something usefulresult = client.Continue(results);

}

Page 21: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

More about search

Please attend one of the presentations in the

next quarter:

Search for Server developers

by Martijn Harthoorn

Search for Client developers

by myself

Page 22: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Validation

DotNetAttributeValidation validates:

Cardinality of an element

Regex patterns of the primitives code, date,

dateTime, id, instant, oid, uri, uuid

Allowed types for a choice element (value[x])

pat.Deceased = new FhirString("Died on 2012-01-30");

Does not validate:

Conformance to ValueSet bindings

Profile conformance

Page 23: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Validation example

using Hl7.Fhir.Validation;

var pat = new Patient() { /* set up data */ };

// Will throw a ValidationException when an error is encountered

DotNetAttributeValidation.Validate(pat);

// Alternatively, use the TryXXXX pattern

var errors = new List<ValidationResult>();

var success = DotNetAttributeValidation.TryValidate(pat, errors);

if(!success) { /* handle errors */ }

Page 24: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Hl7.Fhir Core

Model – Resources and Datatypes in the API

Parsers and Serializers

REST functionality – FhirClient

Validation

Page 25: FHIR API for .Net programmers by Mirjam Baltus

© 2012 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.

Questions?

http://hl7.org/fhir [email protected]