Commit 13288a9f authored by Muhammad Kamran's avatar Muhammad Kamran

created reference component

parent f996eaa8
<!doctype html>
<html>
<head>
<title>
<fhir-reference>demo
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script type="module" src="../node_modules/@lh-toolkit/fhir-reference/fhir-reference.js"></script>
</head>
<body>
<p>
<h1>Default element without passing url</h1>
<fhir-reference></fhir-reference>
</p>
<p>
<h1>Default element without passing url but with JSON</h1>
<fhir-reference value="high"></fhir-reference>
</p>
<p>
<p>
<h1>Default element when url is passed</h1>
<fhir-reference url="http://hapi.fhir.org/baseDstu3/Appointment/1716183"></fhir-reference>
</p>
</body>
</html>
......@@ -60,6 +60,7 @@
<li><a href="demos/fhir-appointment-status.html">fhir-appointment-status</a> </li>
<li><a href="demos/fhir-instant.html">fhir-instant</a> </li>
<li><a href="demos/fhir-positiveInt.html">fhir-positiveInt</a> </li>
<li><a href="demos/fhir-reference.html">fhir-reference</a> </li>
</ul>
<h6>*If you don't see the elements after clicking on the link, you probably forgot
to do: <code>lerna bootstrap --use-workspaces</code></h6>
......
# fhir-reference
The fhir-reference adds reference object. It is commonly used
as a form field. It uses input type text for reference and display name. and iron-ajax.
### Functionality
Default : shows an input field for the display name and the reference of the actor.
######a. GET:
- It selects an value from the text entered into the input fields. `value` can be passed as a string.
- It can also receive value from a 'url' which can be passed as property "url". The `reference` key value is checked for in key-value pair of data.
- If it does not receive any matching value, it shows blank.
- Setting `reference` property as true or false can help show and hide this component.
######b. SET:
### Properties of fhir-reference
- `value`:`Object` - used to take the input value of each field.
- `url`:`String` - used to make AJAX call to FHIR resource. Default: null.
- `typeField`:`String` - selectable option critical nature of allergy. Use this property to show/hide. Default: true.
### License
Mozilla Public License, v. 2.0.
### Typical Use:
- With url:
`<fhir-reference url=""></fhir-reference>`
- Without url:
`<fhir-reference></fhir-reference>`
/**
@license
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/**
* `<fhir-reference>` adds critically of allergy to page to select from code if the critical nature of occurrence was low/moderate/high.
* Uses select to choose options.
* In typical use, just use `<fhir-reference url=""></fhir-reference>`
* @customElement
* @polymer
* @demo https://librehealth.gitlab.io/toolkit/lh-toolkit-webcomponents/demos/fhir-reference.html
*
*/
import { LitElement, html } from '@polymer/lit-element/lit-element.js';
import '@material/mwc-textfield/mwc-textfield.js';
import '@polymer/iron-ajax/iron-ajax.js';
class FhirReference extends LitElement {
static get properties() {
return {
/**reference is a string. Use this property to show/hide. Default: true */
reference: String,
/**display is a string. Use this property to show/hide. Default: true */
display: String,
/**url is used to make AJAX call to FHIR resource. Default: null */
url: String,
/**value is used to take the input value of each field*/
value: Object
};
}
/**default value of properties set in constructor*/
constructor() {
super();
this.reference = 'true';
this.display = 'true';
this.value = {};
}
/**_didRender() delivers only after _render*/
_didRender() {
this.shadowRoot
.getElementById('ajax')
.addEventListener('iron-ajax-response', function(e) {
var ref = this.parentNode.host;
if (e.detail.response.criticality !== undefined) {
ref.value = e.detail.response.reference;
} else {
this.parentNode.removeChild(
this.parentNode.querySelector('#referenceDiv')
);
}
});
}
_render({ reference, display, url, value }) {
return html`
<div id="referenceDiv">
${reference !== 'false'
? html`
<label>Reference</label>
<mwc-textfield
outlined
class="reference"
value="${this.value.reference}"
on-input="${e =>
(this.value.reference = e.target._input.value)}"
></mwc-textfield>
`
: ''}
${display !== 'false'
? html`
<label>Display</label>
<mwc-textfield
outlined
class="display"
value="${this.value.display}"
on-input="${e => (this.value.display = e.target._input.value)}"
></mwc-textfield
><br />
`
: ''}
</div>
<iron-ajax
id="ajax"
bubbles
auto
handle-as="json"
url="${url}"
></iron-ajax>
`;
}
}
window.customElements.define('fhir-reference', FhirReference);
{
"name": "@lh-toolkit/fhir-reference",
"version": "0.0.1",
"description": "The custom element for FHIR allergy criticallity",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gitlab.com/librehealth/toolkit/lh-toolkit-webcomponents.git"
},
"license": "MPL-2.0",
"dependencies": {
"@polymer/lit-element": "^0.5.1",
"@polymer/iron-ajax": "^3.0.0-pre.19"
},
"publishConfig": {
"access": "public"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment