Skip to content

The IFhirService interface explained

verzada edited this page Aug 17, 2017 · 11 revisions

The IFhirService interface is our way of exposing a FHIR service. We've removed lots of the methods that were originally with the FhirController in Furores Spark, the reason why we've done it is due to the fact that we don't have systems which supports everything in the FHIR standard. Eventhough the FHIR standard gives you lots of options for exposing data, the backend will always limit what is possible, therefore we've stuck with the basic CRUD methods as well as the CapabilityStatement methods.

We'll add the methods if there are any requests for it though.

FhirController

The FhirController is initiated by Ninject. The FhirController handles all incoming traffic and figures out which available services are being accessed. For a service to available for the FhirController, the service has to implement the IFhirService interface.

The IFhirService interface explained

    public interface IFhirService
    {
        // The name of the Resource you can query (earlier called GetAlias)
        string GetServiceResourceReference();

        CapabilityStatement.RestComponent GetRestDefinition();

        OperationDefinition GetOperationDefinition();

        // CRUD
        HttpResponseMessage Create(IKey key, Resource resource);
        Base Read(SearchParams searchParams);
        Base Read(string id);
        HttpResponseMessage Update(IKey key, Resource resource);
        HttpResponseMessage Delete(IKey key);

        HttpResponseMessage Patch(IKey key, Resource resource);

        ICollection<string> GetStructureDefinitionNames();
    }

GetServiceResourceReference

Is used to define the FHIR Resource exposed in the service. There can only be one FHIR resource per service (see our example of a FHIR service, but many services in the same Inferno project.

If you have a service which represents a custom query, you can add the name of the custom query service instead of a service. In order to query the service, you'll need to use the path

  /fhir?_query=<customQueryService>&param1=..&param2=... 

if you are querying directly. If you are using the FHIR client (from the STU3 api), you'll have to add the name to the Query attribute when you're adding SearchParams.

    var searchParams = new SearchParams();
    searchParams.Add("name", "Danser");
    searchParams.Query = "<nameOfCustomService>";
    var result = client.Search(searchParams);

Note the above code is from DSTU2, but you get the idea.

GetRestDefinition

To make it easier for your consumers of the FHIR service to understand how to query the service, you should create a CapabilityStatement description (Earlier know as Conformance).

GetOperationDefinition

If you have operations, typically used when you have a custom query search, you add a OperationDefinition. The OperationDefintions is linked in the metadata of the FHIR service. The links should be valid by default and not give an error upon request.

CRUD - Create Read Update Delete

Create

The method receives a key and a FHIR resource. The key can be used to identify the resource your backend, however you can have identifiers in the resource as well which can make the key dispensable. But there are cases where the identifier in the resource does not correspond with the backend.

Read

There are two Read methods, one which takes a identifier, the other reads the FHIR query. The identifier can be anything as long as it is valid in your service and backend.

Update

The update method is similar to the Create method, however instead of adding a new resource the update method will let you handle updates of a given resource.

Delete

Here you have only one parameter and that's the identifier of your FHIR resource.

Patch

Unlike Update, Patch will let you update part of a resource instead of the whole resource. F.ex if you want to update a field in a resource or your datasource.

Key

The key is handled by the ServiceHandler

StructureDefinition

GetStructureDefinitionNames

You can add your custom StructureDefinition(s) to the service, by first adding the names of the StructureDefinitions (see the ExamplePatientService for a quick howto).

Additionally you need to implement IFhirStructureDefinitionService so the FhirController can retrieve the source of the StructureDefinition. You can choose where to get the definition from, but you have to return the result as an ICollection.

The StructureDefinitions are available through the url .../fhir/StructureDefinition/