-
Notifications
You must be signed in to change notification settings - Fork 7
/
module_parser.ts
1334 lines (1195 loc) · 42.2 KB
/
module_parser.ts
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* All algorithms to generate the visualizations for the modules
*
* Name des Moduls
* welche raw-data benoetigt werden
* welche parsed-data benoetigt werden
* die parse-funktion selbst implementieren; default (z.B: on Error etc)
* ein leeres Array ([]) zurueck geben
*/
import { errorDataType } from "./error_log"
import { raw } from "mysql"
import * as d3 from "d3"
import * as d3_sankey from "d3-sankey"
import { get_worse_carrier_status } from "./utilities/carrier_status"
import parse_sl_data from "./utilities/storylineParser"
import { Error_Log } from "./error_log"
import { sankey } from "./utilities/d3-sankey"
import * as cli_color from "cli-color"
import {
get_max_value,
get_min_value,
set_min_max_value,
} from "./utilities/min_max"
import storyline from "./utilities/storyline-vis"
const raw_error_prio: number = 1.7
const parsed_error_prio: number = 2.7
let error_log = new Error_Log()
const module_parser: { [key: string]: any } = {
patientdetail: {
needed_raw_data: [
"Patient_Bewegung_Ps",
"Patient_Labordaten_Ps",
"Patient_Vaccination",
"Patient_Symptom",
],
needed_parsed_data: [
"generate_mibi_investigations",
"generate_movement_rects",
],
call_function: (input_data: any, parameters: any, callback: Function) => {
let {
Patient_Symptom,
Patient_Vaccination,
Patient_Bewegung_Ps,
Patient_Labordaten_Ps,
generate_mibi_investigations,
generate_movement_rects,
} = input_data
let patientList: any[] = []
let min_ts: any = undefined
let max_ts: any = undefined
if (generate_movement_rects.error === undefined) {
set_min_max_value(
min_ts,
max_ts,
generate_mibi_investigations.data.min_ts,
generate_mibi_investigations.data.max_ts
)
}
// TODO: Wie muss ereignisTriangles und ereignisCircles generiert werden ?
let ereignisTriangles: object[] = []
let ereignisCircles: object[] = []
// #region globalTimeStamps , patientList & nosokomiale Patienten
if (generate_mibi_investigations.error === undefined) {
if (generate_mibi_investigations.data.investigations > 0) {
set_min_max_value(
min_ts,
max_ts,
generate_mibi_investigations.data.min_ts,
generate_mibi_investigations.data.max_ts
)
}
} else {
error_log.addError(
"generate_mibi_investigations",
parameters,
parsed_error_prio,
generate_mibi_investigations.error
)
}
if (Patient_Bewegung_Ps.error === undefined) {
Patient_Bewegung_Ps.data.forEach((element: any) => {
let pID = element.PatientID
let beginn = new Date(element.Beginn).getTime()
let ende = new Date(element.Ende).getTime()
if (!patientList.includes(pID)) {
patientList.push(pID)
}
set_min_max_value(min_ts, max_ts, beginn, ende)
})
} else {
error_log.addError(
"Patient_Bewegung_Ps",
parameters,
raw_error_prio,
Patient_Bewegung_Ps.error
)
}
if (Patient_Labordaten_Ps.error === undefined) {
Patient_Labordaten_Ps.data.forEach((element: any) => {
let pID = element.PatientID
if (!patientList.includes(pID)) {
patientList.push(pID)
}
})
} else {
error_log.addError(
"Patient_Labordaten_Ps",
parameters,
raw_error_prio,
Patient_Labordaten_Ps.error
)
}
let counter = 0
if (Patient_Vaccination.error === undefined) {
Patient_Vaccination.data.forEach((element: any) => {
let pID = element.PatientenID
let impfDatum = new Date(element.DokumentationsID).getTime()
//console.log(cli_color.blueBright(pID))
if (!patientList.includes(pID)) {
counter++
//console.log(cli_color.blueBright(counter))
patientList.push(pID)
}
if (impfDatum < min_ts) {
min_ts = impfDatum
}
if (impfDatum > max_ts) {
max_ts = impfDatum
}
})
} else {
error_log.addError(
"Patient_Vaccination",
parameters,
raw_error_prio,
Patient_Vaccination.error
)
}
if (Patient_Symptom.error === undefined) {
Patient_Symptom.data.forEach((element: any) => {
let pID = element.PatientenID
let first_date = new Date(element.Beginn).getTime()
let last_date = new Date(element.Rueckgang).getTime()
if (!patientList.includes(pID)) {
patientList.push(pID)
}
set_min_max_value(min_ts, max_ts, first_date, last_date)
})
} else {
error_log.addError(
"Patient_Symptom",
parameters,
raw_error_prio,
Patient_Symptom.error
)
}
// #region virusLastRects
let virusLastRects: object[] = []
if (Patient_Labordaten_Ps.error === undefined) {
let patient_and_test: object[] = []
// Patient_Labordaten_Ps.data.forEach((labor_data: any) => {
// let patID_test = {
// patID: labor_data.PatientID,
// testDate: new Date(labor_data.Befunddatum).getTime(),
// }
// patient_and_test.push(patID_test)
// })
// Patient_Labordaten_Ps.data.forEach((d: any) => {
// })
patientList.forEach((pid: any) => {
// let virusLastRect: any = {
// patientID: pid,
// }
let virus_data = Patient_Labordaten_Ps.data.filter(
(d: any) => d.PatientID === pid
)
virus_data.sort(
(a: any, b: any) =>
new Date(a.Befunddatum).getTime() -
new Date(b.Befunddatum).getTime()
)
virus_data.forEach((vd: any, i: any) => {
set_min_max_value(
min_ts,
max_ts,
new Date(vd.Befunddatum).getTime()
)
let begin = vd.Befunddatum
let end =
i < virus_data.length - 1
? virus_data[i + 1].Befunddatum
: undefined
let testArt = undefined
if (vd.KeimID === "94558-4") {
testArt = "antiGen"
}
virusLastRects.push({
begin: new Date(begin).getTime(),
end: end ? new Date(end).getTime() : undefined,
testArt,
...vd,
Quantity: Number(vd.Quantity),
})
})
})
} else {
error_log.addError(
"Patient_Labordaten_Ps",
parameters,
raw_error_prio,
Patient_Labordaten_Ps.error
)
}
// #endregion
// #region stationenRects
let stationenRects: object[] = []
let stationsArten: any = [
"CovidStation",
"NormalStation",
"ICR",
"Intensivstation",
]
if (Patient_Bewegung_Ps.error === undefined) {
Patient_Bewegung_Ps.data.forEach((mov: any) => {
let stationsStruct: any = {
aufenthaltsBegin: new Date(mov.Beginn).getTime(),
aufenthaltsEnde: new Date(mov.Ende).getTime(),
patient_id: mov.PatientID,
station_id: mov.Station,
/* wann soll "ICR" gesetzt werden?
* ist es sinnvoll alles was nicht Covid / Intensiv / ICR ist als NormalStation zu deklarieren?
* default für stationsArt: NormalStation
*/
stationsArt: stationsArten[1],
}
// ! Bei Verlegung auf Covid- od. Intensivstation wird erreignisTriangle gesetzt
if (mov.Station === "Coronastation") {
stationsStruct.stationsArt = stationsArten[0]
let triangleStruct: any = {
patientID: mov.PatientID,
ereignisTimeStamp: new Date(mov.Beginn).getTime(),
}
ereignisTriangles.push(triangleStruct)
}
if (mov.Fachabteilung === "Intensivstation") {
stationsStruct.stationsArt = stationsArten[3]
let triangleStruct: any = {
patientID: mov.PatientID,
ereignisTimeStamp: new Date(mov.Beginn).getTime(),
}
ereignisTriangles.push(triangleStruct)
}
set_min_max_value(
min_ts,
max_ts,
stationsStruct.aufenthaltsBegin,
stationsStruct.aufenthaltsEnde
)
stationenRects.push(stationsStruct)
})
} else {
error_log.addError(
"Patient_Bewegung_Ps",
parameters,
raw_error_prio,
Patient_Bewegung_Ps.error
)
}
// #endregion
// #region Impfdaten
let impfDaten: object[] = []
let vacc_injection_data: any[] = []
let vacc_list: string[] = []
if (Patient_Vaccination.error === undefined) {
Patient_Vaccination.data.forEach((vacc_data: any) => {
let vacc_inj_data = vacc_data
vacc_inj_data.doc_ts = new Date(
vacc_inj_data.DokumentationsID
).getTime()
vacc_injection_data.push(vacc_data)
if (!vacc_list.includes(vacc_data.PatientenID)) {
vacc_list.push(vacc_data.PatientenID)
let impfdatenStruct = {
patientID: vacc_data.PatientenID,
medikament: new String(),
anzahl_impfungen: vacc_data.Dosierungsreihenfolge,
}
if (
vacc_data.Impfstoff ===
"Vaccine product containing only Severe acute respiratory syndrome coronavirus 2 messenger ribonucleic acid (medicinal product)"
) {
impfdatenStruct.medikament =
"Comirnaty / COVID-19 Vaccine Moderna"
}
if (
vacc_data.Impfstoff ===
"Vaccine product containing only Severe acute respiratory syndrome coronavirus 2 antigen (medicinal product)"
) {
impfdatenStruct.medikament = "Vaxzevria / Janssen"
}
impfDaten.push(impfdatenStruct)
} else {
impfDaten.forEach((data: any) => {
if (data.patientID === vacc_data.PatientenID) {
if (data.anzahl_impfungen < vacc_data.Dosierungsreihenfolge) {
data.anzahl_impfungen = vacc_data.Dosierungsreihenfolge
}
}
})
}
/**
* @Tom aktuell wird nur ein Objekt pro Patient übergeben. Vllt. ist es sinnvoller pro stattgefundener
* Impfung ein Objekt zu übergeben. (z. Bsp.: Um Kreuzimpfungen darzustellen? )
*
* TODO: ja sollte in überarbeiteter Version definitiv gemacht werden; für v0.9 erstmal so
*/
})
patientList.forEach((pid) => {
if (!vacc_list.includes(pid)) {
vacc_list.push(pid)
let impfdatenStruct = {
patientID: pid,
medikament: "No vaccine",
anzahl_impfungen: 0,
}
impfDaten.push(impfdatenStruct)
}
})
vacc_injection_data.sort(
(a, b) => a.Dosierungsreihenfolge - b.Dosierungsreihenfolge
)
} else {
error_log.addError(
"Patient_Vaccination",
parameters,
raw_error_prio,
Patient_Vaccination.error
)
}
// #endregion
// #region Symptomdaten
let symptomDaten: object[] = []
if (Patient_Symptom.error === undefined) {
Patient_Symptom.data.forEach((symptom_data: any) => {
let symptomStruct = {
patientID: symptom_data.PatientenID,
// ! symptomArt soll gastroenterol. / respirat. / system. sein --> keine Daten vorhanden
symptomArt: symptom_data.NameDesSymptoms,
symptomBeginn: new Date(symptom_data.Beginn).getTime(),
symptomEnde: new Date(symptom_data.Rueckgang).getTime(),
negation: symptom_data.AusschlussAussage,
}
set_min_max_value(
min_ts,
max_ts,
symptomStruct.symptomBeginn,
symptomStruct.symptomEnde
)
symptomDaten.push(symptomStruct)
// ! bei Symptombeginn wird aktuell ereignisTriangle gesetzt ( bei Rueckgang ereignisCircle ) !
let triangleStruct: any = {
patientID: symptom_data.PatientenID,
ereignisTimeStamp: new Date(symptom_data.Beginn).getTime(),
}
ereignisTriangles.push(triangleStruct)
/*
let circleStruct: any = {
patientID: symptom_data.PatientenID,
ereignisTimeStamp: new Date(symptom_data.Rueckgang).getTime()
}
ereignisCircles.push(circleStruct)
*/
})
} else {
error_log.addError(
"Patient_Symptom",
parameters,
raw_error_prio,
Patient_Symptom.error
)
}
//#endregion Symptomdaten
// console.log(cli_color.green(patientList.length))
callback({
virusLastRects,
stationenRects,
ereignisTriangles,
ereignisCircles,
//annotationsTriangles,
min_ts,
max_ts,
impfDaten,
vacc_injection_data,
symptomDaten,
...generate_movement_rects.data,
patientList,
return_log: error_log.clearAndReturnLog(),
})
},
},
epikurve: {
needed_raw_data: [
"Labor_ErregerProTag_TTEsKSs",
"OutbreakDetectionResultSet",
"OutbreakDetectionConfigurations",
],
// needed_raw_data: ["Labor_ErregerProTag_TTEsKSs"],
// needed_parsed_data: ["rki_data_by_day"],
needed_parsed_data: [],
// TODO: PRO ERREGER!!! aktuell alle Erreger in Reihe geschalten
// TODO: die initial timestamps for timelense sind null...
call_function: (input_data: any, parameters: any, callback: Function) => {
let {
Labor_ErregerProTag_TTEsKSs,
OutbreakDetectionResultSet,
OutbreakDetectionConfigurations,
} = input_data
let { starttime, endtime, station, pathogenList, configName } = parameters
let initial_timelense_timestamps: number[] = []
let timespan: number[] = []
let newData: any[] = []
let stationIDs: string[] = []
let pathogenIDs: string[] = []
let dayDataSets: any = {}
let config_stationid: any = undefined
// das bleibt drin, weil "frische" Daten sind ja nie schlecht...
if (
configName !== "" &&
OutbreakDetectionConfigurations.error === undefined
) {
// get the stationid for the selected config
OutbreakDetectionConfigurations.data.forEach((conf: any) => {
if (conf.name === configName) {
config_stationid = conf.StationID
}
})
}
// TODO: Pascal fragen, ob das benötigt wird, oder ob RKI Daten das schon haben...
if (OutbreakDetectionResultSet.error === undefined) {
OutbreakDetectionResultSet.data.forEach((d: any) => {
d.StationID = config_stationid
})
}
if (
Labor_ErregerProTag_TTEsKSs.error === undefined &&
Labor_ErregerProTag_TTEsKSs.data.length > 0
) {
// Fuer jede Station und jeden Pathogen eine Kurve erzeugen
// + Endemische Kurven jeweils
// + für 7 Tage / 28 Tage akkumuliert
let raw_data = Labor_ErregerProTag_TTEsKSs.data
// ! FUER ENDE-MAERZ DAZU GEMACHT
raw_data.forEach((d: any) => {
if (d.anzahl_gesamt !== undefined) {
d.Anzahl_cs = d.anzahl_gesamt
d.MAVG7_cs = d.anzahl_gesamt_av7
d.MAVG28_cs = d.anzahl_gesamt_av28
}
// // fuer jeden Tag die Ausbruchswahrscheinlichkeit
// // und die anderen Daten asu RKIalgo rauslesen
// if (rki_data_by_day.error === undefined) {
// let index = rki_data_by_day.data.findIndex(
// (rki_d: any) =>
// rki_d.timestamp === new Date(d.Datum.split("T")[0]).getTime()
// )
// console.log(index)
// if (index >= 0) {
// console.log("geht rein")
// d = {
// ...d,
// ...rki_data_by_day.data[index],
// }
// console.log(d)
// }
// }
})
raw_data.forEach((d: any, i: any) => {
if (d.StationID === null) [(d.StationID = "klinik")]
d.timestamp = new Date(d.Datum.split(".")[0]).getTime()
// unsere Datenbank liefer da glaube ich einfach nichts zurueck
d.avg7 = d.MAVG7 ? d.MAVG7 : 0
d.avg28 = d.MAVG28 ? d.MAVG28 : 0
d.avg7_cs = d.MAVG7_cs ? d.MAVG7_cs : 0
d.avg28_cs = d.MAVG28_cs ? d.MAVG28_cs : 0
if (!stationIDs.includes(d.StationID)) {
stationIDs.push(d.StationID)
}
if (!pathogenIDs.includes(d.ErregerID)) {
pathogenIDs.push(d.ErregerID)
}
})
pathogenIDs.forEach((pathogen: string) => {
// })
let data = JSON.parse(JSON.stringify(raw_data)).filter(
(p: any) => pathogen === p.ErregerID
)
data.forEach((d: any) => {
// fuer jeden Tag die Ausbruchswahrscheinlichkeit
// und die anderen Daten asu RKIalgo rauslesen
if (OutbreakDetectionResultSet.error === undefined) {
// !TODO nur temporaer zum testen lokal...
if (configName === "") {
OutbreakDetectionResultSet.data = []
}
let index = OutbreakDetectionResultSet.data.findIndex(
(rki_d: any) =>
new Date(rki_d.Zeitstempel.split("T")[0]).getTime() ===
new Date(d.Datum.split("T")[0]).getTime() &&
rki_d.StationID === d.StationID
// && rki_d.pathogen === d.ErregerID
)
//console.log(index);
if (index >= 0) {
//console.log("geht rein");
// d = {
// ...d,
// ...rki_data_by_day.data[index],
// }
d.rki_data = OutbreakDetectionResultSet.data[index]
// console.log(d)
}
} else {
error_log.addError(
"OutbreakDetectionResultSet",
parameters,
raw_error_prio,
OutbreakDetectionResultSet.error
)
}
})
stationIDs.forEach((stationID: any) => {
if (dayDataSets["K" + pathogen] === undefined) {
dayDataSets["K" + pathogen] = {}
}
dayDataSets["K" + pathogen][stationID] = data.filter(
(d: any) => d.StationID === stationID
)
let accumulated_count = 0
let copy_day
dayDataSets["K" + pathogen][stationID].forEach(
(d: any, i: number) => {}
)
})
})
/**
* Initiale Anfangs- und Endzeit abspeichern
*/
timespan = [
raw_data[0].timestamp,
raw_data[raw_data.length - 1].timestamp,
]
initial_timelense_timestamps = [
raw_data[0].timestamp,
raw_data[raw_data.length - 1].timestamp + 1000 * 60 * 60 * 24,
// data[0][0].timestamp + 1000 * 60 * 60 * 24 * 60,
// data[0][data[0].length - 1].timestamp + 1000 * 60 * 60 * 24 - 1000 * 60 * 60 * 24 * 60
]
// let newData = [dayDataSets, weekDataSets, monthDataSets]
} else {
error_log.addError(
"Labor_ErregerProTag_TTEsKSs",
parameters,
raw_error_prio,
Labor_ErregerProTag_TTEsKSs.error
)
}
callback({
timestamp: new Date().getTime(),
// data: { dayDataSets, weekDataSets, monthDataSets },
data: dayDataSets,
timespan,
initial_timelense_timestamps,
stationIDs,
pathogenIDs,
// rki_data_by_day,
return_log: error_log.clearAndReturnLog(),
rki_data_by_day: OutbreakDetectionResultSet,
rki_configs: OutbreakDetectionConfigurations.data,
config_stationid,
configName,
})
// return {
// timestamp: new Date().getTime(),
// // data: { dayDataSets, weekDataSets, monthDataSets },
// data: [dayDataSets, weekDataSets, monthDataSets],
// initial_timelense_timestamps,
// stationIDs,
// pathogenIDs,
// }
},
},
demo_linelist: {
needed_raw_data: ["Patient_Bewegung_Ps"],
needed_parsed_data: ["generate_mibi_investigations"],
call_function: (input_data: any, parameters: any, callback: Function) => {
let { Patient_Bewegung_Ps, generate_mibi_investigations } = input_data
let { patientList } = parameters
let ts_start = Number.MAX_VALUE
let ts_end = 0
let movement_rects: object[] = []
let movement_dots: object[] = []
let investigation_rects: object[] = []
// generate visualization for movement data (horizontal rectangles)
// only if there is no error in the data
if (Patient_Bewegung_Ps.error === undefined) {
let movement_rect_top_position: any = {}
Patient_Bewegung_Ps.data.forEach((movement: any) => {
let begin = new Date(movement.Beginn).getTime()
let end = new Date(movement.Ende).getTime()
if (begin < ts_start) {
ts_start = begin
}
if (end > ts_end) {
ts_end = end
}
let vis_struct: any = {
begin: begin,
end: end,
patient_id: movement.PatientID,
station_id: movement.StationID,
station_name: movement.Station,
movement_type: movement.BewegungstypID,
}
if (movement.BewegungstypID === 4) {
movement_dots.push(vis_struct)
} else {
if (movement_rect_top_position[movement.PatientID]) {
vis_struct.top = true
movement_rect_top_position[movement.PatientID] = false
} else {
vis_struct.top = false
movement_rect_top_position[movement.PatientID] = true
}
movement_rects.push(vis_struct)
}
})
} else {
error_log.addError(
"Patient_Bewegung_Ps",
parameters,
raw_error_prio,
Patient_Bewegung_Ps.error
)
}
// generate visualization for investigation data (vertical rectangles)
// only if there is no error in the data
if (generate_mibi_investigations.error === undefined) {
let { first_timestamp, last_timestamp, investigations } =
generate_mibi_investigations.data
if (ts_start > first_timestamp) {
ts_start = first_timestamp
}
if (ts_end < last_timestamp) {
ts_end = last_timestamp
}
investigation_rects = investigations
} else {
error_log.addError(
"generate_mibi_investigations",
parameters,
parsed_error_prio,
generate_mibi_investigations.error
)
}
// return {
// // data: ["linelist vis data", input_data],
// timestamp: new Date().getTime(),
// ts_start,
// ts_end,
// patientList,
// movement_rects,
// movement_dots,
// investigation_rects,
// }
callback({
// data: ["linelist vis data", input_data],
timestamp: new Date().getTime(),
ts_start,
ts_end,
patientList,
movement_rects,
movement_dots,
investigation_rects,
return_log: error_log.clearAndReturnLog(),
})
},
},
kontaktnetzwerk: {
needed_raw_data: [],
needed_parsed_data: ["generate_contact_graph"],
call_function: (input_data: any, parameters: any, callback: Function) => {
let { generate_contact_graph } = input_data
if (generate_contact_graph.error !== undefined) {
error_log.addError(
"generate_contact_graph",
parameters,
parsed_error_prio,
generate_contact_graph.error
)
}
callback({
...generate_contact_graph.data,
return_log: error_log.clearAndReturnLog(),
})
},
},
linelist: {
needed_raw_data: ["Patient_Bewegung_Ps"],
needed_parsed_data: [
"generate_mibi_investigations",
"generate_movement_rects",
],
call_function: (input_data: any, parameters: any, callback: Function) => {
let {
Patient_Bewegung_Ps,
generate_mibi_investigations,
generate_movement_rects,
} = input_data
// // TODO: SMICS-0.8
// // Patientenliste wegen Nth-Degree rauslesen
// let new_patient_list: any[] = []
// if (Patient_Bewegung_Ps.error === undefined) {
// Patient_Bewegung_Ps.data.forEach((mov: any) => {
// if (!new_patient_list.includes(mov.PatientID)) {
// new_patient_list.push(mov.PatientID)
// }
// })
// } else {
// error_log.addError(
//
// "Patient_Bewegung_Ps",
// parameters,
// raw_error_prio,
// Patient_Bewegung_Ps.error
//
// )
// }
let {
min_ts,
max_ts,
patientList,
movement_rects,
movement_dots,
allStations,
unknown_rects,
} = generate_movement_rects.data
let investigation_rects: object[] = []
let status_rects: any[] = []
if (generate_mibi_investigations.error === undefined) {
// generate visualization for investigation data (vertical rectangles)
// only if there is no error in the data
let { investigations, status_changes } =
generate_mibi_investigations.data
// min_ts = get_min_value(min_ts, generate_mibi_investigations.data.min_ts)
// max_ts = get_max_value(max_ts, generate_mibi_investigations.data.max_ts)
set_min_max_value(
min_ts,
max_ts,
generate_mibi_investigations.data.min_ts,
generate_mibi_investigations.data.max_ts
)
investigation_rects = investigations
if (Patient_Bewegung_Ps.error === undefined) {
/**
* generate status rects
*
* for every patient_id AND pathogen_id
* - begin_min_ts_ts
* - end_max_ts_ts
*
* - "every pathogen":
* - "not_tested" -> einfach grauer balken für "unknown"
* - dann für alle getesteten pathogens -> aus status changes
*/
patientList.forEach((pID: any) => {
// get first and last timestamp
let first_ts: any = undefined
let last_ts: any = undefined
let patient_movements = Patient_Bewegung_Ps.data.filter(
(d: any) => d.PatientID === pID && d.BewegungstypID !== 4
)
patient_movements.forEach((movement: any) => {
let begin = new Date(movement.Beginn).getTime()
let end = new Date(movement.Ende).getTime()
if (first_ts === undefined || begin < first_ts) {
first_ts = begin
}
if (last_ts === undefined || end > last_ts) {
last_ts = end
}
})
// generate blank/"unknown" rectangle
let unknown_rect = {
patient_id: pID,
pathogen_id: undefined,
begin: first_ts,
end: last_ts,
status: "unknown",
}
// status_rects.push(unknown_rect)
// unknown_rects.push(unknown_rect)
unknown_rects[pID] = unknown_rect
// console.log(`.........................Status Rects for ${pID}`)
// console.log("pID", pID)
// console.table(status_changes[pID])
// !wenn jemand NIE getestet wurde, gibt es keine
// !Labordaten fuer ihn, also kann er nicht in der
// !mibiInvestigations-PatientListe auftauchen...
let tested_pathogens: any[] = []
if (status_changes[pID]) {
tested_pathogens = Object.getOwnPropertyNames(status_changes[pID])
}
// let tested_pathogens: any[] = Object.getOwnPropertyNames(
// status_changes[pID]
// )
// console.log(
// `Tested Pathogens for this Patient... ${tested_pathogens}`
// )
// console.table(status_changes[pID])
tested_pathogens.forEach((pathID: any) => {
let current_last_ts = first_ts
let current_status = "unknown"
// Status von vor der Aufnahme ermitteln
status_changes[pID][pathID].forEach(
(stat_change: any, i: number) => {
// console.table(stat_change)
if (stat_change.timestamp <= min_ts) {
// console.log(`before first_ts ${stat_change}`)
current_status = get_worse_carrier_status(
current_status,
stat_change.new_status
)
// TODO: statt nur bei Verschlimmerung kann auch jedes mal neues Rectangle erzeugt werden
// current_status = stat_change.new_status
}
}
)
status_rects.push({
patient_id: pID,
pathogen_id: pathID,
begin: first_ts,
end: last_ts,
status: current_status,
})
// console.log(`Status VOR der Aufnahme: ${current_status}`)
status_changes[pID][pathID].forEach(
(stat_change: any, i: number) => {
let stat_change_ts = stat_change.timestamp
// console.table(stat_change)
// Nur wenn status_change innerhalb des Aufenthaltszeitraums liegt
if (stat_change_ts > min_ts && stat_change_ts < max_ts) {
let new_status = get_worse_carrier_status(
current_status,
stat_change.new_status
)
// console.log(`NEUER STATUS des Patienten: ${new_status}`)
// TODO: statt nur bei Verschlimmerung kann auch jedes mal neues Rectangle erzeugt werden
// new_status = stat_change.new_status
if (new_status !== current_status) {
status_rects[status_rects.length - 1].end = stat_change_ts
status_rects.push({
patient_id: pID,
pathogen_id: pathID,
begin: stat_change_ts,
end: last_ts,
status: new_status,
})
current_status = new_status
// console.log(`GEPSCHTER Status Recht: ${new_status}`)
}
}
}
)
})
})
}
} else {
error_log.addError(
"generate_mibi_investigations",
parameters,
parsed_error_prio,
generate_mibi_investigations.error
)
}
let patients_width_status_rects: any = []
status_rects.forEach((sr: any) => {
if (!patients_width_status_rects.includes(sr.patient_id)) {
patients_width_status_rects.push(sr.patient_id)
}
})
if (patients_width_status_rects.length < patientList.length) {
patientList.forEach((pID: any) => {
if (!patients_width_status_rects.includes(pID)) {
status_rects.push(unknown_rects[pID])
}
})
}