Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 ›...
Transcript of Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 ›...
![Page 1: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/1.jpg)
HL7®, FHIR® and the flame Design mark are the registered trademarks of Health Level Seven International and are used with per mission.
Boston, 19-21 June | @HL7 @FirelyTeam | #fhirdevdays18 | www.fhirdevdays.com
Build your own Vonk FHIR Facade
Christiaan Knaap, Furore
![Page 2: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/2.jpg)
Audience
• Developers
• Architects
• .NET
• Code involved
![Page 3: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/3.jpg)
Speaker
• Christiaan Knaap
• Firely
• 20 yr IT dev / analist / architect
• Lead dev of Vonk FHIR Server
• Zulip
![Page 4: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/4.jpg)
Agenda
• Prerequisites
• What is (Vonk) FHIR Facade?
• ASP.Net Core
• Vonk Architecture
• Components
• Building a facade
• Exercise
• Sneak preview
![Page 5: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/5.jpg)
Prerequisites
For this session
.NET programming
ASP.NET Core
LINQ
FHIR RESTful API
For the exercise
Git client
Visual Studio 2017
.NET Core 2.0 SDK
SQL Server >= 2012
Postman / Fiddler
![Page 6: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/6.jpg)
Example
• https://github.com/FirelyTeam/Vonk.Facade.Starter
![Page 7: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/7.jpg)
FHIR Facade?
Implementation of a
FHIR RESTful API
as an interface
to an existing
backend system.
![Page 8: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/8.jpg)
Vonk FHIR Facade?
Set of NuGet packages
to build a FHIR Facade
with the ASP.NET (Core)
web stack
(NuGet package = .NET library)
![Page 9: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/9.jpg)
Programming?
• Maximum flexibility
• Fast
• Collect common patterns
• Provide those in other formats
• scripting
• mapping tooling
• code generation
• A growth model
![Page 10: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/10.jpg)
ASP.NET Core
Pipeline of Middleware
Chain of function calls
operating on
HttpContext
Request
Response
![Page 11: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/11.jpg)
ASP.NET Core
Middleware component
(Class with)
Invoke:
function on
HttpRequest
‘next’ (call to next middleware)
public class Middleware { private readonly RequestDelegate _next;
public Middleware(RequestDelegate next)
{ _next = next; }
public async Task Invoke(HttpContext httpContext)
{ // do something on the request await _next(httpContext);
// do something on the response }
}
![Page 12: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/12.jpg)
ASP.NET Core Dependency Injection
• Inversion of Control is key in ASP.NET Core
• Declare your dependencies in your constructor
• Register your services in ConfigureServices()
• Pay attention to scopes
• Transient
• Scoped (Request)
• Singleton
![Page 13: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/13.jpg)
Vonk Pipeline
ASP.NET Core Pipeline with Middleware components
implementing parts of the FHIR RESTful API
inte
rpre
t
$sn
apsh
ot
form
at
read
up
dat
e
sear
ch
$va
lidat
e
cre
ate
de
lete
his
tory
con
dit
ion
al .
..
50
1
VonkRequest
VonkResponse
![Page 14: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/14.jpg)
Vonk Layered architecture
Pipeline of Middleware
calling Services
by using Repositories
that Map data to and from FHIR
and access the backend
VonkContext
Interface
![Page 15: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/15.jpg)
A bit of Vonk and a touch of your own
VonkContext
Interface
You have
You get
You build
![Page 16: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/16.jpg)
A minimal server
New ASP.Net Core Web Application
![Page 17: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/17.jpg)
Tour of components
• For background
• IVonkContext
• IResource
• IConformanceContributor
• You implement
• ISearchRepository
• IChangeRepository
![Page 18: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/18.jpg)
IVonkContext
Vonk specific ‘HttpContext’ • VonkRequest
• interaction
• resource
• Arguments
• VonkResponse
• responsecode
• resource
• operationoutcome
public interface IVonkContext
{
IVonkRequest Request { get; }
IVonkResponse Response { get; }
IArgumentCollection Arguments { get; }
Uri ServerBase { get; }
string Description { get; }
}
![Page 19: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/19.jpg)
Arguments
Arguments from anywhere
• Path
• QueryString
• Form variables
And you can report issues on them
![Page 20: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/20.jpg)
IResource
Abstraction of Resource
Provides metadata and status
IElementNavigator
for FhirPath navigation
Currently based on POCO
Future: cross-version; invalid resources
interface IResource
{
Navigator { get; }
Type { get; }
Id { get; set; }
Version { get; set; }
LastUpdated { get; set; }
Currency { get; set; }
Change { get; set; }
Contained { get; }
ContainedResources
}
![Page 21: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/21.jpg)
Express your capabilities
Tell what you can do
Contribute to the CapabilityStatement
With IConformanceContributor
Most of this is done for you
![Page 22: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/22.jpg)
Search
Search
Service
My Search Repository My Query
Factory
Query
Context
Q Q Search
CreateQuery
Filter Q
Q
Q
Execute
Map
![Page 23: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/23.jpg)
Arguments
You get the ‘raw’ Arguments
You can control them directly if you must
But usually you relay them...
Search
Service
My Search Repository
Arguments
![Page 24: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/24.jpg)
Querying
Vonk finds out WHAT to query for
id (token)
value (quantity)
name (string)
... and calls Filter
You control HOW you query
SQL
json
http call
... and implement that in Q
My Query Factory
Q Q Q
Query
Context
My Search Repository
Arguments
Filter
Q
![Page 25: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/25.jpg)
Relational
Vonk comes with base classes
for accessing Relational db
with EntityFrameworkCore
and LINQ
![Page 26: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/26.jpg)
ISearchRepository.Search
![Page 27: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/27.jpg)
ISearchRepository - SearchPatient
Provide a
queryfactory
on your entity
type
map the
results
Vonk will Bundle
& serialize
![Page 28: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/28.jpg)
PatientQueryFactory
LINQ on
Patient
Op.Outcome
to do: check
modifiers
![Page 29: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/29.jpg)
Mapping to resource Patient entity
from your db
Create a FHIR
Patient
And populate it
![Page 30: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/30.jpg)
Dependency Injection
Vonk uses ASP.NET Core DI heavily
Register your:
DbContext
SearchRepository
ChangeRepository
ResourceMapper
![Page 31: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/31.jpg)
Reuse
ISearchRepository
can enable
all read-only access:
- read
- vread
- search
- history
- _include, _revinclude
- SMART authorization re
ad
up
dat
e
sear
ch
...
cre
ate
de
lete
his
tory
My SearchRepository
![Page 32: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/32.jpg)
Change
IChangeRepository
can enable
all read-write access:
- create
- update
- delete
- conditional c/u/d (with ISearchRepository)
read
up
dat
e
sear
ch
...
cre
ate
de
lete
his
tory
My ChangeRepository
![Page 33: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/33.jpg)
Add Validation
![Page 34: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/34.jpg)
Readonly server
Override SearchRepository
+ RelationalQueryFactory
Write a mapping
your model -> FHIR
Startup
AddReadServices()
AddSearchServices()
UseRead()
UseSearch()
![Page 35: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/35.jpg)
Exercise
• Best way to get a feeling for Vonk Facade.... build one!
• Go to http://docs.simplifier.net/vonk/facade/facadestart.html
• Arrange the prerequisites
• Build!
• Find the completed example at: https://github.com/FirelyTeam/Vonk.Facade.Starter
• Find me at the ‘Developer’ table
![Page 36: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/36.jpg)
Sneak preview to Vonk 0.7.0 and Facade
• Server setup and Pipeline of Vonk FHIR Server
• Pick & Choose & Replace
inte
rpre
t
$sn
apsh
ot
form
at
read
up
dat
e
sear
ch
$va
lidat
e
cre
ate
de
lete
his
tory
con
dit
ion
al .
..
50
1
VonkRequest
VonkResponse
my
$o
pe
rati
on
![Page 37: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/37.jpg)
Advantages
• Utilize Vonk Server setup:
• flexible appsettings
• logging
• dependency injection
• application insights
• Focus on your logic
• business
• data access
• Use of Administration API
![Page 38: Build your own Vonk FHIR Facade - Home - FHIR DevDays › wp-content › uploads › 2019 › 02 › DD18-U… · ASP.NET Core Dependency Injection Inversion of Control is key in](https://reader033.fdocuments.in/reader033/viewer/2022060422/5f18cb711e347c335a770bf5/html5/thumbnails/38.jpg)
Configure