Gravitate Health FHIR Implementation Guide, published by Gravitate Health Project. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/hl7-eu/gravitate-health/ and changes regularly. See the Directory of published versions
Draft as of 2024-06-12 |
{
"resourceType" : "Library",
"id" : "pregnancy-lens",
"meta" : {
"profile" : [
🔗 "http://hl7.eu/fhir/ig/gravitate-health/StructureDefinition/lens"
]
},
"text" : {
"status" : "generated",
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p class=\"res-header-id\"><b>Generated Narrative: Library pregnancy-lens</b></p><a name=\"pregnancy-lens\"> </a><a name=\"hcpregnancy-lens\"> </a><a name=\"pregnancy-lens-en-US\"> </a><h2>Parameters</h2><table class=\"grid\"><tr><td/><td>in</td><td/><td/><td>CodeableConcept</td><td>parameter if it exists</td></tr></table><h2>Contents</h2><p>Lens for pregnancy: (<code>application/javascript</code>)</p><pre><code>let pvData = pv;\nlet htmlData = html;\n\nlet epiData = epi;\nlet ipsData = ips;\n\nlet getSpecification = () => {\n return "1.0.0";\n};\n\nlet annotationProcess = (listOfCategories, enhanceTag, document, response) => {\n listOfCategories.forEach((check) => {\n if (response.includes(check)) {\n let elements = document.getElementsByClassName(check);\n for (let i = 0; i < elements.length; i++) {\n elements[i].classList.add(enhanceTag);\n }\n if (document.getElementsByTagName("head").length > 0) {\n document.getElementsByTagName("head")[0].remove();\n }\n if (document.getElementsByTagName("body").length > 0) {\n response = document.getElementsByTagName("body")[0].innerHTML;\n console.log("Response: " + response);\n } else {\n console.log("Response: " + document.documentElement.innerHTML);\n response = document.documentElement.innerHTML;\n }\n }\n });\n\n if (response == null || response == "") {\n throw new Error(\n "Annotation proccess failed: Returned empty or null response"\n );\n //return htmlData\n } else {\n console.log("Response: " + response);\n return response;\n }\n}\n\nlet annotateHTMLsection = async (listOfCategories, enhanceTag) => {\n let response = htmlData;\n let document;\n\n if (typeof window === "undefined") {\n let jsdom = await import("jsdom");\n let { JSDOM } = jsdom;\n let dom = new JSDOM(htmlData);\n document = dom.window.document;\n return annotationProcess(listOfCategories, enhanceTag, document, response);\n } else {\n document = window.document;\n return annotationProcess(listOfCategories, enhanceTag, document, response);\n }\n};\n\nlet getIPSAge = (birthDate) => {\n let today = new Date();\n let birthDateParsed = new Date(birthDate);\n\n let ageMiliseconds = today - birthDateParsed;\n let age = Math.floor(ageMiliseconds / 31536000000);\n\n return age;\n}\n\nlet enhance = async () => {\n // pregnancyCategory breastfeedingCategory\n // SNOMED SNOMED\n let listOfCategoriesToSearch = ["W78", "77386006", "69840006"]; //"contra-indication-pregancy"]\n\n // Get IPS gender and check if is female\n let gender;\n\n let enhanceTag;\n\n if (ips == "" || ips == null) {\n throw new Error("Failed to load IPS: the LEE is getting a empty IPS");\n }\n ips.entry.forEach((element) => {\n if (element.resource.resourceType == "Patient") {\n gender = element.resource.gender;\n if (gender != "female" || getIPSAge(element.resource.birthDate) >= 75) {\n enhanceTag = "collapsed";\n } else {\n enhanceTag = "highlight";\n }\n }\n });\n\n // ePI traslation from terminology codes to their human redable translations in the sections\n let compositions = 0;\n let categories = [];\n epi.entry.forEach((entry) => {\n if (entry.resource.resourceType == "Composition") {\n compositions++;\n //Iterated through the Condition element searching for conditions\n entry.resource.extension.forEach((element) => {\n \n // Check if the position of the extension[1] is correct\n if (element.extension[1].url == "concept") {\n // Search through the different terminologies that may be avaible to check in the condition\n if (element.extension[1].valueCodeableReference.concept != undefined) {\n element.extension[1].valueCodeableReference.concept.coding.forEach(\n (coding) => {\n console.log("Extension: " + element.extension[0].valueString + ":" + coding.code)\n // Check if the code is in the list of categories to search\n if (listOfCategoriesToSearch.includes(coding.code)) {\n // Check if the category is already in the list of categories\n categories.push(element.extension[0].valueString);\n }\n }\n );\n }\n }\n });\n }\n });\n\n if (compositions == 0) {\n throw new Error('Bad ePI: no category "Composition" found');\n }\n\n if (categories.length == 0) {\n // throw new Error("No categories found", categories);\n return htmlData;\n }\n //Focus (adds highlight class) the html applying every category found\n return await annotateHTMLsection(categories, enhanceTag);\n};\n\nreturn {\n enhance: enhance,\n getSpecification: getSpecification,\n};\n</code></pre></div>"
},
"extension" : [
{
"url" : "http://hl7.eu/fhir/ig/gravitate-health/StructureDefinition/lee-version",
"valueString" : "dev"
}
],
"url" : "http://hl7.eu/fhir/ig/gravitate-health/Library/mock-lib",
"identifier" : [
{
"system" : "http://gravitate-health.lst.tfo.upm.es",
"value" : "pregnancy-lens"
}
],
"version" : "0.1.0",
"name" : "pregnancy-lens",
"_name" : {
"extension" : [
{
"extension" : [
{
"url" : "lang",
"valueCode" : "es"
},
{
"url" : "content",
"valueString" : "Lente para el embarazo"
}
],
"url" : "http://hl7.org/fhir/StructureDefinition/translation"
}
]
},
"title" : "pregnancy-lens",
"_title" : {
"extension" : [
{
"extension" : [
{
"url" : "lang",
"valueCode" : "es"
},
{
"url" : "content",
"valueString" : "Lente para el embarazo"
}
],
"url" : "http://hl7.org/fhir/StructureDefinition/translation"
}
]
},
"status" : "draft",
"experimental" : true,
"type" : {
"coding" : [
{
"code" : "logical-library"
}
]
},
"date" : "2024-06-12T12:23:10.005Z",
"publisher" : "Gravitate Health Project",
"contact" : [
{
"name" : "Gravitate Health Project",
"telecom" : [
{
"system" : "url",
"value" : "https://www.gravitatehealth.eu/"
}
]
},
{
"name" : "Gravitate Health Project",
"telecom" : [
{
"system" : "url",
"value" : "https://www.gravitatehealth.eu/"
}
]
}
],
"description" : "Lens that highlight or collapses pregnancy related information",
"_description" : {
"extension" : [
{
"extension" : [
{
"url" : "lang",
"valueCode" : "es"
},
{
"url" : "content",
"valueString" : "Lente que resalta o colapsa la información relacionada con el embarazo"
}
],
"url" : "http://hl7.org/fhir/StructureDefinition/translation"
}
]
},
"purpose" : "Collapse or highlight pregnancy related information on a preprocessed ePI.",
"_purpose" : {
"extension" : [
{
"extension" : [
{
"url" : "lang",
"valueCode" : "es"
},
{
"url" : "content",
"valueString" : "Colapsar o resaltar la información relacionada con el embarazo en un ePI preprocesado."
}
],
"url" : "http://hl7.org/fhir/StructureDefinition/translation"
}
]
},
"usage" : "You can import this lens directly to your FHIR Server which suports Library Resource type.",
"_usage" : {
"extension" : [
{
"extension" : [
{
"url" : "lang",
"valueCode" : "es"
},
{
"url" : "content",
"valueString" : "Puedes importar esta lente directamente a tu servidor FHIR que soporte el tipo de recurso Library."
}
],
"url" : "http://hl7.org/fhir/StructureDefinition/translation"
}
]
},
"copyright" : "© 2024 Gravitate Health",
"parameter" : [
{
"use" : "in",
"documentation" : "parameter if it exists",
"type" : "CodeableConcept"
}
],
"content" : [
{
"contentType" : "application/javascript",
"data" : "bGV0IHB2RGF0YSA9IHB2OwpsZXQgaHRtbERhdGEgPSBodG1sOwoKbGV0IGVwaURhdGEgPSBlcGk7CmxldCBpcHNEYXRhID0gaXBzOwoKbGV0IGdldFNwZWNpZmljYXRpb24gPSAoKSA9PiB7CiAgICByZXR1cm4gIjEuMC4wIjsKfTsKCmxldCBhbm5vdGF0aW9uUHJvY2VzcyA9IChsaXN0T2ZDYXRlZ29yaWVzLCBlbmhhbmNlVGFnLCBkb2N1bWVudCwgcmVzcG9uc2UpID0+IHsKICAgIGxpc3RPZkNhdGVnb3JpZXMuZm9yRWFjaCgoY2hlY2spID0+IHsKICAgICAgICBpZiAocmVzcG9uc2UuaW5jbHVkZXMoY2hlY2spKSB7CiAgICAgICAgICAgIGxldCBlbGVtZW50cyA9IGRvY3VtZW50LmdldEVsZW1lbnRzQnlDbGFzc05hbWUoY2hlY2spOwogICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGVsZW1lbnRzLmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgICBlbGVtZW50c1tpXS5jbGFzc0xpc3QuYWRkKGVuaGFuY2VUYWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChkb2N1bWVudC5nZXRFbGVtZW50c0J5VGFnTmFtZSgiaGVhZCIpLmxlbmd0aCA+IDApIHsKICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRzQnlUYWdOYW1lKCJoZWFkIilbMF0ucmVtb3ZlKCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGRvY3VtZW50LmdldEVsZW1lbnRzQnlUYWdOYW1lKCJib2R5IikubGVuZ3RoID4gMCkgewogICAgICAgICAgICAgICAgcmVzcG9uc2UgPSBkb2N1bWVudC5nZXRFbGVtZW50c0J5VGFnTmFtZSgiYm9keSIpWzBdLmlubmVySFRNTDsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJSZXNwb25zZTogIiArIHJlc3BvbnNlKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJSZXNwb25zZTogIiArIGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5pbm5lckhUTUwpOwogICAgICAgICAgICAgICAgcmVzcG9uc2UgPSBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuaW5uZXJIVE1MOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfSk7CgogICAgaWYgKHJlc3BvbnNlID09IG51bGwgfHwgcmVzcG9uc2UgPT0gIiIpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoCiAgICAgICAgICAgICJBbm5vdGF0aW9uIHByb2NjZXNzIGZhaWxlZDogUmV0dXJuZWQgZW1wdHkgb3IgbnVsbCByZXNwb25zZSIKICAgICAgICApOwogICAgICAgIC8vcmV0dXJuIGh0bWxEYXRhCiAgICB9IGVsc2UgewogICAgICAgIGNvbnNvbGUubG9nKCJSZXNwb25zZTogIiArIHJlc3BvbnNlKTsKICAgICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICB9Cn0KCmxldCBhbm5vdGF0ZUhUTUxzZWN0aW9uID0gYXN5bmMgKGxpc3RPZkNhdGVnb3JpZXMsIGVuaGFuY2VUYWcpID0+IHsKICAgIGxldCByZXNwb25zZSA9IGh0bWxEYXRhOwogICAgbGV0IGRvY3VtZW50OwoKIC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ChlbnRyeS5yZXNvdXJjZS5yZXNvdXJjZVR5cGUgPT0gIkNvbXBvc2l0aW9uIikgewogICAgICAgICAgICBjb21wb3NpdGlvbnMrKzsKICAgICAgICAgICAgLy9JdGVyYXRlZCB0aHJvdWdoIHRoZSBDb25kaXRpb24gZWxlbWVudCBzZWFyY2hpbmcgZm9yIGNvbmRpdGlvbnMKICAgICAgICAgICAgZW50cnkucmVzb3VyY2UuZXh0ZW5zaW9uLmZvckVhY2goKGVsZW1lbnQpID0+IHsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgLy8gQ2hlY2sgaWYgdGhlIHBvc2l0aW9uIG9mIHRoZSBleHRlbnNpb25bMV0gaXMgY29ycmVjdAogICAgICAgICAgICAgICAgaWYgKGVsZW1lbnQuZXh0ZW5zaW9uWzFdLnVybCA9PSAiY29uY2VwdCIpIHsKICAgICAgICAgICAgICAgICAgICAvLyBTZWFyY2ggdGhyb3VnaCB0aGUgZGlmZmVyZW50IHRlcm1pbm9sb2dpZXMgdGhhdCBtYXkgYmUgYXZhaWJsZSB0byBjaGVjayBpbiB0aGUgY29uZGl0aW9uCiAgICAgICAgICAgICAgICAgICAgaWYgKGVsZW1lbnQuZXh0ZW5zaW9uWzFdLnZhbHVlQ29kZWFibGVSZWZlcmVuY2UuY29uY2VwdCAhPSB1bmRlZmluZWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudC5leHRlbnNpb25bMV0udmFsdWVDb2RlYWJsZVJlZmVyZW5jZS5jb25jZXB0LmNvZGluZy5mb3JFYWNoKAogICAgICAgICAgICAgICAgICAgICAgICAgICAgKGNvZGluZykgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJFeHRlbnNpb246ICIgKyBlbGVtZW50LmV4dGVuc2lvblswXS52YWx1ZVN0cmluZyArICI6IiArIGNvZGluZy5jb2RlKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIENoZWNrIGlmIHRoZSBjb2RlIGlzIGluIHRoZSBsaXN0IG9mIGNhdGVnb3JpZXMgdG8gc2VhcmNoCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxpc3RPZkNhdGVnb3JpZXNUb1NlYXJjaC5pbmNsdWRlcyhjb2RpbmcuY29kZSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gQ2hlY2sgaWYgdGhlIGNhdGVnb3J5IGlzIGFscmVhZHkgaW4gdGhlIGxpc3Qgb2YgY2F0ZWdvcmllcwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjYXRlZ29yaWVzLnB1c2goZWxlbWVudC5leHRlbnNpb25bMF0udmFsdWVTdHJpbmcpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgIH0KICAgIH0pOwoKICAgIGlmIChjb21wb3NpdGlvbnMgPT0gMCkgewogICAgICAgIHRocm93IG5ldyBFcnJvcignQmFkIGVQSTogbm8gY2F0ZWdvcnkgIkNvbXBvc2l0aW9uIiBmb3VuZCcpOwogICAgfQoKICAgIGlmIChjYXRlZ29yaWVzLmxlbmd0aCA9PSAwKSB7CiAgICAgICAgLy8gdGhyb3cgbmV3IEVycm9yKCJObyBjYXRlZ29yaWVzIGZvdW5kIiwgY2F0ZWdvcmllcyk7CiAgICAgICAgcmV0dXJuIGh0bWxEYXRhOwogICAgfQogICAgLy9Gb2N1cyAoYWRkcyBoaWdobGlnaHQgY2xhc3MpIHRoZSBodG1sIGFwcGx5aW5nIGV2ZXJ5IGNhdGVnb3J5IGZvdW5kCiAgICByZXR1cm4gYXdhaXQgYW5ub3RhdGVIVE1Mc2VjdGlvbihjYXRlZ29yaWVzLCBlbmhhbmNlVGFnKTsKfTsKCnJldHVybiB7CiAgICBlbmhhbmNlOiBlbmhhbmNlLAogICAgZ2V0U3BlY2lmaWNhdGlvbjogZ2V0U3BlY2lmaWNhdGlvbiwKfTsK",
"title" : "Lens for pregnancy",
"_title" : {
"extension" : [
{
"extension" : [
{
"url" : "lang",
"valueCode" : "es"
},
{
"url" : "content",
"valueString" : "Lente para el embarazo"
}
],
"url" : "http://hl7.org/fhir/StructureDefinition/translation"
}
]
}
}
]
}