Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion env.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "string",
"test": "fhir-test",
"development": "fhir-development",
"default": "fhir",
"default": "remsadmin",
"required": true
},
"WHITELIST": {
Expand Down
11 changes: 11 additions & 0 deletions jest-mongodb-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
mongodbMemoryServerOptions: {
binary: {
version: '4.0.3',
skipMD5: true
},
autoStart: false,
instance: {},
useSharedDBForAllJestWorkers: false
}
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"moduleNameMapper": {
"axios": "axios/dist/node/axios.cjs"
},
"preset": "ts-jest",
"preset": "@shelf/jest-mongodb",
"testEnvironment": "node",
"transform": {
"^.+\\.ts?$": "ts-jest"
Expand Down Expand Up @@ -72,6 +72,7 @@
"winston-daily-rotate-file": "^4.2.1"
},
"devDependencies": {
"@shelf/jest-mongodb": "^4.1.6",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.14",
"@types/jest": "^27.5.2",
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
VsacApiKey: env.VSAC_KEY
},
database: {
selected: 'tingo',
selected: 'mongo',
tingoConfig: {
location: 'tingo_db',
options: ''
Expand Down
12 changes: 6 additions & 6 deletions src/fhir/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class FhirUtilities {
Object.assign(doc, { _id: id });

// Insert our resource record
collection.insert(doc, (err: any) => {
await collection.insertOne(doc, async (err: any) => {
if (err) {
console.log(' Error with %s.create: ', resource.resourceType, err.message);
reject(err);
Expand All @@ -118,7 +118,7 @@ export class FhirUtilities {
const history_collection = db.collection(historyCollectionString);

// Insert our patient record to history but don't assign _id
history_collection.insert(history_doc, (err2: any) => {
await history_collection.insertOne(history_doc, (err2: any) => {
if (err2) {
console.log(' Error with %sHistory.create: ', resource.resourceType, err2.message);
reject(err2);
Expand All @@ -129,20 +129,20 @@ export class FhirUtilities {
});
}

static loadFile(filePath: string, file: any) {
static async loadFile(filePath: string, file: any) {
const extension = re.exec(filePath);
if (extension) {
if (extension[1].toLowerCase() === 'json') {
if (file !== 'TopicMetadata.json') {
console.log("'%s' is a JSON Resource file.", filePath);
fs.readFile(filePath, 'utf8', (err: any, jsonString: string) => {
fs.readFile(filePath, 'utf8', async (err: any, jsonString: string) => {
if (err) {
console.error('Failed to read file:', err);
return;
}
try {
const resource = JSON.parse(jsonString);
FhirUtilities.store(
await FhirUtilities.store(
resource,
function () {
return;
Expand All @@ -160,7 +160,7 @@ export class FhirUtilities {
}
}

static loadResources(resourcePath: string) {
static async loadResources(resourcePath: string) {
console.log('Loading FHIR Resources from: ' + resourcePath);

// Loop through all the files in the directory looking for folders
Expand Down
32 changes: 19 additions & 13 deletions src/lib/__tests__/vsac_cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ import questionnaire from './fixtures/questionnaire.json';
import valueSet from './fixtures/valueSet.json';
import fs from 'fs';
import nock from 'nock';
import { TingoDatabase } from '../TingoDatabase';
import { Globals } from '../../globals';

import { Db, MongoClient } from 'mongodb';
import constants from '../../constants';
describe('VsacCache', () => {
const client = new VsacCache('./tmp', '2c1d55c3-3484-4902-b645-25f3a4974ce6');
const dbClient = new TingoDatabase({
location: './tingo_db',
options: ''

let connection: MongoClient;
let db: Db;

beforeAll(async () => {
if (process.env.MONGO_URL) {
connection = await MongoClient.connect(process.env.MONGO_URL, {});
db = await connection.db(process.env.MONGO_DB_NAME);
Globals.database = db;
}
});
dbClient.connect();
Globals.databaseClient = dbClient.client;
Globals.database = dbClient.database;

afterAll(async () => {
await connection.close();
});
beforeEach(() => {
Globals.database.close();
fs.rmSync('./tingo_db', { recursive: true, force: true });
dbClient.connect();
Globals.databaseClient = dbClient.client;
Globals.database = dbClient.database;
// client.clearCache();
const baseVersion = '4_0_0';
const collectionString = `${constants.COLLECTION.VALUESET}_${baseVersion}`;

db.collection(collectionString).deleteMany({});
client.onlyVsac = false;
jest.resetModules();
});
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default async function main() {
}
try {
await dbClient.connect();
console.log('Connected to Database');
} catch (dbErr: any) {
console.error(dbErr.message);
process.exit(1);
Expand Down