-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3cc2da
commit b866e61
Showing
7 changed files
with
291 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {html, property } from 'lit-element'; | ||
import EhrElement from '../EhrElement'; | ||
import SlInput from '@shoelace-style/shoelace/dist/components/input/input'; | ||
import { ifDefined } from 'lit-html/directives/if-defined'; | ||
|
||
export default abstract class MbProportion extends EhrElement { | ||
abstract type : string; | ||
abstract max : number |string; | ||
abstract min : number |string ; | ||
@property({ type: Object }) data: | ||
| { | ||
denominator: number; | ||
numerator: number; | ||
type: number; | ||
} | ||
| undefined = undefined; | ||
|
||
@property({ type: Boolean, reflect: true }) required: boolean = false; | ||
|
||
@property({ type: String, reflect: true }) step: string; | ||
|
||
|
||
_handleChange(e: CustomEvent) { | ||
const inputElement = e.target as SlInput; | ||
if (inputElement.value === '') { | ||
this.data = undefined; | ||
} else { | ||
this.data = { | ||
numerator: parseFloat(inputElement.value), | ||
denominator: this.type === 'unitary' ? 1 : 100, | ||
type: this.type === 'unitary' ? 1 : 2, | ||
}; | ||
} | ||
this._mbInput.emit(); | ||
} | ||
|
||
reportValidity() { | ||
const input = this.shadowRoot!.querySelector('sl-input') as SlInput; | ||
return input.reportValidity(); | ||
} | ||
|
||
getStep() { | ||
if (this.step) { | ||
return this.step | ||
} else { | ||
if (this.type === 'unitary') { | ||
return "0.01" | ||
} else { | ||
return | ||
} | ||
} | ||
} | ||
|
||
render() { | ||
return html`<sl-input | ||
.required=${this.required} | ||
.min=${this.min} | ||
.max=${this.max} | ||
type="number" | ||
.step=${this.getStep()} | ||
label=${ifDefined(this.label)} | ||
@sl-input=${this._handleChange} | ||
.value=${this.data?.numerator?.toString() || ''} | ||
> | ||
<sl-icon name=${this.type === 'unitary' ? 'decimal': 'percent'} library="medblocks" slot="prefix"></sl-icon> | ||
</sl-input>`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,12 @@ | ||
import { customElement, html, property } from 'lit-element'; | ||
import EhrElement from '../EhrElement'; | ||
import SlInput from '@shoelace-style/shoelace/dist/components/input/input'; | ||
import { customElement, property } from 'lit-element'; | ||
import '@shoelace-style/shoelace/dist/components/input/input'; | ||
import { ifDefined } from 'lit-html/directives/if-defined'; | ||
import './proportion' | ||
@customElement('mb-percent') | ||
export default class MbPercent extends EhrElement { | ||
@property({ type: Object }) data: | ||
| { | ||
denominator: number; | ||
numerator: number; | ||
type: number; | ||
} | ||
| undefined = undefined; | ||
|
||
@property({ type: Boolean, reflect: true }) required: boolean = false; | ||
|
||
@property({ type: Number, reflect: true }) max: number | string; | ||
|
||
@property({ type: Number, reflect: true }) min: number | string; | ||
|
||
// _handleChange(e: CustomEvent) { | ||
// const inputElement = e.target as SlInput; | ||
// if (inputElement.value === '') { | ||
// this.data = undefined; | ||
// } else { | ||
// this.data = { | ||
// numerator: parseFloat(inputElement.value), | ||
// denominator: 100, | ||
// type: 2, | ||
// }; | ||
// } | ||
// this._mbInput.emit(); | ||
// } | ||
|
||
reportValidity() { | ||
const input = this.shadowRoot!.querySelector('mb-proportion') as SlInput; | ||
return input.reportValidity(); | ||
} | ||
|
||
render() { | ||
return html`<mb-proportion ?required=${this.required} .min=${this.min} .max=${this.max} type="percent" | ||
label=${ifDefined(this.label)} .data=${this.data}></mb-proportion>`; | ||
} | ||
import './MbProportion' | ||
import MbProportion from './MbProportion'; | ||
@customElement('mb-percent') | ||
export default class MbPercent extends MbProportion { | ||
@property() type = 'percent' | ||
@property({ type: String, reflect: true })min = '0' | ||
@property({ type: String, reflect: true })max = '100' | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,12 @@ | ||
import { customElement, html, property } from 'lit-element'; | ||
import EhrElement from '../EhrElement'; | ||
import SlInput from '@shoelace-style/shoelace/dist/components/input/input'; | ||
import '@shoelace-style/shoelace/dist/components/input/input'; | ||
import { ifDefined } from 'lit-html/directives/if-defined'; | ||
|
||
@customElement('mb-proportion') | ||
export default class MbProportion extends EhrElement { | ||
@property({ type: Object }) data: | ||
| { | ||
denominator: number; | ||
numerator: number; | ||
type: number; | ||
} | ||
| undefined = undefined; | ||
|
||
@property({ type: Boolean, reflect: true }) required: boolean = false; | ||
|
||
@property({ type: Number, reflect: true }) max: number | string; | ||
|
||
@property({ type: Number, reflect: true }) min: number | string; | ||
|
||
@property({ type: String, reflect: true }) step: string; | ||
import { customElement,property } from 'lit-element'; | ||
|
||
@property({type: String, reflect: true}) type: 'percent' | 'unitary' = 'percent' | ||
|
||
_handleChange(e: CustomEvent) { | ||
const inputElement = e.target as SlInput; | ||
if (inputElement.value === '') { | ||
this.data = undefined; | ||
} else { | ||
this.data = { | ||
numerator: parseFloat(inputElement.value), | ||
denominator: this.type === 'unitary' ? 1 : 100, | ||
type: this.type === 'unitary' ? 1 : 2, | ||
}; | ||
} | ||
this._mbInput.emit(); | ||
} | ||
|
||
reportValidity() { | ||
const input = this.shadowRoot!.querySelector('sl-input') as SlInput; | ||
console.log({data: this.data},{required: this.required}, {report: input.reportValidity()}, {inputValue: input.value}) | ||
return input.reportValidity(); | ||
} | ||
|
||
getStep() { | ||
if (this.step) { | ||
return this.step | ||
} else { | ||
if (this.type === 'unitary') { | ||
return "0.01" | ||
} else { | ||
return | ||
} | ||
} | ||
} | ||
|
||
render() { | ||
return html`<sl-input | ||
.required=${this.required} | ||
.min=${this.min} | ||
.max=${this.max} | ||
type="number" | ||
import '@shoelace-style/shoelace/dist/components/input/input'; | ||
|
||
label=${ifDefined(this.label)} | ||
@sl-input=${this._handleChange} | ||
.value=${this.data?.numerator?.toString() || ''} | ||
> | ||
<sl-icon name=${this.type === 'unitary' ? 'decimal': 'percent'} library="medblocks" slot="prefix"></sl-icon> | ||
</sl-input>`; | ||
} | ||
} | ||
import './MbProportion' | ||
import MbProportion from './MbProportion'; | ||
@customElement('mb-proportion') | ||
export default class MbPercent extends MbProportion { | ||
@property() type = 'unitary' | ||
@property({ type: String, reflect: true })min = '0' | ||
@property({ type: String, reflect: true })max = '1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { | ||
html, | ||
fixture, | ||
expect, | ||
oneEvent, | ||
elementUpdated, | ||
} from '@open-wc/testing'; | ||
import MbPercent from '../src/medblocks/proportion/proportion'; | ||
import '../src/medblocks/proportion/proportion'; | ||
import { querySelectorDeep } from 'query-selector-shadow-dom'; | ||
import MbForm from '../src/medblocks/form/form' | ||
import '../medblocks' | ||
|
||
|
||
|
||
|
||
describe('MbProportion', () => { | ||
|
||
it('data if not provided', async () => { | ||
const mbPercent = await fixture<MbPercent>( | ||
html`<mb-proportion label="Test 1"></mb-proportion>` | ||
); | ||
const input = querySelectorDeep('input') as HTMLInputElement | ||
setTimeout(() => { | ||
input.dispatchEvent(new Event('input')); | ||
}); | ||
const event: any = await oneEvent(mbPercent, 'mb-input'); | ||
expect(event.target.data).to.eq(undefined); | ||
}); | ||
|
||
|
||
it('emits data on input', async () => { | ||
const mbPercent = await fixture<MbPercent>( | ||
html`<mb-proportion label="Test 2"></mb-proportion>` | ||
); | ||
const input = querySelectorDeep('input') as HTMLInputElement | ||
setTimeout(() => { | ||
input.value = '0.2'; | ||
input.dispatchEvent(new Event('input')); | ||
}); | ||
const event: any = await oneEvent(mbPercent, 'mb-input'); | ||
expect(event.target.data).to.eql({ numerator: 0.2, denominator: 1, type: 1 }); | ||
}); | ||
|
||
|
||
it('changes input on setting data', async () => { | ||
const mbPercent = await fixture<MbPercent>( | ||
html`<mb-proportion label="Test 3"></mb-proportion>` | ||
); | ||
const input = querySelectorDeep('input') as HTMLInputElement | ||
setTimeout(()=>{ | ||
mbPercent.data = { numerator: 0.3, denominator: 1, type: 1 }; | ||
},0) | ||
await oneEvent(mbPercent, 'mb-input'); | ||
await elementUpdated(mbPercent); | ||
expect(input.value).to.eq('0.3'); | ||
}); | ||
|
||
it('SpO2 template data loading', async ()=>{ | ||
const form = await fixture<MbForm>(html` | ||
<mb-form> | ||
<mb-context path="ncd/context/start_time"></mb-context> | ||
<mb-context path="ncd/context/setting"></mb-context> | ||
<mb-proportion path="ncd/pulse_oximetry/any_event:0/spo" label="SpO₂" id="percentage"></mb-proportion> | ||
<mb-context path="ncd/pulse_oximetry/any_event:0/time"></mb-context> | ||
<mb-context path="ncd/pulse_oximetry/language"></mb-context> | ||
<mb-context path="ncd/pulse_oximetry/encoding"></mb-context> | ||
<mb-context path="ncd/pulse_oximetry/subject"></mb-context> | ||
<mb-context path="ncd/category"></mb-context> | ||
<mb-context path="ncd/language"></mb-context> | ||
<mb-context path="ncd/territory"></mb-context> | ||
<mb-context path="ncd/composer"></mb-context> | ||
</mb-form> | ||
`) | ||
form.import( | ||
{ | ||
"ncd/language|code": "en", | ||
"ncd/language|terminology": "ISO_639-1", | ||
"ncd/territory|code": "IN", | ||
"ncd/territory|terminology": "ISO_3166-1", | ||
"ncd/context/start_time": "2021-11-05T04:50:52.727Z", | ||
"ncd/context/setting|code": "238", | ||
"ncd/context/setting|value": "other care", | ||
"ncd/context/setting|terminology": "openehr", | ||
"ncd/pulse_oximetry/any_event:0/spo|numerator": 0.2, | ||
"ncd/pulse_oximetry/any_event:0/spo|denominator": 1, | ||
"ncd/pulse_oximetry/any_event:0/spo|type": 1, | ||
"ncd/pulse_oximetry/any_event:0/spo": 0.2, | ||
"ncd/pulse_oximetry/any_event:0/time": "2021-11-05T05:11:05.498Z", | ||
"ncd/pulse_oximetry/language|code": "en", | ||
"ncd/pulse_oximetry/language|terminology": "ISO_639-1", | ||
"ncd/pulse_oximetry/encoding|code": "UTF-8", | ||
"ncd/pulse_oximetry/encoding|terminology": "IANA_character-sets", | ||
"ncd/category|code": "433", | ||
"ncd/category|value": "event", | ||
"ncd/category|terminology": "openehr", | ||
"ncd/composer|name": "Medblocks UI" | ||
} | ||
) | ||
const mbPercent = document.getElementById('percentage') as MbPercent; | ||
expect(mbPercent.data).to.eql({ _root: 0.2, numerator: 0.2, denominator: 1, type: 1 }) | ||
}) | ||
}); | ||
|
Oops, something went wrong.