SlideShare a Scribd company logo
© 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® is the registered trademark of HL7 and is used with the permission of HL7. The Flame Design mark is the registered trademark of HL7 and is used with the permission of HL7.
Amsterdam, 15-17 November | @fhir_furore | #fhirdevdays17 | www.fhirdevdays.com
Validation in .NET and Java
Ewout Kramer, Furore Health Informatics and James Agnew, University Health Network
© 2014 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: Ewout Kramer
 Company: Furore Health Informatics
 Background:
 Computer Science (operating systems)
 In Health IT since 1999
 FHIR Core team
 Lead dev on the .NET API
 e.kramer@furore.com, @ewoutkramer
 http://thefhirplace.com2
© 2014 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: James Agnew
 Company: UHN / Smile CDR
 Background:
 Lead dev on the Java HAPI library
 jamesagnew@gmail.com, @jamesagnew
3
© 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 inputs
 Instance data (resource)
 Definition of what data should look like (StructureDefinitions)
 Terminology services (ValueSet)
 Execution of FhirPath constraints
 Some way to combine it all, validate and return the outcomes
4
© 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 IN .NET
5
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Structure of packages
6
Hl7.Fhir.Support
(Net4, Net4.5, Net1.0, Net1.3)
• Utility methods
• ElementModel
Hl7.FhirPath
(Net4, Net4.5, Net1.0)
• FhirPath compilation
• FhirPath evaluation
Hl7.Fhir.Core
(Net4.5, Net1.1, Net1.3)
• Model classes
• Serialization
• Http client
Hl7.Fhir.Specification
(Net4.5, Net1.3)
• Access to definitions
• Terminology services
• Validation
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Instance data:
IElementNavigator
7
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Specification data
 All the definitions of the core resources, types, search
parameters, operations, etc. are available through the
Hl7.Specification.[STU3/DSTU2] package on NuGet
 The package contains a zip (specification.zip) with meta data
produced by the FHIR publication process
 profiles-resources.xml, profiles-types.xml, extension-definitions.xml
 search-parameters.xml
 v2-tables.xml, v3-codesystems.xml, valuesets.xml
 xsd schemas, schematrons, others....
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Definitions: IResourceResolver
 Concrete implementations in API:
 DirectorySource, ZipSource
 WebSource
 CachedResolver (wraps another resolver)
 MultiResolver (tries a list of resolvers)9
© 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:
ITerminologyService
 Current implementations:
 LocalTerminologyService
Does an in-memory expand & lookup
 ExternalTerminologyService
Uses the FhirClient calls to validate a code (possibly even
sending your valueset across!)
 FallbackTerminologyService
First tries LocalTerminologyService, if that fails (too
complex!), invoke an external service
 Note: returns OperationOutcome
10
© 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 Picture
FHIR Data
<Patient>
</Patient>
IElementNavigator FHIR Definitions
StructureDefinition
OperationDefinition
ValueSet
IResource
Resolver
FindStructure
Definition()
ValueSetExpander
LocalTerminology
Service
ITerminologyService
Validator
FluentPathCompiler
FHIR Poco
OperationOutcome
(with IssueComponents)
ExternalTerminology
Service
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
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
12
© 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
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Caveats
 Validator is still being improved
 Support most features already, except for slicing – only
discriminator-less slicing is supported
 Other improvements: e.g. loop-detection
14
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Playing with the validator
 Windows executable:
 https://github.com/ewoutkramer/Furore.Fhir.ValidationDemo/releases
 Directly calling the Validator in code
 Using “Validate” on Simplifier.net
15
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
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)
16
© 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?
© 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 IN HAPI FHIR
Suggestions for a pleasurable afternoon
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
When and how to Validate
There is no right answer to this question!
 Validate strictly during development but be loose in
production? Always be strict?
 Validate some resource types but not others?
 Validate on the way in but not the way out?
 Structural vs semantic validation? (there is a performance
cost!)
© 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 in HAPI FHIR
Parser Error Handler
(structural validation only)
● Parser can be configured
with an “Error Handler”
which logs or fails on error
● Only catches structural
issues
Validator
(semantic validation)
● Applies a complete set of
rules to a resource instance
● Currently far more powerful
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Parser Error Handler
 Callback mechanism during parsing
 Very fast!
 Catches structural problems:
 Invalid elements
 Invalid cardinalities
 JSON data type mismatches
