Skip to content

Commit b979a63

Browse files
committed
Minor refactoring. Introducing hip as variable.
1 parent c5d5b5b commit b979a63

16 files changed

+123
-82
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
### Random Data Generator For Patients.
99
takes the following parameters
10-
- out - the location directory where the file would be placed. Default in /tmp
11-
- type - PR (Prescription), DR (DiagnosticReport). Must be provided.
12-
- name - should be given and if given, will throw error if not found in *patients.properties* file. Will default to 'navjot' if no name is given. You may add more entries in the patients.properties file. Right now can generate for - hina, navjot, janki, nitesh
13-
- fromDate - provide in format yyyy-MM-dd (e.g 2020-03-21). If not given will default to current date.
14-
- number - how many documents to generate. If not given, only 1 is generated. Documents are generated in 2 days interval.
10+
- **out** - the location directory where the file would be placed. Default in /tmp
11+
- **type** - PR (Prescription), DR (DiagnosticReport). Must be provided.
12+
- **name** - should be given and if given, will throw error if not found in *patients.properties* file. Will default to 'navjot' if no name is given. You may add more entries in the patients.properties file. Right now can generate for - hina, navjot, janki, nitesh
13+
- **fromDate** - provide in format yyyy-MM-dd (e.g 2020-03-21). If not given will default to current date.
14+
- **number** - how many documents to generate. If not given, only 1 is generated. Documents are generated in 2 days interval.
15+
- **hip** - for which HIP to generate data. If not given, max is the default. Possible values are - max, tmh, wbc. You may change by adding another json in the resources/orgs/ directory.
1516

1617
## Build from source
1718

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sourceCompatibility = '11'
99

