@inclouded/fhirapi
v4.0.0
Published
## Introduction
Downloads
152
Keywords
Readme
FhirApi SDK
Introduction
In the repository the Firebase Cloud Firestore SDK can be found that was made for the FHIRApi resource in an installable Angular folder form. The SDK can be installed for every Angular 2+ project. The SDK accomplishes the necessary CRUD operations.
Usage
For using the SDK an Angular 2+ project is needed, in which we can establish a connection to a Firestore database instance. (configured in environments.ts)
Related interfaces (FhirApi.ts, FirestoreDocument.ts):
export class FhirApi {
db: AngularFirestore;
collectionName: string;
documentClass: any;
}
export interface OrderBy {
orderBy?: string;
direction?: string;
}
export interface Paging {
limit?: number;
startAfter?: string;
startAt?: number;
orderByField?: string;
}
export class FirestoreDocument {
id: string;
data: any;
}
- The SDK can be used in a Service in the following way:
import { Injectable } from '@angular/core';
import { FhirApi } from '@inclouded/fhirapi';
import { AngularFirestore } from '@angular/fire/firestore';
@Injectable()
export class FhirApiService {
FhirApi: FhirApi;
collectionName: string;
constructor(private afs: AngularFirestore) {
this.FhirApi = new FhirApi(this.afs, this.collectionName);
}
getAllFhirApis() {
return this.FhirApi.getAll();
}
getAllbyId(id: string) {
return this.FhirApi.getById(id);
}
addFhirApi(fhirApi: any, id?: string) {
return this.FhirApi.add(fhirApi);
}
updateDevice(fhirApi: any) {
return this.FhirApi.update(fhirApi);
}
deleteFhirApi(id: string) {
return this.FhirApi.delete(id);
}
}
Usage with MongoDB
The usage is similar to the description above. The only difference is we need a mongoDB database here.
The related interfaces are the same.
They can be used in a Service in the following way:
- In the cfg it is needed to set the requested parameters to reach the MongoDB.
- Instead of the new FhirApi we can also use the already existing resources. In that case the collectionName and documentClass parameters can be left out.
import { Injectable } from '@angular/core';
import { FhirApi } from '@inclouded/fhirapi';
import { Paging, MongoDBConfig, MongoDBDAO, OrderBy } from '@inclouded/fhirapi';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class FhirApiService {
cfg: MongoDBConfig = {
httpClient: this.http,
url: 'http://localhost:8080',
username: 'username',
password: 'password'
};
dao = new MongoDBDAO(this.http, this.cfg);
collectionName: string;
documentClass: any;
FhirApi: FhirApi;
constructor(private http: HttpClient) {
this.FhirApi = new FhirApi(this.dao, this.collectionName, this.documentClass);
}
getAllFhirApis() {
return this.FhirApi.getAll();
}
getAllbyId(id: string) {
return this.FhirApi.getById(id);
}
addFhirApi(fhirApi: any, id?: string) {
return this.FhirApi.add(fhirApi, id);
}
updateDevice(fhirApi: any) {
return this.FhirApi.update(fhirApi);
}
deleteFhirApi(id: string) {
return this.FhirApi.delete(id);
}
}
Developer: Zoltán R. Jánki ([email protected]), Gábor Simon ([email protected])