Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #20

Merged
merged 17 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
name: Main import action

on:
push:
branches:
- "*"

push:
jobs:
docker:
uses: Gravitate-Health/reusable-workflows/.github/workflows/main.yml@main
secrets:
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
main-GH-workflow:
uses: Gravitate-Health/reusable-workflows/.github/workflows/main.yml@main
secrets:
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
KUBECONFIG_DEV: ${{ secrets.KUBECONFIG_DEV }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,75 @@ let getSpecification = () => {
return "1.0.0";
};

let enhance = async () => {
// Proves that IPS exists
if (ips == "" || ips == null) {
throw new Error("Failed to load IPS: the LEE is getting a empty IPS");
}

// Instantiates the array of condition codes
let arrayOfConditionCodes = [];

// Iterates through the IPS entry searching for conditions
ips.entry.forEach((element) => {
if (element.resource.resourceType == "AllergyIntolerance") {
if (element.resource.code != undefined) {
element.resource.code.coding.forEach((coding) => {
arrayOfConditionCodes.push({
code: coding.code,
system: coding.system,
});
});
}
}
});

// If there are no conditions, return the ePI as it is
if (arrayOfConditionCodes.length == 0) {
return htmlData;
}

// ePI traslation from terminology codes to their human redable translations in the sections
let compositions = 0;
let categories = [];
epi.entry.forEach((entry) => {
if (entry.resource.resourceType == "Composition") {
compositions++;
//Iterated through the Condition element searching for conditions
entry.resource.extension.forEach((element) => {

// Check if the position of the extension[1] is correct
if (element.extension[1].url == "concept") {
// Search through the different terminologies that may be avaible to check in the condition
if (element.extension[1].valueCodeableReference.concept != undefined) {
element.extension[1].valueCodeableReference.concept.coding.forEach(
(coding) => {
console.log("Extension: " + element.extension[0].valueString + ":" + coding.code + " - " + coding.system)
// Check if the code is in the list of categories to search
if (equals(arrayOfConditionCodes, { code: coding.code, system: coding.system })) {
// Check if the category is already in the list of categories
categories.push(element.extension[0].valueString);
}
}
);
}
}
});
}
});

if (compositions == 0) {
throw new Error('Bad ePI: no category "Composition" found');
}

if (categories.length == 0) {
return htmlData;
}

//Focus (adds highlight class) the html applying every category found
return await annotateHTMLsection(categories, "highlight");
};

let annotationProcess = (listOfCategories, enhanceTag, document, response) => {
listOfCategories.forEach((check) => {
if (response.includes(check)) {
Expand Down Expand Up @@ -55,67 +124,11 @@ let annotateHTMLsection = async (listOfCategories, enhanceTag) => {
}
};

let enhance = async () => {

let listOfCategoriesToSearch = [
"NUT-ALLERGY" // dummy allergy
];

// Get IPS gender and check if is female
let gender;

if (ips == "" || ips == null) {
throw new Error("Failed to load IPS: the LEE is getting a empty IPS");
}
ips.entry.forEach((element) => {
if (element.resource.resourceType == "Patient") {
gender = element.resource.gender;
if (gender != "female") {
return htmlData;
}
}
let equals = (array, object) => {
return array.some((element) => {
return (element.code === object.code) && (element.system === object.system);
});

// ePI traslation from terminology codes to their human redable translations in the sections
let compositions = 0;
let categories = [];
epi.entry.forEach((entry) => {
if (entry.resource.resourceType == "Composition") {
compositions++;
//Iterated through the Condition element searching for conditions
entry.resource.extension.forEach((element) => {

// Check if the position of the extension[1] is correct
if (element.extension[1].url == "concept") {
// Search through the different terminologies that may be avaible to check in the condition
if (element.extension[1].valueCodeableReference.concept != undefined) {
element.extension[1].valueCodeableReference.concept.coding.forEach(
(coding) => {
console.log("Extension: " + element.extension[0].valueString + ":" + coding.code)
// Check if the code is in the list of categories to search
if (listOfCategoriesToSearch.includes(coding.code)) {
// Check if the category is already in the list of categories
categories.push(element.extension[0].valueString);
}
}
);
}
}
});
}
});

if (compositions == 0) {
throw new Error('Bad ePI: no category "Composition" found');
}

if (categories.length == 0) {
// throw new Error("No categories found", categories);
return htmlData;
}
//Focus (adds highlight class) the html applying every category found
return await annotateHTMLsection(categories, "highlight");
};
}

return {
enhance: enhance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,31 @@ let getSpecification = () => {
return "1.0.0";
};

let annotationProcess = (listOfCategories, enhanceTag, document, response) => {
listOfCategories.forEach((check) => {
if (response.includes(check)) {
let elements = document.getElementsByClassName(check);
for (let i = 0; i < elements.length; i++) {
elements[i].classList.add(enhanceTag);
}
if (document.getElementsByTagName("head").length > 0) {
document.getElementsByTagName("head")[0].remove();
}
if (document.getElementsByTagName("body").length > 0) {
response = document.getElementsByTagName("body")[0].innerHTML;
console.log("Response: " + response);
} else {
console.log("Response: " + document.documentElement.innerHTML);
response = document.documentElement.innerHTML;
}
}
});

if (response == null || response == "") {
throw new Error(
"Annotation proccess failed: Returned empty or null response"
);
//return htmlData
} else {
console.log("Response: " + response);
return response;
}
}

let annotateHTMLsection = async (listOfCategories, enhanceTag) => {
let response = htmlData;
let document;

if (typeof window === "undefined") {
let jsdom = await import("jsdom");
let { JSDOM } = jsdom;
let dom = new JSDOM(htmlData);
document = dom.window.document;
return annotationProcess(listOfCategories, enhanceTag, document, response);
} else {
document = window.document;
return annotationProcess(listOfCategories, enhanceTag, document, response);
}
};

let enhance = async () => {
let listOfCategoriesToSearch = ["B90", "86406008"];

// Proves that IPS exists
if (ips == "" || ips == null) {
throw new Error("Failed to load IPS: the LEE is getting a empty IPS");
}

//Search for the condition in the IPS
let patientHasCondition = false;
// Instantiates the array of condition codes
let arrayOfConditionCodes = [];

// Iterates through the IPS entry searching for conditions
ips.entry.forEach((element) => {
if (element.resource.resourceType == "Condition") {
if (element.resource.code != undefined) {
element.resource.code.coding.forEach((coding) => {
if (listOfCategoriesToSearch.includes(coding.code)) {
patientHasCondition = true;
}
arrayOfConditionCodes.push({
code: coding.code,
system: coding.system,
});
});
}
}
});

if (!patientHasCondition) {
// If there are no conditions, return the ePI as it is
if (arrayOfConditionCodes.length == 0) {
return htmlData;
}

Expand All @@ -95,9 +51,9 @@ let enhance = async () => {
if (element.extension[1].valueCodeableReference.concept != undefined) {
element.extension[1].valueCodeableReference.concept.coding.forEach(
(coding) => {
console.log("Extension: " + element.extension[0].valueString + ":" + coding.code)
console.log("Extension: " + element.extension[0].valueString + ":" + coding.code + " - " + coding.system)
// Check if the code is in the list of categories to search
if (listOfCategoriesToSearch.includes(coding.code)) {
if (equals(arrayOfConditionCodes, { code: coding.code, system: coding.system })) {
// Check if the category is already in the list of categories
categories.push(element.extension[0].valueString);
}
Expand All @@ -114,12 +70,66 @@ let enhance = async () => {
}

if (categories.length == 0) {
//throw new Error("No categories found", categories);
return htmlData;
}

//Focus (adds highlight class) the html applying every category found
return await annotateHTMLsection(categories, "highlight");
};

let annotationProcess = (listOfCategories, enhanceTag, document, response) => {
listOfCategories.forEach((check) => {
if (response.includes(check)) {
let elements = document.getElementsByClassName(check);
for (let i = 0; i < elements.length; i++) {
elements[i].classList.add(enhanceTag);
}
if (document.getElementsByTagName("head").length > 0) {
document.getElementsByTagName("head")[0].remove();
}
if (document.getElementsByTagName("body").length > 0) {
response = document.getElementsByTagName("body")[0].innerHTML;
console.log("Response: " + response);
} else {
console.log("Response: " + document.documentElement.innerHTML);
response = document.documentElement.innerHTML;
}
}
});

if (response == null || response == "") {
throw new Error(
"Annotation proccess failed: Returned empty or null response"
);
//return htmlData
} else {
console.log("Response: " + response);
return response;
}
}

let annotateHTMLsection = async (listOfCategories, enhanceTag) => {
let response = htmlData;
let document;

if (typeof window === "undefined") {
let jsdom = await import("jsdom");
let { JSDOM } = jsdom;
let dom = new JSDOM(htmlData);
document = dom.window.document;
return annotationProcess(listOfCategories, enhanceTag, document, response);
} else {
document = window.document;
return annotationProcess(listOfCategories, enhanceTag, document, response);
}
};

let equals = (array, object) => {
return array.some((element) => {
return (element.code === object.code) && (element.system === object.system);
});
}

return {
enhance: enhance,
getSpecification: getSpecification,
Expand Down
Loading
Loading