1010
jar {
1111
manifest {
12-
attributes('Main-Class': 'in.projecteka.data.Application')
12+
attributes('Main-Class': 'in.projecteka.utils.Application')
1313
}
1414
from {
1515
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }

src/main/java/in/projecteka/data/Application.java renamed to src/main/java/in/projecteka/utils/Application.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
package in.projecteka.data;
1+
package in.projecteka.utils;
2+
3+
import in.projecteka.utils.data.DiagnosticReportGenerator;
4+
import in.projecteka.utils.data.DocumentGenerator;
5+
import in.projecteka.utils.data.PrescriptionGenerator;
6+
import in.projecteka.utils.data.Utils;
27

38
import java.nio.file.Path;
49
import java.nio.file.Paths;
@@ -27,15 +32,24 @@ public static void main(String[] args) throws Exception {
2732
String patientName = getPatientName(checkRequired("name"));
2833
Date fromDate = getFromDate(checkRequired("fromDate"));
2934
int number = getNumerOfInstances(checkRequired("number"));
35+
String hip = getHip(checkRequired("hip"));
3036
DocumentGenerator documentGenerator = generators.get(type);
3137
documentGenerator.init();
3238
try {
33-
documentGenerator.execute(patientName, fromDate, number, location);
39+
documentGenerator.execute(patientName, fromDate, number, location, hip);
3440
} catch (Exception e) {
3541
e.printStackTrace();
3642
}
3743
}
3844

45+
private static String getHip(String hip) {
46+
if (Utils.isBlank(hip)) {
47+
System.out.println("hip not provided. Defaulting to max");
48+
return "max";
49+
}
50+
return hip;
51+
}
52+
3953
private static String getPatientName(String name) {
4054
if (Utils.isBlank(name)) {
4155
System.out.println("name not provided. Defaulting to navjot");

src/main/java/in/projecteka/data/Constants.java renamed to src/main/java/in/projecteka/utils/data/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package in.projecteka.data;
1+
package in.projecteka.utils.data;
22

33
public class Constants {
44
private static final String EKA_SYSTEM = "https://projecteka.in/%s";

src/main/java/in/projecteka/data/DiagnosticReportGenerator.java renamed to src/main/java/in/projecteka/utils/data/DiagnosticReportGenerator.java

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package in.projecteka.data;
1+
package in.projecteka.utils.data;
22

33
import ca.uhn.fhir.context.FhirContext;
44
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;
88
import org.hl7.fhir.r4.model.Attachment;
99
import org.hl7.fhir.r4.model.Bundle;
1010
import org.hl7.fhir.r4.model.CodeableConcept;
@@ -33,19 +33,8 @@
3333
import java.util.UUID;
3434
import 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

5039
public 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;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package in.projecteka.data;
1+
package in.projecteka.utils.data;
22

33
import java.nio.file.Path;
44
import java.util.Date;
55

66
public interface DocumentGenerator {
77
void init() throws Exception;
8-
void execute(String patientName, Date fromDate, int number, Path location) throws Exception;
8+
void execute(String patientName, Date fromDate, int number, Path location, String hipPrefix) throws Exception;
99
}

src/main/java/in/projecteka/data/FHIRUtils.java renamed to src/main/java/in/projecteka/utils/data/FHIRUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package in.projecteka.data;
1+
package in.projecteka.utils.data;
22

3-
import in.projecteka.data.model.Doctor;
3+
import in.projecteka.utils.data.model.Doctor;
44
import lombok.SneakyThrows;
55
import org.hl7.fhir.r4.model.Bundle;
66
import org.hl7.fhir.r4.model.CodeableConcept;
@@ -65,7 +65,7 @@ static Bundle createBundle(Date forDate, String hipDomain) {
6565
}
6666

6767
static Practitioner createAuthor(String hipPrefix, Properties doctors) {
68-
String details = (String) doctors.get(String.valueOf(Utils.randomInt(1, 3)));
68+
String details = (String) doctors.get(String.valueOf(Utils.randomInt(1, doctors.size())));
6969
Doctor doc = Doctor.parse(details);
7070
Practitioner practitioner = new Practitioner();
7171
practitioner.setId(hipPrefix.toUpperCase() + doc.getDocId());
@@ -79,7 +79,7 @@ static Patient getPatientResource(String name, Properties patients) throws Excep
7979
if (patientDetail == null) {
8080
throw new Exception("Can not identify patient with name: " + name);
8181
}
82-
in.projecteka.data.model.Patient patient = in.projecteka.data.model.Patient.parse((String) patientDetail);
82+
in.projecteka.utils.data.model.Patient patient = in.projecteka.utils.data.model.Patient.parse((String) patientDetail);
8383
Patient patientResource = new Patient();
8484
patientResource.setId(patient.getHid());
8585
patientResource.setName(Collections.singletonList(getHumanName(patient.getName(), null, null)));

src/main/java/in/projecteka/data/PrescriptionGenerator.java renamed to src/main/java/in/projecteka/utils/data/PrescriptionGenerator.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package in.projecteka.data;
1+
package in.projecteka.utils.data;
22

33
import ca.uhn.fhir.context.FhirContext;
4-
import in.projecteka.data.model.Doctor;
5-
import in.projecteka.data.model.Medicine;
4+
import in.projecteka.utils.data.model.Doctor;
5+
import in.projecteka.utils.data.model.Medicine;
66
import org.hl7.fhir.r4.model.Binary;
77
import org.hl7.fhir.r4.model.Bundle;
88
import org.hl7.fhir.r4.model.CodeableConcept;
@@ -39,20 +39,22 @@ public void init() throws Exception {
3939
patients = Utils.loadFromFile("/patients.properties");
4040
}
4141

42-
public void execute(String patientName, Date fromDate, int number, Path location) throws Exception {
42+
public void execute(String patientName, Date fromDate, int number, Path location, String hipPrefix) throws Exception {
4343
FhirContext fhirContext = FhirContext.forR4();
4444
LocalDateTime dateTime = fromDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
4545
for (int i = 0; i < number; i++) {
4646
Date date = Utils.getNextDate(dateTime, i);
47-
Bundle bundle = createPrescriptionBundle(date, patientName, "max");
47+
Bundle bundle = createPrescriptionBundle(date, patientName, hipPrefix);
4848
String encodedString = fhirContext.newJsonParser().encodeResourceToString(bundle);
4949
List<Bundle.BundleEntryComponent> patientEntries =
5050
bundle.getEntry().stream()
5151
.filter(e -> e.getResource().getResourceType().equals(ResourceType.Patient))
5252
.collect(Collectors.toList());
5353
Bundle.BundleEntryComponent patientEntry = patientEntries.get(0);
54-
String fileName = String.format("%sPrescriptionDoc%s.json",
55-
patientEntry.getResource().getId(), Utils.formatDate(date, "yyyyMMdd"));
54+
String fileName = String.format("%s%sPrescriptionDoc%s.json",
55+
hipPrefix.toUpperCase(),
56+
patientEntry.getResource().getId(),
57+
Utils.formatDate(date, "yyyyMMdd"));
5658
Path path = Paths.get(location.toString(), fileName);
5759
System.out.println("Saving Prescription to file:" + path.toString());
5860
Utils.saveToFile(path, encodedString);

src/main/java/in/projecteka/data/Utils.java renamed to src/main/java/in/projecteka/utils/data/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package in.projecteka.data;
1+
package in.projecteka.utils.data;
22

33
import org.hl7.fhir.r4.model.Meta;
44

src/main/java/in/projecteka/data/model/DiagnosticTest.java renamed to src/main/java/in/projecteka/utils/data/model/DiagnosticTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package in.projecteka.data.model;
1+
package in.projecteka.utils.data.model;
22

3-
import in.projecteka.data.Utils;
3+
import in.projecteka.utils.data.Utils;
44
import lombok.AllArgsConstructor;
55
import lombok.Data;
66

src/main/java/in/projecteka/data/model/Doctor.java renamed to src/main/java/in/projecteka/utils/data/model/Doctor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package in.projecteka.data.model;
1+
package in.projecteka.utils.data.model;
22

33
import lombok.AllArgsConstructor;
44
import lombok.Data;

src/main/java/in/projecteka/data/model/Medicine.java renamed to src/main/java/in/projecteka/utils/data/model/Medicine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package in.projecteka.data.model;
1+
package in.projecteka.utils.data.model;
22

33
import lombok.AllArgsConstructor;
44
import lombok.Data;

src/main/java/in/projecteka/data/model/Obs.java renamed to src/main/java/in/projecteka/utils/data/model/Obs.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
package in.projecteka.data.model;
1+
package in.projecteka.utils.data.model;
22

3-
import ca.uhn.fhir.parser.IParser;
4-
import in.projecteka.data.Utils;
3+
import in.projecteka.utils.data.Utils;
54
import lombok.AllArgsConstructor;
65
import lombok.Data;
76

src/main/java/in/projecteka/data/model/Patient.java renamed to src/main/java/in/projecteka/utils/data/model/Patient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package in.projecteka.data.model;
1+
package in.projecteka.utils.data.model;
22

33
import lombok.AllArgsConstructor;
44
import lombok.Data;

0 commit comments

Comments
 (0)