.NET
This page describes .NET library that provide access to fhirbase. This library uses following nuget packages:

Installation

Clone this project somewhere:
1
git clone https://github.com/fhirbase/fhirbase.net
Copied!
Then add reference to library to your project (for example):
1
dotnet add reference ../FhirbaseConnector/FhirbaseConnector.csproj
Copied!
That's all!

Usage

Create Connector to fhirbase and use it's methods to resource access like this:
1
var connector = new Connector();
2
var patient = new Patient
3
{
4
Name = new List<HumanName>
5
{
6
new HumanName
7
{
8
Given = new List<string> { "John" },
9
Family = "Doe"
10
}
11
}
12
};
13
// Create patient
14
patient = connector.Create(patient);
15
// Do something with patient
16
17
patient.Name[0].Family = "Snow";
18
patient.BirthDate = "1985-03-20";
19
// Update patient
20
patient = connector.Update(patient);
21
// Do something with patient
22
23
var sql = "SELECT _fhirbase_to_resource(row(r.*)::_resource) FROM patient AS r WHERE resource#>>'{name,0,family}' ilike '%snow%'";
24
// Search patient by family
25
foreach (var p in connector.Read<Patient>(sql))
26
{
27
// Do something with p
28
}
29
30
// Delete patient
31
patient = connector.Delete(patient);
32
// Do something with patient
Copied!

API Reference

Connector Class

Namespace: FhirbaseConnector

Constructors

1
Connector(string host = "localhost",
2
int port = 5432,
3
string user = "postgres",
4
string password = "",
5
string db = "fhirbase")
Copied!
Parameters:
    host - network address of the Postgresql server where resides fhirbase;
    port - port of the Postgresql server;
    user - Postgresql user that have access to the fhirbase;
    password - user password;
    db - database name of the fhirbase.

Methods:

1
public T Create<T>(T resource) where T : Base
Copied!
Create new resource in the fhirbase.
Parameters:
    resource - resource that will be created in the fhirbase.
Returns:
    Returns updated resource. Base is the type from the Hl7.Fhir.STU3.
1
public T Update<T>(T resource) where T : Base
Copied!
Update resource in the fhirbase.
Parameters:
    resource - resource that will be updated in the fhirbase.
Returns:
    Returns updated resource. Base is the type from the Hl7.Fhir.STU3.
1
public T Delete<T>(T resource) where T : Resource
Copied!
Delete resource from fhirbase.
Parameters:
    resource - resource that will be deleted from the fhirbase.
Returns:
    Returns deleted resource. Resource is the type from the Hl7.Fhir.STU3.
1
public List<T> Read<T>(int limit = -1) where T : Base
Copied!
Read resources from fhirbase.
Parameters:
    limit - if limit is -1 then all resources will be returned else only specified amount.
Returns:
    Returns list of the resources. Base is the type from the Hl7.Fhir.STU3
1
public List<T> Read<T>(string sql) where T : Base
Copied!
Executes arbitrary sql and returns list of resources.
Parameters:
    sql - arbitrary sql string.
Returns:
    Returns list of the resources. Base is the type from the Hl7.Fhir.STU3

Demo

Install and init fhirbase. Then execute following commands (notice that you need dotnet 2.1):
1
git clone https://github.com/fhirbase/fhirbase.net
2
cd fhirbase.net/Demo/
3
dotnet run
Copied!
Last modified 3yr ago