From 92f31def074cecc564963c04eac8d28f47f6bc73 Mon Sep 17 00:00:00 2001 From: Sidharth Ramesh Date: Fri, 21 May 2021 23:13:14 +0530 Subject: [PATCH] feat: warns if wrong paths are set --- src/medblocks/form/form.ts | 12 +++- test/mb-form.e2e.test.ts | 136 +++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 2 deletions(-) diff --git a/src/medblocks/form/form.ts b/src/medblocks/form/form.ts index 135b3f0..2ea27a7 100644 --- a/src/medblocks/form/form.ts +++ b/src/medblocks/form/form.ts @@ -107,10 +107,18 @@ export default class MedblockForm extends LitElement { } set data(data: Data) { - Object.keys(this.mbElements).forEach(path => { + const mbElementPaths = Object.keys(this.mbElements); + const dataPaths = Object.keys(data) + mbElementPaths.forEach(path => { let element = this.mbElements[path] as EhrElement; - element.data = data[path]; + const value = data[path] + element.data = value; }); + // Warnings + const inDataButNotElements = dataPaths.filter(path => !mbElementPaths.includes(path)) + if (inDataButNotElements.length > 0) { + console.warn(`These paths are not present in the current form, but were set: ${inDataButNotElements.join(', ')}.\nTry the "parse" method before setting the data on the form.`) + } } handleInput(e: CustomEvent) { diff --git a/test/mb-form.e2e.test.ts b/test/mb-form.e2e.test.ts index b983bf6..f88ac7b 100644 --- a/test/mb-form.e2e.test.ts +++ b/test/mb-form.e2e.test.ts @@ -32,6 +32,7 @@ describe('Form e2e', ()=>{ expect(form.data).to.eql({'test/1': 'Hello test!'}) }) + it('should serialize to openEHR composition', async ()=>{ }) @@ -40,6 +41,141 @@ describe('Form e2e', ()=>{ }) + it('should bind to the parsed FHIR data', async ()=>{ + const form = await fixture(html` + + +
+ +
+
+ +
+
+ + + + + +
+
+ +
+
+ + +
+
+ +
+ +
+
+ +
+
+ + + + +
+
+ +
+
+
+ Save +
+
+ `) + const resource = { + "address": [ + { + "text": "Manipal" + } + ], + "meta": { + "lastUpdated": "2021-05-19T08:35:52.079131Z", + "createdAt": "2021-05-19T08:35:52.079131Z", + "versionId": "19" + }, + "name": [ + { + "given": [ + "Sidharth R" + ] + } + ], + "birthDate": "1997-09-08", + "resourceType": "Patient", + "id": "c8b0f871-98ed-4a5b-a977-cfa5bf0417f7", + "identifier": [ + { + "value": "123445", + "system": "aadhar" + } + ], + "telecom": [ + { + "value": "9585841964" + } + ], + "gender": "male", + "contact": [ + { + "name": { + "given": [ + "Uma Maheswari" + ] + }, + "telecom": [ + { + "value": "9944941964" + } + ], + "relationship": [ + { + "text": "Mother", + "coding": [ + { + "code": "mother", + "system": "local", + "display": "Mother" + } + ] + } + ] + } + ] + }; + form.data = resource + const parsed = form.parse(resource) + form.data = parsed + await elementUpdated(form) + expect(form.data).to.eql(parsed) + }) it('should serialize to FHIR resource', ()=>{ })