@vidal-community/vidal-web-components
Version:
Vidal Web Components
108 lines • 5.01 kB
JavaScript
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 { styles } from './vidal-prisca-preview.styles';
let VidalPriscaPreview = class VidalPriscaPreview extends LitElement {
constructor() {
super(...arguments);
this.priscaOpener = () => window.open('', '_blank');
this.alertsPreview = [];
}
openPrisca() {
this.priscaOpener();
}
requestSecurisation(prescription) {
if (prescription && this.sendSecurisation) {
this.sendSecurisation(prescription).then(async (response) => {
const domParser = new DOMParser();
const alertXml = await response.text();
const feed = domParser.parseFromString(alertXml, 'text/xml');
this.alertsPreview = [
this.getMaxAlert(Array.from(feed.getElementsByTagName('vidal:maxContraIndicationSeverity'))),
this.getMaxAlert(Array.from(feed.getElementsByTagName('vidal:maxAllergySeverity'))),
this.getMaxAlert(Array.from(feed.getElementsByTagName('vidal:maxDrugDrugInteractionsSeverity'))),
this.getMaxAlert(Array.from(feed.getElementsByTagName('vidal:maxPhysicoChemicalSeverity'))),
this.getMaxAlert(Array.from(feed.getElementsByTagName('vidal:maxPrecautionSeverity'))),
this.getMaxAlert(Array.from(feed.getElementsByTagName('vidal:maxRedundantInteractionsSeverity'))),
this.getMaxAlert(Array.from(feed.getElementsByTagName('vidal:maxPosologySeverity'))),
this.getMaxAlert(Array.from(feed.getElementsByTagName('vidal:maxProcreationSeverity'))),
]
.map((x) => {
var _a, _b;
return {
label: (_a = x.textContent) !== null && _a !== void 0 ? _a : '',
level: (_b = x.getAttribute('severity')) !== null && _b !== void 0 ? _b : '',
};
})
.filter((x) => !!x)
.filter((value, index, self) => self.indexOf(value) === index)
.sort((element1, element2) => SeverityLevel.levelOf(element2.level) -
SeverityLevel.levelOf(element1.level));
});
}
}
getMaxAlert(alerts) {
return alerts.sort((alert1, alert2) => {
const severity1 = SeverityLevel.levelOf(alert1.getAttribute('severity'));
const severity2 = SeverityLevel.levelOf(alert2.getAttribute('severity'));
return severity2 - severity1;
})[0];
}
render() {
return html `
<div>
<div class="alerts">
${this.alertsPreview
.filter((alert) => alert.level !== SeverityLevel.NO_ALERT.label)
.map((alert) => html `<span class="alert" title="${alert.level}"
>${alert.label}</span
>`)}
</div>
<button @click=${() => this.openPrisca()}>
Voir l'analyse détaillée
</button>
</div>
`;
}
};
VidalPriscaPreview.styles = styles;
__decorate([
property({ attribute: false })
], VidalPriscaPreview.prototype, "priscaOpener", void 0);
__decorate([
property({ attribute: false })
], VidalPriscaPreview.prototype, "sendSecurisation", void 0);
__decorate([
state()
], VidalPriscaPreview.prototype, "alertsPreview", void 0);
VidalPriscaPreview = __decorate([
customElement('vidal-prisca-preview')
], VidalPriscaPreview);
export { VidalPriscaPreview };
class SeverityLevel {
constructor(level, label) {
this.level = level;
this.label = label;
}
static levelOf(label) {
var _a;
return ((_a = [
SeverityLevel.NO_ALERT,
SeverityLevel.LEVEL_1,
SeverityLevel.LEVEL_2,
SeverityLevel.LEVEL_3,
SeverityLevel.LEVEL_4,
].filter((severityLevel) => severityLevel.label === label)[0].level) !== null && _a !== void 0 ? _a : 0);
}
}
SeverityLevel.NO_ALERT = new SeverityLevel(0, 'NO_ALERT');
SeverityLevel.LEVEL_1 = new SeverityLevel(1, 'LEVEL_1');
SeverityLevel.LEVEL_2 = new SeverityLevel(2, 'LEVEL_2');
SeverityLevel.LEVEL_3 = new SeverityLevel(3, 'LEVEL_3');
SeverityLevel.LEVEL_4 = new SeverityLevel(4, 'LEVEL_4');
//# sourceMappingURL=vidal-prisca-preview.js.map