Merge pull request #800 from InfiniteLoop90/issue-799-jaxrsrequest-fhir-version-support

Fixes issue #799 by adding logic to handle the R4 and DSTU2_1 contexts in ca.uhn.fhir.jaxrs.server.util.JaxRsRequest.
This commit is contained in:
James Agnew 2018-03-19 05:41:20 -04:00 committed by GitHub
commit 142c4c6caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 126 additions and 67 deletions

View File

@ -149,8 +149,12 @@ public class FhirContext {
myVersion = FhirVersionEnum.DSTU2.getVersionImplementation(); myVersion = FhirVersionEnum.DSTU2.getVersionImplementation();
} else if (FhirVersionEnum.DSTU2_HL7ORG.isPresentOnClasspath()) { } else if (FhirVersionEnum.DSTU2_HL7ORG.isPresentOnClasspath()) {
myVersion = FhirVersionEnum.DSTU2_HL7ORG.getVersionImplementation(); myVersion = FhirVersionEnum.DSTU2_HL7ORG.getVersionImplementation();
} else if (FhirVersionEnum.DSTU2_1.isPresentOnClasspath()) {
myVersion = FhirVersionEnum.DSTU2_1.getVersionImplementation();
} else if (FhirVersionEnum.DSTU3.isPresentOnClasspath()) { } else if (FhirVersionEnum.DSTU3.isPresentOnClasspath()) {
myVersion = FhirVersionEnum.DSTU3.getVersionImplementation(); myVersion = FhirVersionEnum.DSTU3.getVersionImplementation();
} else if (FhirVersionEnum.R4.isPresentOnClasspath()) {
myVersion = FhirVersionEnum.R4.getVersionImplementation();
} else { } else {
throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructures")); throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructures"));
} }

View File

