tidy up and document version conversion advisors

This commit is contained in:
Grahame Grieve 2021-05-05 08:28:03 +10:00
parent 696c16740e
commit 6a7435787f
20 changed files with 124 additions and 245 deletions

View File

@ -33,14 +33,54 @@ package org.hl7.fhir.convertors;
import org.hl7.fhir.exceptions.FHIRException;
/**
* This interface is passed into the version conversion routines when on of the
* converters is producing or converting R3 resources.
*
* The interface allows users of the code to
* 1. manage the life cycle of new resources created (or needed) during the conversion process
* 2. manage how unknown content etc is handled
*
* @author grahame
*
*/
public interface VersionConvertorAdvisor30 {
/**
* when processing a bundle, and converting from R3 to R2 whether to ignore an entry in the bundle.
* typically, return true when it's a resource that isn't handled, and you don't care.
*
* by default, always return false unless you know why not do this
*
* todo: why only R2? generalise this to all targets
*
* @param src
* @return
*/
boolean ignoreEntry(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent src);
// called ?
org.hl7.fhir.dstu2.model.Resource convert(org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException;
// called when an r2 value set has a codeSystem in it
/**
* In R2, code systems are internal to value sets, but in subsequent versions, they
* exist as separate resources. The convertor will create the code system, and then
* call this routine for the host to decide what to do with it
*
* It can make it a contained resource, or it can put it somewhere else
*
* @param tgtcs
* @param source
* @throws FHIRException
*/
void handleCodeSystem(org.hl7.fhir.dstu3.model.CodeSystem tgtcs, org.hl7.fhir.dstu3.model.ValueSet source) throws FHIRException;
/**
* when converting from R3 to R2, and converting a value set, the convertor will need
* to find the code system a value set is referring to, so it can include it inline.
*
* This routine should find the actual resource
*
* @param src
* @return
* @throws FHIRException
*/
org.hl7.fhir.dstu3.model.CodeSystem getCodeSystem(org.hl7.fhir.dstu3.model.ValueSet src) throws FHIRException;
}

View File

@ -33,16 +33,55 @@ package org.hl7.fhir.convertors;
import org.hl7.fhir.exceptions.FHIRException;
/**
* This interface is passed into the version conversion routines when on of the
* converters is producing or converting R4 resources.
*
* The interface allows users of the code to
* 1. manage the life cycle of new resources created (or needed) during the conversion process
* 2. manage how unknown content etc is handled
*
* @author grahame
*
*/
public interface VersionConvertorAdvisor40 {
/**
* when processing a bundle, and converting from R4 to R2 whether to ignore an entry in the bundle.
* typically, return true when it's a resource that isn't handled, and you don't care.
*
* by default, always return false unless you know why not do this
*
* todo: why only R2? generalise this to all targets
*
* @param src
* @return
*/
boolean ignoreEntry(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent src);
// called ?
org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException;
org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException;
org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException;
// called when an r2 value set has a codeSystem in it
/**
* In R2, code systems are internal to value sets, but in subsequent versions, they
* exist as separate resources. The convertor will create the code system, and then
* call this routine for the host to decide what to do with it
*
* It can make it a contained resource, or it can put it somewhere else
*
* @param tgtcs
* @param source
* @throws FHIRException
*/
void handleCodeSystem(org.hl7.fhir.r4.model.CodeSystem tgtcs, org.hl7.fhir.r4.model.ValueSet source) throws FHIRException;
/**
* when converting from R4 to R2, and converting a value set, the convertor will need
* to find the code system a value set is referring to, so it can include it inline.
*
* This routine should find the actual resource
*
* @param src
* @return
* @throws FHIRException
*/
org.hl7.fhir.r4.model.CodeSystem getCodeSystem(org.hl7.fhir.r4.model.ValueSet src) throws FHIRException;
}

View File

@ -34,16 +34,41 @@ package org.hl7.fhir.convertors;
import org.hl7.fhir.exceptions.FHIRException;
public interface VersionConvertorAdvisor50 {
/**
* when processing a bundle, and converting from R5 to R2 whether to ignore an entry in the bundle.
* typically, return true when it's a resource that isn't handled, and you don't care.
*
* by default, always return false unless you know why not do this
*
* todo: why only R2? generalise this to all targets
*
* @param src
* @return
*/
boolean ignoreEntry(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent src);
// called ?
org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException;
org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException;
org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException;
org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException;
// called when an r2 value set has a codeSystem in it
/**
* In R2, code systems are internal to value sets, but in subsequent versions, they
* exist as separate resources. The convertor will create the code system, and then
* call this routine for the host to decide what to do with it
*
* It can make it a contained resource, or it can put it somewhere else
*
* @param tgtcs
* @param source
* @throws FHIRException
*/
void handleCodeSystem(org.hl7.fhir.r5.model.CodeSystem tgtcs, org.hl7.fhir.r5.model.ValueSet source) throws FHIRException;
/**
* when converting from R5 to R2, and converting a value set, the convertor will need
* to find the code system a value set is referring to, so it can include it inline.
*
* This routine should find the actual resource
*
* @param src
* @return
* @throws FHIRException
*/
org.hl7.fhir.r5.model.CodeSystem getCodeSystem(org.hl7.fhir.r5.model.ValueSet src) throws FHIRException;
}

View File

@ -52,9 +52,7 @@ public class Bundle10_30 {
for (org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t));
if (src.hasFullUrlElement())
tgt.setFullUrlElement(VersionConvertor_10_30.convertUri(src.getFullUrlElement()));
org.hl7.fhir.dstu2.model.Resource res = advisor.convert(src.getResource());
if (res == null)
res = VersionConvertor_10_30.convertResource(src.getResource());
org.hl7.fhir.dstu2.model.Resource res = VersionConvertor_10_30.convertResource(src.getResource());
tgt.setResource(res);
if (src.hasSearch())
tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch()));

