1- package in .projecteka .data ;
1+ package in .projecteka .utils . data ;
22
33import ca .uhn .fhir .context .FhirContext ;
44import 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 ;
88import org .hl7 .fhir .r4 .model .Attachment ;
99import org .hl7 .fhir .r4 .model .Bundle ;
1010import org .hl7 .fhir .r4 .model .CodeableConcept ;
3333import java .util .UUID ;
3434import java .util .stream .Collectors ;
3535
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 ;
4938
5039public class DiagnosticReportGenerator implements DocumentGenerator {
5140 private Properties doctors ;
@@ -58,20 +47,22 @@ public void init() throws Exception {
5847 }
5948
6049 @ 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 {
6251 FhirContext fhirContext = FhirContext .forR4 ();
6352 LocalDateTime dateTime = fromDate .toInstant ().atZone (ZoneId .systemDefault ()).toLocalDateTime ();
6453 for (int i = 0 ; i < number ; i ++) {
6554 Date date = Utils .getNextDate (dateTime , i );
66- Bundle bundle = createDiagnosticReportBundle (date , patientName , "max" , fhirContext .newJsonParser ());
55+ Bundle bundle = createDiagnosticReportBundle (date , patientName , hipPrefix , fhirContext .newJsonParser ());
6756 String encodedString = fhirContext .newJsonParser ().encodeResourceToString (bundle );
6857 List <Bundle .BundleEntryComponent > patientEntries =
6958 bundle .getEntry ().stream ()
7059 .filter (e -> e .getResource ().getResourceType ().equals (ResourceType .Patient ))
7160 .collect (Collectors .toList ());
7261 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" ));
7566 Path path = Paths .get (location .toString (), fileName );
7667 System .out .println ("Saving DiagnosticReport to file:" + path .toString ());
7768 Utils .saveToFile (path , encodedString );
@@ -80,61 +71,61 @@ public void execute(String patientName, Date fromDate, int number, Path location
8071 }
8172
8273 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 );
8576 Reference patientRef = new Reference ();
8677 patientRef .setResource (patientResource );
8778 Composition reportDoc = new Composition ();
8879 reportDoc .setId (UUID .randomUUID ().toString ());
8980 reportDoc .setDate (bundle .getTimestamp ());
90- reportDoc .setIdentifier (getIdentifier (reportDoc .getId (), hipPrefix , "document" ));
81+ reportDoc .setIdentifier (FHIRUtils . getIdentifier (reportDoc .getId (), hipPrefix , "document" ));
9182 reportDoc .setStatus (Composition .CompositionStatus .FINAL );
92- reportDoc .setType (getDiagnosticReportType ());
83+ reportDoc .setType (FHIRUtils . getDiagnosticReportType ());
9384 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 );
9788 reportDoc .addAuthor ().setResource (author );
9889 if (randomBool ()) {
9990 reportDoc .getAuthor ().get (0 ).setDisplay (Doctor .getDisplay (author ));
10091 }
101- addToBundleEntry (bundle , patientResource , false );
102- reportDoc .setSubject (getReferenceToPatient (patientResource ));
92+ FHIRUtils . addToBundleEntry (bundle , patientResource , false );
93+ reportDoc .setSubject (FHIRUtils . getReferenceToPatient (patientResource ));
10394 Composition .SectionComponent section = reportDoc .addSection ();
10495 section .setTitle ("# Diagnostic Report" );
105- section .setCode (getDiagnosticReportType ());
96+ section .setCode (FHIRUtils . getDiagnosticReportType ());
10697
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 );
111102 reportDoc .setEncounter (referenceToResource );
112103
113104 DiagnosticReport report = new DiagnosticReport ();
114105 report .setId (UUID .randomUUID ().toString ());
115106 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 ));
119110 if (randomBool ()) {
120111 report .setEncounter (referenceToResource );
121112 }
122113
123114 report .setIssued (date );
124115 if (randomBool ()) {
125- report .setEffective (getDateTimeType (date ));
116+ report .setEffective (FHIRUtils . getDateTimeType (date ));
126117 }
127118
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 )));
131122
132123 Practitioner interpreter = author ;
133124 if (randomBool ()) {
134- interpreter = createAuthor (hipPrefix , doctors );
135- addToBundleEntry (bundle , interpreter , false );
125+ interpreter = FHIRUtils . createAuthor (hipPrefix , doctors );
126+ FHIRUtils . addToBundleEntry (bundle , interpreter , false );
136127 }
137- report .setResultsInterpreter (Collections .singletonList (getReferenceToResource (interpreter )));
128+ report .setResultsInterpreter (Collections .singletonList (FHIRUtils . getReferenceToResource (interpreter )));
138129 report .setCode (getDiagnosticTestCode (DiagnosticTest .getRandomTest ()));
139130
140131 if (randomBool ()) {
@@ -153,8 +144,8 @@ private Bundle createDiagnosticReportBundle(Date date, String patientName, Strin
153144
154145 if (randomBool ()) {
155146 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 ));
158149 }
159150
160151 return bundle ;
@@ -163,22 +154,22 @@ private Bundle createDiagnosticReportBundle(Date date, String patientName, Strin
163154 private void addObservvationsToBundle (IParser parser , Bundle bundle , DiagnosticReport report ) {
164155 Observation observation = parser .parseResource (Observation .class , Obs .getObservationResString ());
165156 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 ));
168159 }
169160
170161 private DocumentReference getReportAsDocReference (Practitioner author ) throws IOException {
171162 DocumentReference documentReference = new DocumentReference ();
172163 documentReference .setStatus (Enumerations .DocumentReferenceStatus .CURRENT );
173164 documentReference .setId (UUID .randomUUID ().toString ());
174- documentReference .setType (getDiagnosticReportType ());
165+ documentReference .setType (FHIRUtils . getDiagnosticReportType ());
175166 CodeableConcept concept = new CodeableConcept ();
176167 Coding coding = concept .addCoding ();
177168 coding .setSystem (EKA_LOINC_SYSTEM );
178169 coding .setCode ("30954-2" );
179170 coding .setDisplay ("Surgical Pathology Report" );
180171 documentReference .setType (concept );
181- documentReference .setAuthor (Collections .singletonList (getReferenceToResource (author )));
172+ documentReference .setAuthor (Collections .singletonList (FHIRUtils . getReferenceToResource (author )));
182173 DocumentReference .DocumentReferenceContentComponent content = documentReference .addContent ();
183174 content .setAttachment (getSurgicalReportAsAttachment ());
184175 return documentReference ;
0 commit comments