Skip to content

Commit

Permalink
Merge branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dermatologist committed May 7, 2021
2 parents 14d35d5 + 8155d47 commit 8399398
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 28,295 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ import Form from "@rjsf/core"
</div>
);
```
### Update
**since v0.8.0: Backend API**
```
import { FhirBackend } from 'fhirformjs'
const backend = new FhirBackend('http://hapi.fhir.org/baseR4');
console.log(backend.getTableOfContents())
console.log(backend.getQuestionnaire('2050148'))
```
### [See an example](https://github.com/dermatologist/fhir-questionnaire-render-react) :point_left:

## Author
Expand Down
28,270 changes: 0 additions & 28,270 deletions package-lock.json

This file was deleted.

21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fhirformjs",
"description": "FHIR Questionnaire To Form Converter for rendering",
"version": "0.7.1",
"version": "0.8.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -32,13 +32,13 @@
"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",
"size": "size-limit",
"analyze": "size-limit --why"
},
"peerDependencies": {},
"husky": {
"hooks": {
"//": "pre-commit tsdx lint"
Expand All @@ -62,16 +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",
"uuidv4": "^6.2.3"
"@ahryman40k/ts-fhir-types": "^4.0.34",
"axios": "^0.21.1",
"uuidv4": "^6.2.7"
}
}
38 changes: 38 additions & 0 deletions src/fhir-backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import axios from 'axios'
import { R4 } from '@ahryman40k/ts-fhir-types';

/**
*
*/
export class FhirBackend {

baseUrl: string = ''
questionnaireBundle: R4.IBundle = {
resourceType: "Bundle"
}

constructor(baseUrl: string){
if(baseUrl != '')
this.baseUrl = baseUrl;
};

async initialize() {
const response = await axios.get(this.baseUrl + '/Questionnaire')
this.questionnaireBundle = response.data
}

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 => {
return entry.resource?.id === id
})?.resource
}
}

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { FhirJsonForm } from './ques-mapper';
export { FhirJsonResp } from './resp-mapper';
export { FhirBackend } from './fhir-backend';
93 changes: 78 additions & 15 deletions src/ques-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ export const FhirJsonForm = (
'ui:widget': GetWidget(groupItem),
};
}

if (GetUIOptions(groupItem) !== '') {
UISchema[groupProperty][myProperty] = {
'ui:options': GetUIOptions(groupItem),
};
}

fhirQuestionnaireResponse.item?.push(CreateResponseItem(groupItem));
});

Expand All @@ -74,6 +81,12 @@ export const FhirJsonForm = (
};
}

if (GetUIOptions(item) !== '') {
UISchema[myProperty] = {
'ui:options': GetUIOptions(item),
};
}

fhirQuestionnaireResponse.item?.push(CreateResponseItem(item));
}
});
Expand Down Expand Up @@ -140,11 +153,27 @@ const GetOptions = (item: R4.IQuestionnaire_Item) => {
enumNames.push(display);
}
});
return {

const options = {
enum: enumOptions,
enumNames,
};
}
}

const ext: R4.IExtension = (item.extension || [])[0]
const coding: R4.ICoding = (ext?.valueCodeableConcept?.coding || [])[0]

if (coding?.code === EXTENSION_CHECKBOX) {
return {
uniqueItems: true,
items: {
type: "string",
...options
}
}
}

return options;
}
// if (
// item.type == R4.Questionnaire_ItemTypeKind._choice ||
// item.type == R4.Questionnaire_ItemTypeKind._openChoice
Expand All @@ -165,18 +194,37 @@ const GetWidget = (item: R4.IQuestionnaire_Item) => {
) {
return 'datetime';
}
// if (
// item.type == R4.Questionnaire_ItemTypeKind._choice ||
// item.type == R4.Questionnaire_ItemTypeKind._openChoice
// ) {
// return 'select';
// }
if (
item.type == R4.Questionnaire_ItemTypeKind._choice ||
item.type == R4.Questionnaire_ItemTypeKind._openChoice
) {
const ext: R4.IExtension = (item.extension || [])[0]
const coding: R4.ICoding = (ext?.valueCodeableConcept?.coding || [])[0]

if (coding?.code && extensionToWidget[coding?.code]) {
return extensionToWidget[coding?.code]
}
}
// if (item.type === R4.Questionnaire_ItemTypeKind._boolean) {
// return 'boolean';
// }
return '';
};

const GetUIOptions = (item: R4.IQuestionnaire_Item) => {
const ext: R4.IExtension = (item.extension || [])[0]
const splitUrl = ext?.url?.split('/')
const extensionName = splitUrl && splitUrl[splitUrl.length-1]

if (ext?.valueCoding?.display && extensionName === 'questionnaire-unit') {
return {
unit: ext.valueCoding.display
}
}

return '';
}

const GetControlType = (item: R4.IQuestionnaire_Item) => {
// if (
// item.type == R4.Questionnaire_ItemTypeKind._date ||
Expand All @@ -185,12 +233,17 @@ const GetControlType = (item: R4.IQuestionnaire_Item) => {
// ) {
// return 'dateTimePicker';
// }
// if (
// item.type == R4.Questionnaire_ItemTypeKind._choice ||
// item.type == R4.Questionnaire_ItemTypeKind._openChoice
// ) {
// return 'select';
// }
if (
item.type == R4.Questionnaire_ItemTypeKind._choice ||
item.type == R4.Questionnaire_ItemTypeKind._openChoice
) {
const ext: R4.IExtension = (item.extension || [])[0]
const coding: R4.ICoding = (ext?.valueCodeableConcept?.coding || [])[0]

if (coding?.code === EXTENSION_CHECKBOX) {
return 'array'
}
}
if (item.type === R4.Questionnaire_ItemTypeKind._boolean) {
return 'boolean';
}
Expand Down Expand Up @@ -258,3 +311,13 @@ const GetOnlyValueType = (valueType: string) => {
var pieces = valueType.split(/[\s.]+/); // Split on .
return pieces[pieces.length - 1];
};


const EXTENSION_DROPDOWN = 'drop-down'
const EXTENSION_RADIOBUTTON = 'radio-button'
const EXTENSION_CHECKBOX = 'check-box'
const extensionToWidget = {
[EXTENSION_DROPDOWN]: 'select',
[EXTENSION_RADIOBUTTON]: 'radio',
[EXTENSION_CHECKBOX]: 'checkboxes'
}
34 changes: 34 additions & 0 deletions test/fhir-backend.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FhirBackend } from '../src/fhir-backend'
import { R4 } from '@ahryman40k/ts-fhir-types';

describe('Testing Fhir Backend', () => {

const backend = new FhirBackend('http://hapi.fhir.org/baseR4');
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 () => {
if (backend.getQuestionnaire('2050148') != undefined) {
const questionnaire: R4.IResourceList = backend.getQuestionnaire('2050148')!
expect(questionnaire.id).toBe('2050148')
} else {
throw new Error("Bundle not found");
}
});
});

0 comments on commit 8399398

Please sign in to comment.