@@ -192,6 +192,13 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
192
192
return myStrategy .valueSetFromCanonical (theValueSet );
193
193
}
194
194
195
+ /**
196
+ * Canonical version: R4
197
+ */
198
+ public IBaseResource codeSystemFromCanonical (CodeSystem theCodeSystem ) {
199
+ return myStrategy .codeSystemFromCanonical (theCodeSystem );
200
+ }
201
+
195
202
/**
196
203
* Canonical version: R4
197
204
*/
@@ -322,6 +329,8 @@ private interface IStrategy {
322
329
323
330
IBaseResource valueSetFromCanonical (ValueSet theValueSet );
324
331
332
+ IBaseResource codeSystemFromCanonical (CodeSystem theCodeSystem );
333
+
325
334
ConceptMap conceptMapToCanonical (IBaseResource theConceptMap );
326
335
327
336
SearchParameter searchParameterToCanonical (IBaseResource theSearchParameter );
@@ -443,6 +452,13 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
443
452
return reencodeFromHl7Org (valueSetDstu2Hl7Org );
444
453
}
445
454
455
+ @ Override
456
+ public IBaseResource codeSystemFromCanonical (CodeSystem theCodeSystem ) {
457
+ Resource codeSystemDstu2Hl7Org =
458
+ VersionConvertorFactory_10_40 .convertResource (theCodeSystem , ADVISOR_10_40 );
459
+ return reencodeFromHl7Org (codeSystemDstu2Hl7Org );
460
+ }
461
+
446
462
@ Override
447
463
public ConceptMap conceptMapToCanonical (IBaseResource theConceptMap ) {
448
464
org .hl7 .fhir .dstu2 .model .Resource reencoded = reencodeToHl7Org (theConceptMap );
@@ -524,21 +540,34 @@ public IBaseConformance capabilityStatementFromCanonical(CapabilityStatement the
524
540
}
525
541
526
542
private Resource reencodeToHl7Org (IBaseResource theInput ) {
543
+ if (theInput == null ) {
544
+ return null ;
545
+ }
527
546
if (myHl7OrgStructures ) {
528
547
return (Resource ) theInput ;
529
548
}
530
- return (Resource ) myDstu2Hl7OrgContext
531
- .newJsonParser ()
532
- .parseResource (myDstu2Context .newJsonParser ().encodeResourceToString (theInput ));
549
+ return (Resource ) myDstu2Hl7OrgContext .newJsonParser ().parseResource (encodeAsString (theInput ));
533
550
}
534
551
535
552
private IBaseResource reencodeFromHl7Org (Resource theInput ) {
553
+ if (theInput == null ) {
554
+ return null ;
555
+ }
536
556
if (myHl7OrgStructures ) {
537
557
return theInput ;
538
558
}
539
- return myDstu2Context
540
- .newJsonParser ()
541
- .parseResource (myDstu2Hl7OrgContext .newJsonParser ().encodeResourceToString (theInput ));
559
+ return myDstu2Context .newJsonParser ().parseResource (encodeAsString (theInput ));
560
+ }
561
+
562
+ private String encodeAsString (IBaseResource theResource ) {
563
+ FhirVersionEnum version = theResource .getStructureFhirVersionEnum ();
564
+ if (myDstu2Context .getVersion ().getVersion ().equals (version )) {
565
+ return myDstu2Context .newJsonParser ().encodeResourceToString (theResource );
566
+ } else if (myDstu2Hl7OrgContext .getVersion ().getVersion ().equals (version )) {
567
+ return myDstu2Hl7OrgContext .newJsonParser ().encodeResourceToString (theResource );
568
+ } else {
569
+ throw new IllegalArgumentException ("Cannot encode resource with version: %s" .formatted (version ));
570
+ }
542
571
}
543
572
}
544
573
@@ -579,6 +608,11 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
579
608
return VersionConvertorFactory_14_40 .convertResource (theValueSet , ADVISOR_14_40 );
580
609
}
581
610
611
+ @ Override
612
+ public IBaseResource codeSystemFromCanonical (CodeSystem theCodeSystem ) {
613
+ return VersionConvertorFactory_14_40 .convertResource (theCodeSystem , ADVISOR_14_40 );
614
+ }
615
+
582
616
@ Override
583
617
public ConceptMap conceptMapToCanonical (IBaseResource theConceptMap ) {
584
618
return (ConceptMap ) VersionConvertorFactory_14_40 .convertResource (
@@ -683,6 +717,11 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
683
717
return VersionConvertorFactory_30_40 .convertResource (theValueSet , ADVISOR_30_40 );
684
718
}
685
719
720
+ @ Override
721
+ public IBaseResource codeSystemFromCanonical (CodeSystem theCodeSystem ) {
722
+ return VersionConvertorFactory_30_40 .convertResource (theCodeSystem , ADVISOR_30_40 );
723
+ }
724
+
686
725
@ Override
687
726
public ConceptMap conceptMapToCanonical (IBaseResource theConceptMap ) {
688
727
return (ConceptMap ) VersionConvertorFactory_30_40 .convertResource (
@@ -782,6 +821,11 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
782
821
return theValueSet ;
783
822
}
784
823
824
+ @ Override
825
+ public IBaseResource codeSystemFromCanonical (CodeSystem theCodeSystem ) {
826
+ return theCodeSystem ;
827
+ }
828
+
785
829
@ Override
786
830
public ConceptMap conceptMapToCanonical (IBaseResource theConceptMap ) {
787
831
return (ConceptMap ) theConceptMap ;
@@ -897,6 +941,13 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
897
941
return VersionConvertorFactory_43_50 .convertResource (valueSetR5 , ADVISOR_43_50 );
898
942
}
899
943
944
+ @ Override
945
+ public IBaseResource codeSystemFromCanonical (CodeSystem theCodeSystem ) {
946
+ org .hl7 .fhir .r5 .model .CodeSystem codeSystemR5 = (org .hl7 .fhir .r5 .model .CodeSystem )
947
+ VersionConvertorFactory_40_50 .convertResource (theCodeSystem , ADVISOR_40_50 );
948
+ return VersionConvertorFactory_43_50 .convertResource (codeSystemR5 , ADVISOR_43_50 );
949
+ }
950
+
900
951
@ Override
901
952
public ConceptMap conceptMapToCanonical (IBaseResource theConceptMap ) {
902
953
org .hl7 .fhir .r5 .model .ConceptMap conceptMapR5 =
@@ -1006,6 +1057,11 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
1006
1057
return VersionConvertorFactory_40_50 .convertResource (theValueSet , ADVISOR_40_50 );
1007
1058
}
1008
1059
1060
+ @ Override
1061
+ public IBaseResource codeSystemFromCanonical (CodeSystem theCodeSystem ) {
1062
+ return VersionConvertorFactory_40_50 .convertResource (theCodeSystem , ADVISOR_40_50 );
1063
+ }
1064
+
1009
1065
@ Override
1010
1066
public ConceptMap conceptMapToCanonical (IBaseResource theConceptMap ) {
1011
1067
return (ConceptMap ) VersionConvertorFactory_40_50 .convertResource (
0 commit comments