// EJI API for Google Sheets: Medical. Paste this whole file into Extensions > Apps Script // (replace what is there), save, then reload the sheet. Every formula starts with EJI_: type =EJI_ in a cell to see them, or use // EJI API > Insert formula… One sheet needs only this one script; to add an area, copy a new script that has it and paste over this one. // ===== EJI API core: one menu for every EJI family in this sheet (Finance, Accounting, Medical, ...) ===== /** @OnlyCurrentDoc */ // Google asks for this sheet only, not for all your Google Sheets // Every family part below registers itself with a function ejiFamily__(); nothing here depends on file order. var EJI_CATALOG_ = [{"family":"Medical","name":"EJI_MED_PRICE","doc":"MRP of a pack in rupees. Works on a column of up to 50 medicines.","example":"=EJI_MED_PRICE(\"DOLO 650 MG TABLET 15\")","params":[{"name":"medicine","desc":"pack name, search text or pack id, or a range of them"}]},{"family":"Medical","name":"EJI_MED_PRICE_PER_UNIT","doc":"MRP per unit (per tablet, per ml, ...).","example":"=EJI_MED_PRICE_PER_UNIT(\"dolo 650\")","params":[{"name":"medicine","desc":"pack name, search text or pack id, or a range of them"}]},{"family":"Medical","name":"EJI_MED_INFO","doc":"One detail of a pack: \"composition\", \"company\", \"packSize\", \"dosageForm\", \"brand\", \"ceilingPrice\", \"priceControlled\", \"priceFlag\", \"month\", \"id\".","example":"=EJI_MED_INFO(\"dolo 650\", \"composition\")","params":[{"name":"medicine","desc":"pack name, search text or pack id, or a range of them"},{"name":"field","desc":"the detail to show"}]},{"family":"Medical","name":"EJI_MED_SEARCH","doc":"Table of packs whose name or composition contains the text, brand matches first.","example":"=EJI_MED_SEARCH(\"paracetamol 650\", 50)","params":[{"name":"query","desc":"at least 2 characters"},{"name":"limit","desc":"optional, up to 100 (default 25)"}]},{"family":"Medical","name":"EJI_MED_SUBSTITUTES","doc":"Table of other brands with the same composition and form, cheapest per unit first, with the saving. =EJI_MED_SUBSTITUTES(\"dolo 650\") Packs whose NPPA price looks wrong are left out. Same composition is not always interchangeable; a doctor or pharmacist decides.","example":"=EJI_MED_SUBSTITUTES(\"dolo 650\")","params":[{"name":"medicine","desc":"pack name, search text or pack id"},{"name":"limit","desc":"optional, up to 100 (default 20)"}]},{"family":"Medical","name":"EJI_MED_CHEAPEST","doc":"The cheapest pack (per unit) with the same composition and form, or \"\" when there is none cheaper.","example":"=EJI_MED_CHEAPEST(\"dolo 650\")","params":[{"name":"medicine","desc":"pack name, search text or pack id, or a range of them"}]},{"family":"Medical","name":"EJI_MED_SALT","doc":"Table of every pack of a salt (or salt combination), cheapest per unit first.","example":"=EJI_MED_SALT(\"PARACETAMOL\", \"TABLET\")","params":[{"name":"salt","desc":"salt name; the closest match from the NPPA list is used"},{"name":"form","desc":"optional dosage form, e.g. TABLET, SYRUP, INJECTION"},{"name":"limit","desc":"optional, up to 500 (default 100)"}]},{"family":"Medical","name":"EJI_MED_SALTS","doc":"Table of salts and combinations whose name contains the text, with their number of packs.","example":"=EJI_MED_SALTS(\"metformin\")","params":[{"name":"query","desc":"text to look for"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_CEILING","doc":"Table of NPPA ceiling prices with the Gazette S.O. number and date.","example":"=EJI_MED_CEILING(\"paracetamol\")","params":[{"name":"formulation","desc":"formulation name as NPPA lists it"}]},{"family":"Medical","name":"EJI_MED_COMPANY_PACKS","doc":"Table of every pack a company has filed with NPPA.","example":"=EJI_MED_COMPANY_PACKS(\"IPCA LABORATORIES LTD\")","params":[{"name":"company","desc":"the name as =EJI_MED_COMPANIES shows it; the first match is used"},{"name":"limit","desc":"optional, up to 500 (default 200)"}]},{"family":"Medical","name":"EJI_MED_COMPANIES","doc":"Table of companies whose name contains the text, with their packs and brands.","example":"=EJI_MED_COMPANIES(\"cipla\")","params":[{"name":"query","desc":"text to look for"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_IS_ESSENTIAL","doc":"\"Yes\" when the medicine is in the National List of Essential Medicines 2022, otherwise \"No\". A column works.","example":"=EJI_MED_IS_ESSENTIAL(\"metformin\")","params":[{"name":"medicine","desc":"medicine (salt) name, or a range of them"}]},{"family":"Medical","name":"EJI_MED_NLEM","doc":"Table of NLEM 2022 entries for a medicine: number, medicine, level, dosage forms, section.","example":"=EJI_MED_NLEM(\"paracetamol\")","params":[{"name":"medicine","desc":"pack name, a shorter text such as dolo 650, or a pack id; a column of medicines works"}]},{"family":"Medical","name":"EJI_MED_BANNED","doc":"Table of prohibited or restricted drugs and FDCs naming every part of a combination, with the Gazette notification. =EJI_MED_BANNED(\"nimesulide + paracetamol\"). A match points to a notification; check its exact strengths and form.","example":"=EJI_MED_BANNED(\"nimesulide + paracetamol\")","params":[{"name":"combination","desc":"drugs joined with +, e.g. nimesulide + paracetamol"}]},{"family":"Medical","name":"EJI_MED_BATCH_ALERT","doc":"CDSCO alert for a batch: \"Not of standard quality (SEP-2026)\", \"Spurious (...)\" or \"\" when the batch is not in the alerts. =EJI_MED_BATCH_ALERT(\"pan 40\", \"B12345\"). No alert does not prove a batch was tested.","example":"=EJI_MED_BATCH_ALERT(\"pan 40\", \"B12345\")","params":[{"name":"medicine","desc":"pack name, a shorter text such as dolo 650, or a pack id; a column of medicines works"},{"name":"batch","desc":"batch number from the pack"}]},{"family":"Medical","name":"EJI_MED_ALERTS","doc":"Table of CDSCO alerts for a medicine or brand, newest first.","example":"=EJI_MED_ALERTS(\"paracetamol\")","params":[{"name":"medicine","desc":"pack name, a shorter text such as dolo 650, or a pack id; a column of medicines works"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_SCHEDULE","doc":"The Drugs Rules schedules that name a drug: \"X\", \"H1\", \"H\", \"H2\" (brand with QR code), joined, or \"\" if none. A column works. =EJI_MED_SCHEDULE(\"alprazolam\") gives \"H1\". A drug not named can still need a prescription.","example":"=EJI_MED_SCHEDULE(\"alprazolam\")","params":[{"name":"drug","desc":"drug name"}]},{"family":"Medical","name":"EJI_MED_US_RECALLS","doc":"Table of US FDA drug recalls (openFDA), newest first. =EJI_MED_US_RECALLS(\"metformin\") or =EJI_MED_US_RECALLS(\"\", TRUE) for Indian firms.","example":"=EJI_MED_US_RECALLS(\"metformin\")","params":[{"name":"query","desc":"text to look for"},{"name":"indiaOnly","desc":"indiaOnly"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_INSURER_ICR","doc":"Health incurred claims ratio (%) of an insurer for its latest year, from IRDAI. A column of insurers works. =EJI_MED_INSURER_ICR(\"star health\"). The ratio is claims incurred / net earned premium, not the share of claims settled.","example":"=EJI_MED_INSURER_ICR(\"star health\")","params":[{"name":"insurer","desc":"insurer's name, or a column of names"}]},{"family":"Medical","name":"EJI_MED_INSURANCE_PRODUCTS","doc":"Table of IRDAI-approved health insurance products.","example":"=EJI_MED_INSURANCE_PRODUCTS(\"arogya\", \"star\")","params":[{"name":"query","desc":"text to look for"},{"name":"insurer","desc":"insurer's name, or a column of names"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_DEVICE_PRICES","doc":"Table of NPPA ceiling prices of coronary stents and knee implants (per unit, before GST).","example":"=EJI_MED_DEVICE_PRICES(\"stent\")","params":[{"name":"query","desc":"text to look for"}]},{"family":"Medical","name":"EJI_MED_CGHS_RATE","doc":"CGHS rate of a test or procedure: a CGHS code (\"LB125\") or a name (\"lipid profile\", first match). A column works. What CGHS pays empanelled hospitals; a private patient may be charged differently.","example":"=EJI_MED_CGHS_RATE(\"lipid profile\", 1, \"nabh\", \"general\")","params":[{"name":"item","desc":"CGHS code or name, or a range of them"},{"name":"tier","desc":"optional city tier 1, 2 or 3 (default 1)"},{"name":"hospital","desc":"optional \"nabh\" (default), \"non_nabh\" or \"super_speciality\""},{"name":"ward","desc":"optional \"general\" (default), \"semi_private\" or \"private\""}]},{"family":"Medical","name":"EJI_MED_CGHS_RATES","doc":"Table of CGHS items matching a name, with code, specialty and rate.","example":"=EJI_MED_CGHS_RATES(\"mri\", 2)","params":[{"name":"query","desc":"text to look for"},{"name":"tier","desc":"optional: city tier 1, 2 or 3"},{"name":"hospital","desc":"optional: NABH or non-NABH"},{"name":"ward","desc":"optional: general, semi-private or private"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_HOSPITALS","doc":"Table of CGHS empanelled hospitals in a city, optionally with a speciality. =EJI_MED_HOSPITALS(\"Jaipur\", \"Cardiology\") Call the hospital before going; empanelment changes often.","example":"=EJI_MED_HOSPITALS(\"Jaipur\", \"Cardiology\")","params":[{"name":"city","desc":"city name"},{"name":"speciality","desc":"optional: speciality"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_ICD11","doc":"Table of ICD-11 codes and titles for a condition (WHO ICD-11 MMS, unchanged).","example":"=EJI_MED_ICD11(\"type 2 diabetes\")","params":[{"name":"query","desc":"text to look for"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_ICD11_TITLE","doc":"The ICD-11 title of a code. A column of codes works.","example":"=EJI_MED_ICD11_TITLE(\"5A11\")","params":[{"name":"code","desc":"ICD-11 code, or a column of codes"}]},{"family":"Medical","name":"EJI_MED_LOINC","doc":"Table of LOINC codes for a lab test (active codes). =EJI_MED_LOINC(\"glucose serum\") This material contains content from LOINC (http://loinc.org), copyright Regenstrief Institute, Inc.","example":"=EJI_MED_LOINC(\"glucose serum\")","params":[{"name":"query","desc":"text to look for"},{"name":"limit","desc":"optional: how many rows at most"}]},{"family":"Medical","name":"EJI_MED_AS_OF","doc":"The month NPPA's prices are for, e.g. \"Sep-2026\".","example":"=EJI_MED_AS_OF()","params":[]},{"family":"Medical","name":"EJI_MED","doc":"Any field of any EJI API Medical answer: a path after /api/med and a field. Leave the field empty to see every field.","example":"=EJI_MED(\"v1/medicines/search?q=dolo 650\", \"0.mrp\")","params":[{"name":"path","desc":"API path after /api/med, e.g. v1/medicines/search?q=dolo"},{"name":"field","desc":"field of the answer, e.g. 0.mrp; leave empty to see them all"}]}]; function ejiFamilies_() { var out = []; if (typeof ejiFamily_fin_ === "function") out.push(ejiFamily_fin_()); if (typeof ejiFamily_acc_ === "function") out.push(ejiFamily_acc_()); if (typeof ejiFamily_med_ === "function") out.push(ejiFamily_med_()); return out; } function onOpen() { var ui = SpreadsheetApp.getUi(); var menu = ui.createMenu("EJI API") .addItem("Insert formula…", "ejiFormulaSidebar") .addItem("Add a formula guide tab", "ejiFormulaGuide") .addItem("Refresh values", "ejiRefresh") .addSeparator(); ejiFamilies_().forEach(function (f) { var sub = ui.createMenu(f.name); f.items.forEach(function (it) { sub.addItem(it[0], it[1]); }); menu.addSubMenu(sub); }); menu.addToUi(); } // Forget cached answers (every family) and enter the EJI formulas of the current sheet again, so their values are fetched // fresh. Nothing else is touched: other formulas and everything typed stay exactly as they are. function ejiRefresh() { ejiFamilies_().forEach(function (f) { if (f.bump) f.bump(); }); var sheet = SpreadsheetApp.getActiveSheet(); var formulas = sheet.getDataRange().getFormulas(); var mine = new RegExp("\\b(" + "EJI_[A-Z0-9_]+|TALLY_[A-Z0-9_]+|MED_[A-Z0-9_]+|IPOLISTGAIN|STOCKCLOSE|INDEXCLOSE|NAVRETURN|IPOSTATUS|FUNDNAME|IPOPRICE|FUNDNAV|IPODATE|IPOSUBS|INDEXPE|IPOLOT|IPOGMP|NAVON|FXINR|EJI" + ")\\s*\\(", "i"); var runs = []; formulas.forEach(function (row, i) { var j = 0; while (j < row.length) { if (!mine.test(row[j])) { j++; continue; } var start = j; while (j < row.length && mine.test(row[j])) j++; runs.push({ r: i + 1, c: start + 1, f: row.slice(start, j) }); } }); if (!runs.length) { SpreadsheetApp.getUi().alert("There are no EJI formulas on this sheet."); return; } // Clear, wait, enter again. Whatever happens in between, the formulas that were cleared are put back (finally). var cleared = [], failed = []; try { runs.forEach(function (x) { sheet.getRange(x.r, x.c, 1, x.f.length).clearContent(); cleared.push(x); }); SpreadsheetApp.flush(); } finally { cleared.forEach(function (x) { try { sheet.getRange(x.r, x.c, 1, x.f.length).setFormulas([x.f]); } catch (e) { failed.push(x.r + ":" + x.c); } }); } if (failed.length) throw new Error("Could not enter the formulas again at row:column " + failed.join(", ") + ". Use Edit > Undo to bring them back."); } // ---- fields: one value out of an API answer ---- // A dotted field of the answer: latestNav, returns.1y, 0.nav (first item), -1.nav (last), *.nav (every item: a column). function ejiField_(data, field) { var parts = (field == null || String(field).trim() === "") ? [] : String(field).trim().split("."); function walk(v, i) { if (i >= parts.length) return v; var k = parts[i]; if (k === "*") { if (!Array.isArray(v)) throw new Error("* needs a list"); return v.map(function (x) { return walk(x, i + 1); }); } if (Array.isArray(v)) { if (!/^-?\d+$/.test(k)) throw new Error("This is a list: use 0 for the first item, -1 for the last, or * for all"); var x = v[Number(k) < 0 ? v.length + Number(k) : Number(k)]; if (x === undefined) throw new Error("The list has " + v.length + " items, no item " + k); return walk(x, i + 1); } if (v === null || typeof v !== "object" || !Object.prototype.hasOwnProperty.call(v, k)) { var here = (v !== null && typeof v === "object") ? Object.keys(v).slice(0, 12).join(", ") : ""; throw new Error("No field " + parts.slice(0, i + 1).join(".") + (here ? ". Fields here: " + here : "")); } return walk(v[k], i + 1); } function cell(x) { if (x === null || x === undefined) return ""; if (typeof x === "object") throw new Error("That is a group of fields; pick one inside it: " + Object.keys(x).slice(0, 6).join(", ")); return x; } var v = walk(data, 0); if (Array.isArray(v)) return v.length ? v.map(function (x) { return [cell(x)]; }) : ""; return cell(v); } // Every single-value field of an answer as [field, sample]: objects opened, a list as "0.x" and "*.x". function ejiListFields_(data) { var out = []; function visit(v, at, depth) { if (out.length >= 300) return; if (v === null || typeof v !== "object") { if (at) out.push([at, v === null || v === undefined ? "" : v]); return; } if (depth > 5) return; if (Array.isArray(v)) { if (!v.length) return; var pre = at ? at + "." : ""; if (v[0] !== null && typeof v[0] === "object" && !Array.isArray(v[0])) { Object.keys(v[0]).forEach(function (k) { var x = v[0][k]; if (x === null || typeof x !== "object") out.push([pre + "*." + k, x === null ? "" : x]); }); } else if (v[0] === null || typeof v[0] !== "object") out.push([pre + "*", v[0]]); visit(v[0], pre + "0", depth + 1); return; } Object.keys(v).forEach(function (k) { visit(v[k], at ? at + "." + k : k, depth + 1); }); } visit(data, "", 0); return out; } // What a cell shows when the field is left empty: the fields to choose from. function ejiPickHint_(data) { var names = ejiListFields_(data).map(function (f) { return f[0]; }).filter(function (n) { return n.indexOf("*") < 0; }); return names.length ? "Pick a field: " + names.slice(0, 40).join(", ") + (names.length > 40 ? ", …" : "") : "This answer has no fields"; } // ---- Insert formula… (a sidebar) and the formula guide tab ---- var EJI_SIDEBAR_ = "\n\n\n\n
\n
\n \n
\n
\n\n

