1
1
package com .hilotec .elexis .kgview ;
2
2
3
3
import java .time .LocalDate ;
4
+ import java .time .format .DateTimeFormatter ;
4
5
import java .util .Collections ;
5
6
import java .util .Comparator ;
6
7
import java .util .List ;
7
8
import java .util .StringJoiner ;
9
+ import java .util .stream .Collectors ;
8
10
9
11
import javax .inject .Inject ;
10
12
11
13
import org .eclipse .core .runtime .IProgressMonitor ;
12
14
13
15
import com .hilotec .elexis .kgview .diagnoseliste .DiagnoselisteItem ;
14
16
17
+ import ch .elexis .core .findings .ICoding ;
15
18
import ch .elexis .core .findings .ICondition ;
16
19
import ch .elexis .core .findings .ICondition .ConditionCategory ;
17
20
import ch .elexis .core .findings .ICondition .ConditionStatus ;
18
21
import ch .elexis .core .findings .IFindingsService ;
22
+ import ch .elexis .core .findings .IObservation ;
23
+ import ch .elexis .core .findings .IObservation .ObservationCategory ;
24
+ import ch .elexis .core .findings .IObservation .ObservationCode ;
19
25
import ch .elexis .core .findings .migration .IMigratorService ;
26
+ import ch .elexis .core .findings .util .model .TransientCoding ;
20
27
import ch .elexis .core .services .holder .ConfigServiceHolder ;
21
28
import ch .elexis .core .ui .e4 .util .CoreUiUtil ;
22
29
import ch .elexis .data .Patient ;
@@ -35,35 +42,86 @@ public DiagnosisMigrator() {
35
42
public void migrate (IProgressMonitor monitor ) {
36
43
37
44
List <Patient > allPatients = new Query <Patient >(Patient .class ).execute ();
38
- monitor .beginTask ("Hilotec Diagnosen Migration" , allPatients .size ());
45
+ monitor .beginTask ("Hilotec Diagnosen/Anamnese Migration" , allPatients .size ());
39
46
ConfigServiceHolder .get ().set (IMigratorService .DIAGNOSE_SETTINGS_USE_STRUCTURED , true );
47
+ ConfigServiceHolder .get ().set (IMigratorService .PERSANAM_SETTINGS_USE_STRUCTURED , true );
40
48
for (Patient patient : allPatients ) {
41
- DiagnoselisteItem rootDiagnosis = DiagnoselisteItem .getRoot (patient , DiagnoselisteItem .TYP_DIAGNOSELISTE );
42
- LocalDate dateRecorded = new TimeTool (rootDiagnosis .getDatum ()).toLocalDate ();
43
- for (DiagnoselisteItem di : getSortedChildren (rootDiagnosis )) {
49
+ DiagnoselisteItem rootSysAnamnesis = DiagnoselisteItem .getRoot (patient , DiagnoselisteItem .TYP_SYSANAMNESE );
50
+ LocalDate dateRecorded = new TimeTool (rootSysAnamnesis .getDatum ()).toLocalDate ();
51
+ for (DiagnoselisteItem di : getSortedChildren (rootSysAnamnesis )) {
52
+ LocalDate itemDate = new TimeTool (di .getDatum ()).toLocalDate ();
44
53
ICondition condition = findingsService .create (ICondition .class );
45
54
condition .setPatientId (patient .getId ());
46
55
condition .setCategory (ConditionCategory .PROBLEMLISTITEM );
47
- condition .setStart (di .getText ());
56
+ condition .setStart (
57
+ di .getText () + " (" + itemDate .format (DateTimeFormatter .ofPattern ("dd.MM.yyyy" )) + ")" );
48
58
condition .setStatus (ConditionStatus .ACTIVE );
49
59
dateRecorded = dateRecorded .minusDays (1 );
50
60
condition .setDateRecorded (dateRecorded );
51
61
StringJoiner textJoiner = new StringJoiner ("\n " );
52
- addSubConditions (textJoiner , getSortedChildren (di ), 0 );
62
+ addSubItems (textJoiner , getSortedChildren (di ), 0 , true );
53
63
condition .setText (textJoiner .toString ());
54
64
findingsService .saveFinding (condition );
55
65
}
66
+
67
+ DiagnoselisteItem rootPersAnamnesis = DiagnoselisteItem .getRoot (patient ,
68
+ DiagnoselisteItem .TYP_PERSANAMNESE );
69
+ for (DiagnoselisteItem di : getSortedChildren (rootPersAnamnesis )) {
70
+ LocalDate itemDate = new TimeTool (di .getDatum ()).toLocalDate ();
71
+ IObservation observation = getOrCreatePersonalAnamnesis (patient .getId ());
72
+ StringJoiner textJoiner = new StringJoiner ("\n " );
73
+ // append to existing text
74
+ observation .getText ().ifPresent (text -> textJoiner .add (text ));
75
+ textJoiner .add (di .getText () + " (" + itemDate .format (DateTimeFormatter .ofPattern ("dd.MM.yyyy" )) + ")" );
76
+ addSubItems (textJoiner , getSortedChildren (di ), 2 , true );
77
+ observation .setText (textJoiner .toString ());
78
+ findingsService .saveFinding (observation );
79
+ }
56
80
monitor .worked (1 );
57
81
}
58
82
monitor .done ();
59
83
}
60
84
61
- private void addSubConditions (StringJoiner textJoiner , List <DiagnoselisteItem > sortedChildren , int depth ) {
85
+ private IObservation getOrCreatePersonalAnamnesis (String patientId ) {
86
+ List <IObservation > observations = findingsService .getPatientsFindings (patientId , IObservation .class );
87
+ observations = observations .parallelStream ().filter (iFinding -> isPersAnamnese (iFinding ))
88
+ .collect (Collectors .toList ());
89
+ if (observations .isEmpty ()) {
90
+ IObservation observation = findingsService .create (IObservation .class );
91
+ observation .setPatientId (patientId );
92
+ observation .setCategory (ObservationCategory .SOCIALHISTORY );
93
+ observation .setCoding (Collections .singletonList (new TransientCoding (ObservationCode .ANAM_PERSONAL )));
94
+ findingsService .saveFinding (observation );
95
+ return observation ;
96
+ } else {
97
+ return observations .get (0 );
98
+ }
99
+ }
100
+
101
+ private boolean isPersAnamnese (IObservation iFinding ) {
102
+ if (iFinding instanceof IObservation && iFinding .getCategory () == ObservationCategory .SOCIALHISTORY ) {
103
+ for (ICoding code : iFinding .getCoding ()) {
104
+ if (ObservationCode .ANAM_PERSONAL .isSame (code )) {
105
+ return true ;
106
+ }
107
+ }
108
+ }
109
+ return false ;
110
+ }
111
+
112
+ private void addSubItems (StringJoiner textJoiner , List <DiagnoselisteItem > sortedChildren , int depth ,
113
+ boolean addDate ) {
62
114
String postfix = " " .repeat (depth );
63
115
for (DiagnoselisteItem sub : sortedChildren ) {
64
- textJoiner .add (postfix + sub .getText ());
116
+ LocalDate dateRecorded = new TimeTool (sub .getDatum ()).toLocalDate ();
117
+ if (addDate ) {
118
+ textJoiner .add (postfix + sub .getText () + " ("
119
+ + dateRecorded .format (DateTimeFormatter .ofPattern ("dd.MM.yyyy" )) + ")" );
120
+ } else {
121
+ textJoiner .add (postfix + sub .getText ());
122
+ }
65
123
if (getSortedChildren (sub ).size () > 0 ) {
66
- addSubConditions (textJoiner , getSortedChildren (sub ), depth + 2 );
124
+ addSubItems (textJoiner , getSortedChildren (sub ), depth + 2 , addDate );
67
125
}
68
126
}
69
127
}
@@ -75,9 +133,9 @@ private List<DiagnoselisteItem> getSortedChildren(DiagnoselisteItem item) {
75
133
}
76
134
77
135
private class DiagnoselisteItemComparator implements Comparator <DiagnoselisteItem > {
78
- @ Override
79
- public int compare (DiagnoselisteItem o1 , DiagnoselisteItem o2 ) {
80
- return Integer .compare (o1 .getPosition (), o2 .getPosition ());
81
- }
136
+ @ Override
137
+ public int compare (DiagnoselisteItem o1 , DiagnoselisteItem o2 ) {
138
+ return Integer .compare (o1 .getPosition (), o2 .getPosition ());
82
139
}
140
+ }
83
141
}
0 commit comments