build your own vonk fhir facade - home - fhir devdays › wp-content › uploads › 2019 › 02 ›...

39
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

Upload: others

Post on 03-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

Speaker

• Christiaan Knaap

• Firely

• 20 yr IT dev / analist / architect

• Lead dev of Vonk FHIR Server

[email protected]

• 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Configure

Page 39: 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

Credits

Icons made by several authors from www.flaticon.com