From 79cff47e40823164849a6c85cc8772142a6f730c Mon Sep 17 00:00:00 2001 From: Bellraj Eapen Date: Thu, 6 May 2021 05:23:53 -0700 Subject: [PATCH 1/5] get all questionnaires --- package.json | 2 +- src/fhir-backend.ts | 26 ++++++++++++++++++++++++++ test/fhir-backend.test.ts | 16 ++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/fhir-backend.ts create mode 100644 test/fhir-backend.test.ts diff --git a/package.json b/package.json index b321278..79385ef 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "size": "size-limit", "analyze": "size-limit --why" }, - "peerDependencies": {}, "husky": { "hooks": { "//": "pre-commit tsdx lint" @@ -72,6 +71,7 @@ }, "dependencies": { "@ahryman40k/ts-fhir-types": "^4.0.32", + "axios": "^0.21.1", "uuidv4": "^6.2.3" } } diff --git a/src/fhir-backend.ts b/src/fhir-backend.ts new file mode 100644 index 0000000..e8dd79e --- /dev/null +++ b/src/fhir-backend.ts @@ -0,0 +1,26 @@ +// Based on SMART on FHIR Example Backend Service App @ https://github.com/smart-on-fhir/sample-apps-stu3/tree/master/backend-service +import axios from 'axios' +import { R4 } from '@ahryman40k/ts-fhir-types'; +export class FhirBackend { + + baseUrl: string = "http://hapi.fhir.org/baseR4" + questionnaireBundle: R4.IBundle | undefined + + constructor(baseUrl: string){ + if(baseUrl != '') + this.baseUrl = baseUrl; + }; + + async initialize() { + + this.questionnaireBundle = await axios.get(this.baseUrl + '/Questionnaire') + + } + + getQuestionnaires(): R4.IBundle | undefined { + return this.questionnaireBundle; + } + + +} + diff --git a/test/fhir-backend.test.ts b/test/fhir-backend.test.ts new file mode 100644 index 0000000..da78d9b --- /dev/null +++ b/test/fhir-backend.test.ts @@ -0,0 +1,16 @@ +import { FhirBackend } from '../src/fhir-backend' + +describe('Testing Fhir Backend', () => { + + + it('counts questionnaires on FHIR server', async () => { + const backend = new FhirBackend(''); + await backend.initialize() + console.log(backend.getQuestionnaires()) + //expect(ff.schema.title).toBe('f201'); + }); + + + + +}); \ No newline at end of file From 9adaafb5a0fc1f5ffef0fc6486266bd7f5c8766b Mon Sep 17 00:00:00 2001 From: Bellraj Eapen Date: Thu, 6 May 2021 08:03:09 -0700 Subject: [PATCH 2/5] getques and toc complete --- package.json | 1 + src/fhir-backend.ts | 26 ++++++++++++++++++++++---- test/fhir-backend.test.ts | 29 +++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 79385ef..f002246 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "start": "tsdx watch", "build": "tsdx build", "test": "tsdx test", + "test-watch": "tsdx test --watch", "lint": "tsdx lint --fix", "prepare": "tsdx build", "docs": "typedoc --out docs src", diff --git a/src/fhir-backend.ts b/src/fhir-backend.ts index e8dd79e..156ac02 100644 --- a/src/fhir-backend.ts +++ b/src/fhir-backend.ts @@ -1,10 +1,17 @@ // Based on SMART on FHIR Example Backend Service App @ https://github.com/smart-on-fhir/sample-apps-stu3/tree/master/backend-service import axios from 'axios' import { R4 } from '@ahryman40k/ts-fhir-types'; + +export interface FhirBackendToc { + fullUrl?: string; + id?: string; +} export class FhirBackend { baseUrl: string = "http://hapi.fhir.org/baseR4" - questionnaireBundle: R4.IBundle | undefined + questionnaireBundle: R4.IBundle = { + resourceType: "Bundle" + } constructor(baseUrl: string){ if(baseUrl != '') @@ -13,14 +20,25 @@ export class FhirBackend { async initialize() { - this.questionnaireBundle = await axios.get(this.baseUrl + '/Questionnaire') - + const response = await axios.get(this.baseUrl + '/Questionnaire') + this.questionnaireBundle = response.data } - getQuestionnaires(): R4.IBundle | undefined { + getQuestionnaires(): R4.IBundle { return this.questionnaireBundle; } + getTableOfContents(){ + return this.questionnaireBundle?.entry?.map(entry => {return {fullUrl: entry.fullUrl, id: entry.resource?.id}}) + } + + getQuestionnaire(id: string){ + return this.questionnaireBundle?.entry?.find(entry => { + console.log(entry.resource?.id?.toString() + id) + entry.resource?.id?.toString() === id + }) + } + } diff --git a/test/fhir-backend.test.ts b/test/fhir-backend.test.ts index da78d9b..f9ae236 100644 --- a/test/fhir-backend.test.ts +++ b/test/fhir-backend.test.ts @@ -1,16 +1,33 @@ import { FhirBackend } from '../src/fhir-backend' +import { R4 } from '@ahryman40k/ts-fhir-types'; describe('Testing Fhir Backend', () => { - - it('counts questionnaires on FHIR server', async () => { - const backend = new FhirBackend(''); - await backend.initialize() - console.log(backend.getQuestionnaires()) - //expect(ff.schema.title).toBe('f201'); + const backend = new FhirBackend(''); + beforeAll( async () => { + await backend.initialize() }); + it('gets questionnaires on FHIR server', async () => { + if(backend.getQuestionnaires() != undefined){ + const bundle: R4.IBundle = backend.getQuestionnaires() + expect(bundle.resourceType).toBe('Bundle') + }else{ + throw new Error("Bundle not found"); + } + }); + it('gets table of contents', async () => { + const toc: unknown = backend.getTableOfContents() + expect(toc).toBeTruthy() + }); + + it('gets single questionnaire', async () => { + + console.log(backend.getQuestionnaire('2050148')) + const questionnaire: R4.IQuestionnaire = {...backend.getQuestionnaire('2050138'), resourceType: 'Questionnaire'} + console.log(questionnaire) + }); }); \ No newline at end of file From 44614c5239a3677ea9e7f7851bfa80ed07e3ab46 Mon Sep 17 00:00:00 2001 From: Bellraj Eapen Date: Thu, 6 May 2021 08:50:38 -0700 Subject: [PATCH 3/5] working test --- src/fhir-backend.ts | 16 +++++----------- src/index.ts | 1 + test/fhir-backend.test.ts | 5 ++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/fhir-backend.ts b/src/fhir-backend.ts index 156ac02..94ff6e0 100644 --- a/src/fhir-backend.ts +++ b/src/fhir-backend.ts @@ -1,11 +1,9 @@ -// Based on SMART on FHIR Example Backend Service App @ https://github.com/smart-on-fhir/sample-apps-stu3/tree/master/backend-service import axios from 'axios' import { R4 } from '@ahryman40k/ts-fhir-types'; -export interface FhirBackendToc { - fullUrl?: string; - id?: string; -} +/** + * + */ export class FhirBackend { baseUrl: string = "http://hapi.fhir.org/baseR4" @@ -19,7 +17,6 @@ export class FhirBackend { }; async initialize() { - const response = await axios.get(this.baseUrl + '/Questionnaire') this.questionnaireBundle = response.data } @@ -33,12 +30,9 @@ export class FhirBackend { } getQuestionnaire(id: string){ - return this.questionnaireBundle?.entry?.find(entry => { - console.log(entry.resource?.id?.toString() + id) - entry.resource?.id?.toString() === id + return this.questionnaireBundle?.entry?.find(entry => { + return entry.resource?.id === id }) } - - } diff --git a/src/index.ts b/src/index.ts index df3308c..02e387e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export { FhirJsonForm } from './ques-mapper'; export { FhirJsonResp } from './resp-mapper'; +export { FhirBackend } from './fhir-backend'; diff --git a/test/fhir-backend.test.ts b/test/fhir-backend.test.ts index f9ae236..4488259 100644 --- a/test/fhir-backend.test.ts +++ b/test/fhir-backend.test.ts @@ -25,9 +25,8 @@ describe('Testing Fhir Backend', () => { }); it('gets single questionnaire', async () => { - - console.log(backend.getQuestionnaire('2050148')) - const questionnaire: R4.IQuestionnaire = {...backend.getQuestionnaire('2050138'), resourceType: 'Questionnaire'} + const questionnaire: R4.IBundle_Entry = backend.getQuestionnaire('2050148') + expect(questionnaire.id).toBe('2050148') console.log(questionnaire) }); }); \ No newline at end of file From a6d0f4edfd65bdf49172e08d89c2c2e0a66be2bd Mon Sep 17 00:00:00 2001 From: Bellraj Eapen Date: Thu, 6 May 2021 09:04:21 -0700 Subject: [PATCH 4/5] progress --- package.json | 16 ++++++++-------- test/fhir-backend.test.ts | 11 +++++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index f002246..1c20b30 100644 --- a/package.json +++ b/package.json @@ -62,17 +62,17 @@ } ], "devDependencies": { - "@size-limit/preset-small-lib": "^4.6.0", - "husky": "^4.3.0", - "size-limit": "^4.6.0", + "@size-limit/preset-small-lib": "^4.10.2", + "husky": "^4.3.8", + "size-limit": "^4.10.2", "tsdx": "^0.14.1", - "tslib": "^2.0.1", - "typedoc": "^0.20.0-beta.32", - "typescript": "^4.0.3" + "tslib": "^2.2.0", + "typedoc": "^0.20.36", + "typescript": "^4.2.4" }, "dependencies": { - "@ahryman40k/ts-fhir-types": "^4.0.32", + "@ahryman40k/ts-fhir-types": "^4.0.34", "axios": "^0.21.1", - "uuidv4": "^6.2.3" + "uuidv4": "^6.2.7" } } diff --git a/test/fhir-backend.test.ts b/test/fhir-backend.test.ts index 4488259..562232f 100644 --- a/test/fhir-backend.test.ts +++ b/test/fhir-backend.test.ts @@ -19,14 +19,17 @@ describe('Testing Fhir Backend', () => { }); it('gets table of contents', async () => { - const toc: unknown = backend.getTableOfContents() expect(toc).toBeTruthy() }); it('gets single questionnaire', async () => { - const questionnaire: R4.IBundle_Entry = backend.getQuestionnaire('2050148') - expect(questionnaire.id).toBe('2050148') - console.log(questionnaire) + if (backend.getQuestionnaire('2050148') != undefined) { + const questionnaire: R4.IBundle_Entry = backend.getQuestionnaire('2050148')! + expect(questionnaire.id).toBe('2050148') + console.log(questionnaire) + } else { + throw new Error("Bundle not found"); + } }); }); \ No newline at end of file From c14b7c22c7b1702df0ca52422a8bcf1dcefdeb2d Mon Sep 17 00:00:00 2001 From: Bellraj Eapen Date: Thu, 6 May 2021 13:05:19 -0400 Subject: [PATCH 5/5] Add backend api support --- src/fhir-backend.ts | 2 +- test/fhir-backend.test.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/fhir-backend.ts b/src/fhir-backend.ts index 94ff6e0..0901c09 100644 --- a/src/fhir-backend.ts +++ b/src/fhir-backend.ts @@ -32,7 +32,7 @@ export class FhirBackend { getQuestionnaire(id: string){ return this.questionnaireBundle?.entry?.find(entry => { return entry.resource?.id === id - }) + })?.resource } } diff --git a/test/fhir-backend.test.ts b/test/fhir-backend.test.ts index 562232f..e0fdf3d 100644 --- a/test/fhir-backend.test.ts +++ b/test/fhir-backend.test.ts @@ -25,9 +25,8 @@ describe('Testing Fhir Backend', () => { it('gets single questionnaire', async () => { if (backend.getQuestionnaire('2050148') != undefined) { - const questionnaire: R4.IBundle_Entry = backend.getQuestionnaire('2050148')! + const questionnaire: R4.IResourceList = backend.getQuestionnaire('2050148')! expect(questionnaire.id).toBe('2050148') - console.log(questionnaire) } else { throw new Error("Bundle not found"); }