@ -34,8 +34,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.dstu3.hapi.rest.server.ServerCapabilityStatementProvider;
import org.hl7.fhir.dstu3.model.CapabilityStatement;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -67,10 +65,10 @@ public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProv
/** the conformance. It is created once during startup */ /** the conformance. It is created once during startup */
private org.hl7.fhir.r4.model.CapabilityStatement myR4CapabilityStatement; private org.hl7.fhir.r4.model.CapabilityStatement myR4CapabilityStatement;
private CapabilityStatement myDstu3CapabilityStatement; private org.hl7.fhir.dstu3.model.CapabilityStatement myDstu3CapabilityStatement;
private org.hl7.fhir.dstu2016may.model.Conformance myDstu2_1Conformance; private org.hl7.fhir.dstu2016may.model.Conformance myDstu2_1Conformance;
private ca.uhn.fhir.model.dstu2.resource.Conformance myDstu2Conformance;
private org.hl7.fhir.instance.model.Conformance myDstu2Hl7OrgConformance; private org.hl7.fhir.instance.model.Conformance myDstu2Hl7OrgConformance;
private ca.uhn.fhir.model.dstu2.resource.Conformance myDstu2Conformance;
/** /**
* Constructor allowing the description, servername and server to be set * Constructor allowing the description, servername and server to be set
@ -127,26 +125,35 @@ public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProv
HardcodedServerAddressStrategy hardcodedServerAddressStrategy = new HardcodedServerAddressStrategy(); HardcodedServerAddressStrategy hardcodedServerAddressStrategy = new HardcodedServerAddressStrategy();
hardcodedServerAddressStrategy.setValue(getBaseForServer()); hardcodedServerAddressStrategy.setValue(getBaseForServer());
serverConfiguration.setServerAddressStrategy(hardcodedServerAddressStrategy); serverConfiguration.setServerAddressStrategy(hardcodedServerAddressStrategy);
if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.R4)) { FhirVersionEnum fhirContextVersion = super.getFhirContext().getVersion().getVersion();
org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider serverCapabilityStatementProvider = new org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider(serverConfiguration); switch (fhirContextVersion) {
serverCapabilityStatementProvider.initializeOperations(); case R4:
myR4CapabilityStatement = serverCapabilityStatementProvider.getServerConformance(null); org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider r4ServerCapabilityStatementProvider = new org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider(serverConfiguration);
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU3)) { r4ServerCapabilityStatementProvider.initializeOperations();
ServerCapabilityStatementProvider serverCapabilityStatementProvider = new ServerCapabilityStatementProvider(serverConfiguration); myR4CapabilityStatement = r4ServerCapabilityStatementProvider.getServerConformance(null);
serverCapabilityStatementProvider.initializeOperations(); break;
myDstu3CapabilityStatement = serverCapabilityStatementProvider.getServerConformance(null); case DSTU3:
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2_1)) { org.hl7.fhir.dstu3.hapi.rest.server.ServerCapabilityStatementProvider dstu3ServerCapabilityStatementProvider = new org.hl7.fhir.dstu3.hapi.rest.server.ServerCapabilityStatementProvider(serverConfiguration);
org.hl7.fhir.dstu2016may.hapi.rest.server.ServerConformanceProvider serverCapabilityStatementProvider = new org.hl7.fhir.dstu2016may.hapi.rest.server.ServerConformanceProvider(serverConfiguration); dstu3ServerCapabilityStatementProvider.initializeOperations();
serverCapabilityStatementProvider.initializeOperations(); myDstu3CapabilityStatement = dstu3ServerCapabilityStatementProvider.getServerConformance(null);
myDstu2_1Conformance = serverCapabilityStatementProvider.getServerConformance(null); break;
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2)) { case DSTU2_1:
ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider serverCapabilityStatementProvider = new ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider(serverConfiguration); org.hl7.fhir.dstu2016may.hapi.rest.server.ServerConformanceProvider dstu2_1ServerConformanceProvider = new org.hl7.fhir.dstu2016may.hapi.rest.server.ServerConformanceProvider(serverConfiguration);
serverCapabilityStatementProvider.initializeOperations(); dstu2_1ServerConformanceProvider.initializeOperations();
myDstu2Conformance = serverCapabilityStatementProvider.getServerConformance(null); myDstu2_1Conformance = dstu2_1ServerConformanceProvider.getServerConformance(null);
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) { break;
org.hl7.fhir.instance.conf.ServerConformanceProvider serverCapabilityStatementProvider = new org.hl7.fhir.instance.conf.ServerConformanceProvider(serverConfiguration); case DSTU2_HL7ORG:
serverCapabilityStatementProvider.initializeOperations(); org.hl7.fhir.instance.conf.ServerConformanceProvider dstu2Hl7OrgServerConformanceProvider = new org.hl7.fhir.instance.conf.ServerConformanceProvider(serverConfiguration);
myDstu2Hl7OrgConformance = serverCapabilityStatementProvider.getServerConformance(null); dstu2Hl7OrgServerConformanceProvider.initializeOperations();
myDstu2Hl7OrgConformance = dstu2Hl7OrgServerConformanceProvider.getServerConformance(null);
break;
case DSTU2:
ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider dstu2ServerConformanceProvider = new ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider(serverConfiguration);
dstu2ServerConformanceProvider.initializeOperations();
myDstu2Conformance = dstu2ServerConformanceProvider.getServerConformance(null);
break;
default:
throw new ConfigurationException("Unsupported Fhir version: " + fhirContextVersion);
} }
} }
@ -181,20 +188,26 @@ public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProv
IRestfulResponse response = request.build().getResponse(); IRestfulResponse response = request.build().getResponse();
response.addHeader(Constants.HEADER_CORS_ALLOW_ORIGIN, "*"); response.addHeader(Constants.HEADER_CORS_ALLOW_ORIGIN, "*");
IBaseResource conformance = null; IBaseResource conformance;
if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.R4)) { FhirVersionEnum fhirContextVersion = super.getFhirContext().getVersion().getVersion();
conformance = myR4CapabilityStatement; switch (fhirContextVersion) {
// return (Response) response.returnResponse(ParseAction.create(myDstu3CapabilityStatement), Constants.STATUS_HTTP_200_OK, true, null, getResourceType().getSimpleName()); case R4:
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU3)) { conformance = myR4CapabilityStatement;
conformance = myDstu3CapabilityStatement; break;
// return (Response) response.returnResponse(ParseAction.create(myDstu3CapabilityStatement), Constants.STATUS_HTTP_200_OK, true, null, getResourceType().getSimpleName()); case DSTU3:
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2_1)) { conformance = myDstu3CapabilityStatement;
conformance = myDstu2_1Conformance; break;
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2)) { case DSTU2_1:
conformance = myDstu2Conformance; conformance = myDstu2_1Conformance;
// return (Response) response.returnResponse(ParseAction.create(myDstu2CapabilityStatement), Constants.STATUS_HTTP_200_OK, true, null, getResourceType().getSimpleName()); break;
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) { case DSTU2_HL7ORG:
conformance = myDstu2Hl7OrgConformance; conformance = myDstu2Hl7OrgConformance;
break;
case DSTU2:
conformance = myDstu2Conformance;
break;
default:
throw new ConfigurationException("Unsupported Fhir version: " + fhirContextVersion);
} }
if (conformance != null) { if (conformance != null) {
@ -279,18 +292,21 @@ public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProv
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Class<IBaseResource> getResourceType() { public Class<IBaseResource> getResourceType() {
if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.R4)) { FhirVersionEnum fhirContextVersion = super.getFhirContext().getVersion().getVersion();
return Class.class.cast(org.hl7.fhir.r4.model.CapabilityStatement.class); switch (fhirContextVersion) {
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU3)) { case R4:
return Class.class.cast(CapabilityStatement.class); return Class.class.cast(org.hl7.fhir.r4.model.CapabilityStatement.class);
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2_1)) { case DSTU3:
return Class.class.cast(org.hl7.fhir.dstu2016may.model.Conformance.class); return Class.class.cast(org.hl7.fhir.dstu3.model.CapabilityStatement.class);
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2)) { case DSTU2_1:
return Class.class.cast(ca.uhn.fhir.model.dstu2.resource.Conformance.class); return Class.class.cast(org.hl7.fhir.dstu2016may.model.Conformance.class);
} else if (super.getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) { case DSTU2_HL7ORG:
return Class.class.cast(org.hl7.fhir.instance.model.Conformance.class); return Class.class.cast(org.hl7.fhir.instance.model.Conformance.class);
case DSTU2:
return Class.class.cast(ca.uhn.fhir.model.dstu2.resource.Conformance.class);
default:
throw new ConfigurationException("Unsupported Fhir version: " + fhirContextVersion);
} }
return null;
} }
} }

View File

@ -28,12 +28,11 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.dstu3.model.IdType;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsProvider; import ca.uhn.fhir.jaxrs.server.AbstractJaxRsProvider;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.api.*;
import ca.uhn.fhir.rest.api.server.IRestfulResponse; import ca.uhn.fhir.rest.api.server.IRestfulResponse;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
@ -93,28 +92,68 @@ public class JaxRsRequest extends RequestDetails {
FhirVersionEnum fhirContextVersion = myServer.getFhirContext().getVersion().getVersion(); FhirVersionEnum fhirContextVersion = myServer.getFhirContext().getVersion().getVersion();
if (StringUtils.isNotBlank(myVersion)) { if (StringUtils.isNotBlank(myVersion)) {
if (FhirVersionEnum.DSTU3.equals(fhirContextVersion) || FhirVersionEnum.DSTU2_HL7ORG.equals(fhirContextVersion)) { switch (fhirContextVersion) {
result.setId( case R4:
new IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId), UrlUtil.unescape(myVersion))); result.setId(new org.hl7.fhir.r4.model.IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId), UrlUtil.unescape(myVersion)));
} else if (FhirVersionEnum.DSTU2.equals(fhirContextVersion)) { break;
result.setId( case DSTU3:
new IdDt(myServer.getBaseForRequest(), UrlUtil.unescape(myId), UrlUtil.unescape(myVersion))); result.setId(new org.hl7.fhir.dstu3.model.IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId), UrlUtil.unescape(myVersion)));
} break;
case DSTU2_1:
result.setId(new org.hl7.fhir.dstu2016may.model.IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId), UrlUtil.unescape(myVersion)));
break;
case DSTU2_HL7ORG:
result.setId(new org.hl7.fhir.instance.model.IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId), UrlUtil.unescape(myVersion)));
break;
case DSTU2:
result.setId(new ca.uhn.fhir.model.primitive.IdDt(myServer.getBaseForRequest(), UrlUtil.unescape(myId), UrlUtil.unescape(myVersion)));
break;
default:
throw new ConfigurationException("Unsupported Fhir version: " + fhirContextVersion);
}
} else if (StringUtils.isNotBlank(myId)) { } else if (StringUtils.isNotBlank(myId)) {
if (FhirVersionEnum.DSTU3.equals(fhirContextVersion) || FhirVersionEnum.DSTU2_HL7ORG.equals(fhirContextVersion)) { switch (fhirContextVersion) {
result.setId(new IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId))); case R4:
} else if (FhirVersionEnum.DSTU2.equals(fhirContextVersion)) { result.setId(new org.hl7.fhir.r4.model.IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId)));
result.setId(new IdDt(myServer.getBaseForRequest(), UrlUtil.unescape(myId))); break;
} case DSTU3:
result.setId(new org.hl7.fhir.dstu3.model.IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId)));
break;
case DSTU2_1:
result.setId(new org.hl7.fhir.dstu2016may.model.IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId)));
break;
case DSTU2_HL7ORG:
result.setId(new org.hl7.fhir.instance.model.IdType(myServer.getBaseForRequest(), UrlUtil.unescape(myId)));
break;
case DSTU2:
result.setId(new ca.uhn.fhir.model.primitive.IdDt(myServer.getBaseForRequest(), UrlUtil.unescape(myId)));
break;
default:
throw new ConfigurationException("Unsupported Fhir version: " + fhirContextVersion);
}
} }
if (myRestOperation == RestOperationTypeEnum.UPDATE) { if (myRestOperation == RestOperationTypeEnum.UPDATE) {
String contentLocation = result.getHeader(Constants.HEADER_CONTENT_LOCATION); String contentLocation = result.getHeader(Constants.HEADER_CONTENT_LOCATION);
if (contentLocation != null) { if (contentLocation != null) {
if (FhirVersionEnum.DSTU3.equals(fhirContextVersion) || FhirVersionEnum.DSTU2_HL7ORG.equals(fhirContextVersion)) { switch (fhirContextVersion) {
result.setId(new IdType(contentLocation)); case R4:
} else if (FhirVersionEnum.DSTU2.equals(fhirContextVersion)) { result.setId(new org.hl7.fhir.r4.model.IdType(contentLocation));
result.setId(new IdDt(contentLocation)); break;
case DSTU3:
result.setId(new org.hl7.fhir.dstu3.model.IdType(contentLocation));
break;
case DSTU2_1:
result.setId(new org.hl7.fhir.dstu2016may.model.IdType(contentLocation));
break;
case DSTU2_HL7ORG:
result.setId(new org.hl7.fhir.instance.model.IdType(contentLocation));
break;
case DSTU2:
result.setId(new ca.uhn.fhir.model.primitive.IdDt(contentLocation));
break;
default:
throw new ConfigurationException("Unsupported Fhir version: " + fhirContextVersion);
} }
} }
} }