Skip to content

Commit

Permalink
feat: warns if wrong paths are set
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthramesh committed May 21, 2021
1 parent 0740a38 commit 92f31de
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/medblocks/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
136 changes: 136 additions & 0 deletions test/mb-form.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Form e2e', ()=>{
expect(form.data).to.eql({'test/1': 'Hello test!'})

})

it('should serialize to openEHR composition', async ()=>{

})
Expand All @@ -40,6 +41,141 @@ describe('Form e2e', ()=>{

})

it('should bind to the parsed FHIR data', async ()=>{
const form = await fixture<MbForm>(html`
<mb-fhir-form>
<mb-input
class="is-hidden"
path="resourceType"
data="Patient"
></mb-input>
<div class="field">
<mb-input label="Name" path="name[0].given[0]"></mb-input>
</div>
<div class="field">
<mb-date label="Date of birth" path="birthDate"></mb-date>
</div>
<div class="field">
<mb-buttons type="code" label="Gender" path="gender">
<mb-option value="male" label="Male"></mb-option>
<mb-option value="female" label="Female"></mb-option>
<mb-option value="other" label="Other"></mb-option>
</mb-buttons>
</div>
<div class="field">
<mb-input label="Phone number" path="telecom[0].value"></mb-input>
</div>
<div class="field">
<mb-input
path="identifier[0].value"
label="Aadhar card number"
></mb-input>
<mb-input
path="identifier[0].system"
class="is-hidden"
data="aadhar"
></mb-input>
</div>
<div class="field">
<mb-input
label="Address"
textarea
path="address[0].text"
></mb-input>
</div>
<label for="" class="label">Attendant information</label>
<div class="box">
<div class="field">
<mb-input label="Name" path="contact[0].name.given[0]"></mb-input>
</div>
<div class="field">
<mb-select
label="Relationship"
path="contact[0].relationship[0]"
type="CodableConcept"
>
<mb-option value="mother" label="Mother"></mb-option>
<mb-option value="father" label="Father"></mb-option>
</mb-select>
</div>
<div class="field">
<mb-input
label="Contact number"
path="contact[0].telecom[0].value"
></mb-input>
</div>
</div>
<div class="field">
<mb-submit type="primary">Save</mb-submit>
</div>
</mb-fhir-form>
`)
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', ()=>{

})
Expand Down

0 comments on commit 92f31de

Please sign in to comment.