[0eda78]: / frontend / src / app / components / home / home.component.ts

Download this file

153 lines (133 with data), 5.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import {Component} from '@angular/core';
import {Router} from "@angular/router";
import {AnalyzerService} from "../../services/analyzer.service";
import {ToastrService} from 'ngx-toastr';
interface Colors {
[key: string]: string;
}
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent {
analyzing = false;
analyzed = false;
text = '';
analyzedText = '';
colors: Colors = {
'B-MEDCOND': 'green'
}
constructor(
private router: Router,
private analyzerService: AnalyzerService,
private notification: ToastrService,
) {
}
sanitizeHTML(htmlString: string): string {
const allowedTagsRegex = /<(?!\/?(span|mark)\b)[^>]+>/gi;
return htmlString.replace(allowedTagsRegex, '');
}
loadExample() {
this.text = 'Patient is a 45-year-old man with a history of anaplastic astrocytoma of the spine complicated by sever' +
'e lower extremity weakness and urinary retention s/p Foley catheter, high-dose steroids, hypertension, and chroni' +
'c pain. The tumor is located in the T-L spine, unresectable anaplastic astrocytoma s/p radiation. Complicated by ' +
'progressive lower extremity weakness and urinary retention. Patient initially presented with RLE weakness where h' +
'is right knee gave out with difficulty walking and right anterior thigh numbness. MRI showed a spinal cord conus ' +
'mass which was biopsied and found to be anaplastic astrocytoma.'
}
analyzeNote() {
this.analyzing = true;
if (this.text.toLowerCase() === 'github') {
window.location.href = 'https://github.com/Padraig20/Applied-Deep-Learning-VU';
} else if (this.text.toLowerCase() === 'linkedin') {
window.location.href = 'https://linkedin.com/in/patrick-styll-009286244';
} else {
this.analyzerService.analyzeNote(this.text).subscribe({
next: data => {
console.log(data);
this.analyzedText = '';
const tokens: string[] = data.tokens;
const entities: string[] = data.entities;
let i = 0;
while (i < tokens.length) {
if (entities[i] === 'O') {
this.analyzedText += tokens[i++];
// Check if token is no dot, exclamatory mark, question mark, comma, or semicolon
if (i < tokens.length && !['.', '!', '?', ',', ';'].includes(tokens[i])) {
this.analyzedText += ' ';
}
} else {
// Token is not 'O'; might be 'B' or 'I' entity but 'I' will be handled by the loop below
if (entities[i].toString().startsWith('B-')) {
this.analyzedText += '<mark class="highlight ' + this.colors[entities[i]] + '">' + tokens[i] + ' ';
i++;
while (i < tokens.length && entities[i].toString().startsWith('I-')) {
this.analyzedText += tokens[i] + ' ';
i++;
}
// Remove last space
this.analyzedText = this.analyzedText.substring(0, this.analyzedText.length - 1);
this.analyzedText += '<span class="descriptor">' + entities[i - 1].toString().substring(2) + '</span></mark> ';
}
}
}
this.notification.info('Successfully analyzed note!');
console.log(this.analyzedText);
this.analyzed = true;
this.analyzing = false;
},
error: error => {
console.log('Error analyzing note: ' + error);
this.analyzing = false;
this.notification.error('Error analyzing note');
}
});
}
}
analyze() {
this.analyzing = true;
this.analyzerService.analyzeNote(this.text).subscribe({
next: data => {
this.analyzedText = '';
console.log(data);
const tokens = data.tokens[0];
const entities = data.entities[0];
let tmp = '';
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
const entity = entities[i];
console.log(token);
console.log(entity);
if (entity === 'O') {
this.analyzedText = this.analyzedText + (token + ' ');
} else {
if (entity === 'B-MEDCOND') {
if ((i + 1) < tokens.length && entities[i + 1] === 'I-MEDCOND') {
tmp = token;
} else {
this.analyzedText = this.analyzedText + '<span class="fw-bold bg-green-300 text-green-800 rounded px-1 py-1 m-1">' + (token) + '<span class="fw-light ml-2 text-green-950">MEDICAL CONDITION</span></span> ';
tmp = '';
}
} else if (entity === 'I-MEDCOND') {
tmp = tmp + (' ' + token);
if ((i + 1) < tokens.length && entities[i + 1] !== 'I-MEDCOND' || i === tokens.length - 1) {
this.analyzedText = this.analyzedText + '<span class="fw-bold bg-green-300 text-green-800 rounded px-1 py-1 m-1">' + (tmp) + '<span class="fw-light ml-2 text-green-950">MEDICAL CONDITION</span></span> ';
tmp = '';
}
}
}
}
this.notification.info('Successfully analyzed admission note!');
console.log(this.analyzedText)
this.analyzed = true;
this.analyzing = false;
},
error: error => {
console.log('Error analyzing note: ', error);
this.analyzing = false;
this.notification.error(error.error.message, 'Error analyzing note');
}
});
}
}