@ahryman40k/typescript-over-asymmetrik

Library that run a FHIR microserver that handle a single FHIR resource

Usage no npm install needed!

<script type="module">
  import ahryman40kTypescriptOverAsymmetrik from 'https://cdn.skypack.dev/@ahryman40k/typescript-over-asymmetrik';
</script>

README

Introduction

Library based on Asymmetrik node-fhir-server-core library
Thanks to it, I'm proud to offer to Typescript community a fully typed typescript FHIR server !

As asymmetrik still not accepted my pull request, I must use a fork.
You can find sources of that fork here

codecov

License: GPL v3

How it's work

If you are familiar with Angular framework, you will understand quickly how thing works.

You can also find a working exemple in the sample folder

1.Implement the server

A base class is present to help you to quickly define your own server. I mean:

  • Add custom middleware
  • Add additional routes to FHIR server

But in the most basic use, you have to define a server object as following

class MyServer extends AbstractServer {
    constructor(capabilities: CapabilitiesModule) {
        super(capabilities);
    }

    start(options: IServerOptions): Observable<IServerStatus> {
        return super.start(options);
    }

    stop(): void {
        return super.stop();
    }
}

2.Implement FHIR resources class

Now we can create classes to handle a fhir request on specific resource

class MyPatient implements ISearchCapability {
    search(): any {

    }
}

Fine, the most difficult is done !

3.Add decorators

Now we need to add some decorations on our resource class to tell the library how to use it. In the following exemple I will add Capability to my object to:

  • define a search capability in server's metadata
  • set kind of FHIR resource this object will handle
  • define which search parameters should be used with this object
@Capability({
    capability: ['search'],
    resource: "patient",
    criterias: ['identifier', 'name']

})
class MyPatient implements ISearchCapability {
    [...]
}

we also decorate our server to let it know about our capabilities

@Server({
    capabilities: [
        MyPatient
    ]
})
class MyServer extends AbstractServer {
    [...]
}

4.Bootstrap the server

Finally we call a bootstrapping function that will set up the asymmetrik server for us.

Static.Bootstrap(MyServer)
    .then(server => {
        server.start({ port: 3001 });
        console.log('server is running on port 3001')
    });

No more step is required, you can now focus on how resolve your search request !