\n\n\n"; function ejiFormulaSidebar() { var fields = []; ejiFamilies_().forEach(function (f) { (f.fields || []).forEach(function (s) { fields.push({ fn: s.fn, label: f.name + ": " + s.label, arg: s.arg, example: s.example }); }); }); var data = "var CAT = " + JSON.stringify(EJI_CATALOG_) + ", FIELDS = " + JSON.stringify(fields) + ";"; var html = HtmlService.createHtmlOutput(EJI_SIDEBAR_.replace("/*DATA*/", data.replace(/ 0) { var m = (n - 1) % 26; s = String.fromCharCode(65 + m) + s; n = Math.floor((n - 1) / 26); } return s; } // Called by the sidebar: a table at the selected cell. A header row, then one row per value, each formula reading its row's value. function ejiInsertTable(fn, keysText, fields) { var spec = ejiFieldSpec_(fn); var keys = String(keysText == null ? "" : keysText).split(/[,;\n]+/).map(function (k) { return k.trim(); }).filter(Boolean); if (!keys.length) keys = [spec.example]; fields = (fields || []).map(String).filter(function (f) { return /^[A-Za-z0-9_.\-]+$/.test(f); }); if (!fields.length) throw new Error("Tick at least one field"); var cell = SpreadsheetApp.getActiveRange().getCell(1, 1), sh = cell.getSheet(), r0 = cell.getRow(), c0 = cell.getColumn(); var col = ejiColName_(c0); var rows = [[spec.arg].concat(fields)]; keys.forEach(function (k, i) { rows.push([k].concat(fields.map(function (f) { return "=" + fn + "(" + col + (r0 + 1 + i) + ", \"" + f + "\")"; }))); }); var range = sh.getRange(r0, c0, rows.length, rows[0].length); range.setValues(rows); sh.getRange(r0, c0, 1, rows[0].length).setFontWeight("bold"); return range.getA1Notation(); } // A tab named "EJI formulas" listing every formula of this script, what it gives and an example to copy. function ejiFormulaGuide() { var ss = SpreadsheetApp.getActive(); var sh = ss.getSheetByName("EJI formulas") || ss.insertSheet("EJI formulas"); sh.clear(); var rows = [["Area", "Formula", "What it gives", "Example (copy into a cell)"]].concat(EJI_CATALOG_.map(function (c) { return [c.family, c.name + "(" + c.params.map(function (p) { return p.name; }).join(", ") + ")", c.doc, c.example ? "'" + c.example : ""]; })); sh.getRange(1, 1, rows.length, 4).setValues(rows); sh.getRange(1, 1, 1, 4).setFontWeight("bold"); sh.setFrozenRows(1); sh.autoResizeColumns(1, 2); sh.setColumnWidth(3, 460); sh.setColumnWidth(4, 320); ss.setActiveSheet(sh); } // ===== end of the core ===== // EJI API Medical for Google Sheets. This is the Medical part of an EJI API script. // Menu "EJI API" > Medical > Set API key stores your medical key (med_...) in this script's properties, never in a cell. // Prices are as filed with NPPA (Pharma Sahi Daam) for the month =EJI_MED_AS_OF() shows. Reference information only, not // medical advice: ask a doctor or pharmacist before changing a medicine. Source: NPPA, Government of India. // // A medicine can be given as a pack name ("DOLO 650 MG TABLET 15"), a shorter text ("dolo 650"; the first match is used, // an exact pack name wins) or a pack id from =EJI_MED_SEARCH (the text with @ signs). var EJI_MED_BASE_ = "https://med.ejiapi.com/api/med"; var EJI_MED_CACHE_SECONDS_ = 21600; // 6 hours (NPPA's figures change monthly); EJI API > Medical > Refresh values fetches fresh answers var EJI_MED_MAX_CELLS_ = 50; // a range of medicines is looked up one by one, so it is capped // ---------- plumbing ---------- function ejiMed_(path, noKey) { var props = PropertiesService.getScriptProperties(); var cacheKey = "m" + (props.getProperty("EJI_MED_CACHE_V") || "0") + ":" + path; if (cacheKey.length > 240) cacheKey = cacheKey.slice(0, 200) + Utilities.base64Encode(Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, cacheKey)); var cache = CacheService.getScriptCache(); var hit = cache.get(cacheKey); if (hit) return JSON.parse(hit); var headers = { "X-Client": "sheets" }; if (!noKey) { var key = props.getProperty("EJI_MED_KEY"); if (!key) throw new Error("Set your key first: menu EJI API > Medical > Set API key"); headers["X-API-Key"] = key; } var res; try { res = UrlFetchApp.fetch(EJI_MED_BASE_ + path, { method: "get", headers: headers, muteHttpExceptions: true }); } catch (e) { throw new Error("Could not reach EJI (" + e.message + "). Run EJI API > Medical > Check setup once to give the script permission."); } var text = res.getContentText(), code = res.getResponseCode(); if (code !== 200) { var detail = text; try { detail = JSON.parse(text).detail || text; } catch (e) {} throw new Error(code === 401 ? "The API key was not accepted. EJI API > Medical > Set API key." : String(detail).slice(0, 160)); } if (text.length < 90000) cache.put(cacheKey, text, EJI_MED_CACHE_SECONDS_); // a cached value may not exceed 100 KB return JSON.parse(text); } function ejiMedQs_(params) { var parts = []; for (var k in params) if (params[k] !== "" && params[k] !== undefined && params[k] !== null) parts.push(k + "=" + encodeURIComponent(params[k])); return parts.length ? "?" + parts.join("&") : ""; } function ejiMedText_(v, field) { var s = v === undefined || v === null ? "" : String(v).trim(); if (s.length < 2) throw new Error(field + " needs at least 2 characters"); return s; } function ejiMedLimit_(v, def, max) { if (v === undefined || v === null || v === "") return def; var n = Math.floor(Number(v)); if (!(n >= 1)) throw new Error("limit must be a number from 1 to " + max); return Math.min(n, max); } // One pack for a name, a search text or a pack id. function ejiMedPack_(medicine) { var s = ejiMedText_(medicine, "medicine"); if (/^[0-9@]+$/.test(s) && s.indexOf("@") > 0) return ejiMed_("/v1/medicines/pack" + ejiMedQs_({ id: s })).data; var rows = ejiMed_("/v1/medicines/search" + ejiMedQs_({ q: s, limit: 25 })).data; if (!rows.length) throw new Error("No medicine matches '" + s + "'"); var want = s.toUpperCase().replace(/\s+/g, " "); for (var i = 0; i < rows.length; i++) if (rows[i].name === want) return rows[i]; return rows[0]; } // A cell or a range: one value, or one value per cell (a column), blanks kept blank. function ejiMedEach_(medicine, fn) { if (!Array.isArray(medicine)) return fn(ejiMedPack_(medicine)); var cells = []; medicine.forEach(function (row) { (Array.isArray(row) ? row : [row]).forEach(function (x) { cells.push(x); }); }); if (cells.filter(function (x) { return x !== "" && x !== null; }).length > EJI_MED_MAX_CELLS_) throw new Error("Up to " + EJI_MED_MAX_CELLS_ + " medicines per formula; split the range"); return cells.map(function (x) { if (x === "" || x === null) return [""]; try { return [fn(ejiMedPack_(x))]; } catch (e) { return ["#N/A " + e.message.slice(0, 60)]; } }); } var EJI_MED_PACK_HEAD_ = ["Pack", "Composition", "Form", "Pack size", "Company", "MRP", "MRP per unit", "Ceiling price", "Price-controlled", "Price check", "Pack id"]; var EJI_MED_FLAG_ = { missing: "No MRP in NPPA's list", low: "Looks too low (likely a filing error)", high: "Looks too high (check pack and unit)" }; function ejiMedPackRow_(p) { return [p.name, p.composition, p.dosageForm || "", p.packSize || "", p.company || "", p.mrp === null ? "" : p.mrp, p.mrpPerUnit === null ? "" : p.mrpPerUnit, p.ceilingPrice === null ? "" : p.ceilingPrice, p.priceControlled ? "Yes" : "No", p.priceFlag ? EJI_MED_FLAG_[p.priceFlag] || p.priceFlag : "", p.id]; } // ---------- medicines ---------- /** MRP of a pack in rupees. Works on a column of up to 50 medicines. =EJI_MED_PRICE("DOLO 650 MG TABLET 15") * @param {string|Array} medicine pack name, search text or pack id, or a range of them * @customfunction */ function EJI_MED_PRICE(medicine) { return ejiMedEach_(medicine, function (p) { return p.mrp === null || p.priceFlag === "missing" ? "" : p.mrp; }); } /** MRP per unit (per tablet, per ml, ...). =EJI_MED_PRICE_PER_UNIT("dolo 650") * @param {string|Array} medicine pack name, search text or pack id, or a range of them * @customfunction */ function EJI_MED_PRICE_PER_UNIT(medicine) { return ejiMedEach_(medicine, function (p) { return p.mrpPerUnit === null ? "" : p.mrpPerUnit; }); } /** One detail of a pack: "composition", "company", "packSize", "dosageForm", "brand", "ceilingPrice", "priceControlled", "priceFlag", "month", "id". * =EJI_MED_INFO("dolo 650", "composition") * @param {string|Array} medicine pack name, search text or pack id, or a range of them * @param {string} field the detail to show * @customfunction */ function EJI_MED_INFO(medicine, field) { var f = String(field == null ? "" : field).trim(); if (!f) return ejiPickHint_(ejiMedPack_(Array.isArray(medicine) ? [].concat.apply([], medicine).filter(String)[0] : medicine)); return ejiMedEach_(medicine, function (p) { if (!Object.prototype.hasOwnProperty.call(p, f)) throw new Error("No field " + f + ". Fields here: " + Object.keys(p).join(", ")); var v = p[f]; return v === null || v === undefined ? "" : (typeof v === "boolean" ? (v ? "Yes" : "No") : v); }); } /** Table of packs whose name or composition contains the text, brand matches first. =EJI_MED_SEARCH("paracetamol 650", 50) * @param {string} query at least 2 characters * @param {number} limit optional, up to 100 (default 25) * @customfunction */ function EJI_MED_SEARCH(query, limit) { var rows = ejiMed_("/v1/medicines/search" + ejiMedQs_({ q: ejiMedText_(query, "query"), limit: ejiMedLimit_(limit, 25, 100) })).data; return [EJI_MED_PACK_HEAD_].concat(rows.map(ejiMedPackRow_)); } // ---------- substitutes ---------- /** Table of other brands with the same composition and form, cheapest per unit first, with the saving. =EJI_MED_SUBSTITUTES("dolo 650") * Packs whose NPPA price looks wrong are left out. Same composition is not always interchangeable; a doctor or pharmacist decides. * @param {string} medicine pack name, search text or pack id * @param {number} limit optional, up to 100 (default 20) * @customfunction */ function EJI_MED_SUBSTITUTES(medicine, limit) { var me = ejiMedPack_(medicine); var r = ejiMed_("/v1/medicines/substitutes" + ejiMedQs_({ id: me.id, limit: ejiMedLimit_(limit, 20, 100) })); var out = [EJI_MED_PACK_HEAD_.concat(["Saving per unit %"]), ejiMedPackRow_(me).concat(["(this pack)"])]; r.data.forEach(function (p) { out.push(ejiMedPackRow_(p).concat([p.savingPct === null ? "" : p.savingPct])); }); return out; } /** The cheapest pack (per unit) with the same composition and form, or "" when there is none cheaper. =EJI_MED_CHEAPEST("dolo 650") * @param {string|Array} medicine pack name, search text or pack id, or a range of them * @customfunction */ function EJI_MED_CHEAPEST(medicine) { return ejiMedEach_(medicine, function (p) { var s = ejiMed_("/v1/medicines/substitutes" + ejiMedQs_({ id: p.id, limit: 1 })).data[0]; return s && p.mrpPerUnit !== null && s.mrpPerUnit < p.mrpPerUnit ? s.name : ""; }); } // ---------- salts ---------- /** Table of every pack of a salt (or salt combination), cheapest per unit first. =EJI_MED_SALT("PARACETAMOL", "TABLET") * @param {string} salt salt name; the closest match from the NPPA list is used * @param {string} form optional dosage form, e.g. TABLET, SYRUP, INJECTION * @param {number} limit optional, up to 500 (default 100) * @customfunction */ function EJI_MED_SALT(salt, form, limit) { var found = ejiMed_("/v1/salts/search" + ejiMedQs_({ q: ejiMedText_(salt, "salt"), limit: 1 })).data; if (!found.length) throw new Error("No salt matches '" + salt + "'"); var d = ejiMed_("/v1/salts/" + found[0].saltId + ejiMedQs_({ form: form, limit: ejiMedLimit_(limit, 100, 500) })).data; return [EJI_MED_PACK_HEAD_].concat(d.packs.map(ejiMedPackRow_)); } /** Table of salts and combinations whose name contains the text, with their number of packs. =EJI_MED_SALTS("metformin") * @param {string} query text to look for * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_SALTS(query, limit) { var rows = ejiMed_("/v1/salts/search" + ejiMedQs_({ q: ejiMedText_(query, "query"), limit: ejiMedLimit_(limit, 25, 100) })).data; return [["Salt", "Packs", "Salt id"]].concat(rows.map(function (s) { return [s.name, s.packs, s.saltId]; })); } // ---------- ceiling prices ---------- /** Table of NPPA ceiling prices with the Gazette S.O. number and date. =EJI_MED_CEILING("paracetamol") * @param {string} formulation formulation name as NPPA lists it * @customfunction */ function EJI_MED_CEILING(formulation) { var rows = ejiMed_("/v1/ceiling-prices" + ejiMedQs_({ q: ejiMedText_(formulation, "formulation") })).data; return [["Formulation", "Strength", "Ceiling price", "Per", "S.O. no.", "S.O. date"]].concat(rows.map(function (r) { return [r.formulation, r.strength, r.ceilingPrice === null ? "" : r.ceilingPrice, r.per || "", r.soNo || "", r.soDate || ""]; })); } // ---------- companies ---------- /** Table of every pack a company has filed with NPPA. =EJI_MED_COMPANY_PACKS("IPCA LABORATORIES LTD") * @param {string} company the name as =EJI_MED_COMPANIES shows it; the first match is used * @param {number} limit optional, up to 500 (default 200) * @customfunction */ function EJI_MED_COMPANY_PACKS(company, limit) { var found = ejiMed_("/v1/companies/search" + ejiMedQs_({ q: ejiMedText_(company, "company"), limit: 1 })).data; if (!found.length) throw new Error("No company matches '" + company + "'"); var rows = ejiMed_("/v1/companies/packs" + ejiMedQs_({ name: found[0].company, limit: ejiMedLimit_(limit, 200, 500) })).data; return [EJI_MED_PACK_HEAD_].concat(rows.map(ejiMedPackRow_)); } /** Table of companies whose name contains the text, with their packs and brands. =EJI_MED_COMPANIES("cipla") * @param {string} query text to look for * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_COMPANIES(query, limit) { var rows = ejiMed_("/v1/companies/search" + ejiMedQs_({ q: ejiMedText_(query, "query"), limit: ejiMedLimit_(limit, 25, 100) })).data; return [["Company", "Packs", "Brands"]].concat(rows.map(function (c) { return [c.company, c.packs, c.brands]; })); } // ---------- essential medicines, banned FDCs, devices ---------- /** "Yes" when the medicine is in the National List of Essential Medicines 2022, otherwise "No". A column works. * =EJI_MED_IS_ESSENTIAL("metformin") * @param {string|Array} medicine medicine (salt) name, or a range of them * @customfunction */ function EJI_MED_IS_ESSENTIAL(medicine) { var one = function (m) { if (m === "" || m === null) return ""; return ejiMed_("/v1/nlem" + ejiMedQs_({ q: ejiMedText_(m, "medicine"), limit: 1 })).data.length ? "Yes" : "No"; }; if (!Array.isArray(medicine)) return one(medicine); var cells = []; medicine.forEach(function (row) { (Array.isArray(row) ? row : [row]).forEach(function (x) { cells.push(x); }); }); if (cells.length > EJI_MED_MAX_CELLS_) throw new Error("Up to " + EJI_MED_MAX_CELLS_ + " medicines per formula; split the range"); return cells.map(function (x) { try { return [one(x)]; } catch (e) { return ["#N/A " + e.message.slice(0, 60)]; } }); } /** Table of NLEM 2022 entries for a medicine: number, medicine, level, dosage forms, section. =EJI_MED_NLEM("paracetamol") * @param {string} medicine pack name, a shorter text such as dolo 650, or a pack id; a column of medicines works * @customfunction */ function EJI_MED_NLEM(medicine) { var rows = ejiMed_("/v1/nlem" + ejiMedQs_({ q: ejiMedText_(medicine, "medicine") })).data; return [["No.", "Medicine", "Level", "Dosage forms", "Section"]].concat(rows.map(function (e) { return [e.code, e.medicine, e.level, e.forms.join("; "), e.section || ""]; })); } /** Table of prohibited or restricted drugs and FDCs naming every part of a combination, with the Gazette notification. * =EJI_MED_BANNED("nimesulide + paracetamol"). A match points to a notification; check its exact strengths and form. * @param {string} combination drugs joined with +, e.g. nimesulide + paracetamol * @customfunction */ function EJI_MED_BANNED(combination) { var rows = ejiMed_("/v1/banned" + ejiMedQs_({ q: ejiMedText_(combination, "combination") })).data; if (!rows.length) return "Not found in CDSCO's prohibited or restricted lists"; return [["Drug or combination", "Status", "Notification", "Date", "Note"]].concat(rows.map(function (e) { return [e.name, e.status, e.notification || "", e.date || "", e.note || ""]; })); } /** CDSCO alert for a batch: "Not of standard quality (SEP-2026)", "Spurious (...)" or "" when the batch is not in the * alerts. =EJI_MED_BATCH_ALERT("pan 40", "B12345"). No alert does not prove a batch was tested. * @param {string} medicine pack name, a shorter text such as dolo 650, or a pack id; a column of medicines works * @param {string} batch batch number from the pack * @customfunction */ function EJI_MED_BATCH_ALERT(medicine, batch) { var b = ejiMedText_(batch, "batch"); var r = ejiMed_("/v1/alerts" + ejiMedQs_({ q: medicine ? ejiMedText_(medicine, "medicine") : "", batch: b, limit: 5 })).data; return r.length ? r.map(function (x) { return (x.kind === "spurious" ? "Spurious" : "Not of standard quality") + " (" + x.month + ")"; }).join("; ") : ""; } /** Table of CDSCO alerts for a medicine or brand, newest first. =EJI_MED_ALERTS("paracetamol") * @param {string} medicine pack name, a shorter text such as dolo 650, or a pack id; a column of medicines works * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_ALERTS(medicine, limit) { var r = ejiMed_("/v1/alerts" + ejiMedQs_({ q: ejiMedText_(medicine, "medicine"), limit: ejiMedLimit_(limit, 50, 500) })).data; return [["Month", "Alert", "Medicine", "Brand", "Batch", "Mfg", "Expiry", "Maker", "Failure", "Reported by"]].concat(r.map(function (x) { return [x.month, x.kind, x.product, x.brand || "", x.batch || "", x.mfg || "", x.expiry || "", x.maker || "", x.reason || "", x.reportedBy || ""]; })); } /** The Drugs Rules schedules that name a drug: "X", "H1", "H", "H2" (brand with QR code), joined, or "" if none. A column works. * =EJI_MED_SCHEDULE("alprazolam") gives "H1". A drug not named can still need a prescription. * @param {string} drug drug name * @customfunction */ function EJI_MED_SCHEDULE(drug) { var one = function (d) { if (d === "" || d === null) return ""; var r = ejiMed_("/v1/schedules" + ejiMedQs_({ q: ejiMedText_(d, "drug") })).data, seen = []; r.forEach(function (x) { if (seen.indexOf(x.schedule) < 0) seen.push(x.schedule); }); return seen.join(", "); }; if (!Array.isArray(drug)) return one(drug); var cells = []; drug.forEach(function (row) { (Array.isArray(row) ? row : [row]).forEach(function (x) { cells.push(x); }); }); if (cells.length > EJI_MED_MAX_CELLS_) throw new Error("Up to " + EJI_MED_MAX_CELLS_ + " drugs per formula; split the range"); return cells.map(function (x) { try { return [one(x)]; } catch (e) { return ["#N/A " + e.message.slice(0, 60)]; } }); } /** Table of US FDA drug recalls (openFDA), newest first. =EJI_MED_US_RECALLS("metformin") or =EJI_MED_US_RECALLS("", TRUE) for Indian firms. * @param {string} query text to look for * @param {string} indiaOnly indiaOnly * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_US_RECALLS(query, indiaOnly, limit) { var q = query === undefined || query === null ? "" : String(query).trim(); if (q.length < 3 && indiaOnly !== true) throw new Error("Give a salt or product (3+ letters), or TRUE for Indian firms"); var r = ejiMed_("/v1/us/recalls" + ejiMedQs_({ q: q.length >= 3 ? q : "", india: indiaOnly === true ? "true" : "", limit: ejiMedLimit_(limit, 25, 100) })).data; return [["Reported", "Class", "Product", "Firm", "Country", "Reason", "Status"]].concat(r.map(function (x) { return [x.reportDate || "", x.classification || "", x.product || "", x.firm || "", x.country || "", x.reason || "", x.status || ""]; })); } /** Health incurred claims ratio (%) of an insurer for its latest year, from IRDAI. A column of insurers works. * =EJI_MED_INSURER_ICR("star health"). The ratio is claims incurred / net earned premium, not the share of claims settled. * @param {string} insurer insurer's name, or a column of names * @customfunction */ function EJI_MED_INSURER_ICR(insurer) { var all = ejiMed_("/v1/insurance/insurers").data; var one = function (n) { if (n === "" || n === null) return ""; var w = String(n).toLowerCase().split(/\s+/).filter(String); for (var i = 0; i < all.length; i++) { var name = all[i].insurer.toLowerCase(); if (w.every(function (x) { return name.indexOf(x) >= 0; })) return all[i].icrPct === null ? "" : all[i].icrPct; } return "#N/A no such insurer"; }; if (!Array.isArray(insurer)) return one(insurer); var out = []; insurer.forEach(function (row) { (Array.isArray(row) ? row : [row]).forEach(function (x) { out.push([one(x)]); }); }); return out; } /** Table of IRDAI-approved health insurance products. =EJI_MED_INSURANCE_PRODUCTS("arogya", "star") * @param {string} query text to look for * @param {string} insurer insurer's name, or a column of names * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_INSURANCE_PRODUCTS(query, insurer, limit) { var r = ejiMed_("/v1/insurance/products" + ejiMedQs_({ q: query, insurer: insurer, limit: ejiMedLimit_(limit, 50, 200) })).data; return [["Product", "Insurer", "Type", "Approved", "UIN", "Wording"]].concat(r.map(function (x) { return [x.name, x.insurer, x.type || "", x.approved || "", x.uin, x.wordingUrl || ""]; })); } /** Table of NPPA ceiling prices of coronary stents and knee implants (per unit, before GST). =EJI_MED_DEVICE_PRICES("stent") * @param {string} query text to look for * @customfunction */ function EJI_MED_DEVICE_PRICES(query) { var rows = ejiMed_("/v1/device-prices" + ejiMedQs_({ q: query })).data; return [["Device", "Item", "Material / type", "Ceiling price", "S.O.", "S.O. date", "Valid to"]].concat(rows.map(function (d) { return [d.group, d.item, d.detail || "", d.ceilingPrice, d.soNo, d.soDate, d.validTo || ""]; })); } // ---------- CGHS rates and hospitals ---------- /** CGHS rate of a test or procedure: a CGHS code ("LB125") or a name ("lipid profile", first match). A column works. * What CGHS pays empanelled hospitals; a private patient may be charged differently. * =EJI_MED_CGHS_RATE("lipid profile", 1, "nabh", "general") * @param {string|Array} item CGHS code or name, or a range of them * @param {number} tier optional city tier 1, 2 or 3 (default 1) * @param {string} hospital optional "nabh" (default), "non_nabh" or "super_speciality" * @param {string} ward optional "general" (default), "semi_private" or "private" * @customfunction */ function EJI_MED_CGHS_RATE(item, tier, hospital, ward) { var p = { tier: tier || 1, hospital: hospital || "nabh", ward: ward || "general", limit: 1 }; var one = function (x) { if (x === "" || x === null) return ""; var r = ejiMed_("/v1/rates/search" + ejiMedQs_(Object.assign({ q: ejiMedText_(x, "item") }, p))).data; if (!r.length) throw new Error("No CGHS item matches '" + x + "'"); return r[0].rate === null ? (r[0].rateText || "") : r[0].rate; }; if (!Array.isArray(item)) return one(item); var cells = []; item.forEach(function (row) { (Array.isArray(row) ? row : [row]).forEach(function (x) { cells.push(x); }); }); if (cells.length > EJI_MED_MAX_CELLS_) throw new Error("Up to " + EJI_MED_MAX_CELLS_ + " items per formula; split the range"); return cells.map(function (x) { try { return [one(x)]; } catch (e) { return ["#N/A " + e.message.slice(0, 60)]; } }); } /** Table of CGHS items matching a name, with code, specialty and rate. =EJI_MED_CGHS_RATES("mri", 2) * @param {string} query text to look for * @param {number} tier optional: city tier 1, 2 or 3 * @param {string} hospital optional: NABH or non-NABH * @param {string} ward optional: general, semi-private or private * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_CGHS_RATES(query, tier, hospital, ward, limit) { var r = ejiMed_("/v1/rates/search" + ejiMedQs_({ q: ejiMedText_(query, "query"), tier: tier || 1, hospital: hospital || "nabh", ward: ward || "general", limit: ejiMedLimit_(limit, 50, 200) })).data; return [["Code", "Item", "Specialty", "Rate"]].concat(r.map(function (x) { return [x.code, x.name, x.specialty || "", x.rate === null ? (x.rateText || "") : x.rate]; })); } /** Table of CGHS empanelled hospitals in a city, optionally with a speciality. =EJI_MED_HOSPITALS("Jaipur", "Cardiology") * Call the hospital before going; empanelment changes often. * @param {string} city city name * @param {string} speciality optional: speciality * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_HOSPITALS(city, speciality, limit) { var r = ejiMed_("/v1/hospitals/search" + ejiMedQs_({ city: ejiMedText_(city, "city"), speciality: speciality, limit: ejiMedLimit_(limit, 100, 200) })).data; return [["Hospital", "Address", "City", "Tier", "Specialities", "Phone", "Valid to", "ABDM facility id"]].concat(r.map(function (h) { return [h.name, h.address || "", h.city || "", h.tier || "", h.specialities || "", h.phone || "", h.validTo || "", h.hfrId || ""]; })); } // ---------- codes ---------- /** Table of ICD-11 codes and titles for a condition (WHO ICD-11 MMS, unchanged). =EJI_MED_ICD11("type 2 diabetes") * @param {string} query text to look for * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_ICD11(query, limit) { var r = ejiMed_("/v1/icd11/search" + ejiMedQs_({ q: ejiMedText_(query, "query"), limit: ejiMedLimit_(limit, 25, 200) })).data; return [["Code", "Title", "Kind", "Chapter"]].concat(r.map(function (x) { return [x.code || "", x.title, x.kind || "", x.chapter || ""]; })); } /** The ICD-11 title of a code. A column of codes works. =EJI_MED_ICD11_TITLE("5A11") * @param {string} code ICD-11 code, or a column of codes * @customfunction */ function EJI_MED_ICD11_TITLE(code) { var one = function (c) { if (c === "" || c === null) return ""; try { return ejiMed_("/v1/icd11/code/" + encodeURIComponent(String(c).trim())).data.title; } catch (e) { return "#N/A no such code"; } }; if (!Array.isArray(code)) return one(code); var cells = []; code.forEach(function (row) { (Array.isArray(row) ? row : [row]).forEach(function (x) { cells.push(x); }); }); if (cells.length > EJI_MED_MAX_CELLS_) throw new Error("Up to " + EJI_MED_MAX_CELLS_ + " codes per formula; split the range"); return cells.map(function (x) { return [one(x)]; }); } /** Table of LOINC codes for a lab test (active codes). =EJI_MED_LOINC("glucose serum") * This material contains content from LOINC (http://loinc.org), copyright Regenstrief Institute, Inc. * @param {string} query text to look for * @param {number} limit optional: how many rows at most * @customfunction */ function EJI_MED_LOINC(query, limit) { var r = ejiMed_("/v1/loinc/search" + ejiMedQs_({ q: ejiMedText_(query, "query"), limit: ejiMedLimit_(limit, 25, 200) })).data; return [["LOINC", "Long name", "Component", "System", "Scale", "Class"]].concat(r.map(function (x) { return [x.code, x.longName || "", x.component || "", x.system || "", x.scale || "", x["class"] || ""]; })); } // ---------- freshness ---------- /** The month NPPA's prices are for, e.g. "Sep-2026". =EJI_MED_AS_OF() * @customfunction */ function EJI_MED_AS_OF() { return ejiMed_("/status", true).data.asOf || ""; } function ejiMedSetKey() { var ui = SpreadsheetApp.getUi(); var r = ui.prompt("EJI Medical", "Paste your medical API key (it starts with med_). Get a free beta key at med.ejiapi.com/get-key", ui.ButtonSet.OK_CANCEL); if (r.getSelectedButton() !== ui.Button.OK) return; var key = r.getResponseText().trim(); if (!/^med_[A-Za-z0-9_-]{10,}$/.test(key)) { ui.alert("That does not look like a medical key (med_...)."); return; } PropertiesService.getScriptProperties().setProperty("EJI_MED_KEY", key); ejiMedRefresh(); ui.alert("Key saved. Try =EJI_MED_PRICE(\"dolo 650\") in any cell."); } function ejiMedCheck() { var ui = SpreadsheetApp.getUi(); try { var asOf = EJI_MED_AS_OF(); var key = PropertiesService.getScriptProperties().getProperty("EJI_MED_KEY"); if (!key) { ui.alert("EJI is reachable (prices for " + asOf + "). Now set your API key."); return; } var p = ejiMedPack_("dolo 650"); ui.alert("All set. Prices are for " + asOf + ". Example: " + p.name + " costs Rs " + p.mrp + "."); } catch (e) { ui.alert("Not working yet: " + e.message); } } // Kept for menus made before 21 Nov 2026: the core's EJI API > Refresh values does this for every area. function ejiMedRefresh() { ejiMedBump_(); SpreadsheetApp.getActiveSpreadsheet().toast("Formulas fetch fresh values from now on. Edit a cell or reload the sheet to recalculate.", "EJI Medical"); } /** Any field of any EJI API Medical answer: a path after /api/med and a field. Leave the field empty to see every field. =EJI_MED("v1/medicines/search?q=dolo 650", "0.mrp") * @param {string} path API path after /api/med, e.g. v1/medicines/search?q=dolo * @param {string} field field of the answer, e.g. 0.mrp; leave empty to see them all * @customfunction */ function EJI_MED(path, field) { var p = String(path == null ? "" : path).trim().replace(/^\/+/, ""); if (!p || /\.\.|%2e|%2f|%5c|[\s<>"'`\\]/i.test(p.replace(/ /g, ""))) throw new Error("Give an API path such as v1/medicines/search?q=dolo, without .. or encoded slashes"); var data = ejiMed_("/" + p.replace(/ /g, "%20")).data; return (field == null || String(field).trim() === "") ? ejiPickHint_(data) : ejiField_(data, field); } // ---------- family registration (the core's EJI API menu shows these under Medical) ---------- function ejiFamily_med_() { return { id: "med", name: "Medical", bump: function () { ejiMedBump_(); }, items: [["Set API key", "ejiMedSetKey"], ["Check setup", "ejiMedCheck"]], fields: [{ fn: "EJI_MED_INFO", label: "A medicine's details", arg: "Medicines", example: "dolo 650", data: function (v) { return ejiMedPack_(v); } }] }; } function ejiMedBump_() { var props = PropertiesService.getScriptProperties(); props.setProperty("EJI_MED_CACHE_V", String(Number(props.getProperty("EJI_MED_CACHE_V") || "0") + 1)); } // ---- old names (before 21 Nov 2026), kept so sheets made with them keep working ---- function MED_PRICE() { return EJI_MED_PRICE.apply(null, arguments); } function MED_PRICE_PER_UNIT() { return EJI_MED_PRICE_PER_UNIT.apply(null, arguments); } function MED_INFO() { return EJI_MED_INFO.apply(null, arguments); } function MED_SEARCH() { return EJI_MED_SEARCH.apply(null, arguments); } function MED_SUBSTITUTES() { return EJI_MED_SUBSTITUTES.apply(null, arguments); } function MED_CHEAPEST() { return EJI_MED_CHEAPEST.apply(null, arguments); } function MED_SALT() { return EJI_MED_SALT.apply(null, arguments); } function MED_SALTS() { return EJI_MED_SALTS.apply(null, arguments); } function MED_CEILING() { return EJI_MED_CEILING.apply(null, arguments); } function MED_COMPANY_PACKS() { return EJI_MED_COMPANY_PACKS.apply(null, arguments); } function MED_COMPANIES() { return EJI_MED_COMPANIES.apply(null, arguments); } function MED_IS_ESSENTIAL() { return EJI_MED_IS_ESSENTIAL.apply(null, arguments); } function MED_NLEM() { return EJI_MED_NLEM.apply(null, arguments); } function MED_BANNED() { return EJI_MED_BANNED.apply(null, arguments); } function MED_BATCH_ALERT() { return EJI_MED_BATCH_ALERT.apply(null, arguments); } function MED_ALERTS() { return EJI_MED_ALERTS.apply(null, arguments); } function MED_SCHEDULE() { return EJI_MED_SCHEDULE.apply(null, arguments); } function MED_US_RECALLS() { return EJI_MED_US_RECALLS.apply(null, arguments); } function MED_INSURER_ICR() { return EJI_MED_INSURER_ICR.apply(null, arguments); } function MED_INSURANCE_PRODUCTS() { return EJI_MED_INSURANCE_PRODUCTS.apply(null, arguments); } function MED_DEVICE_PRICES() { return EJI_MED_DEVICE_PRICES.apply(null, arguments); } function MED_CGHS_RATE() { return EJI_MED_CGHS_RATE.apply(null, arguments); } function MED_CGHS_RATES() { return EJI_MED_CGHS_RATES.apply(null, arguments); } function MED_HOSPITALS() { return EJI_MED_HOSPITALS.apply(null, arguments); } function MED_ICD11() { return EJI_MED_ICD11.apply(null, arguments); } function MED_ICD11_TITLE() { return EJI_MED_ICD11_TITLE.apply(null, arguments); } function MED_LOINC() { return EJI_MED_LOINC.apply(null, arguments); } function MED_AS_OF() { return EJI_MED_AS_OF.apply(null, arguments); }