I have a difficult algorithmic problem that I am running into. I have the below long form string that I am feeding into a model that pulls out diseases and drugs from an (anonymous in this case) patient's record. I want to mark it up with html to highlight the diseases and drugs in the record, and I am looking for a reliable mechanism to do this. Right now, I just reverse the arrays and show them one at a time, but ideally, I can show them both at the same time.
Here is what the patient record looks like
Ashton is an 78 year old man with diabetes. He has reported feeling stomach pains when he awakens in the morning and after eating meals which he describes as an aching sensation in his lower abdomen. He identified his diet as mainly consisting of carbs with protein and vegetables as side dishes. Strongly affected by wrist and finger inflammation, he complains that his arthritis is worsening with some reports of dystonia of the fingers, with fingers getting locked in place during daily activities such as brushing teeth and fine motor activities like eating food and washing plates. Santos is taking 20 mg Leflunomide daily and 325mg of Aspirin as needed. He is also on 10 units of Insulin taken after meals and Metformin before meals.
And here is what the diseases and drugs arrays look like from the model
nerArray['diseases']: [
{
"word": "dystonia",
"start": 415,
"end": 423
},
{
"word": "arthritis",
"start": 371,
"end": 380
},
{
"word": "wrist and finger inflammation",
"start": 318,
"end": 347
},
{
"word": "stomach pains",
"start": 68,
"end": 81
},
{
"word": "diabetes",
"start": 34,
"end": 42
}
]
nerArray['drugs']: [
{
"word": "metformin",
"start": 716,
"end": 725
},
{
"word": "insulin",
"start": 686,
"end": 693
},
{
"word": "aspirin",
"start": 641,
"end": 648
},
{
"word": "leflunomide",
"start": 610,
"end": 621
}
]
I also color them:
indexColor['drugs']: 'red',
indexColor['diseases']: 'green,
For just the diseases, the processed string in red highlight would look like this:
Ashton is an 78 year old man with <span class="pa-1" style="color: red; border-radius:5px; border:1px solid red">diabetes</span>. He has reported feeling <span class="pa-1" style="color: red; border-radius:5px; border:1px solid red">stomach pains</span> when he awakens in the morning and after eating meals which he describes as an aching sensation in his lower abdomen. He identified his diet as mainly consisting of carbs with protein and vegetables as side dishes. Strongly affected by <span class="pa-1" style="color: red; border-radius:5px; border:1px solid red">wrist and finger inflammation</span>, he complains that his <span class="pa-1" style="color: red; border-radius:5px; border:1px solid red">arthritis</span> is worsening with some reports of <span class="pa-1" style="color: red; border-radius:5px; border:1px solid red">dystonia</span> of the fingers, with fingers getting locked in place during daily activities such as brushing teeth and fine motor activities like eating food and washing plates. Santos is taking 20 mg Leflunomide daily and 325mg of Aspirin as needed. He is also on 10 units of Insulin taken after meals and Metformin before meals.
and for the drugs in green:
Ashton is an 78 year old man with diabetes. He has reported feeling stomach pains when he awakens in the morning and after eating meals which he describes as an aching sensation in his lower abdomen. He identified his diet as mainly consisting of carbs with protein and vegetables as side dishes. Strongly affected by wrist and finger inflammation, he complains that his arthritis is worsening with some reports of dystonia of the fingers, with fingers getting locked in place during daily activities such as brushing teeth and fine motor activities like eating food and washing plates. Santos is taking 20 mg <span class="pa-1" style="color: green; border-radius:5px; border:1px solid green">Leflunomide</span> daily and 325mg of <span class="pa-1" style="color: green; border-radius:5px; border:1px solid green">Aspirin</span> as needed. He is also on 10 units of <span class="pa-1" style="color: green; border-radius:5px; border:1px solid green">Insulin</span> taken after meals and <span class="pa-1" style="color: green; border-radius:5px; border:1px solid green">Metformin</span> before meals.
Here is the method I use to make that now for one of them, the array is reversed since I do it back to front to make it easier.
processForNerArray(index) { // index is either 'drugs' or 'diseases
this.processedNote = this.note;
const seqStart =
'<span class="pa-1" style="color: ' +
this.indexColor[index] +
"; border-radius:5px; border:1px solid " +
this.indexColor[index] +
'">';
const seqEnd = "</span>";
this.nerArray[index].reverse().forEach((nerObj) => {
this.processedNote =
this.processedNote.slice(0, nerObj.start) +
seqStart +
this.processedNote.slice(
nerObj.start,
nerObj.end
) +
seqEnd +
this.processedNote.slice(
nerObj.end
);
});
},