UNPKG

@vidal-community/vidal-web-components

Version:

Vidal Web Components

256 lines (255 loc) 11.4 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { html, LitElement } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; import { style } from './vidal-substitution-styles'; import './equivalent/vidal-equivalents'; import './shared-components/vidal-loading-spinner'; import { logoVidal, logoValidate } from './images'; import { VersionService } from './services/version-service'; import { useDrugService } from './services/drug-service'; import { Unit } from './model/unit'; import { PrescriptionLine } from './model/prescription-line'; import { OutputPrescriptionEquivalent } from './model/output/output-prescription-equivalent'; import { OutputPrescription } from './model/output/output-prescription'; let VidalSubstitution = class VidalSubstitution extends LitElement { constructor() { super(...arguments); this.emitSubmitEvent = () => { }; this.inputPrescriptionDrugs = []; this.availableFormularyDrugUris = []; this.prescriptionLines = []; this.vidalWebComponentVersion = '0'; this.loading = false; this.loadingError = false; this.versionService = new VersionService(); this.drugService = useDrugService(); } async updated(changedProperties) { if (this.fetchingSupplier && this.fetchingSupplierWithBody && (changedProperties.has('fetchingSupplier') || changedProperties.has('fetchingSupplierWithBody') || changedProperties.has('availableFormularyDrugUris') || changedProperties.has('inputPrescriptionDrugs') || changedProperties.has('emitSubmitEvent'))) { this.loading = true; if (changedProperties.has('inputPrescriptionDrugs')) { this.prescriptionLines = []; } this.vidalWebComponentVersion = this.versionService.getVidalWebComponentVersion(); this.retrieveAndDisplaySecurizationAPIVersion(); const drugUrisWithUnits = await this.drugService .getUnitsByIds(this.inputPrescriptionDrugs.map((value) => value.drugUri), this.fetchingSupplierWithBody) .catch((err) => { console.error(err); this.loadingError = true; this.loading = false; }); if (drugUrisWithUnits) { this.drugService .getDrugsByIds(this.inputPrescriptionDrugs.map((value) => value.drugUri), this.fetchingSupplierWithBody) .then((drugs) => { this.inputPrescriptionDrugs.forEach((input) => { drugs.forEach((drug) => { if (input.drugUri === drug.uri) { this.prescriptionLines = [ ...this.prescriptionLines, this.buildPrescriptionLine(drug, drugUrisWithUnits, input), ]; } }); }); }) .catch((error) => { this.loadingError = true; console.error(error); }) .finally(() => { this.loading = false; }); } } } buildPrescriptionLine(drug, drugUrisWithUnits, input) { var _a; const prescriptionLine = new PrescriptionLine(drug); const associatedUnits = (_a = drugUrisWithUnits.get(drug.uri)) !== null && _a !== void 0 ? _a : []; prescriptionLine.dose = input.dose; prescriptionLine.routeUri = input.routeUri; if (this.isUnitNotInVidalRef(input, associatedUnits)) { prescriptionLine.error = true; if (input.unitUri) { prescriptionLine.unit = new Unit(input.unitUri, ''); } return prescriptionLine; } associatedUnits === null || associatedUnits === void 0 ? void 0 : associatedUnits.filter((element) => element.uri === input.unitUri).forEach((element) => { prescriptionLine.unit = element; }); prescriptionLine.dispensingUnit = associatedUnits.find((associatedUnit) => associatedUnit.isDispensingUnit); return prescriptionLine; } isUnitNotInVidalRef(input, associatedUnits) { var _a; return !!((input.dose && input.dose <= 0) || (input.dose && !input.unitUri) || (input.dose && input.unitUri && !((_a = associatedUnits === null || associatedUnits === void 0 ? void 0 : associatedUnits.map((element) => element.uri)) === null || _a === void 0 ? void 0 : _a.includes(input.unitUri)))); } retrieveAndDisplaySecurizationAPIVersion() { if (this.fetchingSupplier) { this.fetchingSupplier('/rest/api/version') .then(async (response) => { if (response.ok) { const versionFeed = await response.text(); const domParser = new DOMParser(); const dom = domParser.parseFromString(versionFeed, 'text/xml'); const entry = dom.querySelector('feed > entry > content'); this.getHtmlElement('.version-modal .version-tag').innerHTML = entry.textContent; } else { console.error('Cannot get API version', response.status, response.statusText); } }) .catch((error) => console.error('Cannot get API version', error)); } } getHtmlElement(selector) { return this.renderRoot.querySelector(selector); } toggleVersionModal() { const suggestionModal = this.renderRoot.querySelector('.version-modal'); const displayStyle = suggestionModal.style.display; suggestionModal.style.display = displayStyle === 'flex' ? 'none' : 'flex'; } displayCorrectContent(loading, loadingError) { if (loading) { return html ` <vidal-loading-spinner></vidal-loading-spinner>`; } if (loadingError) { return html `<p class="centered"> Impossible de récupérer les informations nécessaires. </p>`; } return html ` <div class="content-titles"> <div class="content-title">PRESCRIPTION INITIALE</div> <div class="content-title"> PROPOSITION DE SUBSTITUTION (MÉDICAMENTS AU LIVRET) </div> </div> <vidal-equivalent .prescriptionLines="${this.prescriptionLines}" .availableFormularyDrugUris="${this.availableFormularyDrugUris}" .prescribableFetchingSupplier="${this.fetchingSupplier}" .fetchingSupplierWithBody="${this.fetchingSupplierWithBody}" .emitSubmitEvent="${this.emitSubmitEvent}" > </vidal-equivalent>`; } render() { return html ` <div id="substitution"> <header> <span class="title-container"> <span class="bullet"></span> <span class="title">Proposition de substitution</span> </span> <img class="vidal-logo" src="${logoVidal}" alt="vidal-substitution" /> </header> <div class="content"> ${this.displayCorrectContent(this.loading, this.loadingError)} </div> <div class="version-modal"> <div class="version-tag"></div> <span class="close-button" @click="${() => this.toggleVersionModal()}" > X </span> </div> <footer> <div> <span >Vidal Substitution version: ${this.vidalWebComponentVersion} utilisant</span > <span class="source" title="Afficher l'étiquette du marquage CE de Vidal Sécurisation" @click="${() => this.toggleVersionModal()}" > Vidal Sécurisation </span> </div> <button class="validate-button" @click="${() => this.submitEvent()}"> <img src="${logoValidate}" alt="Validate" /> Valider </button> </footer> </div> `; } submitEvent() { var _a; const result = []; (_a = this.renderRoot .querySelector('vidal-equivalent')) === null || _a === void 0 ? void 0 : _a.renderRoot.querySelectorAll('vidal-equivalent-form').forEach((vidalEquivalentForm) => { result.push(this.buildPrescriptionLineOutput(vidalEquivalentForm)); }); this.emitSubmitEvent(result); } buildPrescriptionLineOutput(vidalEquivalentForm) { var _a; const prescriptionLineForm = vidalEquivalentForm.prescriptionLine; const prescriptionLine = new OutputPrescription(prescriptionLineForm.drug.uri, (_a = prescriptionLineForm.unit) === null || _a === void 0 ? void 0 : _a.uri, prescriptionLineForm.dose, prescriptionLineForm.routeUri); const selectedEquivalents = []; if (vidalEquivalentForm.selectedEquivalentCombinationForm && vidalEquivalentForm.selectedEquivalentCombinationForm.length !== 0) { vidalEquivalentForm.selectedEquivalentCombinationForm.forEach((eq) => selectedEquivalents.push(eq)); } else { return new OutputPrescriptionEquivalent(prescriptionLine); } const outputPrescriptionEquivalent = new OutputPrescriptionEquivalent(prescriptionLine, selectedEquivalents); outputPrescriptionEquivalent.unitError = !!prescriptionLineForm.error; return outputPrescriptionEquivalent; } }; VidalSubstitution.styles = style; __decorate([ property({ attribute: false }) ], VidalSubstitution.prototype, "fetchingSupplier", void 0); __decorate([ property({ attribute: false }) ], VidalSubstitution.prototype, "fetchingSupplierWithBody", void 0); __decorate([ property() ], VidalSubstitution.prototype, "emitSubmitEvent", void 0); __decorate([ property({ attribute: false }) ], VidalSubstitution.prototype, "inputPrescriptionDrugs", void 0); __decorate([ property({ attribute: false }) ], VidalSubstitution.prototype, "availableFormularyDrugUris", void 0); __decorate([ state() ], VidalSubstitution.prototype, "prescriptionLines", void 0); __decorate([ state() ], VidalSubstitution.prototype, "vidalWebComponentVersion", void 0); __decorate([ state() ], VidalSubstitution.prototype, "loading", void 0); VidalSubstitution = __decorate([ customElement('vidal-substitution') ], VidalSubstitution); export { VidalSubstitution }; //# sourceMappingURL=vidal-substitution.js.map