build your own vonk fhir facade - home - fhir devdays › wp-content › uploads › 2019 › 02 ›...
TRANSCRIPT
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
Audience
• Developers
• Architects
• .NET
• Code involved
Speaker
• Christiaan Knaap
• Firely
• 20 yr IT dev / analist / architect
• Lead dev of Vonk FHIR Server
• Zulip
Agenda
• Prerequisites
• What is (Vonk) FHIR Facade?
• ASP.Net Core
• Vonk Architecture
• Components
• Building a facade
• Exercise
• Sneak preview
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
Example
• https://github.com/FirelyTeam/Vonk.Facade.Starter
FHIR Facade?
Implementation of a
FHIR RESTful API
as an interface
to an existing
backend system.
Vonk FHIR Facade?
Set of NuGet packages
to build a FHIR Facade
with the ASP.NET (Core)
web stack
(NuGet package = .NET library)
Programming?
• Maximum flexibility
• Fast
• Collect common patterns
• Provide those in other formats
• scripting
• mapping tooling
• code generation
• A growth model
ASP.NET Core
Pipeline of Middleware
Chain of function calls
operating on
HttpContext
Request
Response
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 }
}
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
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
Vonk Layered architecture
Pipeline of Middleware
calling Services
by using Repositories
that Map data to and from FHIR
and access the backend
VonkContext
Interface
A bit of Vonk and a touch of your own
VonkContext
Interface
You have
You get
You build
A minimal server
New ASP.Net Core Web Application
Tour of components
• For background
• IVonkContext
• IResource
• IConformanceContributor
• You implement
• ISearchRepository
• IChangeRepository
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; }
}
Arguments
Arguments from anywhere
• Path
• QueryString
• Form variables
And you can report issues on them
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
}
Express your capabilities
Tell what you can do
Contribute to the CapabilityStatement
With IConformanceContributor
Most of this is done for you
Search
Search
Service
My Search Repository My Query
Factory
Query
Context
Q Q Search
CreateQuery
Filter Q
Q
Q
Execute
Map
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
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
Relational
Vonk comes with base classes
for accessing Relational db
with EntityFrameworkCore
and LINQ
ISearchRepository.Search
ISearchRepository - SearchPatient
Provide a
queryfactory
on your entity
type
map the
results
Vonk will Bundle
& serialize
PatientQueryFactory
LINQ on
Patient
Op.Outcome
to do: check
modifiers
Mapping to resource Patient entity
from your db
Create a FHIR
Patient
And populate it
Dependency Injection
Vonk uses ASP.NET Core DI heavily
Register your:
DbContext
SearchRepository
ChangeRepository
ResourceMapper
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
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
Add Validation
Readonly server
Override SearchRepository
+ RelationalQueryFactory
Write a mapping
your model -> FHIR
Startup
AddReadServices()
AddSearchServices()
UseRead()
UseSearch()
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
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
Advantages
• Utilize Vonk Server setup:
• flexible appsettings
• logging
• dependency injection
• application insights
• Focus on your logic
• business
• data access
• Use of Administration API
Configure