Besa FHIR Client Getting Started
A light-weight and fast FHIR client. It use Indy's HTTP component (TIdHTTP) for connecting. For FHIR object model, with support for efficiently parsing and writing in JSON and XML format.
This is the documentation of the the settings of the TbsFhirClient and the CRUD interactions you can perform with it. We will then give some examples of search interactions, and explain how to perform operations and transactions.
Contents:
Create a FHIR Client
FhirClient communication options
FhirClient Http connection types
CRUD interactions
Create a new resource
Reading an existing resource
Updating a resource
Deleting a Resource
Looking at LastResult
Searching for resources
Searching within a specific type of resource
General overview of the data flow in fhir:
Before you create a fhir client, you need to load the message library. This library contains FHIR definitions.
A library was created for each FHIR version.
Library names formatted as BSFRXX.BSL, XX is FHIR release name.
For FHIR STU 3 version library name BSFRSTU3.BSL.
//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
BSFHIRLibrary.LoadFromFile('..\data\BSFRSTU3.BSL');
end;
Create a FHIR Client
Before we can do any of the interactions, we have to create a new TbsFhirClient instance.
This is done by passing the url of the FHIR server's endpoint as a parameter to the constructor:
var
client: TbsFHIRClient;
begin
client := TbsFHIRClient.Create('http://server.url/');
end;
FhirClient communication options
To specify the preferred format JSON or XML of the content to be used when communicating with the FHIR server,
you can use the EncodingFormat attribute:
client.EncodingFormat := ffmtJSON; // JSON is default encoding format.
The FHIR client will send all requests in the specified format. The default setting for this field is JSON.
When communicating the preferred format to the server, this can either be done by appending _format=[format]
to the URL.
The client uses the _format
by default, but if you want, you can disable _format
parameter:
client.UseFormatParam := false;
FhirClient Http component options
FhirClient supports different http component type (Indy, NetClient, Custom ). You must set HttpType property.
Indy Components
client.HttpType := hcIndy;
client.HttpIndy := idHttp1;
TNetHTTPClient component (XE8+)
client.HttpType := hcNetClient;
client.HttpNetClient := NetHTTPClient1;
Custom components. If you want to use other components for http connection (ICS Overbyte, Synopse mORMOT, synapse ..). You must use hcCustom type. And you must create your handler method.
procedure TForm3.btnCreate(Sender: TObject);
begin
client.HttpType := hcCustom;
client.OnExecuteVerbStream := ExecuteVerbStream;
end;
procedure TForm3.ExecuteVerbStream(AVerb:TBSFhirHTTPVerb; AUrl:String; ARequest, AResponse:TStream; const ARequestHeaders, AResponseHeaders: TStrings; var AResponseCode:Integer; var AResponseText:String);
var
LRequestStr:string;
begin
// Request Stream
LRequestStr:= TStringStream(ARequest).DataString;
// Execute your components equivalent method.
case AVerb of
fverbGet: ;// samplecomponent.Get(AUrl)
fverbPost: ; // samplecomponent.Post(AUrl)
fverbPut: ;
fverbDelete: ;
fverbOptions: ;
fverbPatch: ;
end;
(*
//Set response stream. (Stream is TStringStream type)
TStringStream(AResponse).WriteString(response);
//Set response headers.
AResponseHeaders.
AResponseCode:= samplecomponent.StatusCode;
AResponseText:= samplecomponent.StatusText;
*)
end;
CRUD interactions
A TbsFhirClient named client has been setup in the previous topic, now let's do something with it.
Create a new resource
Assume we want to create a new resource instance and want to ask the server to store it for us. This is done using Create.
var
patient : TPatient;
id : string;
begin
patient:=TPatient.Create;
// ...
// set up data
// ...
id := client.CreateResource(patient);
end;
Sample Code:
var
client:TbsFHIRClient;
patient:TPatient;
id: string;
begin
client:=TbsFHIRClient.Create('http://server.url/');
client.HttpIndy:=IdHTTP1;
patient:=TPatient.Create;
patient.active:=True;
patient.text:=TNarrative.Create;
patient.text.status:='generated';
patient.identifier.Add;
patient.identifier[0].system:='urn:system';
patient.identifier[0].value:='12345';
patient.name_.Add; //Adds new THumanName
patient.name_[0].family:='James';
patient.name_[0].given[0]:='John';
Id:= client.CreateResource(patient);
patient.Free;
client.Free;
end;
Reading an existing resource
To read the data for a given resource instance from a server, you'll need its technical id.
You may have previously stored this after a Create, or you have found its address in a ResourceReference (e.g. Observation.Subject.Reference).
The Read interaction on the TbsFhirClient has two overloads to cover both cases. Furthermore,
it accepts both relative paths and absolute paths (as long as they are within the endpoint passed to the constructor of the TbsFhirClient).
// Read the current version of a Patient resource with technical id '1'
var
client:TbsFHIRClient;
patient:TPatient;
begin
client:=TbsFHIRClient.Create('http://server.url/');
client.HttpIndy:=IdHTTP1;
patient:=TPatient( client.ReadResource('Patient','1'));
patient.Free;
client.Free;
end;
Note that Read can be used to get the most recent version of a resource as well as a specific version,
and thus covers the two '˜logical' REST interactions ReadResource and ReadResourceV.
Updating a resource
Once you have retrieved a resource, you may edit its contents and send it back to the server. This is done using the Update interaction.
It takes the resource instance previously retrieved as a parameter:
var
client:TbsFHIRClient;
patient:TPatient;
begin
client:=TbsFHIRClient.Create('http://server.url/');
client.HttpIndy:=IdHTTP1;
// Read patient info.
patient:=TPatient( client.ReadResource('Patient','1'));
// Add a name to the patient, and update
patient.name_[0].family:='James1';
patient.name_[0].given[0]:='Given';
client.UpdateResource(patient);
patient.Free;
client.Free;
end;
There's always a chance that between retrieving the resource and sending an update, someone else has updated the resource as well.
Servers supporting version-aware updates may refuse your update in this case and return a HTTP status code 409 (Conflict),
which causes the Update interaction to throw a Exception with the same status code.
Deleting a Resource
The Delete interaction on the TbsFHIRClient deletes a resource from the server.
It is up to the server to decide whether the resource is actually removed from storage, or whether previous versions are still available for retrieval.
The Delete interaction has multiple overloads to allow you to delete based on a url or a resource instance:
var
client:TbsFHIRClient;
//patient:TPatient;
begin
client:=TbsFHIRClient.Create('http://server.url/');
client.HttpIndy:=IdHTTP1;
//patient:=TPatient( client.ReadResource('Patient','1'));
//client.DeleteResource(patient);
// or
client.DeleteResource('Patient','1');
//Patient.Free
client.Free;
end;
The Delete interaction will fail and throw a Exception if the resource was already deleted or if the resource did not exist before deletion, and the server returned an error indicating that.
Note that sending an update to a resource after it has been deleted is not considered an error and may effectively "undelete" it.
Looking at LastResult
After the TbsFhirClient has received a response from the server, you will usually work with the resource instance that was returned.
If you still need to check the response from the server, for example to lookup the technical id or version id the server has assigned to your resource instance,
you can do this by looking at the LastResponseCode property of the FhirClient.
client.CreateResource(patient);
if (client.LastResponseCode = 201) then
begin
ShowMessage('The response text for the resource is: ' + client.LastResponseText);
end;
Searching for resources
FHIR has extensive support for searching resources through the use of the REST interface.
Describing all the possibilities is outside the scope of this document, but much more details can be found online in the specification.
The FHIR client has a few operations to do basic search.
Searching within a specific type of resource
The most basic search is the client's Search( AResourceName: String; Params: String)
function.
It searches all resources of a specific type based on zero or more criteria. Criteria must conform to the parameters as they would be
specified on the search URL in the REST interface, so for example searching for all patients named 'James' would look like this
var
results:TBundle;
begin
results:= client.Search('Patient', 'family=James');
end;
The search will return a Bundle containing entries for each resource found. It is even possible to leave out all criteria, effectively resulting in a search that returns all resources of the given type.
Sample code:
var
client:TbsFHIRClient;
bundle:TBundle;
i:integer;
begin
client:=TbsFHIRClient.Create('http://server.url/');
client.HttpIndy:=IdHTTP1;
bundle :=TBundle(client.Search('Patient', 'family=James'));
ShowMessage('Total:'+IntToStr( bundle.total));
if bundle.total > 0 then
begin
mLog.Lines.Append('--- id(s)---');
for i:=0 to bundle.entry.Count-1 do
begin
mLog.Lines.Add(
TPatient(bundle.entry[i].resource).id
);
end;
end;
bundle.Free;
client.Free;
end;
Sample XML, JSON With Source Code
Example of Practitioner v. STU3 (nNGM: Example - Practitioner - External Oncologist)
<Practitioner>
<id value="10f1b821-b243-4e32-b44a-0b4cb4bd3f81" />
<meta>
<profile value="http://uk-koeln.de/fhir/StructureDefinition/Practitioner/nNGM/0.1" />
</meta>
<extension url="http://uk-koeln.de/fhir/StructureDefinition/Extension/nNGM/netzwerkpartner/0.1">
<valueBoolean value="true" />
</extension>
<identifier>
<system value="http://fhir.de/NamingSystem/nngm/netzwerkpartnernummer" />
<value value="654321" />
</identifier>
<name>
<text value="Dr. Manfred Mustermann" />
<family value="Mustermann" />
<given value="Manfred" />
<prefix value="Dr." />
</name>
<telecom>
<system value="email" />
<value value="manfred.mustermann@musterklinik.de" />
</telecom>
</Practitioner>
{
"resourceType":"Practitioner",
"id":"10f1b821-b243-4e32-b44a-0b4cb4bd3f81",
"meta":{
"profile": [
"http://uk-koeln.de/fhir/StructureDefinition/Practitioner/nNGM/0.1"
]
},
"extension": [
{
"url":"http://uk-koeln.de/fhir/StructureDefinition/Extension/nNGM/netzwerkpartner/0.1",
"valueBoolean":true
}
],
"identifier": [
{
"system":"http://fhir.de/NamingSystem/nngm/netzwerkpartnernummer",
"value":"654321"
}
],
"name": [
{
"text":"Dr. Manfred Mustermann",
"family":"Mustermann",
"given": [
"Manfred"
],
"prefix": [
"Dr."
]
}
],
"telecom": [
{
"system":"email",
"value":"manfred.mustermann@musterklinik.de"
}
]
}
var
APractitioner: TPractitioner;
AnExtension: TExtension;
AnIdentifier: TIdentifier;
AHumanName: THumanName;
AContact: TContactPoint;
begin
APractitioner:= TPractitioner.Create;
APractitioner.id:='10f1b821-b243-4e32-b44a-0b4cb4bd3f81';
APractitioner.meta:=TMeta.Create;
APractitioner.meta.profile.Add('http://uk-koeln.de/fhir/StructureDefinition/Practitioner/nNGM/0.1');
AnExtension:=APractitioner.extension.Add;
AnExtension.Url:='http://uk-koeln.de/fhir/StructureDefinition/Extension/nNGM/netzwerkpartner/0.1';
AnExtension.Value:=Tboolean.Create(True);
AnIdentifier:=APractitioner.identifier.Add;
AnIdentifier.system:='http://fhir.de/NamingSystem/nngm/netzwerkpartnernummer';
AnIdentifier.value:='654321';
AHumanName:=APractitioner.name_.Add;
AHumanName.text:='Dr. Manfred Mustermann';
AHumanName.family:='Mustermann';
AHumanName.given.Add('Manfred');
AHumanName.prefix.Add('Dr.');
AContact:=APractitioner.telecom.Add;
AContact.system:='email';
AContact.value:='manfred.mustermann@musterklinik.de';
Memo1.Lines.Text:=APractitioner.AsXML;
APractitioner.Free;
end;
An Example of a Practitioner (Konrad Graf von Waldburg-Zeil)
<Practitioner>
<meta>
<profile value="http://www.kbv.de/fhir/Profil/74_PR_VM_Behandler"/>
</meta>
<identifier>
<system value="http://fhir.de/NamingSystem/kbv/lanr" />
<value value="987654321" />
</identifier>
<active value="true" />
<name>
<use value="official" />
<text value="Dr. Manfred Mustermann" />
<family value="Graf von Waldburg-Zeil">
<extension url="http://fhir.de/StructureDefinition/humanname-namenszusatz/0.2">
<valueString value="Graf" />
</extension>
<extension url="http://hl7.org/fhir/StructureDefinition/humanname-own-name">
<valueString value="Waldburg-Zeil" />
</extension>
<extension url="http://hl7.org/fhir/StructureDefinition/humanname-own-prefix">
<valueString value="von" />
</extension>
</family>
<given value="Konrad"/>
<prefix value="Prof. Dr. med. Dr. med. h.c. mult.">
<extension url="http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier">
<valueCode value="AC" />
</extension>
</prefix>
</name>
</Practitioner>
{
"resourceType":"Practitioner",
"meta":{
"profile": [
"http://www.kbv.de/fhir/Profil/74_PR_VM_Behandler"
]
},
"identifier": [
{
"system":"http://fhir.de/NamingSystem/kbv/lanr",
"value":"987654321"
}
],
"active":true,
"name": [
{
"use":"official",
"family":"Graf von Waldburg-Zeil",
"_family":{
"extension": [
{
"url":"http://fhir.de/StructureDefinition/humanname-namenszusatz/0.2",
"valueString":"Graf"
},
{
"url":"http://hl7.org/fhir/StructureDefinition/humanname-own-name",
"valueString":"Waldburg-Zeil"
},
{
"url":"http://hl7.org/fhir/StructureDefinition/humanname-own-prefix",
"valueString":"von"
}
]
},
"given": [
"Konrad"
],
"prefix": [
"Prof. Dr. med. Dr. med. h.c. mult."
],
"_prefix": [
{
"extension": [
{
"url":"http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier",
"valueCode":"AC"
}
]
}
]
}
]
}
var
APractitioner: TPractitioner;
AnExtension: TExtension;
AnIdentifier: TIdentifier;
AHumanName: THumanName;
AnElement: TElement;
AString: Tstring;
begin
APractitioner:= TPractitioner.Create;
APractitioner.meta:=TMeta.Create;
APractitioner.meta.profile.Add('http://www.kbv.de/fhir/Profil/74_PR_VM_Behandler');
AnIdentifier:=APractitioner.identifier.Add;
AnIdentifier.system:='http://fhir.de/NamingSystem/kbv/lanr';
AnIdentifier.value:='987654321';
APractitioner.active:=True;
AHumanName:=APractitioner.name_.Add;
AHumanName.use:='official';
AHumanName.text:='Dr. Manfred Mustermann';
AHumanName.family:='Graf von Waldburg-Zeil';
AnElement:= AHumanName.familyElement;
AnExtension:= AnElement.extension.Add;
AnExtension.Url:='http://fhir.de/StructureDefinition/humanname-namenszusatz/0.2';
AnExtension.Value:=Tstring.Create('Graf');
AnExtension:= AnElement.extension.Add;
AnExtension.Url:='http://hl7.org/fhir/StructureDefinition/humanname-own-name';
AnExtension.Value:=Tstring.Create('Waldburg-Zeil');
AnExtension:= AnElement.extension.Add;
AnExtension.Url:='http://hl7.org/fhir/StructureDefinition/humanname-own-prefix';
AnExtension.Value:=Tstring.Create('von');
AHumanName.given.Add('Konrad');
AString:=Tstring.Create('Prof. Dr. med. Dr. med. h.c. mult.');
AHumanName.prefix.AddElement(AString);
AnExtension:= AString.extension.Add;
AnExtension.Url:='http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier';
AnExtension.Value:=Tcode.Create('AC');
Memo1.Lines.Text:=APractitioner.AsXML;
APractitioner.Free;
end;
Example of Bundle v. STU3
<Bundle>
<id value="d753473c-34f2-4576-a4e8-e74e555ef14e" />
<meta>
<profile value="https://fhir.kbv.de/StructureDefinition/74_PR_ETS_Bundle" />
</meta>
<type value="message" />
<entry>
<fullUrl value="urn:uuid:e3ddbded-31d3-4505-805a-03b0d941621e" />
<resource>
<MessageHeader>
<id value="e3ddbded-31d3-4505-805a-03b0d941621e" />
<meta>
<profile value="https://fhir.kbv.de/StructureDefinition/74_PR_ETS_MH_Vermittlungscodes-anfordern_Request" />
</meta>
<event>
<system value="https://fhir.kbv.de/CodeSystem/74_CS_ETS_Events" />
<code value="vermittlungscode-anfordern" />
</event>
<timestamp value="2018-11-14T08:00:00+01:00" />
<source>
<endpoint value="mailto:ueberweisende@kv-safenet.de" />
</source>
<focus>
<reference value="urn:uuid:b777414e-7a7f-4391-9f46-7d0c9fb6a42b" />
</focus>
</MessageHeader>
</resource>
</entry>
<entry>
<fullUrl value="urn:uuid:b777414e-7a7f-4391-9f46-7d0c9fb6a42b" />
<resource>
<ReferralRequest>
<id value="b777414e-7a7f-4391-9f46-7d0c9fb6a42b" />
<meta>
<profile value="https://fhir.kbv.de/StructureDefinition/74_PR_ETS_Referralrequest_anforderung_muster06" />
</meta>
<status value="draft" />
<intent value="order" />
<type>
<coding>
<system value="http://www.kbv.de/fhir/CodeSystem/74_CS_AW_Anlagetyp" />
<code value="KV-Muster_6" />
</coding>
</type>
<priority value="routine" />
<subject>
<display value="-" />
</subject>
<requester>
<agent>
<identifier>
<system value="http://fhir.de/NamingSystem/kbv/lanr" />
<value value="123456400" />
</identifier>
</agent>
<onBehalfOf>
<identifier>
<system value="http://fhir.de/NamingSystem/kbv/bsnr" />
<value value="991234500" />
</identifier>
</onBehalfOf>
</requester>
<specialty>
<extension url="https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification">
<valueCoding>
<system value="https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG" />
<code value="009" />
</valueCoding>
</extension>
<extension url="https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification">
<valueCoding>
<system value="https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG" />
<code value="015" />
</valueCoding>
</extension>
<extension url="https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification">
<valueCoding>
<system value="https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG" />
<code value="027" />
</valueCoding>
</extension>
<coding>
<system value="https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR2_WBO" />
<code value="080" />
</coding>
</specialty>
</ReferralRequest>
</resource>
</entry>
</Bundle>
{
"resourceType":"Bundle",
"id":"d753473c-34f2-4576-a4e8-e74e555ef14e",
"meta":{
"profile": [
"https://fhir.kbv.de/StructureDefinition/74_PR_ETS_Bundle"
]
},
"type":"message",
"entry": [
{
"fullUrl":"urn:uuid:e3ddbded-31d3-4505-805a-03b0d941621e",
"resource":{
"resourceType":"MessageHeader",
"id":"e3ddbded-31d3-4505-805a-03b0d941621e",
"meta":{
"profile": [
"https://fhir.kbv.de/StructureDefinition/74_PR_ETS_MH_Vermittlungscodes-anfordern_Request"
]
},
"event":{
"system":"https://fhir.kbv.de/CodeSystem/74_CS_ETS_Events",
"code":"vermittlungscode-anfordern"
},
"timestamp":"2018-11-14T08:00:00+01:00",
"source":{
"endpoint":"mailto:ueberweisende@kv-safenet.de"
},
"focus": [
{
"reference":"urn:uuid:b777414e-7a7f-4391-9f46-7d0c9fb6a42b"
}
]
}
},
{
"fullUrl":"urn:uuid:b777414e-7a7f-4391-9f46-7d0c9fb6a42b",
"resource":{
"resourceType":"ReferralRequest",
"id":"b777414e-7a7f-4391-9f46-7d0c9fb6a42b",
"meta":{
"profile": [
"https://fhir.kbv.de/StructureDefinition/74_PR_ETS_Referralrequest_anforderung_muster06"
]
},
"status":"draft",
"intent":"order",
"type":{
"coding": [
{
"system":"http://www.kbv.de/fhir/CodeSystem/74_CS_AW_Anlagetyp",
"code":"KV-Muster_6"
}
]
},
"priority":"routine",
"subject":{
"display":"-"
},
"requester":{
"agent":{
"identifier":{
"system":"http://fhir.de/NamingSystem/kbv/lanr",
"value":"123456400"
}
},
"onBehalfOf":{
"identifier":{
"system":"http://fhir.de/NamingSystem/kbv/bsnr",
"value":"991234500"
}
}
},
"specialty":{
"extension": [
{
"url":"https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification",
"valueCoding":{
"system":"https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG",
"code":"009"
}
},
{
"url":"https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification",
"valueCoding":{
"system":"https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG",
"code":"015"
}
},
{
"url":"https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification",
"valueCoding":{
"system":"https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG",
"code":"027"
}
}
],
"coding": [
{
"system":"https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR2_WBO",
"code":"080"
}
]
}
}
}
]
}
var
ABundle: TBundle;
AnEntry: TBundleEntry;
AMsgHeader: TMessageHeader;
ARefRequest: TReferralRequest;
ACoding: TCoding;
AnExtension: TExtension;
begin
ABundle:= TBundle.Create;
ABundle.id:='d753473c-34f2-4576-a4e8-e74e555ef14e';
ABundle.meta:= TMeta.Create;
ABundle.meta.profile.Add('https://fhir.kbv.de/StructureDefinition/74_PR_ETS_Bundle');
ABundle.type_:='message';
//1.Entry
AnEntry:=ABundle.entry.Add;
AnEntry.fullUrl:='urn:uuid:e3ddbded-31d3-4505-805a-03b0d941621e';
AMsgHeader:=TMessageHeader.Create;
AnEntry.resource:=AMsgHeader;
AMsgHeader.id:='e3ddbded-31d3-4505-805a-03b0d941621e';
AMsgHeader.meta:=TMeta.Create;
AMsgHeader.meta.profile.Add('https://fhir.kbv.de/StructureDefinition/74_PR_ETS_MH_Vermittlungscodes-anfordern_Request');
AMsgHeader.event:=TCoding.Create;
AMsgHeader.event.system:='https://fhir.kbv.de/CodeSystem/74_CS_ETS_Events';
AMsgHeader.event.code:='vermittlungscode-anfordern';
AMsgHeader.timestamp:='2018-11-14T08:00:00+01:00';
AMsgHeader.source:=TMessageHeaderSource.Create;
AMsgHeader.source.endpoint:='mailto:ueberweisende@kv-safenet.de';
AMsgHeader.focus.Add.reference:='urn:uuid:b777414e-7a7f-4391-9f46-7d0c9fb6a42b';
//2.Entry
AnEntry:=ABundle.entry.Add;
AnEntry.fullUrl:='urn:uuid:b777414e-7a7f-4391-9f46-7d0c9fb6a42b';
ARefRequest:=TReferralRequest.Create;
AnEntry.resource:=ARefRequest;
ARefRequest.id:='b777414e-7a7f-4391-9f46-7d0c9fb6a42b';
ARefRequest.meta:=TMeta.Create;
ARefRequest.meta.profile.Add('https://fhir.kbv.de/StructureDefinition/74_PR_ETS_Referralrequest_anforderung_muster06');
ARefRequest.status:='draft';
ARefRequest.intent:='order';
ARefRequest.type_:=TCodeableConcept.Create;
ACoding:=ARefRequest.type_.coding.Add;
ACoding.system:='http://www.kbv.de/fhir/CodeSystem/74_CS_AW_Anlagetyp';
ACoding.code:='KV-Muster_6';
ARefRequest.priority:='routine';
ARefRequest.subject:=TReference.Create;
ARefRequest.subject.display:='-';
ARefRequest.requester:=TReferralRequestRequester.Create;
ARefRequest.requester.agent:=TReference.Create;
ARefRequest.requester.agent.identifier:=TIdentifier.Create;
ARefRequest.requester.agent.identifier.system:='http://fhir.de/NamingSystem/kbv/lanr';
ARefRequest.requester.agent.identifier.value:='123456400';
ARefRequest.requester.onBehalfOf:=TReference.Create;
ARefRequest.requester.onBehalfOf.identifier:=TIdentifier.Create;
ARefRequest.requester.onBehalfOf.identifier.system:='http://fhir.de/NamingSystem/kbv/bsnr';
ARefRequest.requester.onBehalfOf.identifier.value:='991234500';
ARefRequest.specialty:=TCodeableConcept.Create;
AnExtension:=ARefRequest.specialty.extension.Add;
AnExtension.Url:='https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification';
ACoding:=TCoding.Create;
AnExtension.Value:=ACoding;
ACoding.system:='https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG';
ACoding.code:='009';
AnExtension:=ARefRequest.specialty.extension.Add;
AnExtension.Url:='https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification';
ACoding:=TCoding.Create;
AnExtension.Value:=ACoding;
ACoding.system:='https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG';
ACoding.code:='015';
AnExtension:=ARefRequest.specialty.extension.Add;
AnExtension.Url:='https://fhir.kbv.de/StructureDefinition/74_EX_ETS_AdditionalQualification';
ACoding:=TCoding.Create;
AnExtension.Value:=ACoding;
ACoding.system:='https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR_ZUSATZBEZEICHNUNG';
ACoding.code:='027';
ACoding:=ARefRequest.specialty.coding.Add;
ACoding.system:='https://fhir.kbv.de/CodeSystem/74_CS_SFHIR_BAR2_WBO';
ACoding.code:='080';
Memo1.Lines.Text:=ABundle.AsJSON;
ABundle.Free;
end;