advanced .net api (ewout)
TRANSCRIPT
![Page 1: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/1.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Advanced.NET API
Ewout KramerFHIR Developer DaysNovember 17, 2016
![Page 2: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/2.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
2
Who am I?
Name: Ewout Kramer Company: Furore Background:
Computer Science (operating systems) In Health IT since 1999 FHIR Core team Lead dev on the .NET API
[email protected], @ewoutkramer http://thefhirplace.com
![Page 3: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/3.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
BEYOND THE POCO
3
![Page 4: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/4.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
4
Why?
No need to parse whole POCO’s in memory Generic clients/servers not needing pre-
compiled model classes Tools that can parse (partly) invalid FHIR
data Accessing DSTU2 and STU3 data
![Page 5: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/5.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
5
“Logical” structure of FHIR data
![Page 6: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/6.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
6
IElementNavigator
Represents a position in a tree of FHIR data Has all the aspects of a node (from last slide) Path: Patient.name[1].family[0]
![Page 7: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/7.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
7
INavigator<T>
GetChildrenByName(this IElementNavigator navigator, string name)
IEnumerable<object> Values(this IElementNavigator navigator)
![Page 8: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/8.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
8
Caveat
We are showing you work in progress Interfaces may change Will be implemented for DSTU2 and STU3 Currently prackaged as part of the
FluentPath .NET Core library (HL7.FluentPath)
Use the latest 0.4.x (alpha) releases Only available implementation is the PocoNavigator
![Page 9: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/9.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
GETTING TO METADATA
![Page 10: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/10.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Conformance Resources
Provide “metadata” about Model Definitions (StructureDefinition) Operations (OperationDefinition) Search parameters (SearchParameter) List of codes (ValueSet)
Identified by a “canonical url” that SHOULD resolve, e.g. “http://hl7.org/fhir/StructureDefinition/Patient”
![Page 11: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/11.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
11
Resolution
Directly using a FHIR REST call to the url More likely:
As part of a “snapshot”/zip of files delivered with your app
Compiled into your app In a database
![Page 12: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/12.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
12
IResourceResolver
Concrete implementations in API: DirectorySource, ZipSource WebSource CachedResolver (wraps another resolver) MultiResolver (tries a list of resolvers)
![Page 13: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/13.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
13
Combine at will
MyDbResolver ZipSource WebResolver
MultiResolver
CachedResolverMultiResolver
![Page 14: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/14.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
14
Practicalities
Packaged in Hl7.Fhir.Specification assembly Namespace Hl7.Fhir.Specification.Source Includes useful extension methods like:
FindStructureDefinition(this IResourceResolver resolver, string uri, bool requireSnapshot = false)
FindStructureDefinitionForCoreType(this IResourceResolver resolver, FHIRDefinedType type)
FindExtensionDefinition(this IResourceResolver resolver, string uri, bool requireSnapshot = false)
Data for base spec is in “specification.zip”, easy to get to using ZipSource.CreateValidationSource()
![Page 15: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/15.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
TERMINOLOGY
![Page 16: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/16.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
FHIR Resources
CodingSystem resource (STU3) A dictionary of concepts (possibly huge!)
ValueSet (DSTU2, STU3) A (use-case specific) selection of concepts from
1..* CodingSystems May be directly enumerated (‘extensional’) May be composed using filters (‘intensional’)
“all the LOINC codes in LOINC Part Concept Cholesterol | Bld-Ser-Plas (LP43571-6), except for 5932-9 Cholesterol [Presence] in Blood by Test strip”
May be composed from other ValueSets
![Page 17: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/17.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
17
Main functionality
Expand an intensional ValueSet Determine whether some code is member of
a ValueSet Do a code-lookup
Find details like alternative designation
Could be done “in-memory” (i.e. using an expanded ValueSet)
By calling the FHIR terminology operations
![Page 18: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/18.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
18
In-memory
Expand using the ValueSetExpander class in Hl7.Fhir.Specification.Terminology
Set limits on expansion size Uses IResourceResolver to locate
ValueSets Current limitations:
No filters No imports of whole CodeSystems
![Page 19: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/19.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
19
Working with the expansion Useful extension methods on ValueSet
HasExpansion() ExpansionSize() FindInExpansion(String code, string system) bool CodeInExpansion(String code, string system)
Note: no automatic expansion, use ValueSetExpander
![Page 20: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/20.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
20
Terminology operations
https://www.hl7.org/FHIR/valueset-operations.html
$expand, $lookup, $validate-code
class FhirClient ExpandValueSet() ConceptLookup() ValidateCode()
![Page 21: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/21.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
21
ITerminologyService
Currently available: LocalTerminologyServer Does an in-memory expand & lookup
Planned: try cache - then the LocalTerminologyServer - then the operations on a “real” terminology server.
Note: returns OperationOutcome
![Page 22: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/22.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
FHIRPATH SUPPORT
22
![Page 23: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/23.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
FhirPath in .NET
First, the name FhirPath -> FluentPath -> FhirPath
Available as a .NET Core library Hl7.FluentPath on NuGet (0.4.x)
Is built on top of IElementNavigator – so it could work on *any* object model
![Page 24: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/24.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
24
Compiling FhirPath
Advantage: Compile once, run many (fast) class FluentPathCompiler public CompiledExpression Compile(string expression)
CompiledExpression is a native Lambda that will run the statement against an IElementNavigator
You can also compile to an Expression tree (for debug/display purposes)
![Page 25: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/25.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
25
Using CompiledExpression First, compile the statement
var ce = compiler.Compile(“Patient.name”);
Then: var result = ce(…) result is a set of IElementNavigators
Or: object s = ce.Scalar(…); bool p = ce.Predicate(…); bool b = ce.IsBoolean(true, …);
![Page 26: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/26.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
26
Convenience methods
Comparable methods exist on IElementNavigator so you can directly query a source of data
Example: IElementNavigator nav = new PocoNavigator(myPatient); object cnt = nav.Scalar(“Patient.name.count()”); Compiles & caches last 500 expressions for
you
![Page 27: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/27.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
27
On POCO’s directly…
The Hl7.Fhir.Core assembly has extension methods in Hl7.Fhir.FluentPath for working directly on FHIR POCO’s
Patient p = …;object cnt = p.Scalar(“Patient.name.count()”);
![Page 28: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/28.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
VALIDATION
![Page 29: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/29.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
The Big PictureFHIR Data
<Patient></Patient>
IElementNavigator FHIR Definitions
StructureDefinitionOperationDefinitionValueSet
IResource Resolver
FindStructure Definition()
ValueSetExpander
LocalTerminology Server
ITerminologyService
Validator
FluentPathCompiler
FHIR Poco
OperationOutcome(with IssueComponents)
![Page 30: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/30.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
30
Practicalities
class Validator in Hl7.Fhir.Validation namespace (Hl7.Fhir.Specification assembly)
Configure: new Validator(settings) Resolver, terminology service to use
Validate: call one of the overloads: Validate(IElementNavigator) Validate(Base) Validate(XmlReader)
Result is an OperationOutcome
![Page 31: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/31.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
31
Caveats
Validator is still being developed as we speak
Support most features already, except for slicing – only discriminator-less slicing is supported
Other improvements: e.g. loop-detection
Almost daily updates with more functionality
![Page 32: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/32.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
32
OperationOutcome- on steroids Lots of helper methods Properties:
Success (!information,!warning) Fatals, Errors, Warnings properties
Extension methods (in Hl7.Fhir.Support) ErrorsAt(string path) Where(severity, type, …) Set/GetHierachyLevel() Include(outcome), Add(outcome)
![Page 33: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/33.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
QUESTIONS?
33
![Page 34: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/34.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
HANDS-ON TRACKSuggestions for a pleasurable afternoon
![Page 35: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/35.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
IResourceResolver
Try to use the ZipSource with the specification.zip to get some core resource definitions
Write your own IResourceResolver that resolves from a .NET compiled-in resource (not a FHIR resource ;-)
![Page 36: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/36.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
36
ITerminologyService
Use your new IResourceResolver to resolve a ValueSet & expand it.
Use ValueSet’s FindInExpansion to verify whether you succeeded
Look at the C# implementation of LocalTerminologyService. Could you make one that calls the FhirClient.ValidateCode() instead?
![Page 37: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/37.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
37
Play with the validator Check out https://
github.com/ewoutkramer/Furore.Fhir.ValidationDemo & compile
Try to incorporate your resolver and terminology service (if any)
Try running the examples at https://github.com/ewoutkramer/fhir-net-api/tree/develop/src/Hl7.Fhir.Specification.Tests/TestData/validation
Alter the examples so they trigger your code (change a binding…)
![Page 38: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/38.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
HIDDEN GEMS
![Page 39: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/39.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
ResourceIdentity
class ResoureIdentity : Uri Builds FHIR RESTful Uri’s Factory methods Build():
.Build(“Patient”, “4E75”, vid: “4”) “/Patient/4E75/_history/4”
StructureDefinition URLs for core types .Core(FHIRDefinedType.HumanName)
“http://hl7.org/fhir/StructureDefinition/HumanName”
![Page 40: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/40.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
40
ResourceIdentity (2)
Even more useful: parsing RESTful Urls var ep = “http://server.org/fhir/Patient/4”
var u = new ResourceIdentity(ep);
u.ResourceType “Patient”
u.Id “4”
![Page 41: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/41.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
41
Extension Manipulations
![Page 42: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/42.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
42
TransactionBuilder
![Page 43: Advanced .net api (ewout)](https://reader037.vdocument.in/reader037/viewer/2022102612/5871fb661a28ab5c348b785d/html5/thumbnails/43.jpg)
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
43
SnapshotGenerator