Skip to content

Commit

Permalink
Interaction Lens - Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
aalonsolopez committed May 14, 2024
1 parent 19ecbea commit 72c5b40
Showing 1 changed file with 77 additions and 61 deletions.
138 changes: 77 additions & 61 deletions src/lenses/lens-selector-mvp2_interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,79 @@ 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 arrayOfIngredientCodes = [];

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

// If there are no conditions, return the ePI as it is
if (arrayOfIngredientCodes.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(arrayOfIngredientCodes, { 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,68 +128,11 @@ let annotateHTMLsection = async (listOfCategories, enhanceTag) => {
}
};

let enhance = async () => {

let listOfCategoriesToSearch = [
"XK4IUX8MNB", // contra-indication-hypericum
"SY7Q814VUP", // contra-indication-calcium
];

// 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

0 comments on commit 72c5b40

Please sign in to comment.