I want to use a native javascript
library in my Angular2
project. I built it and created a bundled js
file. Now, I need only one class named fhir
from this file. I tried to create a new javascript
class and create an instance of the fhir
class in it. Then, I am calling functions from that instance in my own functions:
/// <reference path='./FhirClient.d.ts' />
import { fhir } from './nativeFhir';
export var FhirClient = (function() {
function FhirClient(config) {
this.client = fhir(config);
}
FhirClient.prototype.conformance = function(query) {
return this.client.conformance(query);
};
FhirClient.prototype.document = function(query) {
return this.client.document(query);
};
FhirClient.prototype.profile = function(query) {
return this.client.profile(query);
};
FhirClient.prototype.transaction = function(query) {
return this.client.transaction(query);
};
FhirClient.prototype.history = function(query) {
return this.client.history(query);
};
FhirClient.prototype.typeHistory = function(query) {
return this.client.typeHistory(query);
};
FhirClient.prototype.resourceHistory = function(query) {
return this.client.resourceHistory(query);
};
FhirClient.prototype.read = function(query) {
return this.client.read(query);
};
FhirClient.prototype.vread = function(query) {
return this.client.vread(query);
};
FhirClient.prototype.delete = function(query) {
return this.client.delete(query);
};
FhirClient.prototype.create = function(query) {
return this.client.create(query);
};
FhirClient.prototype.validate = function(query) {
return this.client.validate(query);
};
FhirClient.prototype.search = function(query) {
return this.client.search(query);
};
FhirClient.prototype.update = function(query) {
return this.client.update(query);
};
FhirClient.prototype.nextPage = function(query) {
return this.client.nextPage(query);
};
FhirClient.prototype.prevPage = function(query) {
return this.client.prevPage(query);
};
FhirClient.prototype.resolve = function(query) {
return this.client.resolve(query);
};
});
And I created a .d.ts
file for this class:
import { fhir } from './nativeFHIR';
export declare class FhirClient {
private client: fhir;
constructor(config: any);
conformance(query: any): any;
document(query: any): any;
profile(query: any): any;
transaction(query: any): any;
history(query: any): any;
typeHistory(query: any): any;
resourceHistory(query: any): any;
read(query: any): any;
vread(query: any): any;
delete(query: any): any;
create(query: any): any;
validate(query: any): any;
search(query: any): any;
update(query: any): any;
nextPage(query: any): any;
prevPage(query: any): any;
resolve(query: any): any;
}
However, I didn't write a .d.ts
file for the library I'm using.
When I tried to import my class (FhirClient
) in the Angular
and call a function from an instance of that class,
this.client = new FhirClient(env.environment.server.config);
this.client.search({type: 'Patient', id: 'pa000001'}).then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
It gives ... is not a function
error:
This is my first time trying to use a .d.ts
file and probably I'm completely using it wrong. Can you help me to use the fhir
class from the native library in my Angular project?