View File

@ -71,9 +71,7 @@ public class Bundle10_40 {
for (org.hl7.fhir.r4.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t));
if (src.hasFullUrlElement())
tgt.setFullUrlElement(VersionConvertor_10_40.convertUri(src.getFullUrlElement()));
org.hl7.fhir.dstu2.model.Resource res = advisor.convertR2(src.getResource());
if (res == null)
res = VersionConvertor_10_40.convertResource(src.getResource());
org.hl7.fhir.dstu2.model.Resource res = VersionConvertor_10_40.convertResource(src.getResource());
tgt.setResource(res);
if (src.hasSearch())
tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch()));

View File

@ -71,9 +71,7 @@ public class Bundle10_50 {
for (org.hl7.fhir.r5.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t));
if (src.hasFullUrlElement())
tgt.setFullUrlElement(VersionConvertor_10_50.convertUri(src.getFullUrlElement()));
org.hl7.fhir.dstu2.model.Resource res = advisor.convertR2(src.getResource());
if (res == null)
res = VersionConvertor_10_50.convertResource(src.getResource());
org.hl7.fhir.dstu2.model.Resource res = VersionConvertor_10_50.convertResource(src.getResource());
tgt.setResource(res);
if (src.hasSearch())
tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch()));

View File

@ -116,21 +116,6 @@ public class R2016MayToR4Loader extends BaseLoaderR4 implements IContextResource
return false;
}
@Override
public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
cs.setId(vs.getId());

View File

@ -163,21 +163,6 @@ public class R2016MayToR5Loader extends BaseLoaderR5 implements VersionConvertor
return false;
}
@Override
public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
cs.setId(vs.getId());
@ -191,11 +176,5 @@ public class R2016MayToR5Loader extends BaseLoaderR5 implements VersionConvertor
return null;
}
@Override
public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
}

View File

@ -113,10 +113,6 @@ public class R2ToR3Loader extends BaseLoaderR3 implements VersionConvertorAdviso
return false;
}
@Override
public Resource convert(org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {

View File

@ -115,20 +115,6 @@ public class R2ToR4Loader extends BaseLoaderR4 implements VersionConvertorAdviso
return false;
}
@Override
public Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
cs.setId(vs.getId());

View File

@ -163,20 +163,6 @@ public class R2ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
return false;
}
@Override
public Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
cs.setId(vs.getId());
@ -190,10 +176,5 @@ public class R2ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
return null;
}
@Override
public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
}

View File

@ -125,20 +125,6 @@ public class R3ToR4Loader extends BaseLoaderR4 implements IContextResourceLoader
return false;
}
@Override
public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {

View File

@ -166,21 +166,6 @@ public class R3ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
return false;
}
@Override
public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
cs.setId(vs.getId());
@ -194,9 +179,4 @@ public class R3ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
return null;
}
@Override
public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
}

View File

@ -166,21 +166,6 @@ public class R4ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
return false;
}
@Override
public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
cs.setId(vs.getId());
@ -194,9 +179,4 @@ public class R4ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
return null;
}
@Override
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
}

View File

@ -163,21 +163,6 @@ public class R5ToR5Loader extends BaseLoaderR5 implements VersionConvertorAdviso
return false;
}
@Override
public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
cs.setId(vs.getId());
@ -191,9 +176,4 @@ public class R5ToR5Loader extends BaseLoaderR5 implements VersionConvertorAdviso
return null;
}
@Override
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
}

View File

@ -89,10 +89,6 @@ public class IGPackConverter102 implements VersionConvertorAdvisor30 {
return false;
}
@Override
public Resource convert(org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem tgtcs, ValueSet vs) {

View File

@ -46,20 +46,7 @@ public class IGR2ConvertorAdvisor implements VersionConvertorAdvisor40 {
return false;
}
@Override
public Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {

View File

@ -46,21 +46,6 @@ public class IGR2ConvertorAdvisor5 implements VersionConvertorAdvisor50 {
return false;
}
@Override
public Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
cs.setId(vs.getId());
@ -71,9 +56,4 @@ public class IGR2ConvertorAdvisor5 implements VersionConvertorAdvisor50 {
return null;
}
@Override
public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
return null;
}
}

View File

@ -50,20 +50,6 @@ public class NpmPackageVersionConverter {
return false;
}
@Override
public Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
throw new Error("Not done yet");
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
throw new Error("Not done yet");
}
@Override
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException {
throw new Error("Not done yet");
}
@Override
public void handleCodeSystem(CodeSystem tgtcs, ValueSet source) throws FHIRException {

View File

@ -108,21 +108,6 @@ public class NativeHostServices {
return false;
}
@Override
public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu2.model.Resource convertR2(Resource resource) throws FHIRException {
return null;
}
@Override
public org.hl7.fhir.dstu3.model.Resource convertR3(Resource resource) throws FHIRException {
return null;
}
@Override
public void handleCodeSystem(CodeSystem tgtcs, ValueSet source) throws FHIRException {
}
@ -132,12 +117,6 @@ public class NativeHostServices {
throw new FHIRException("Code systems cannot be handled at this time"); // what to do? need thread local storage?
}
@Override
public org.hl7.fhir.r4.model.Resource convertR4(Resource resource) throws FHIRException {
// still to do
return null;
}
}
private ValidationEngine validator;