1
- package in .projecteka .data ;
1
+ package in .projecteka .utils . data ;
2
2
3
3
import ca .uhn .fhir .context .FhirContext ;
4
4
import ca .uhn .fhir .parser .IParser ;
5
- import in .projecteka .data .model .DiagnosticTest ;
6
- import in .projecteka .data .model .Doctor ;
7
- import in .projecteka .data .model .Obs ;
5
+ import in .projecteka .utils . data .model .DiagnosticTest ;
6
+ import in .projecteka .utils . data .model .Doctor ;
7
+ import in .projecteka .utils . data .model .Obs ;
8
8
import org .hl7 .fhir .r4 .model .Attachment ;
9
9
import org .hl7 .fhir .r4 .model .Bundle ;
10
10
import org .hl7 .fhir .r4 .model .CodeableConcept ;
33
33
import java .util .UUID ;
34
34
import java .util .stream .Collectors ;
35
35
36
- import static in .projecteka .data .Constants .EKA_LOINC_SYSTEM ;
37
- import static in .projecteka .data .FHIRUtils .addToBundleEntry ;
38
- import static in .projecteka .data .FHIRUtils .createAuthor ;
39
- import static in .projecteka .data .FHIRUtils .createBundle ;
40
- import static in .projecteka .data .FHIRUtils .createEncounter ;
41
- import static in .projecteka .data .FHIRUtils .getDateTimeType ;
42
- import static in .projecteka .data .FHIRUtils .getDiagnosticReportType ;
43
- import static in .projecteka .data .FHIRUtils .getIdentifier ;
44
- import static in .projecteka .data .FHIRUtils .getPatientResource ;
45
- import static in .projecteka .data .FHIRUtils .getReferenceToPatient ;
46
- import static in .projecteka .data .FHIRUtils .getReferenceToResource ;
47
- import static in .projecteka .data .FHIRUtils .loadOrganization ;
48
- import static in .projecteka .data .Utils .randomBool ;
36
+ import static in .projecteka .utils .data .Constants .EKA_LOINC_SYSTEM ;
37
+ import static in .projecteka .utils .data .Utils .randomBool ;
49
38
50
39
public class DiagnosticReportGenerator implements DocumentGenerator {
51
40
private Properties doctors ;
@@ -58,20 +47,22 @@ public void init() throws Exception {
58
47
}
59
48
60
49
@ Override
61
- public void execute (String patientName , Date fromDate , int number , Path location ) throws Exception {
50
+ public void execute (String patientName , Date fromDate , int number , Path location , String hipPrefix ) throws Exception {
62
51
FhirContext fhirContext = FhirContext .forR4 ();
63
52
LocalDateTime dateTime = fromDate .toInstant ().atZone (ZoneId .systemDefault ()).toLocalDateTime ();
64
53
for (int i = 0 ; i < number ; i ++) {
65
54
Date date = Utils .getNextDate (dateTime , i );
66
- Bundle bundle = createDiagnosticReportBundle (date , patientName , "max" , fhirContext .newJsonParser ());
55
+ Bundle bundle = createDiagnosticReportBundle (date , patientName , hipPrefix , fhirContext .newJsonParser ());
67
56
String encodedString = fhirContext .newJsonParser ().encodeResourceToString (bundle );
68
57
List <Bundle .BundleEntryComponent > patientEntries =
69
58
bundle .getEntry ().stream ()
70
59
.filter (e -> e .getResource ().getResourceType ().equals (ResourceType .Patient ))
71
60
.collect (Collectors .toList ());
72
61
Bundle .BundleEntryComponent patientEntry = patientEntries .get (0 );
73
- String fileName = String .format ("%sDiagnosticReportDoc%s.json" ,
74
- patientEntry .getResource ().getId (), Utils .formatDate (date , "yyyyMMdd" ));
62
+ String fileName = String .format ("%s%sDiagnosticReportDoc%s.json" ,
63
+ hipPrefix .toUpperCase (),
64
+ patientEntry .getResource ().getId (),
65
+ Utils .formatDate (date , "yyyyMMdd" ));
75
66
Path path = Paths .get (location .toString (), fileName );
76
67
System .out .println ("Saving DiagnosticReport to file:" + path .toString ());
77
68
Utils .saveToFile (path , encodedString );
@@ -80,61 +71,61 @@ public void execute(String patientName, Date fromDate, int number, Path location
80
71
}
81
72
82
73
private Bundle createDiagnosticReportBundle (Date date , String patientName , String hipPrefix , IParser parser ) throws Exception {
83
- Bundle bundle = createBundle (date , hipPrefix );
84
- Patient patientResource = getPatientResource (patientName , patients );
74
+ Bundle bundle = FHIRUtils . createBundle (date , hipPrefix );
75
+ Patient patientResource = FHIRUtils . getPatientResource (patientName , patients );
85
76
Reference patientRef = new Reference ();
86
77
patientRef .setResource (patientResource );
87
78
Composition reportDoc = new Composition ();
88
79
reportDoc .setId (UUID .randomUUID ().toString ());
89
80
reportDoc .setDate (bundle .getTimestamp ());
90
- reportDoc .setIdentifier (getIdentifier (reportDoc .getId (), hipPrefix , "document" ));
81
+ reportDoc .setIdentifier (FHIRUtils . getIdentifier (reportDoc .getId (), hipPrefix , "document" ));
91
82
reportDoc .setStatus (Composition .CompositionStatus .FINAL );
92
- reportDoc .setType (getDiagnosticReportType ());
83
+ reportDoc .setType (FHIRUtils . getDiagnosticReportType ());
93
84
reportDoc .setTitle ("Diagnostic Report Document" );
94
- addToBundleEntry (bundle , reportDoc , false );
95
- Practitioner author = createAuthor (hipPrefix , doctors );
96
- addToBundleEntry (bundle , author , false );
85
+ FHIRUtils . addToBundleEntry (bundle , reportDoc , false );
86
+ Practitioner author = FHIRUtils . createAuthor (hipPrefix , doctors );
87
+ FHIRUtils . addToBundleEntry (bundle , author , false );
97
88
reportDoc .addAuthor ().setResource (author );
98
89
if (randomBool ()) {
99
90
reportDoc .getAuthor ().get (0 ).setDisplay (Doctor .getDisplay (author ));
100
91
}
101
- addToBundleEntry (bundle , patientResource , false );
102
- reportDoc .setSubject (getReferenceToPatient (patientResource ));
92
+ FHIRUtils . addToBundleEntry (bundle , patientResource , false );
93
+ reportDoc .setSubject (FHIRUtils . getReferenceToPatient (patientResource ));
103
94
Composition .SectionComponent section = reportDoc .addSection ();
104
95
section .setTitle ("# Diagnostic Report" );
105
- section .setCode (getDiagnosticReportType ());
96
+ section .setCode (FHIRUtils . getDiagnosticReportType ());
106
97
107
- Encounter encounter = createEncounter ("Outpatient visit" , "AMB" , reportDoc .getDate ());
108
- encounter .setSubject (getReferenceToPatient (patientResource ));
109
- addToBundleEntry (bundle , encounter , false );
110
- Reference referenceToResource = getReferenceToResource (encounter );
98
+ Encounter encounter = FHIRUtils . createEncounter ("Outpatient visit" , "AMB" , reportDoc .getDate ());
99
+ encounter .setSubject (FHIRUtils . getReferenceToPatient (patientResource ));
100
+ FHIRUtils . addToBundleEntry (bundle , encounter , false );
101
+ Reference referenceToResource = FHIRUtils . getReferenceToResource (encounter );
111
102
reportDoc .setEncounter (referenceToResource );
112
103
113
104
DiagnosticReport report = new DiagnosticReport ();
114
105
report .setId (UUID .randomUUID ().toString ());
115
106
report .setStatus (DiagnosticReport .DiagnosticReportStatus .FINAL );
116
- section .getEntry ().add (getReferenceToResource (report ));
117
- addToBundleEntry (bundle , report , false );
118
- report .setSubject (getReferenceToPatient (patientResource ));
107
+ section .getEntry ().add (FHIRUtils . getReferenceToResource (report ));
108
+ FHIRUtils . addToBundleEntry (bundle , report , false );
109
+ report .setSubject (FHIRUtils . getReferenceToPatient (patientResource ));
119
110
if (randomBool ()) {
120
111
report .setEncounter (referenceToResource );
121
112
}
122
113
123
114
report .setIssued (date );
124
115
if (randomBool ()) {
125
- report .setEffective (getDateTimeType (date ));
116
+ report .setEffective (FHIRUtils . getDateTimeType (date ));
126
117
}
127
118
128
- Organization organization = parser .parseResource (Organization .class , loadOrganization (hipPrefix ));
129
- addToBundleEntry (bundle , organization , true );
130
- report .setPerformer (Collections .singletonList (getReferenceToResource (organization )));
119
+ Organization organization = parser .parseResource (Organization .class , FHIRUtils . loadOrganization (hipPrefix ));
120
+ FHIRUtils . addToBundleEntry (bundle , organization , true );
121
+ report .setPerformer (Collections .singletonList (FHIRUtils . getReferenceToResource (organization )));
131
122
132
123
Practitioner interpreter = author ;
133
124
if (randomBool ()) {
134
- interpreter = createAuthor (hipPrefix , doctors );
135
- addToBundleEntry (bundle , interpreter , false );
125
+ interpreter = FHIRUtils . createAuthor (hipPrefix , doctors );
126
+ FHIRUtils . addToBundleEntry (bundle , interpreter , false );
136
127
}
137
- report .setResultsInterpreter (Collections .singletonList (getReferenceToResource (interpreter )));
128
+ report .setResultsInterpreter (Collections .singletonList (FHIRUtils . getReferenceToResource (interpreter )));
138
129
report .setCode (getDiagnosticTestCode (DiagnosticTest .getRandomTest ()));
139
130
140
131
if (randomBool ()) {
@@ -153,8 +144,8 @@ private Bundle createDiagnosticReportBundle(Date date, String patientName, Strin
153
144
154
145
if (randomBool ()) {
155
146
DocumentReference docReference = getReportAsDocReference (author );
156
- addToBundleEntry (bundle , docReference , false );
157
- section .getEntry ().add (getReferenceToResource (docReference ));
147
+ FHIRUtils . addToBundleEntry (bundle , docReference , false );
148
+ section .getEntry ().add (FHIRUtils . getReferenceToResource (docReference ));
158
149
}
159
150
160
151
return bundle ;
@@ -163,22 +154,22 @@ private Bundle createDiagnosticReportBundle(Date date, String patientName, Strin
163
154
private void addObservvationsToBundle (IParser parser , Bundle bundle , DiagnosticReport report ) {
164
155
Observation observation = parser .parseResource (Observation .class , Obs .getObservationResString ());
165
156
observation .setId (UUID .randomUUID ().toString ());
166
- addToBundleEntry (bundle , observation , true );
167
- report .addResult (getReferenceToResource (observation ));
157
+ FHIRUtils . addToBundleEntry (bundle , observation , true );
158
+ report .addResult (FHIRUtils . getReferenceToResource (observation ));
168
159
}
169
160
170
161
private DocumentReference getReportAsDocReference (Practitioner author ) throws IOException {
171
162
DocumentReference documentReference = new DocumentReference ();
172
163
documentReference .setStatus (Enumerations .DocumentReferenceStatus .CURRENT );
173
164
documentReference .setId (UUID .randomUUID ().toString ());
174
- documentReference .setType (getDiagnosticReportType ());
165
+ documentReference .setType (FHIRUtils . getDiagnosticReportType ());
175
166
CodeableConcept concept = new CodeableConcept ();
176
167
Coding coding = concept .addCoding ();
177
168
coding .setSystem (EKA_LOINC_SYSTEM );
178
169
coding .setCode ("30954-2" );
179
170
coding .setDisplay ("Surgical Pathology Report" );
180
171
documentReference .setType (concept );
181
- documentReference .setAuthor (Collections .singletonList (getReferenceToResource (author )));
172
+ documentReference .setAuthor (Collections .singletonList (FHIRUtils . getReferenceToResource (author )));
182
173
DocumentReference .DocumentReferenceContentComponent content = documentReference .addContent ();
183
174
content .setAttachment (getSurgicalReportAsAttachment ());
184
175
return documentReference ;
0 commit comments