21
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Parser Validator
String input = "{"resourceType":"Patient","isnice":true}";
FhirContext ctx = FhirContext.forDstu3();
IParser parser = ctx.newJsonParser();
parser.setParserErrorHandler(new LenientErrorHandler(true));
parser.parseResource(input);
22
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Parser Validator
String input = "{"resourceType":"Patient","isnice":true}";
FhirContext ctx = FhirContext.forDstu3();
IParser parser = ctx.newJsonParser();
parser.setParserErrorHandler(new LenientErrorHandler(true));
parser.parseResource(input);
23
[main] WARN
ca.uhn.fhir.parser.LenientErrorHandler -
Unknown element 'isnice' found while
parsing
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Parser Validator
String input = "{"resourceType":"Patient","isnice":true}";
FhirContext ctx = FhirContext.forDstu3();
IParser parser = ctx.newJsonParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(input);
24
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Parser Validator
String input = "{"resourceType":"Patient","isnice":true}";
FhirContext ctx = FhirContext.forDstu3();
IParser parser = ctx.newJsonParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(input);
25
ca.uhn.fhir.parser.DataFormatException:
Unknown element 'isnice' found during parse
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Profile Validation
 Applies semantic validation based on “Profiles”
 Slower than parser error handler!
 Validates various things:
 All the same structural validation as parser error handler
 Terminology bindings
 Invariants
 Constraints and extensions
26
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Validator
● HAPI’s validator uses modules and collects the results from
any that are enabled
● Create your own if you want!
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Schema/Schematron Validator
 FHIR provides schemas + schematrons for validating
conformance to basic resource requirements:
 Cardinality
 Optionality
 Required bindings
 Datatype rules
 The Schema + Schematron modules are the defaults if
