UNPKG

@vidal-community/vidal-web-components

Version:

Vidal Web Components

486 lines 35.9 kB
import '@open-wc/testing'; import { assert, fixture } from '@open-wc/testing'; import { VidalEquivalents } from './vidal-equivalents'; import { Drug } from '../model/drug'; import { Unit } from '../model/unit'; import { ConversionRate } from '../model/conversion-rate'; import { PrescriptionLine } from '../model/prescription-line'; import { EquivalentDrug } from '../model/equivalent-drug'; import { Package } from '../model/package'; import { Product } from '../model/product'; import { MultiComposableDrugData } from '../model/multi-composable-drug-data'; import { ActivePrinciple } from '../model/active-principle'; suite('vidal-equivalent component', () => { test('is defined', () => { const el = document.createElement('vidal-equivalent'); assert.instanceOf(el, VidalEquivalents); }); suite('prescribable equivalence', () => { test('should display UCD prescriptible name', async () => { var _a, _b, _c; const el = document.createElement('vidal-equivalent'); const drug = new Drug('vidal://ucd/8070', 'DOLIPRANE 1000MG CPR'); drug.prescribable = createPrescribable(); const prescriptionLine = createPrescriptionLine({ drug: drug }); el.availableFormularyDrugUris = ['vidal://ucd/2080']; el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/2080', 'DOLIPRANE 500MG CPR', []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'DOLIPRANE 1000MG CPR'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Niv. 2'); assert.include((_c = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _c === void 0 ? void 0 : _c.querySelector('.formulary').textContent.trim(), 'DOLIPRANE 500MG CPR'); }); test('should display prescribable name for package', async () => { var _a, _b, _c; const el = document.createElement('vidal-equivalent'); const drug = new Drug('vidal://package/24103', 'MUSE 250 µg Bâton p us urétral B/1'); drug.prescribable = createPrescribable(); const prescriptionLine = createPrescriptionLine({ drug: drug }); el.availableFormularyDrugUris = ['vidal://ucd/6225']; el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/6225', 'MUSE 1000µG BATON', []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'MUSE 250 µg Bâton p us urétral B/1'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Niv. 2'); assert.include((_c = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _c === void 0 ? void 0 : _c.querySelector('.formulary').textContent.trim(), 'MUSE 1000µG BATON'); }); test('should display prescribable name for UCD', async () => { var _a, _b, _c; const el = document.createElement('vidal-equivalent'); const drug = new Drug('vidal://ucd/8070', 'DOLIPRANE 1000MG CPR'); drug.prescribable = createPrescribable(); const prescriptionLine = createPrescriptionLine({ drug: drug }); el.availableFormularyDrugUris = ['vidal://ucd/2080']; el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/2080', 'DOLIPRANE 500MG CPR', []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription').textContent.trim(), 'DOLIPRANE 1000MG CPR'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Niv. 2'); assert.include((_c = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _c === void 0 ? void 0 : _c.querySelector('.formulary').textContent.trim(), 'DOLIPRANE 500MG CPR'); }); test('should display prescribable name for vmp', async () => { var _a, _b, _c; const el = document.createElement('vidal-equivalent'); const drug = new Drug('vidal://vmp/4009', 'ALPROSTADIL 500 µg bâton p us urétral'); drug.prescribable = createPrescribable(); const prescriptionLine = createPrescriptionLine({ drug: drug }); el.availableFormularyDrugUris = ['vidal://ucd/6223']; el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/6223', 'MUSE 250µG BATON', []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'ALPROSTADIL 500 µg bâton p us urétral'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Niv. 2'); assert.include((_c = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _c === void 0 ? void 0 : _c.querySelector('.formulary').textContent.trim(), 'MUSE 250µG BATON'); }); test('should display prescribable name for product', async () => { var _a, _b, _c; const el = document.createElement('vidal-equivalent'); const drug = new Drug('vidal://product/200581', 'ILOPROST TEVA 100 µg/ml sol diluer p perf'); drug.prescribable = createPrescribable(); const prescriptionLine = createPrescriptionLine({ drug: drug }); el.availableFormularyDrugUris = ['vidal://ucd/10034']; el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/10034', 'ILOMEDINE 0,1MG/1ML AMP0,5ML', []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'ILOPROST TEVA 100 µg/ml sol diluer p perf'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Niv. 2'); assert.include((_c = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _c === void 0 ? void 0 : _c.querySelector('.formulary').textContent.trim(), 'ILOMEDINE 0,1MG/1ML AMP0,5ML'); }); test('should add test-data attribute for end-to-end tests', async () => { var _a; const el = document.createElement('vidal-equivalent'); const drug = new Drug('vidal://ucd/8070', 'DOLIPRANE 1000MG CPR'); const prescriptionLine = createPrescriptionLine({ drug: drug }); el.availableFormularyDrugUris = ['vidal://ucd/2080']; el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/2080', 'DOLIPRANE 500MG CPR', []), ]); const renderedElement = await fixture(el); assert.exists((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector("div[data-test='substitution-vidal-ucd-8070-level-1']")); }); }); suite('direct equivalence', () => { test('should display pas au livret for UCD that is not available', async () => { var _a, _b; const el = document.createElement('vidal-equivalent'); const ucd = new Drug('vidal://ucd/007', 'PARAMOXICILICLINE'); const prescriptionLine = createPrescriptionLine({ drug: ucd }); el.associatedFormularyAndEquivalents.set(prescriptionLine, []); el.prescriptionLines = [prescriptionLine]; const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'PARAMOXICILICLINE'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Pas au livret'); }); test('should display UCD name', async () => { var _a, _b; const el = document.createElement('vidal-equivalent'); el.availableFormularyDrugUris = ['vidal://ucd/007']; const drug = new Drug('vidal://ucd/007', 'PARAMOXICILICLINE'); const prescriptionLine = createPrescriptionLine({ drug: drug }); el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug(drug.uri, drug.name, []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'PARAMOXICILICLINE'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Niv. 1'); }); test('should display package name and formulary UCD', async () => { var _a, _b; const el = document.createElement('vidal-equivalent'); el.availableFormularyDrugUris = ['vidal://ucd/007']; const pack = new Package('vidal://package/118', 'PARAMOXICILICLINE 2G PDR CP 10F', new Drug('vidal://ucd/007', 'PARAMOXICILICLINE')); const prescriptionLine = createPrescriptionLine({ drug: pack }); el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/007', 'PARAMOXICILICLINE', []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'PARAMOXICILICLINE 2G PDR CP 10F'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'PARAMOXICILICLINE'); }); test('should display pas au livret for package', async () => { var _a, _b; const el = document.createElement('vidal-equivalent'); const pack = new Package('vidal://package/118', 'PARAMOXICILICLINE 2G PDR CP 10F', new Drug('vidal://ucd/007', 'PARAMOXICILICLINE')); const prescriptionLine = createPrescriptionLine({ drug: pack }); el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, []); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'PARAMOXICILICLINE 2G PDR CP 10F'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Pas au livret'); }); test('should display pas au livret for product', async () => { var _a, _b; const el = document.createElement('vidal-equivalent'); const product = new Product([new Drug('vidal://ucd/007', 'PARAMOXICILICLINE')], 'vidal://product/3660', 'CHLORURE DE MAGNESIUM LAVOISIER 10 % (1 g/10 ml) sol inj en ampoule I'); const prescriptionLine = createPrescriptionLine({ drug: product }); el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, []); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'CHLORURE DE MAGNESIUM LAVOISIER 10 % (1 g/10 ml) sol inj en ampoule I'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'Pas au livret'); }); test('should display one product UCD for product', async () => { var _a, _b; const el = document.createElement('vidal-equivalent'); const product = new Product([ new Drug('vidal://ucd/007', 'PARAMOXICILICLINE'), new Drug('vidal://ucd/12662', 'MAGNESIUM'), ], 'vidal://product/3660', 'CHLORURE DE MAGNESIUM LAVOISIER 10 % (1 g/10 ml) sol inj en ampoule I'); const prescriptionLine = createPrescriptionLine({ drug: product }); el.prescriptionLines = [prescriptionLine]; el.availableFormularyDrugUris = ['vidal://ucd/007']; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/007', 'PARAMOXICILICLINE', []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'CHLORURE DE MAGNESIUM LAVOISIER 10 % (1 g/10 ml) sol inj en ampoule I'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'PARAMOXICILICLINE'); }); test('should display all product UCDs for product', async () => { var _a, _b, _c; const el = document.createElement('vidal-equivalent'); const product = new Product([ new Drug('vidal://ucd/007', 'PARAMOXICILICLINE'), new Drug('vidal://ucd/12662', 'MAGNESIUM'), ], 'vidal://product/3660', 'CHLORURE DE MAGNESIUM LAVOISIER 10 % (1 g/10 ml) sol inj en ampoule I'); const prescriptionLine = createPrescriptionLine({ drug: product }); el.prescriptionLines = [prescriptionLine]; el.availableFormularyDrugUris = ['vidal://ucd/007', 'vidal://ucd/12662']; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/007', 'PARAMOXICILICLINE', []), new EquivalentDrug('vidal://ucd/12662', 'MAGNESIUM', []), ]); const renderedElement = await fixture(el); assert.equal((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.prescription-drug-name').textContent.trim(), 'CHLORURE DE MAGNESIUM LAVOISIER 10 % (1 g/10 ml) sol inj en ampoule I'); assert.include((_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.formulary').textContent.trim(), 'PARAMOXICILICLINE'); assert.exists((_c = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _c === void 0 ? void 0 : _c.querySelector('[data-test=more-or-less-equivalents]')); }); }); suite('should display dose', () => { test('empty for a package', async () => { var _a, _b, _c, _d; const el = document.createElement('vidal-equivalent'); const drug = new Drug('vidal://package/24103', 'MUSE 250 µg Bâton p us urétral B/1'); drug.prescribable = createPrescribable(); const prescriptionLine = createPrescriptionLine({ drug: drug }); el.availableFormularyDrugUris = ['vidal://ucd/6225']; el.prescriptionLines = [prescriptionLine]; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/6225', 'MUSE 1000µG BATON', []), ]); const renderedElement = await fixture(el); assert.exists((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.dose')); assert.equal((_d = (_c = (_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.dose')) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.trim(), ''); }); test('error message for a product', async () => { var _a, _b, _c, _d; const el = document.createElement('vidal-equivalent'); const product = new Product([ new Drug('vidal://ucd/007', 'PARAMOXICILICLINE'), new Drug('vidal://ucd/12662', 'MAGNESIUM'), ], 'vidal://product/3660', 'CHLORURE DE MAGNESIUM LAVOISIER 10 % (1 g/10 ml) sol inj en ampoule I'); const prescriptionLine = createPrescriptionLine({ drug: product, error: true, }); el.prescriptionLines = [prescriptionLine]; el.availableFormularyDrugUris = ['vidal://ucd/007', 'vidal://ucd/12662']; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/007', 'PARAMOXICILICLINE', []), new EquivalentDrug('vidal://ucd/12662', 'MAGNESIUM', []), ]); const renderedElement = await fixture(el); assert.exists((_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.dose')); assert.equal((_d = (_c = (_b = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _b === void 0 ? void 0 : _b.querySelector('.dose')) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.trim(), 'Unité non retrouvée dans le référentiel Vidal'); }); }); suite('should display converted dose', () => { test('for a product', async () => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; const el = document.createElement('vidal-equivalent'); const conversionRate = new ConversionRate(new Unit('vidal://unit/57', 'mg'), new Unit('vidal://unit/35', 'g'), 1, 1000); const product = new Product([ new Drug('vidal://ucd/007', 'PARAMOXICILICLINE'), new Drug('vidal://ucd/12662', 'MAGNESIUM'), ], 'vidal://product/3660', 'CHLORURE DE MAGNESIUM LAVOISIER 10 % (1 g/10 ml) sol inj en ampoule I'); product.prescribable = createPrescribable({ refUnit: new Unit('vidal://unit/35', 'g'), }); const prescriptionLine = createPrescriptionLine({ drug: product, dose: 99, unit: { name: 'mg', uri: 'vidal://unit/57', conversionRates: [conversionRate], isDispensingUnit: false, }, }); el.prescriptionLines = [prescriptionLine]; el.availableFormularyDrugUris = ['vidal://ucd/12784']; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/007', 'MAGNESIUM CHL 10% REN A.B', [ new Unit('vidal://unit/35', 'g', [conversionRate]), new Unit('vidal://unit/57', 'mg', [conversionRate]), ]), ]); const renderedElement = await fixture(el); assert.include((_c = (_b = (_a = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _a === void 0 ? void 0 : _a.querySelector('.formulary')) === null || _b === void 0 ? void 0 : _b.textContent) === null || _c === void 0 ? void 0 : _c.trim(), 'MAGNESIUM CHL 10% REN A.B'); assert.include((_f = (_e = (_d = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _d === void 0 ? void 0 : _d.querySelector('.formulary')) === null || _e === void 0 ? void 0 : _e.textContent) === null || _f === void 0 ? void 0 : _f.trim(), '0.099 g'); assert.include((_j = (_h = (_g = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _g === void 0 ? void 0 : _g.querySelector('.formulary')) === null || _h === void 0 ? void 0 : _h.textContent) === null || _j === void 0 ? void 0 : _j.trim(), '99 mg'); assert.exists((_k = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _k === void 0 ? void 0 : _k.querySelector('.dose')); assert.equal((_o = (_m = (_l = getVidalEquivalentFormShadowRoot(renderedElement)) === null || _l === void 0 ? void 0 : _l.querySelector('.dose')) === null || _m === void 0 ? void 0 : _m.textContent) === null || _o === void 0 ? void 0 : _o.trim(), '99 mg'); }); test('for a package with multiple prescribable ucds in formulary', async () => { var _a, _b, _c, _d, _e, _f, _g, _h, _j; const el = document.createElement('vidal-equivalent'); const conversionRateMgToG = new ConversionRate(new Unit('vidal://unit/57', 'mg'), new Unit('vidal://unit/35', 'g'), 1, 1000); const conversionRateMgToMl = new ConversionRate(new Unit('vidal://unit/57', 'mg'), new Unit('vidal://unit/60', 'ml'), 1, 50); const conversionRateMgToFl = new ConversionRate(new Unit('vidal://unit/57', 'mg'), new Unit('vidal://unit/138', 'fl'), 1, 2000); const pack = new Package('vidal://package/1732', 'AMOXICILLINE PANPHARMA 2 g Pdr sol inj 10Fl', new Drug('vidal://ucd/10448', 'AMOXICILLINE PAN 2G INJ FL')); pack.prescribable = createPrescribable({ refUnit: new Unit('vidal://unit/57', 'mg'), }); const conversionRateArray = [ conversionRateMgToG, conversionRateMgToMl, conversionRateMgToFl, ]; const prescriptionLine = createPrescriptionLine({ drug: pack, dose: 99, unit: { name: 'flacon', uri: 'vidal://unit/138', conversionRates: conversionRateArray, isDispensingUnit: false, }, }); el.prescriptionLines = [prescriptionLine]; el.availableFormularyDrugUris = ['vidal://ucd/5165', 'vidal://ucd/9860']; el.associatedFormularyAndEquivalents.set(prescriptionLine, [ new EquivalentDrug('vidal://ucd/5165', 'AMOXICILLINE PAN 1G FL+AMP', [ new Unit('vidal://unit/57', 'mg', conversionRateArray), new Unit('vidal://unit/60', 'ml', conversionRateArray), new Unit('vidal://unit/35', 'g', conversionRateArray), new Unit('vidal://unit/138', 'fl', conversionRateArray), ]), new EquivalentDrug('vidal://ucd/9860', 'XYLLOMAC 500MG IM IV FL', [ new Unit('vidal://unit/57', 'mg', conversionRateArray), new Unit('vidal://unit/60', 'ml', conversionRateArray), new Unit('vidal://unit/138', 'fl', conversionRateArray), ]), ]); const renderedElement = await fixture(el); const vidalEquivalentForm = getVidalEquivalentFormShadowRoot(renderedElement); assert.include((_b = (_a = vidalEquivalentForm === null || vidalEquivalentForm === void 0 ? void 0 : vidalEquivalentForm.querySelector('.formulary')) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim(), 'AMOXICILLINE PAN 1G FL+AMP'); assert.include((_c = vidalEquivalentForm === null || vidalEquivalentForm === void 0 ? void 0 : vidalEquivalentForm.querySelector('.formulary')) === null || _c === void 0 ? void 0 : _c.textContent, '198000 mg'); assert.include((_e = (_d = vidalEquivalentForm === null || vidalEquivalentForm === void 0 ? void 0 : vidalEquivalentForm.querySelector('.formulary')) === null || _d === void 0 ? void 0 : _d.textContent) === null || _e === void 0 ? void 0 : _e.trim(), '3960 ml'); assert.include((_g = (_f = vidalEquivalentForm === null || vidalEquivalentForm === void 0 ? void 0 : vidalEquivalentForm.querySelector('.formulary')) === null || _f === void 0 ? void 0 : _f.textContent) === null || _g === void 0 ? void 0 : _g.trim(), '198 g'); assert.include((_j = (_h = vidalEquivalentForm === null || vidalEquivalentForm === void 0 ? void 0 : vidalEquivalentForm.querySelector('.formulary')) === null || _h === void 0 ? void 0 : _h.textContent) === null || _j === void 0 ? void 0 : _j.trim(), '99 fl'); }); }); suite('should populate prescriptions with indicators', () => { test('for prescription lines without equivalents', async () => { const alcoolModifieCooper = new PrescriptionLine(new Product([], 'vidal://product/468', 'ALCOOL MODIFIE COOPER sol p appl cut')); const doliprane = new PrescriptionLine(new Drug('vidal://ucd/8070', 'DOLIPRANE 1000MG CPR')); const xanax = new PrescriptionLine(new Package('vidal://package/123', 'LE XANAXE')); const xanaxEquivalent = new EquivalentDrug('vidal://ucd/123', 'LE XANAXE 2', []); const equivalentFormulary = new Map(); equivalentFormulary.set(alcoolModifieCooper, []); equivalentFormulary.set(doliprane, []); equivalentFormulary.set(xanax, [xanaxEquivalent]); const vidalEquivalents = new VidalEquivalents(); vidalEquivalents.fetchingSupplierWithBody = () => fetch('../../components/vidal-substitution/test-resources/searchIdsAggregateIndicatorsProducts.xml'); const result = await vidalEquivalents.hydrateIndicatorsForPrescriptionLineWithoutEquivalents(equivalentFormulary); assert.equal(result.size, 3); assert.sameMembers(alcoolModifieCooper.multiComposableDrugData.indicators, ['16', '19', '73', '74']); assert.sameMembers(doliprane.multiComposableDrugData.indicators, [ '9', '26', '74', '27', '28', '30', ]); assert.notExists(xanax.multiComposableDrugData); }); }); suite('should find multi composable equivalent', () => { test('empty when there are no multiComposableDrugData in prescription line', async () => { const alcoolModifieCooper = new PrescriptionLine(new Product([], 'vidal://product/468', 'ALCOOL MODIFIE COOPER sol p appl cut')); const result = await new VidalEquivalents().findMultiComposableEquivalents(alcoolModifieCooper, undefined); assert.deepEqual(result, []); }); test('empty when there is no ucd for molecule in formulary', async () => { const coRenitec = new PrescriptionLine(new Drug('vidal://ucd/3076', 'CO-RENITEC 20MG/12,5MG CPR 0,02/3MG C')); coRenitec.multiComposableDrugData = new MultiComposableDrugData([], '/molecules/2649'); coRenitec.multiComposableDrugData.activePrinciples = [ new ActivePrinciple(2649, 57, 20.0), new ActivePrinciple(1798, 57, 30.0), ]; const vidalEquivalents = new VidalEquivalents(); vidalEquivalents.availableFormularyDrugUris = []; const result = await vidalEquivalents.findMultiComposableEquivalents(coRenitec, () => fetch('../../components/vidal-substitution/test-resources/ucdsForMoleculesResults.xml')); assert.deepEqual(result, []); }); test('when there are mono composed ucds in formulary for every active principle in the prescription line', async () => { const coRenitec = new PrescriptionLine(new Drug('vidal://ucd/3076', 'CO-RENITEC 20MG/12,5MG CPR 0,02/3MG C')); coRenitec.routeUri = 'vidal://route/38'; coRenitec.multiComposableDrugData = new MultiComposableDrugData(['32', '9', '10'], '/molecules/2649'); coRenitec.multiComposableDrugData.activePrinciples = [ new ActivePrinciple(2649, 57, 20.0), new ActivePrinciple(2649, 57, 20.0), ]; const vidalEquivalents = new VidalEquivalents(); vidalEquivalents.availableFormularyDrugUris = ['vidal://ucd/7248']; const multiComposableEquivalentsResult = await vidalEquivalents.findMultiComposableEquivalents(coRenitec, (url) => sharedMockDataSupplier(url)); assert.equal(multiComposableEquivalentsResult.length, 2); multiComposableEquivalentsResult.forEach((monoComposedEquivalent) => { assert.equal(monoComposedEquivalent.uri, 'vidal://ucd/7248'); assert.equal(monoComposedEquivalent.name, 'ACTIFED RHUME CPR'); assert.deepEqual(monoComposedEquivalent.dose, []); assert.deepEqual(monoComposedEquivalent.units, []); assert.equal(monoComposedEquivalent.divisibility, 1); const multiComposableDrugData = monoComposedEquivalent.multiComposableDrugData; assert.exists(multiComposableDrugData); assert.equal(multiComposableDrugData === null || multiComposableDrugData === void 0 ? void 0 : multiComposableDrugData.relatedMoleculeHref, '/rest/api/product/18728/molecules'); assert.equal(multiComposableDrugData === null || multiComposableDrugData === void 0 ? void 0 : multiComposableDrugData.activePrinciples.length, 1); const activePrinciple = multiComposableDrugData === null || multiComposableDrugData === void 0 ? void 0 : multiComposableDrugData.activePrinciples[0]; assert.equal(activePrinciple === null || activePrinciple === void 0 ? void 0 : activePrinciple.id, 2649); assert.equal(activePrinciple === null || activePrinciple === void 0 ? void 0 : activePrinciple.totalQuantityValue, 500); assert.equal(activePrinciple === null || activePrinciple === void 0 ? void 0 : activePrinciple.totalQuantityValueUnitId, 57); const indicators = multiComposableDrugData === null || multiComposableDrugData === void 0 ? void 0 : multiComposableDrugData.indicators; assert.sameDeepMembers(indicators, [ '9', '10', '26', '27', '28', '29', '30', ]); assert.sameDeepMembers(multiComposableDrugData.routeUris, [ 'vidal://route/38', ]); }); }); test('empty when there are no mono composed ucds in formulary for every active principle in the prescription line', async () => { const coRenitec = new PrescriptionLine(new Drug('vidal://ucd/3076', 'CO-RENITEC 20MG/12,5MG CPR 0,02/3MG C')); coRenitec.routeUri = 'vidal://route/38'; coRenitec.multiComposableDrugData = new MultiComposableDrugData(['32', '9', '10'], '/molecules/2649'); coRenitec.multiComposableDrugData.activePrinciples = [ new ActivePrinciple(2649, 57, 20.0), new ActivePrinciple(2649, 57, 20.0), ]; const vidalEquivalents = new VidalEquivalents(); vidalEquivalents.availableFormularyDrugUris = ['vidal://ucd/7248']; const multiComposableEquivalentsResult = await vidalEquivalents.findMultiComposableEquivalents(coRenitec, (url) => sharedMockDataSupplierTwoActivePrinciples(url)); assert.deepEqual(multiComposableEquivalentsResult, []); }); }); const createPrescriptionLine = (pL) => ({ drug: new Drug('vidal://ucd/default', 'ucd by default'), isDoseValid: function () { return !!(this.dose && this.unit); }, ...pL, }); const createPrescribable = (prescribable) => ({ id: 'vidal://prescribable/default', ...prescribable, }); const getVidalEquivalentFormShadowRoot = (renderedElement) => { return renderedElement.renderRoot.querySelector('vidal-equivalent-form') .shadowRoot; }; function sharedMockDataSupplier(url) { if (url === '/rest/api/ucds/molecules?moleculeIds=2649&substanceTypes=ACTIVE_PRINCIPLE&withChildrens=true&operatorType=AND&page-size=100000') { return fetch('../../components/vidal-substitution/test-resources/ucdsForMoleculesResults.xml'); } if (url === '/rest/api/ucd/7248?aggregate=routes&aggregate=indicators') { return fetch('../../components/vidal-substitution/test-resources/ucd7248WithRouteAndIndicators.xml'); } if (url === '/rest/api/product/18728/molecules') { return fetch('../../components/vidal-substitution/test-resources/ucd7248Molecules.xml'); } if (url === '/rest/api/ucd/7248/packages') { return fetch('../../components/vidal-substitution/test-resources/ucd7248PackagesResult.xml'); } if (url === '/rest/api/package/39052?aggregate=ucdvs') { return fetch('../../components/vidal-substitution/test-resources/ucd7248UcdvResult.xml'); } if (url === '/rest/api/ucdv/2618?aggregate=units&aggregate=molecules') { return fetch('../../components/vidal-substitution/test-resources/ucdv7248UnitAndMolecules.xml'); } return Promise.reject(new Response()); } function sharedMockDataSupplierTwoActivePrinciples(url) { if (url === '/rest/api/ucds/molecules?moleculeIds=2649&substanceTypes=ACTIVE_PRINCIPLE&withChildrens=true&operatorType=AND&page-size=100000') { return fetch('../../components/vidal-substitution/test-resources/ucdsForMoleculesResults.xml'); } if (url === '/rest/api/ucd/7248?aggregate=routes&aggregate=indicators') { return fetch('../../components/vidal-substitution/test-resources/ucd7248WithRouteAndIndicators.xml'); } if (url === '/rest/api/product/18728/molecules') { return fetch('../../components/vidal-substitution/test-resources/ucd7248MoleculesWithTwoActivePrinciples.xml'); } return Promise.reject(new Response()); } }); //# sourceMappingURL=vidal-equivalents_test.js.map