gcp-nrces-fhir
Version:
Google cloud healthcare api NRCES FHIR implimenataion
73 lines • 3.42 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
// import google from "@googleapis/healthcare";
const google = require("@googleapis/healthcare");
const config_1 = require("../config");
class GcpFhirSearch {
constructor(_Credentials, _DatabasePath) {
_Credentials
? (this.Credentials = _Credentials)
: (this.Credentials = config_1.credentials);
_DatabasePath
? (this.DatabasePath = _DatabasePath)
: (this.DatabasePath = config_1.databasePath);
this.parent = `projects/${this.DatabasePath.projectId}/locations/${this.DatabasePath.cloudRegion}/datasets/${this.DatabasePath.datasetId}/fhirStores/${this.DatabasePath.fhirStoreId}`;
this.healthcare = google.healthcare({
version: "v1",
auth: new google.auth.GoogleAuth({
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
credentials: this.Credentials || config_1.credentials,
}),
});
}
searchFhirResourcesGet(resourceType, args) {
return __awaiter(this, void 0, void 0, function* () {
try {
let request = {
parent: this.parent,
resourceType: resourceType,
};
args === null || args === void 0 ? void 0 : args.forEach((el) => {
request[el.key] = el.value;
});
const response = yield this.healthcare.projects.locations.datasets.fhirStores.fhir.search(request);
let data = response.data;
if (data && typeof data.text === 'function') {
data = JSON.parse(yield data.text());
}
response.data = data;
return response;
}
catch (error) {
console.log(error);
}
});
}
search(resourceType, parameters) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield this.healthcare.projects.locations.datasets.fhirStores.fhir.read({ name: `${this.parent}/fhir/${resourceType}?${parameters}` }, { method: "GET" });
let data = response.data;
if (data && typeof data.text === 'function') {
data = JSON.parse(yield data.text());
}
response.data = data;
return response;
}
catch (error) {
console.log(error);
}
});
}
}
exports.default = GcpFhirSearch;
//# sourceMappingURL=gcpSearch.js.map