nothing else is selected
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Schema/Schematron Validator (2)
Dependencies:
● hapi-fhir-validation-resources-dstu3-2.5.jar
● phloc-schematron-2.7.0.jar
Inputs (pick one):
● Resource Java model object
● Raw JSON Resource
● Raw XML Resource
© 2014 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 Schema Validator
public class Example20_ValidateResource {
public static void main(String[] args) {
// Create an incomplete encounter (status is required)
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345");
// Create a new validator
FhirContext ctx = FhirContext.forDstu3();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(enc);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
}
© 2014 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 Schema Validator
public class Example20_ValidateResource {
public static void main(String[] args) {
// Create an incomplete encounter (status is required)
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345");
// Create a new validator
FhirContext ctx = FhirContext.forDstu3();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(enc);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
}
<OperationOutcome xmlns="http://hl7.org/fhir">
<issue>
<severity value="error"/>
<code value="processing"/>
<diagnostics value="cvc-complex-type.2.4.b: The content of
element 'Encounter' is not complete. One of
'{&quot;http://hl7.org/fhir&quot;:identifier,
&quot;http://hl7.org/fhir&quot;:status}' is expected."/>
<location value="Line[1] Col[140]"/>
</issue>
</OperationOutcome>
false
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Schema Validation with String Input
Strings are also valid input (JSON is converted to XML!)public class Example21_ValidateResourceString {
public static void main(String[] args) {
String input = "<Encounter xmlns="http://hl7.org/fhir"></Encounter>";
// Create a new validator
FhirContext ctx = FhirContext.forDstu3();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(input);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Profile Validation
 In FHIR, a “Profile” is a collection of special resources:
 StructureDefinition
 ValueSet
 CodeSystem
 A resource can declare conformance to a profile in its
metadata
 A server can require conformance to a profile
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Profile Validator
● FhirInstanceValidator module requires an instance of
IValidationSupport
● Several implementations are supplied with HAPI FHIR
● You can also create your own
© 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 Support
Use built-in FHIR definitions and terminology
Load your own definitions and terminology
Chain multiple providers together
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
Questionnaires are Validated
● FhirInstanceValidator will also validate
QuestionnaireResponse compliance to
Questionnaire
© 2014 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 Profile Validator
public class Example22_ValidateResourceInstanceValidator {
public static void main(String[] args) {
// Create an incomplete encounter (status is required)
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345");
// Create a new validator
FhirValidator validator = FhirContext.forDstu3().newValidator();
// Cache this object! Supplies structure definitions
DefaultProfileValidationSupport support = new DefaultProfileValidationSupport();
// Create the validator
FhirInstanceValidator module = new FhirInstanceValidator(support);
validator.registerValidatorModule(module);
// Did we succeed?
IParser parser = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(validator.validateWithResult(enc).toOperationOutcome()));
}
}
© 2014 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 Profile Validator
public class Example22_ValidateResourceInstanceValidator {
public static void main(String[] args) {
// Create an incomplete encounter (status is required)
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345");
// Create a new validator
FhirValidator validator = FhirContext.forDstu3().newValidator();
// Cache this object! Supplies structure definitions
DefaultProfileValidationSupport support = new DefaultProfileValidationSupport();
// Create the validator
FhirInstanceValidator module = new FhirInstanceValidator(support);
validator.registerValidatorModule(module);
// Did we succeed?
IParser parser = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(validator.validateWithResult(enc).toOperationOutcome()));
}
}
<OperationOutcome xmlns="http://hl7.org/fhir">
<issue>
<severity value="error"/>
<code value="processing"/>
<diagnostics value="Profile
http://hl7.org/fhir/StructureDefinition/Encounter, Element
'Encounter.status': minimum required = 1, but only found 0"/>
<location value="Encounter"/>
</issue>
</OperationOutcome>
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
39
© 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 TRACK
Suggestions for a pleasurable afternoon
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office.
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…)
41

More Related Content

PDF
Building on cerner with smart on fhir fhir dev days 2017
PPTX
IHE on FHIR and DICOMweb 2017
PDF
Integrating with the epic platform fhir dev days 17
PPTX
Building bridges devdays 2017- powerpoint template
PPTX
Security overview (grahame)
PPTX
Advanced .net api (ewout)
PPTX
final Keynote (grahame)
PPTX
fhir-documents
Building on cerner with smart on fhir fhir dev days 2017
IHE on FHIR and DICOMweb 2017
Integrating with the epic platform fhir dev days 17
Building bridges devdays 2017- powerpoint template
Security overview (grahame)
Advanced .net api (ewout)
final Keynote (grahame)
fhir-documents

What's hot (20)

PPTX
Devdays 2017 implementation guide authoring - ardon toonstra
PPTX
Structure definition 101 (ewout)
PPTX
Furore devdays2017 general-introtofhir
PPTX
Discover the new face of HL7 FHIR v4 - Ideas2IT
PPTX
20171127 rene spronk_messaging_the_unloved_paradigm
PPTX
20171116 rene spronk_profiling_governance
PPTX
Furore devdays 2017- continua implementing fhir
PPTX
HL7 New Zealand: FHIR for developers
PPTX
SMART on FHIR by Scot Post van der Burg
PPTX
Accessing SNOMED CT With FHIR Terminology Services
PPTX
FHIR API for Java programmers by James Agnew
PPTX
Whats new (grahame)
PPTX
Furore devdays2017 tdd-1-intro
PPTX
FHIR Search for client developers by Mirjam Baltus
PPTX
Furore devdays2017 tdd-2-advanced
PPTX
Furore devdays 2017 - workflow
PPTX
FHIR Profiles
PPTX
2017 11-ccda-on-fhir
PPTX
FHIR tutorial - Afternoon
PPTX
Authoring FHIR Profiles - extended version
Devdays 2017 implementation guide authoring - ardon toonstra
Structure definition 101 (ewout)
Furore devdays2017 general-introtofhir
Discover the new face of HL7 FHIR v4 - Ideas2IT
20171127 rene spronk_messaging_the_unloved_paradigm
20171116 rene spronk_profiling_governance
Furore devdays 2017- continua implementing fhir
HL7 New Zealand: FHIR for developers
SMART on FHIR by Scot Post van der Burg
Accessing SNOMED CT With FHIR Terminology Services
FHIR API for Java programmers by James Agnew
Whats new (grahame)
Furore devdays2017 tdd-1-intro
FHIR Search for client developers by Mirjam Baltus
Furore devdays2017 tdd-2-advanced
Furore devdays 2017 - workflow
FHIR Profiles
2017 11-ccda-on-fhir
FHIR tutorial - Afternoon
Authoring FHIR Profiles - extended version
Ad

Similar to Validation in net and java (ewout james) (20)

PPTX
FHIR API for .Net programmers by Mirjam Baltus
PPTX
Advanced .NET API (Ewout)
PPTX
Fhir path (ewout)
PPTX
Introduction to FHIR™
PPTX
FHIR Tutorial - Morning
PPTX
FHIR architecture overview for non-programmers by René Spronk
PPTX
FHIR architecture overview for non-programmers by René Spronk
PPTX
Getting started with FHIR by Ewout Kramer
PPTX
FHIR DevDays 2015 - introduction to FHIR
PPTX
Rolling out FHIR - architecture and implementation considerations by Lloyd Mc...
PPTX
Terminology, value-sets, codesystems by Lloyd McKenzie
PPTX
SMART on FHIR by Scot Post van der Burg
PPTX
IHE France on FHIR
PPTX
The FHIR burns brighter (what's new in DSTU2)
PPTX
Nhs trusts meeting at salford
PPTX
Patient matching in FHIR
PPTX
HL7 Fhir for Developers
PPTX
FHIR intro and background at HL7 Germany 2014
PPTX
FHIR: What's it All About?
PPTX
Vitalis 2016 FHIR Introduction
FHIR API for .Net programmers by Mirjam Baltus
Advanced .NET API (Ewout)
Fhir path (ewout)
Introduction to FHIR™
FHIR Tutorial - Morning
FHIR architecture overview for non-programmers by René Spronk
FHIR architecture overview for non-programmers by René Spronk
Getting started with FHIR by Ewout Kramer
FHIR DevDays 2015 - introduction to FHIR
Rolling out FHIR - architecture and implementation considerations by Lloyd Mc...
Terminology, value-sets, codesystems by Lloyd McKenzie
SMART on FHIR by Scot Post van der Burg
IHE France on FHIR
The FHIR burns brighter (what's new in DSTU2)
Nhs trusts meeting at salford
Patient matching in FHIR
HL7 Fhir for Developers
FHIR intro and background at HL7 Germany 2014
FHIR: What's it All About?
Vitalis 2016 FHIR Introduction
Ad

More from DevDays (20)

PPTX
Consent dev days
PPTX
Mohannad hussain dicom and imaging tools
PPTX
Mohannad hussain community track - siim dataset & dico mweb proxy
PPTX
Fhir dev days 2017 fhir profiling - overview and introduction v07
PPTX
Transforming other content (grahame)
PPTX
Quality improvement dev days-2017
PPTX
Furore devdays 2017-sdc (lloyd)
PPTX
Furore devdays 2017- rdf2(solbrig)
PPTX
Furore devdays 2017- rdf1(solbrig)
PPTX
Furore devdays 2017- oai
PPTX
Furore devdays 2017 - implementation guides (lloyd)
PPTX
Dev days 2017 questionnaires (brian postlethwaite)
PPTX
Dev days 2017 advanced directories (brian postlethwaite)
PPTX
Connectathon opening 2017
PPTX
Vonk fhir facade (christiaan)
PPTX
Profiling with clin fhir
PPTX
Opening student track
PPTX
Fhir tooling (grahame)
PPTX
Fhir dev days_basic_fhir_terminology_services
PPTX
Fhir dev days_advanced_fhir_terminology_services
Consent dev days
Mohannad hussain dicom and imaging tools
Mohannad hussain community track - siim dataset & dico mweb proxy
Fhir dev days 2017 fhir profiling - overview and introduction v07
Transforming other content (grahame)
Quality improvement dev days-2017
Furore devdays 2017-sdc (lloyd)
Furore devdays 2017- rdf2(solbrig)
Furore devdays 2017- rdf1(solbrig)
Furore devdays 2017- oai
Furore devdays 2017 - implementation guides (lloyd)
Dev days 2017 questionnaires (brian postlethwaite)
Dev days 2017 advanced directories (brian postlethwaite)
Connectathon opening 2017
Vonk fhir facade (christiaan)
Profiling with clin fhir
Opening student track
Fhir tooling (grahame)
Fhir dev days_basic_fhir_terminology_services
Fhir dev days_advanced_fhir_terminology_services

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PDF
Pre independence Education in Inndia.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Sports Quiz easy sports quiz sports quiz
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Cell Structure & Organelles in detailed.
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Lesson notes of climatology university.
PPTX
Pharma ospi slides which help in ospi learning
RMMM.pdf make it easy to upload and study
Pre independence Education in Inndia.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
2.FourierTransform-ShortQuestionswithAnswers.pdf
TR - Agricultural Crops Production NC III.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
GDM (1) (1).pptx small presentation for students
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
VCE English Exam - Section C Student Revision Booklet
Microbial diseases, their pathogenesis and prophylaxis
Sports Quiz easy sports quiz sports quiz
01-Introduction-to-Information-Management.pdf
Cell Types and Its function , kingdom of life
Cell Structure & Organelles in detailed.
STATICS OF THE RIGID BODIES Hibbelers.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Lesson notes of climatology university.
Pharma ospi slides which help in ospi learning

Validation in net and java (ewout james)

  • 1. © 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® is the registered trademark of HL7 and is used with the permission of HL7. The Flame Design mark is the registered trademark of HL7 and is used with the permission of HL7. Amsterdam, 15-17 November | @fhir_furore | #fhirdevdays17 | www.fhirdevdays.com Validation in .NET and Java Ewout Kramer, Furore Health Informatics and James Agnew, University Health Network
  • 2. © 2014 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: Ewout Kramer  Company: Furore Health Informatics  Background:  Computer Science (operating systems)  In Health IT since 1999  FHIR Core team  Lead dev on the .NET API  e.kramer@furore.com, @ewoutkramer  http://thefhirplace.com2
  • 3. © 2014 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: James Agnew  Company: UHN / Smile CDR  Background:  Lead dev on the Java HAPI library  jamesagnew@gmail.com, @jamesagnew 3
  • 4. © 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 inputs  Instance data (resource)  Definition of what data should look like (StructureDefinitions)  Terminology services (ValueSet)  Execution of FhirPath constraints  Some way to combine it all, validate and return the outcomes 4
  • 5. © 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 IN .NET 5
  • 6. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Structure of packages 6 Hl7.Fhir.Support (Net4, Net4.5, Net1.0, Net1.3) • Utility methods • ElementModel Hl7.FhirPath (Net4, Net4.5, Net1.0) • FhirPath compilation • FhirPath evaluation Hl7.Fhir.Core (Net4.5, Net1.1, Net1.3) • Model classes • Serialization • Http client Hl7.Fhir.Specification (Net4.5, Net1.3) • Access to definitions • Terminology services • Validation
  • 7. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Instance data: IElementNavigator 7
  • 8. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Specification data  All the definitions of the core resources, types, search parameters, operations, etc. are available through the Hl7.Specification.[STU3/DSTU2] package on NuGet  The package contains a zip (specification.zip) with meta data produced by the FHIR publication process  profiles-resources.xml, profiles-types.xml, extension-definitions.xml  search-parameters.xml  v2-tables.xml, v3-codesystems.xml, valuesets.xml  xsd schemas, schematrons, others....
  • 9. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Definitions: IResourceResolver  Concrete implementations in API:  DirectorySource, ZipSource  WebSource  CachedResolver (wraps another resolver)  MultiResolver (tries a list of resolvers)9
  • 10. © 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: ITerminologyService  Current implementations:  LocalTerminologyService Does an in-memory expand & lookup  ExternalTerminologyService Uses the FhirClient calls to validate a code (possibly even sending your valueset across!)  FallbackTerminologyService First tries LocalTerminologyService, if that fails (too complex!), invoke an external service  Note: returns OperationOutcome 10
  • 11. © 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 Picture FHIR Data <Patient> </Patient> IElementNavigator FHIR Definitions StructureDefinition OperationDefinition ValueSet IResource Resolver FindStructure Definition() ValueSetExpander LocalTerminology Service ITerminologyService Validator FluentPathCompiler FHIR Poco OperationOutcome (with IssueComponents) ExternalTerminology Service
  • 12. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. 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 12
  • 13. © 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
  • 14. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Caveats  Validator is still being improved  Support most features already, except for slicing – only discriminator-less slicing is supported  Other improvements: e.g. loop-detection 14
  • 15. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Playing with the validator  Windows executable:  https://github.com/ewoutkramer/Furore.Fhir.ValidationDemo/releases  Directly calling the Validator in code  Using “Validate” on Simplifier.net 15
  • 16. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. 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) 16
  • 17. © 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?
  • 18. © 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 IN HAPI FHIR Suggestions for a pleasurable afternoon
  • 19. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. When and how to Validate There is no right answer to this question!  Validate strictly during development but be loose in production? Always be strict?  Validate some resource types but not others?  Validate on the way in but not the way out?  Structural vs semantic validation? (there is a performance cost!)
  • 20. © 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 in HAPI FHIR Parser Error Handler (structural validation only) ● Parser can be configured with an “Error Handler” which logs or fails on error ● Only catches structural issues Validator (semantic validation) ● Applies a complete set of rules to a resource instance ● Currently far more powerful
  • 21. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Parser Error Handler  Callback mechanism during parsing  Very fast!  Catches structural problems:  Invalid elements  Invalid cardinalities  JSON data type mismatches 21
  • 22. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Parser Validator String input = "{"resourceType":"Patient","isnice":true}"; FhirContext ctx = FhirContext.forDstu3(); IParser parser = ctx.newJsonParser(); parser.setParserErrorHandler(new LenientErrorHandler(true)); parser.parseResource(input); 22
  • 23. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Parser Validator String input = "{"resourceType":"Patient","isnice":true}"; FhirContext ctx = FhirContext.forDstu3(); IParser parser = ctx.newJsonParser(); parser.setParserErrorHandler(new LenientErrorHandler(true)); parser.parseResource(input); 23 [main] WARN ca.uhn.fhir.parser.LenientErrorHandler - Unknown element 'isnice' found while parsing
  • 24. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Parser Validator String input = "{"resourceType":"Patient","isnice":true}"; FhirContext ctx = FhirContext.forDstu3(); IParser parser = ctx.newJsonParser(); parser.setParserErrorHandler(new StrictErrorHandler()); parser.parseResource(input); 24
  • 25. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Parser Validator String input = "{"resourceType":"Patient","isnice":true}"; FhirContext ctx = FhirContext.forDstu3(); IParser parser = ctx.newJsonParser(); parser.setParserErrorHandler(new StrictErrorHandler()); parser.parseResource(input); 25 ca.uhn.fhir.parser.DataFormatException: Unknown element 'isnice' found during parse
  • 26. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Profile Validation  Applies semantic validation based on “Profiles”  Slower than parser error handler!  Validates various things:  All the same structural validation as parser error handler  Terminology bindings  Invariants  Constraints and extensions 26
  • 27. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Validator ● HAPI’s validator uses modules and collects the results from any that are enabled ● Create your own if you want!
  • 28. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Schema/Schematron Validator  FHIR provides schemas + schematrons for validating conformance to basic resource requirements:  Cardinality  Optionality  Required bindings  Datatype rules  The Schema + Schematron modules are the defaults if nothing else is selected
  • 29. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Schema/Schematron Validator (2) Dependencies: ● hapi-fhir-validation-resources-dstu3-2.5.jar ● phloc-schematron-2.7.0.jar Inputs (pick one): ● Resource Java model object ● Raw JSON Resource ● Raw XML Resource
  • 30. © 2014 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 Schema Validator public class Example20_ValidateResource { public static void main(String[] args) { // Create an incomplete encounter (status is required) Encounter enc = new Encounter(); enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345"); // Create a new validator FhirContext ctx = FhirContext.forDstu3(); FhirValidator validator = ctx.newValidator(); // Did we succeed? ValidationResult result = validator.validateWithResult(enc); System.out.println("Success: " + result.isSuccessful()); // What was the result OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome(); IParser parser = ctx.newXmlParser().setPrettyPrint(true); System.out.println(parser.encodeResourceToString(outcome)); } }
  • 31. © 2014 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 Schema Validator public class Example20_ValidateResource { public static void main(String[] args) { // Create an incomplete encounter (status is required) Encounter enc = new Encounter(); enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345"); // Create a new validator FhirContext ctx = FhirContext.forDstu3(); FhirValidator validator = ctx.newValidator(); // Did we succeed? ValidationResult result = validator.validateWithResult(enc); System.out.println("Success: " + result.isSuccessful()); // What was the result OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome(); IParser parser = ctx.newXmlParser().setPrettyPrint(true); System.out.println(parser.encodeResourceToString(outcome)); } } <OperationOutcome xmlns="http://hl7.org/fhir"> <issue> <severity value="error"/> <code value="processing"/> <diagnostics value="cvc-complex-type.2.4.b: The content of element 'Encounter' is not complete. One of '{&quot;http://hl7.org/fhir&quot;:identifier, &quot;http://hl7.org/fhir&quot;:status}' is expected."/> <location value="Line[1] Col[140]"/> </issue> </OperationOutcome> false
  • 32. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Schema Validation with String Input Strings are also valid input (JSON is converted to XML!)public class Example21_ValidateResourceString { public static void main(String[] args) { String input = "<Encounter xmlns="http://hl7.org/fhir"></Encounter>"; // Create a new validator FhirContext ctx = FhirContext.forDstu3(); FhirValidator validator = ctx.newValidator(); // Did we succeed? ValidationResult result = validator.validateWithResult(input); System.out.println("Success: " + result.isSuccessful()); // What was the result OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome(); IParser parser = ctx.newXmlParser().setPrettyPrint(true); System.out.println(parser.encodeResourceToString(outcome)); }
  • 33. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Profile Validation  In FHIR, a “Profile” is a collection of special resources:  StructureDefinition  ValueSet  CodeSystem  A resource can declare conformance to a profile in its metadata  A server can require conformance to a profile
  • 34. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Profile Validator ● FhirInstanceValidator module requires an instance of IValidationSupport ● Several implementations are supplied with HAPI FHIR ● You can also create your own
  • 35. © 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 Support Use built-in FHIR definitions and terminology Load your own definitions and terminology Chain multiple providers together
  • 36. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. Questionnaires are Validated ● FhirInstanceValidator will also validate QuestionnaireResponse compliance to Questionnaire
  • 37. © 2014 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 Profile Validator public class Example22_ValidateResourceInstanceValidator { public static void main(String[] args) { // Create an incomplete encounter (status is required) Encounter enc = new Encounter(); enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345"); // Create a new validator FhirValidator validator = FhirContext.forDstu3().newValidator(); // Cache this object! Supplies structure definitions DefaultProfileValidationSupport support = new DefaultProfileValidationSupport(); // Create the validator FhirInstanceValidator module = new FhirInstanceValidator(support); validator.registerValidatorModule(module); // Did we succeed? IParser parser = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true); System.out.println(parser.encodeResourceToString(validator.validateWithResult(enc).toOperationOutcome())); } }
  • 38. © 2014 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 Profile Validator public class Example22_ValidateResourceInstanceValidator { public static void main(String[] args) { // Create an incomplete encounter (status is required) Encounter enc = new Encounter(); enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345"); // Create a new validator FhirValidator validator = FhirContext.forDstu3().newValidator(); // Cache this object! Supplies structure definitions DefaultProfileValidationSupport support = new DefaultProfileValidationSupport(); // Create the validator FhirInstanceValidator module = new FhirInstanceValidator(support); validator.registerValidatorModule(module); // Did we succeed? IParser parser = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true); System.out.println(parser.encodeResourceToString(validator.validateWithResult(enc).toOperationOutcome())); } } <OperationOutcome xmlns="http://hl7.org/fhir"> <issue> <severity value="error"/> <code value="processing"/> <diagnostics value="Profile http://hl7.org/fhir/StructureDefinition/Encounter, Element 'Encounter.status': minimum required = 1, but only found 0"/> <location value="Encounter"/> </issue> </OperationOutcome>
  • 39. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. 39
  • 40. © 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 TRACK Suggestions for a pleasurable afternoon
  • 41. © 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg. U.S. TM Office. 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…) 41