forked from amida-tech/cda2r4
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ResourceTransformerTest.java
1138 lines (1021 loc) · 45.6 KB
/
ResourceTransformerTest.java
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
package tr.com.srdc.cda2fhir;
/*
* #%L
* CDA to FHIR Transformer Library
* %%
* Copyright (C) 2016 SRDC Yazilim Arastirma ve Gelistirme ve Danismanlik Tic. A.S.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Composition.SectionComponent;
import org.hl7.fhir.r4.model.Condition;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.FamilyMemberHistory;
import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Immunization;
import org.hl7.fhir.r4.model.Medication;
import org.hl7.fhir.r4.model.MedicationStatement;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Patient.ContactComponent;
import org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent;
import org.hl7.fhir.r4.model.PractitionerRole;
import org.hl7.fhir.r4.model.Procedure;
import org.hl7.fhir.r4.model.Reference;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openhealthtools.mdht.uml.cda.Organizer;
import org.openhealthtools.mdht.uml.cda.PatientRole;
import org.openhealthtools.mdht.uml.cda.consol.AllergyProblemAct;
import org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument;
import org.openhealthtools.mdht.uml.cda.consol.FunctionalStatusResultOrganizer;
import org.openhealthtools.mdht.uml.cda.consol.FunctionalStatusSection;
import org.openhealthtools.mdht.uml.cda.consol.ImmunizationActivity;
import org.openhealthtools.mdht.uml.cda.consol.ImmunizationsSectionEntriesOptional;
import org.openhealthtools.mdht.uml.cda.consol.MedicationActivity;
import org.openhealthtools.mdht.uml.cda.consol.ProblemConcernAct;
import org.openhealthtools.mdht.uml.cda.consol.ResultOrganizer;
import org.openhealthtools.mdht.uml.cda.consol.ResultsSection;
import org.openhealthtools.mdht.uml.cda.consol.SocialHistorySection;
import org.openhealthtools.mdht.uml.cda.consol.VitalSignObservation;
import org.openhealthtools.mdht.uml.cda.consol.VitalSignsOrganizer;
import org.openhealthtools.mdht.uml.cda.consol.VitalSignsSectionEntriesOptional;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
import org.openhealthtools.mdht.uml.hl7.datatypes.EN;
import org.openhealthtools.mdht.uml.hl7.datatypes.ENXP;
import org.openhealthtools.mdht.uml.hl7.datatypes.II;
import ca.uhn.fhir.model.api.IResource;
import tr.com.srdc.cda2fhir.transform.ResourceTransformerImpl;
import tr.com.srdc.cda2fhir.transform.ValueSetsTransformerImpl;
import tr.com.srdc.cda2fhir.transform.entry.IEntryResult;
import tr.com.srdc.cda2fhir.transform.entry.impl.EntryResult;
import tr.com.srdc.cda2fhir.transform.util.impl.BundleInfo;
import tr.com.srdc.cda2fhir.util.FHIRUtil;
public class ResourceTransformerTest {
private static final ResourceTransformerImpl rt = new ResourceTransformerImpl();
private static final ValueSetsTransformerImpl vsti = new ValueSetsTransformerImpl();
private static FileInputStream fisCCD;
private static FileInputStream fisCCD2;
private static FileWriter resultFW;
private static ContinuityOfCareDocument ccd;
private static ContinuityOfCareDocument ccd2;
private static final String resultFilePath = "src/test/resources/output/ResourceTransformerTest.txt";
private static final String transformationStartMsg = "\n# TRANSFORMATION STARTING..\n";
private static final String transformationEndMsg = "# END OF TRANSFORMATION.\n";
private static final String endOfTestMsg = "\n## END OF TEST\n";
@BeforeClass
public static void init() {
CDAUtil.loadPackages();
// read the input test file
try {
fisCCD = new FileInputStream("src/test/resources/C-CDA_R2-1_CCD.xml");
fisCCD2 = new FileInputStream("src/test/resources/C-CDA_R2-1_CCD2.xml"); // Original does not have authoring
// device.
ccd = (ContinuityOfCareDocument) CDAUtil.load(fisCCD);
ccd2 = (ContinuityOfCareDocument) CDAUtil.load(fisCCD2);
} catch (Exception ex) {
ex.printStackTrace();
}
// init the output file writer
File resultFile = new File(resultFilePath);
resultFile.getParentFile().mkdirs();
try {
resultFW = new FileWriter(resultFile);
} catch (IOException e) {
e.printStackTrace();
}
}
@AfterClass
public static void finalise() {
try {
resultFW.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void referenceOrgNameStringTest() {
String name = "Organization Name";
Organization org = new Organization();
org.setName(name);
Reference ref = rt.getReference(org);
Assert.assertEquals("Organization name becomes reference display", ref.getDisplay(), name);
}
@Test
public void referenceHumanNameTest() {
String firstName = "Homer";
String lastName = "Simpson";
HumanName name = new HumanName();
name.setFamily(lastName);
name.addGiven(firstName);
Patient patient = new Patient();
patient.addName(name);
Reference ref = rt.getReference(patient);
Assert.assertEquals("Organization name becomes reference display", ref.getDisplay(),
name.getNameAsSingleString());
}
@Test
public void referenceImmunizationTest() {
CodeableConcept cc = new CodeableConcept();
String expectedDisplay = "expected display";
cc.setText(expectedDisplay);
Immunization immunization = new Immunization();
immunization.setVaccineCode(cc);
Reference ref = rt.getReference(immunization);
Assert.assertEquals("Organization name becomes reference display", ref.getDisplay(), expectedDisplay);
}
@Test
public void referenceDisplayFirstRepTest() {
Reference ref;
CodeableConcept cc = new CodeableConcept();
String expectedDisplay = "expected display";
Coding coding = new Coding();
coding.setDisplay(expectedDisplay);
cc.addCoding(coding);
PractitionerRole pracRole = new PractitionerRole();
Procedure procedure = new Procedure();
pracRole.addCode(cc);
procedure.setCode(cc);
ref = rt.getReference(pracRole);
Assert.assertEquals("Organization name becomes reference display", ref.getDisplay(), expectedDisplay);
ref = rt.getReference(procedure);
Assert.assertEquals("Organization name becomes reference display", ref.getDisplay(), expectedDisplay);
}
@Test
public void referenceCodeTest() {
Reference ref;
String expectedTestID = "testID/0";
String expectedDisplay = "expected display";
CodeableConcept cc = new CodeableConcept();
cc.setText(expectedDisplay);
Medication med = new Medication();
IdType id = new IdType("testID", "0");
med.setId(id);
med.setCode(cc);
ref = rt.getReference(med);
Assert.assertTrue(ref.getReference().contentEquals(expectedTestID));
MedicationStatement medStatement = new MedicationStatement();
medStatement.setId(id);
ref = rt.getReference(medStatement);
Assert.assertTrue(ref.getReference().contentEquals(expectedTestID));
Condition condition = new Condition();
condition.setId(id);
condition.setCode(cc);
ref = rt.getReference(condition);
Assert.assertTrue(ref.getReference().contentEquals(expectedTestID));
}
// Most of the test methods just print the transformed object in JSON form.
@Test
public void testAllergyProblemAct2AllergyIntolerance() {
appendToResultFile("## TEST: AllergyProblemAct2AllergyIntolerance\n");
// null instance test
AllergyProblemAct cdaNull = null;
BundleInfo bundleInfo = new BundleInfo(rt);
Bundle fhirNull = rt.tAllergyProblemAct2AllergyIntolerance(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
for (AllergyProblemAct cdaAPA : ResourceTransformerTest.ccd.getAllergiesSection().getAllergyProblemActs()) {
appendToResultFile(transformationStartMsg);
Bundle allergyBundle = rt.tAllergyProblemAct2AllergyIntolerance(cdaAPA, bundleInfo).getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(allergyBundle);
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testAssignedAuthor2Device() {
appendToResultFile("## TEST: AssignedAuthor2Device\n");
// null instance test
BundleInfo bundleInfo = new BundleInfo(rt);
org.openhealthtools.mdht.uml.cda.AssignedAuthor cdaNull = null;
Bundle fhirNull = rt.tAssignedAuthor2Device(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd2.getAuthors() != null) {
for (org.openhealthtools.mdht.uml.cda.Author author : ResourceTransformerTest.ccd2.getAuthors()) {
// traversing authors
if (author != null && author.getAssignedAuthor() != null) {
appendToResultFile(transformationStartMsg);
Bundle deviceBundle = rt.tAssignedAuthor2Device(author.getAssignedAuthor(), bundleInfo).getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(deviceBundle);
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testAssignedAuthor2Practitioner() {
appendToResultFile("## TEST: AssignedAuthor2Practitioner\n");
// null instance test
BundleInfo bundleInfo = new BundleInfo(rt);
org.openhealthtools.mdht.uml.cda.AssignedAuthor cdaNull = null;
Bundle fhirNull = rt.tAssignedAuthor2Practitioner(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd.getAuthors() != null) {
for (org.openhealthtools.mdht.uml.cda.Author author : ResourceTransformerTest.ccd.getAuthors()) {
// traversing authors
if (author != null && author.getAssignedAuthor() != null) {
appendToResultFile(transformationStartMsg);
Bundle practitionerBundle = rt.tAssignedAuthor2Practitioner(author.getAssignedAuthor(), bundleInfo)
.getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(practitionerBundle);
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testAssignedEntity2Practitioner() {
appendToResultFile("## TEST: AssignedEntity2Practitioner\n");
// null instance test
org.openhealthtools.mdht.uml.cda.AssignedEntity cdaNull = null;
BundleInfo bundleInfo = new BundleInfo(rt);
Bundle fhirNull = rt.tAssignedEntity2Practitioner(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd.getProceduresSection() != null
&& !ResourceTransformerTest.ccd.getProceduresSection().isSetNullFlavor()) {
if (ResourceTransformerTest.ccd.getProceduresSection().getProcedures() != null
&& !ResourceTransformerTest.ccd.getProceduresSection().getProcedures().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.Procedure procedure : ResourceTransformerTest.ccd
.getProceduresSection().getProcedures()) {
// traversing procedures
if (procedure.getPerformers() != null && !procedure.getPerformers().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.Performer2 performer : procedure.getPerformers()) {
if (performer.getAssignedEntity() != null
&& !performer.getAssignedEntity().isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
Bundle fhirPractitionerBundle = rt
.tAssignedEntity2Practitioner(performer.getAssignedEntity(), bundleInfo)
.getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirPractitionerBundle);
}
}
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testClinicalDocument2Composition() {
appendToResultFile("## TEST: ClinicalDocument2Composition\n");
// null instance test
org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument cdaNull = null;
Bundle fhirNull = rt.tClinicalDocument2Composition(cdaNull).getBundle();
Assert.assertNull(fhirNull);
// instance from file
if (ResourceTransformerTest.ccd != null && !ResourceTransformerTest.ccd.isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
Bundle fhirComp = rt.tClinicalDocument2Composition(ResourceTransformerTest.ccd).getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirComp);
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testEncounterActivity2Encounter() {
appendToResultFile("## TEST: EncounterActivity2Encounter\n");
// null instance test
org.openhealthtools.mdht.uml.cda.consol.EncounterActivities cdaNull = null;
BundleInfo bundleInfo = new BundleInfo(rt);
Bundle fhirNull = rt.tEncounterActivity2Encounter(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd.getEncountersSection() != null
&& !ResourceTransformerTest.ccd.getEncountersSection().isSetNullFlavor()) {
if (ResourceTransformerTest.ccd.getEncountersSection().getEncounterActivitiess() != null
&& !ResourceTransformerTest.ccd.getEncountersSection().getEncounterActivitiess().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.consol.EncounterActivities encounterActivity : ResourceTransformerTest.ccd
.getEncountersSection().getEncounterActivitiess()) {
if (encounterActivity != null && !encounterActivity.isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
Bundle fhirEncounterBundle = rt.tEncounterActivity2Encounter(encounterActivity, bundleInfo)
.getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirEncounterBundle);
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testFamilyHistoryOrganizer2FamilyMemberHistory() {
appendToResultFile("## TEST: FamilyHistoryOrganizer2FamilyMemberHistory\n");
// null instance test
org.openhealthtools.mdht.uml.cda.consol.FamilyHistoryOrganizer cdaNull = null;
FamilyMemberHistory fhirNull = rt.tFamilyHistoryOrganizer2FamilyMemberHistory(cdaNull);
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd.getFamilyHistorySection() != null
&& ResourceTransformerTest.ccd.getFamilyHistorySection().getFamilyHistories() != null) {
for (org.openhealthtools.mdht.uml.cda.consol.FamilyHistoryOrganizer familyHistoryOrganizer : ResourceTransformerTest.ccd
.getFamilyHistorySection().getFamilyHistories()) {
if (familyHistoryOrganizer != null) {
appendToResultFile(transformationStartMsg);
FamilyMemberHistory fmHistory = rt
.tFamilyHistoryOrganizer2FamilyMemberHistory(familyHistoryOrganizer);
appendToResultFile(transformationEndMsg);
appendToResultFile(fmHistory);
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testFunctionalStatus2Observation() {
appendToResultFile("## TEST: FunctionalStatus2Observation\n");
// null instance test
org.openhealthtools.mdht.uml.cda.Observation cdaNull = null;
BundleInfo bundleInfo = new BundleInfo(rt);
Bundle fhirNull = rt.tFunctionalStatus2Observation(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instance from file
FunctionalStatusSection funcStatSec = ResourceTransformerTest.ccd.getFunctionalStatusSection();
if (funcStatSec != null && !funcStatSec.isSetNullFlavor()) {
if (funcStatSec.getOrganizers() != null && !funcStatSec.getOrganizers().isEmpty()) {
for (Organizer funcStatOrg : funcStatSec.getOrganizers()) {
if (funcStatOrg != null && !funcStatOrg.isSetNullFlavor()) {
if (funcStatOrg instanceof FunctionalStatusResultOrganizer) {
if (((FunctionalStatusResultOrganizer) funcStatOrg).getObservations() != null
&& !((FunctionalStatusResultOrganizer) funcStatOrg).getObservations().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.Observation cdaObs : ((FunctionalStatusResultOrganizer) funcStatOrg)
.getObservations()) {
appendToResultFile(transformationStartMsg);
Bundle fhirObs = rt.tFunctionalStatus2Observation(cdaObs, bundleInfo).getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirObs);
}
}
}
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testGuardian2Contact() {
appendToResultFile("## TEST: Guardian2Contact\n");
// null instance test
org.openhealthtools.mdht.uml.cda.Guardian cdaNull = null;
ContactComponent fhirNull = rt.tGuardian2Contact(cdaNull);
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd.getPatientRoles() != null
&& !ResourceTransformerTest.ccd.getPatientRoles().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.PatientRole patientRole : ResourceTransformerTest.ccd
.getPatientRoles()) {
if (patientRole != null && !patientRole.isSetNullFlavor() && patientRole.getPatient() != null
&& !patientRole.getPatient().isSetNullFlavor()) {
for (org.openhealthtools.mdht.uml.cda.Guardian guardian : patientRole.getPatient().getGuardians()) {
if (guardian != null && !guardian.isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
ContactComponent contact = rt.tGuardian2Contact(guardian);
appendToResultFile(transformationEndMsg);
org.hl7.fhir.r4.model.Patient patient = new Patient().addContact(contact);
appendToResultFile(patient);
}
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testImmunizationActivity2Immunization() {
appendToResultFile("## TEST: ImmunizationActivity2Immunization\n");
// null instance test
org.openhealthtools.mdht.uml.cda.consol.ImmunizationActivity cdaNull = null;
BundleInfo bundleInfo = new BundleInfo(rt);
Bundle fhirNull = rt.tImmunizationActivity2Immunization(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
ImmunizationsSectionEntriesOptional immSec = ResourceTransformerTest.ccd
.getImmunizationsSectionEntriesOptional();
if (immSec != null && !immSec.isSetNullFlavor()) {
for (ImmunizationActivity immAct : immSec.getImmunizationActivities()) {
if (immAct != null && !immAct.isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
Bundle fhirImm = rt.tImmunizationActivity2Immunization(immAct, bundleInfo).getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirImm);
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testLanguageCommunication2Communication() {
appendToResultFile("## TEST: LanguageCommunication2Communication\n");
// null instance test
org.openhealthtools.mdht.uml.cda.LanguageCommunication cdaNull = null;
PatientCommunicationComponent fhirNull = rt.tLanguageCommunication2Communication(cdaNull);
Assert.assertNull(fhirNull);
// instances from file
for (org.openhealthtools.mdht.uml.cda.Patient patient : ResourceTransformerTest.ccd.getPatients()) {
for (org.openhealthtools.mdht.uml.cda.LanguageCommunication LC : patient.getLanguageCommunications()) {
appendToResultFile(transformationStartMsg);
PatientCommunicationComponent fhirCommunication = rt.tLanguageCommunication2Communication(LC);
appendToResultFile(transformationEndMsg);
org.hl7.fhir.r4.model.Patient fhirPatient = new org.hl7.fhir.r4.model.Patient();
fhirPatient.addCommunication(fhirCommunication);
appendToResultFile(fhirPatient);
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testManufacturedProduct2Medication() {
appendToResultFile("## TEST: ManufacturedProduct2Medication\n");
// null instance test
org.openhealthtools.mdht.uml.cda.ManufacturedProduct cdaNull = null;
BundleInfo bundleInfo = new BundleInfo(rt);
EntryResult nullResult = rt.tManufacturedProduct2Medication(cdaNull, bundleInfo);
Assert.assertFalse(nullResult.hasResult());
// instances from file
ImmunizationsSectionEntriesOptional immSection = ResourceTransformerTest.ccd
.getImmunizationsSectionEntriesOptional();
if (immSection != null && !immSection.isSetNullFlavor()) {
if (immSection.getImmunizationActivities() != null && !immSection.getImmunizationActivities().isEmpty()) {
for (ImmunizationActivity immAct : immSection.getImmunizationActivities()) {
if (immAct != null && !immAct.isSetNullFlavor()) {
if (immAct.getConsumable() != null && !immAct.getConsumable().isSetNullFlavor()) {
if (immAct.getConsumable().getManufacturedProduct() != null
&& !immAct.getConsumable().getManufacturedProduct().isSetNullFlavor()) {
// immAct.immSection.immAct.consumable.manuProd
appendToResultFile(transformationStartMsg);
EntryResult fhirMed = rt.tManufacturedProduct2Medication(
immAct.getConsumable().getManufacturedProduct(), bundleInfo);
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirMed.getBundle());
}
}
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testMedicationActivity2MedicationStatement() {
BundleInfo bundleInfo = new BundleInfo(rt);
appendToResultFile("## TEST: MedicationActivity2MedicationStatement\n");
// null instance test
org.openhealthtools.mdht.uml.cda.consol.MedicationActivity cdaNull = null;
Bundle fhirNull = rt.tMedicationActivity2MedicationStatement(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd.getMedicationsSection() != null
&& !ResourceTransformerTest.ccd.getMedicationsSection().isSetNullFlavor()) {
if (ResourceTransformerTest.ccd.getMedicationsSection().getMedicationActivities() != null
&& !ResourceTransformerTest.ccd.getMedicationsSection().getMedicationActivities().isEmpty()) {
for (MedicationActivity cdaMedAct : ResourceTransformerTest.ccd.getMedicationsSection()
.getMedicationActivities()) {
if (cdaMedAct != null && !cdaMedAct.isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
Bundle fhirMedStBundle = rt.tMedicationActivity2MedicationStatement(cdaMedAct, bundleInfo)
.getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirMedStBundle);
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testMedicationDispense2MedicationDispense() {
BundleInfo bundleInfo = new BundleInfo(rt);
appendToResultFile("## TEST: MedicationDispense2MedicationDispense\n");
// null instance test
org.openhealthtools.mdht.uml.cda.consol.MedicationDispense cdaNull = null;
Bundle fhirNull = rt.tMedicationDispense2MedicationDispense(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
// medicationsSection.medicationActivities.medicationDispense
if (ResourceTransformerTest.ccd.getMedicationsSection() != null
&& !ResourceTransformerTest.ccd.getMedicationsSection().isSetNullFlavor()) {
org.openhealthtools.mdht.uml.cda.consol.MedicationsSection medSec = ResourceTransformerTest.ccd
.getMedicationsSection();
if (medSec.getMedicationActivities() != null && !medSec.getMedicationActivities().isEmpty()) {
for (MedicationActivity medAct : medSec.getMedicationActivities()) {
if (medAct != null && !medAct.isSetNullFlavor()) {
if (medAct.getMedicationDispenses() != null && !medAct.getMedicationDispenses().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.consol.MedicationDispense medDisp : medAct
.getMedicationDispenses()) {
if (medDisp != null && !medDisp.isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
Bundle fhirMedDispBundle = rt
.tMedicationDispense2MedicationDispense(medDisp, bundleInfo).getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirMedDispBundle);
}
}
}
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testObservation2Observation() {
appendToResultFile("## TEST: Observation2Observation\n");
BundleInfo bundleInfo = new BundleInfo(rt);
// null instance test
org.openhealthtools.mdht.uml.cda.Observation cdaNull = null;
Bundle fhirNull = rt.tObservation2Observation(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd.getSocialHistorySection() != null
&& !ResourceTransformerTest.ccd.getSocialHistorySection().isSetNullFlavor()) {
if (ResourceTransformerTest.ccd.getSocialHistorySection().getObservations() != null
&& !ResourceTransformerTest.ccd.getSocialHistorySection().getObservations().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.Observation cdaObs : ResourceTransformerTest.ccd
.getSocialHistorySection().getObservations()) {
if (cdaObs != null && !cdaObs.isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
Bundle obsBundle = rt.tObservation2Observation(cdaObs, bundleInfo).getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(obsBundle);
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testOrganization2Organization() {
appendToResultFile("## TEST: Organization2Organization\n");
// null instance test
org.openhealthtools.mdht.uml.cda.Organization cdaNull = null;
IEntryResult result1 = rt.tOrganization2Organization(cdaNull, new BundleInfo(rt));
Assert.assertFalse(result1.hasResult());
// instances from file
for (org.openhealthtools.mdht.uml.cda.PatientRole patRole : ResourceTransformerTest.ccd.getPatientRoles()) {
org.openhealthtools.mdht.uml.cda.Organization cdaOrg = patRole.getProviderOrganization();
appendToResultFile(transformationStartMsg);
IEntryResult result2 = rt.tOrganization2Organization(cdaOrg, new BundleInfo(rt));
org.hl7.fhir.r4.model.Organization fhirOrg = FHIRUtil.findFirstResource(result2.getBundle(),
org.hl7.fhir.r4.model.Organization.class);
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirOrg);
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testPatientRole2Patient() {
appendToResultFile("## TEST: PatientRole2Patient\n");
// null instance test
org.openhealthtools.mdht.uml.cda.PatientRole cdaNull = null;
IEntryResult patientResult1 = rt.tPatientRole2Patient(cdaNull, new BundleInfo(rt));
Assert.assertFalse(patientResult1.hasResult());
// instances from file
for (PatientRole pr : ResourceTransformerTest.ccd.getPatientRoles()) {
// here we do the transformation by calling the method rt.PatientRole2Patient
Patient patient = null;
appendToResultFile(transformationStartMsg);
IEntryResult patientResult2 = rt.tPatientRole2Patient(pr, new BundleInfo(rt));
appendToResultFile(transformationEndMsg);
appendToResultFile(patientResult2.getBundle());
for (BundleEntryComponent entry : patientResult2.getFullBundle().getEntry()) {
if (entry.getResource() instanceof Patient) {
patient = (Patient) entry.getResource();
}
}
// patient.identifier
int idCount = 0;
for (II id : pr.getIds()) {
if (id.getRoot() != null && id.getExtension() != null) {
// since extension may contain "urn:oid:" or "urn:uuid:", assertion is about
// containing the value as a piece
Assert.assertTrue("pr.id.extension #" + idCount + " was not transformed",
patient.getIdentifier().get(idCount).getValue().contains(id.getExtension()));
Assert.assertTrue("pr.id.root #" + idCount + " was not transformed",
patient.getIdentifier().get(idCount).getSystem().contains(id.getRoot()));
} else if (id.getRoot() != null) {
Assert.assertTrue("pr.id.root #" + idCount + " was not transformed",
patient.getIdentifier().get(idCount).getValue().contains(id.getRoot()));
} else if (id.getExtension() != null) {
Assert.assertTrue("pr.id.root #" + idCount + " was not transformed",
patient.getIdentifier().get(idCount).getValue().contains(id.getExtension()));
}
// codeSystem method is changed and tested
idCount++;
}
// patient.name
// Notice that patient.name is fullfilled by the method EN2HumanName.
int nameCount = 0;
for (EN pn : pr.getPatient().getNames()) {
// patient.name.use
if (pn.getUses() == null || pn.getUses().isEmpty()) {
Assert.assertNull(patient.getName().get(nameCount).getUse().toCode());
} else {
Assert.assertEquals("pr.patient.name[" + nameCount + "]" + ".use was not transformed",
vsti.tEntityNameUse2NameUse(pn.getUses().get(0)).toString().toLowerCase(),
patient.getName().get(nameCount).getUse().toCode());
}
// patient.name.text
Assert.assertEquals("pr.patient.name[" + nameCount + "].text was not transformed", pn.getText(),
patient.getName().get(nameCount).getText());
// patient.name.family
for (ENXP family : pn.getFamilies()) {
if (family == null || family.isSetNullFlavor()) {
// It can return null or an empty list
Assert.assertTrue(patient.getName().get(nameCount).getFamily() == null
|| !patient.getName().get(nameCount)
.hasFamily()/* patient.getName().get(nameCount).getFamily().size() == 0 */);
} else {
Assert.assertEquals("pr.patient.name[" + nameCount + "].family was not transformed",
family.getText(),
patient.getName().get(nameCount).getFamily()/* .get(familyCount).getValue() */);
}
}
// patient.name.given
int givenCount = 0;
for (ENXP given : pn.getGivens()) {
if (given == null || given.isSetNullFlavor()) {
// It can return null or an empty list
Assert.assertTrue(patient.getName().get(nameCount).getGiven() == null
|| patient.getName().get(nameCount).getGiven().size() == 0);
} else {
Assert.assertEquals("pr.patient.name[" + nameCount + "].given was not transformed",
given.getText(),
patient.getName().get(nameCount).getGiven().get(givenCount).getValue());
}
givenCount++;
}
// patient.name.prefix
int prefixCount = 0;
for (ENXP prefix : pn.getPrefixes()) {
if (prefix == null || prefix.isSetNullFlavor()) {
// It can return null or an empty list
Assert.assertTrue(patient.getName().get(nameCount).getPrefix() == null
|| patient.getName().get(nameCount).getPrefix().size() == 0);
} else {
Assert.assertEquals("pr.patient.name[" + nameCount + "].prefix was not transformed",
prefix.getText(),
patient.getName().get(nameCount).getPrefix().get(prefixCount).getValue());
}
prefixCount++;
}
// patient.name.suffix
int suffixCount = 0;
for (ENXP suffix : pn.getPrefixes()) {
if (suffix == null || suffix.isSetNullFlavor()) {
// It can return null or an empty list
Assert.assertTrue(patient.getName().get(nameCount).getSuffix() == null
|| patient.getName().get(nameCount).getSuffix().size() == 0);
} else {
Assert.assertEquals("pr.patient.name[" + nameCount + "].suffix was not transformed",
suffix.getText(),
patient.getName().get(nameCount).getSuffix().get(suffixCount).getValue());
}
suffixCount++;
}
// patient.name.period
if (pn.getValidTime() == null || pn.getValidTime().isSetNullFlavor()) {
// It can return null or an empty list
Assert.assertTrue(patient.getName().get(nameCount).getPeriod() == null
|| patient.getName().get(nameCount).getPeriod().isEmpty());
}
}
// patient.telecom
// Notice that patient.telecom is fullfilled by the method dtt.TEL2ContactPoint
if (pr.getTelecoms() == null || pr.getTelecoms().isEmpty()) {
Assert.assertTrue(patient.getTelecom() == null || patient.getTelecom().isEmpty());
} else {
// size check
Assert.assertTrue(pr.getTelecoms().size() == patient.getTelecom().size());
// We have already tested the method TEL2ContactPoint. Therefore, null-check and
// size-check is enough for now.
}
// patient.gender
// vst.AdministrativeGenderCode2AdministrativeGenderEnum is used in this
// transformation.
// Following test aims to test that ValueSetTransformer method.
if (pr.getPatient().getAdministrativeGenderCode() == null
|| pr.getPatient().getAdministrativeGenderCode().isSetNullFlavor()) {
Assert.assertTrue(patient.getGender() == null || !patient.getGenderElement().hasValue());
}
// patient.birthDate
// Notice that patient.birthDate is fullfilled by the method dtt.TS2Date
if (pr.getPatient().getBirthTime() == null || pr.getPatient().getBirthTime().isSetNullFlavor()) {
Assert.assertTrue(patient.getBirthDate() == null);
}
// patient.address
// Notice that patient.address is fullfilled by the method dtt.AD2Address
if (pr.getAddrs() == null || pr.getAddrs().isEmpty()) {
Assert.assertTrue(patient.getAddress() == null || patient.getAddress().isEmpty());
} else {
// We have already tested the method AD2Address. Therefore, null-check and
// size-check is enough for now.
Assert.assertTrue(pr.getAddrs().size() == patient.getAddress().size());
}
// patient.maritalStatus
// vst.MaritalStatusCode2MaritalStatusCodesEnum is used in this transformation.
// Following test aims to test that ValueSetTransformer method.
if (pr.getPatient().getMaritalStatusCode() == null
|| pr.getPatient().getMaritalStatusCode().isSetNullFlavor()) {
Assert.assertTrue(patient.getMaritalStatus() == null || patient.getMaritalStatus().isEmpty());
} else {
Assert.assertTrue(patient.getMaritalStatus().getCoding().get(0).getCode().toLowerCase().charAt(0) == pr
.getPatient().getMaritalStatusCode().getCode().toLowerCase().charAt(0));
}
// patient.languageCommunication
if (pr.getPatient().getLanguageCommunications() == null
|| pr.getPatient().getLanguageCommunications().isEmpty()) {
Assert.assertTrue(patient.getCommunication() == null || patient.getCommunication().isEmpty());
} else {
Assert.assertTrue(
pr.getPatient().getLanguageCommunications().size() == patient.getCommunication().size());
int sizeCommunication = pr.getPatient().getLanguageCommunications().size();
while (sizeCommunication != 0) {
// language
if (pr.getPatient().getLanguageCommunications().get(sizeCommunication - 1).getLanguageCode() == null
|| pr.getPatient().getLanguageCommunications().get(0).getLanguageCode().isSetNullFlavor()) {
Assert.assertTrue(patient.getCommunication().get(sizeCommunication - 1).getLanguage() == null
|| patient.getCommunication().get(sizeCommunication - 1).getLanguage().isEmpty());
} else {
// We have already tested the method CD2CodeableConcept. Therefore, null-check
// is enough for now.
}
// preference
if (pr.getPatient().getLanguageCommunications().get(sizeCommunication - 1)
.getPreferenceInd() == null
|| pr.getPatient().getLanguageCommunications().get(sizeCommunication - 1).getPreferenceInd()
.isSetNullFlavor()) {
// Assert.assertTrue(patient.getCommunication().get(sizeCommunication -
// 1).getPreferred() == null);
Assert.assertTrue(!patient.getCommunication().get(sizeCommunication - 1).hasPreferred());
} else {
Assert.assertEquals(
pr.getPatient().getLanguageCommunications().get(sizeCommunication - 1)
.getPreferenceInd().getValue(),
patient.getCommunication().get(sizeCommunication - 1).getPreferred());
}
sizeCommunication--;
}
}
// providerOrganization
if (pr.getProviderOrganization() == null || pr.getProviderOrganization().isSetNullFlavor()) {
Assert.assertTrue(
patient.getManagingOrganization() == null || patient.getManagingOrganization().isEmpty());
} else {
if (pr.getProviderOrganization().getNames() == null) {
Assert.assertTrue(patient.getManagingOrganization().getDisplay() == null);
}
}
// guardian
if (pr.getPatient().getGuardians() == null || pr.getPatient().getGuardians().isEmpty()) {
Assert.assertTrue(patient.getContact() == null || patient.getContact().isEmpty());
} else {
// Notice that, inside this mapping, the methods dtt.TEL2ContactPoint and
// dtt.AD2Address are used.
// Therefore, null-check and size-check are enough
Assert.assertTrue(pr.getPatient().getGuardians().size() == patient.getContact().size());
}
// extensions
for (Extension extension : patient.getExtension()) {
Assert.assertTrue(extension.getUrl() != null);
Assert.assertTrue(extension.getValue() != null);
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testProblemConcernAct2Condition() {
BundleInfo bundleInfo = new BundleInfo(rt);
appendToResultFile("## TEST: ProblemConcernAct2Condition\n");
// null instance test
org.openhealthtools.mdht.uml.cda.consol.ProblemConcernAct cdaNull = null;
Bundle fhirNull = rt.tProblemConcernAct2Condition(cdaNull, bundleInfo).getBundle();
Assert.assertNull(fhirNull);
// instances from file
if (ResourceTransformerTest.ccd.getProblemSection() != null
&& !ResourceTransformerTest.ccd.getProblemSection().isSetNullFlavor()) {
if (ResourceTransformerTest.ccd.getProblemSection().getProblemConcerns() != null
&& !ResourceTransformerTest.ccd.getProblemSection().getProblemConcerns().isEmpty()) {
for (ProblemConcernAct problemConcernAct : ResourceTransformerTest.ccd.getProblemSection()
.getProblemConcerns()) {
if (problemConcernAct != null && !problemConcernAct.isSetNullFlavor()) {
appendToResultFile(transformationStartMsg);
Bundle fhirConditionBundle = rt.tProblemConcernAct2Condition(problemConcernAct, bundleInfo)
.getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirConditionBundle);
}
}
}
}
appendToResultFile(endOfTestMsg);
}
@Test
public void testProcedure2Procedure() {
BundleInfo bundleInfo = new BundleInfo(rt);
appendToResultFile("## TEST: Procedure2Procedure\n");
// null instance test
org.openhealthtools.mdht.uml.cda.Procedure cdaNull = null;
EntryResult entryResultNull = rt.tProcedure2Procedure(cdaNull, bundleInfo);
Assert.assertNull(entryResultNull.getBundle());
// instances from file
if (ResourceTransformerTest.ccd.getProceduresSection() != null
&& !ResourceTransformerTest.ccd.getProceduresSection().isSetNullFlavor()) {
if (ResourceTransformerTest.ccd.getProceduresSection().getProcedures() != null
&& !ResourceTransformerTest.ccd.getProceduresSection().getProcedures().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.Procedure cdaProcedure : ResourceTransformerTest.ccd
.getProceduresSection().getProcedures()) {
// traversing procedures
appendToResultFile(transformationStartMsg);
EntryResult entryResult = rt.tProcedure2Procedure(cdaProcedure, bundleInfo);
Bundle fhirProcedureBundle = entryResult.getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirProcedureBundle);
}
}
}
if (ResourceTransformerTest.ccd.getEncountersSection() != null
&& !ResourceTransformerTest.ccd.getEncountersSection().isSetNullFlavor()) {
if (ResourceTransformerTest.ccd.getEncountersSection().getProcedures() != null
&& !ResourceTransformerTest.ccd.getEncountersSection().getProcedures().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.Procedure cdaProcedure : ResourceTransformerTest.ccd
.getEncountersSection().getProcedures()) {
// traversing procedures
appendToResultFile(transformationStartMsg);
EntryResult entryResult = rt.tProcedure2Procedure(cdaProcedure, bundleInfo);
Bundle fhirProcedureBundle = entryResult.getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirProcedureBundle);
}
}
}
if (ResourceTransformerTest.ccd.getAllSections() != null
&& !ResourceTransformerTest.ccd.getAllSections().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.Section section : ResourceTransformerTest.ccd.getAllSections()) {
if (section.getProcedures() != null && !section.getProcedures().isEmpty()) {
for (org.openhealthtools.mdht.uml.cda.Procedure cdaProcedure : section.getProcedures()) {
// traversing procedures
appendToResultFile(transformationStartMsg);
EntryResult entryResult = rt.tProcedure2Procedure(cdaProcedure, bundleInfo);
Bundle fhirProcedureBundle = entryResult.getBundle();
appendToResultFile(transformationEndMsg);
appendToResultFile(fhirProcedureBundle);
}
}
}
}