commit
2d5293c2ef
|
@ -30,6 +30,9 @@ import java.util.Map;
|
|||
import ca.uhn.fhir.model.api.IElement;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import com.phloc.commons.url.URLValidator;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition<IResource> {
|
||||
|
||||
|
@ -74,10 +77,30 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
|
|||
return ChildTypeEnum.RESOURCE;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getResourceProfile() {
|
||||
return myResourceProfile;
|
||||
}
|
||||
|
||||
public String getResourceProfile(String theServerBase) {
|
||||
String profile;
|
||||
if (!myResourceProfile.isEmpty()) {
|
||||
profile = myResourceProfile;
|
||||
} else if (!myId.isEmpty()) {
|
||||
profile = myId;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!URLValidator.isValid(profile)) {
|
||||
String profileWithUrl = theServerBase + "/Profile/" + profile;
|
||||
if (URLValidator.isValid(profileWithUrl)) {
|
||||
return profileWithUrl;
|
||||
}
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
public RuntimeSearchParam getSearchParam(String theName) {
|
||||
return myNameToSearchParam.get(theName);
|
||||
}
|
||||
|
@ -115,17 +138,26 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
|
|||
} while (target.equals(Object.class)==false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public synchronized IResource toProfile() {
|
||||
if (myProfileDef != null) {
|
||||
return myProfileDef;
|
||||
}
|
||||
|
||||
IResource retVal = myContext.getVersion().generateProfile(this);
|
||||
IResource retVal = myContext.getVersion().generateProfile(this, null);
|
||||
myProfileDef = retVal;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public synchronized IResource toProfile(String theServerBase) {
|
||||
if (myProfileDef != null) {
|
||||
return myProfileDef;
|
||||
}
|
||||
|
||||
IResource retVal = myContext.getVersion().generateProfile(this, theServerBase);
|
||||
myProfileDef = retVal;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,11 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
|||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public interface IFhirVersion {
|
||||
|
||||
IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition);
|
||||
IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase);
|
||||
|
||||
Object createServerConformanceProvider(RestfulServer theServer);
|
||||
|
||||
|
|
|
@ -469,11 +469,7 @@ public class RestfulServer extends HttpServlet {
|
|||
requestPath = requestPath.substring(1);
|
||||
}
|
||||
|
||||
fhirServerBase = myServerAddressStrategy.determineServerBase(getServletContext(), theRequest);
|
||||
|
||||
if (fhirServerBase.endsWith("/")) {
|
||||
fhirServerBase = fhirServerBase.substring(0, fhirServerBase.length() - 1);
|
||||
}
|
||||
fhirServerBase = getServerBaseForRequest(theRequest);
|
||||
|
||||
String completeUrl = StringUtils.isNotBlank(theRequest.getQueryString()) ? requestUrl + "?" + theRequest.getQueryString() : requestUrl.toString();
|
||||
|
||||
|
@ -707,7 +703,16 @@ public class RestfulServer extends HttpServlet {
|
|||
theResponse.getWriter().close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String getServerBaseForRequest(HttpServletRequest theRequest) {
|
||||
String fhirServerBase;
|
||||
fhirServerBase = myServerAddressStrategy.determineServerBase(getServletContext(), theRequest);
|
||||
|
||||
if (fhirServerBase.endsWith("/")) {
|
||||
fhirServerBase = fhirServerBase.substring(0, fhirServerBase.length() - 1);
|
||||
}
|
||||
return fhirServerBase;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -944,7 +949,7 @@ public class RestfulServer extends HttpServlet {
|
|||
myInterceptors.remove(theInterceptor);
|
||||
}
|
||||
|
||||
private static void addProfileToBundleEntry(FhirContext theContext, IResource theResource) {
|
||||
private static void addProfileToBundleEntry(FhirContext theContext, IResource theResource, String theServerBase) {
|
||||
|
||||
TagList tl = ResourceMetadataKeyEnum.TAG_LIST.get(theResource);
|
||||
if (tl == null) {
|
||||
|
@ -953,7 +958,7 @@ public class RestfulServer extends HttpServlet {
|
|||
}
|
||||
|
||||
RuntimeResourceDefinition nextDef = theContext.getResourceDefinition(theResource);
|
||||
String profile = nextDef.getResourceProfile();
|
||||
String profile = nextDef.getResourceProfile(theServerBase);
|
||||
if (isNotBlank(profile)) {
|
||||
tl.add(new Tag(Tag.HL7_ORG_PROFILE_TAG, profile, null));
|
||||
}
|
||||
|
@ -1017,7 +1022,7 @@ public class RestfulServer extends HttpServlet {
|
|||
for (IResource nextRes : resourceList) {
|
||||
RuntimeResourceDefinition def = theServer.getFhirContext().getResourceDefinition(nextRes);
|
||||
if (theServer.getAddProfileTag() == AddProfileTagEnum.ALWAYS || !def.isStandardProfile()) {
|
||||
addProfileToBundleEntry(theServer.getFhirContext(), nextRes);
|
||||
addProfileToBundleEntry(theServer.getFhirContext(), nextRes, theServerBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1336,7 +1341,7 @@ public class RestfulServer extends HttpServlet {
|
|||
if (theServer.getAddProfileTag() != AddProfileTagEnum.NEVER) {
|
||||
RuntimeResourceDefinition def = theServer.getFhirContext().getResourceDefinition(theResource);
|
||||
if (theServer.getAddProfileTag() == AddProfileTagEnum.ALWAYS || !def.isStandardProfile()) {
|
||||
addProfileToBundleEntry(theServer.getFhirContext(), theResource);
|
||||
addProfileToBundleEntry(theServer.getFhirContext(), theResource, theServerBase);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ import ca.uhn.fhir.rest.server.RestfulServer;
|
|||
import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider;
|
||||
import ca.uhn.fhir.util.ExtensionConstants;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class JpaConformanceProvider extends ServerConformanceProvider {
|
||||
|
||||
private String myImplementationDescription;
|
||||
|
@ -34,14 +36,14 @@ public class JpaConformanceProvider extends ServerConformanceProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Conformance getServerConformance() {
|
||||
public Conformance getServerConformance(HttpServletRequest theRequest) {
|
||||
Conformance retVal = myCachedValue;
|
||||
|
||||
Map<String, Long> counts = mySystemDao.getResourceCounts();
|
||||
|
||||
FhirContext ctx = myRestfulServer.getFhirContext();
|
||||
|
||||
retVal = super.getServerConformance();
|
||||
retVal = super.getServerConformance(theRequest);
|
||||
for (Rest nextRest : retVal.getRest()) {
|
||||
for (RestResource nextResource : nextRest.getResource()) {
|
||||
|
||||
|
|
|
@ -72,7 +72,8 @@ public class TestRestfulServer extends RestfulServer {
|
|||
|
||||
String baseUrl = System.getProperty("fhir.baseurl");
|
||||
if (StringUtils.isBlank(baseUrl)) {
|
||||
throw new ServletException("Missing system property: fhir.baseurl");
|
||||
//throw new ServletException("Missing system property: fhir.baseurl");
|
||||
baseUrl = "http://localhost:8080/base";
|
||||
}
|
||||
|
||||
setServerAddressStrategy(new HardcodedServerAddressStrategy(baseUrl));
|
||||
|
|
|
@ -32,6 +32,8 @@ import ca.uhn.fhir.rest.server.RestfulServer;
|
|||
import ca.uhn.fhir.rest.server.provider.dev.ServerConformanceProvider;
|
||||
import ca.uhn.fhir.rest.server.provider.dev.ServerProfileProvider;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class FhirDev implements IFhirVersion {
|
||||
|
||||
private String myId;
|
||||
|
@ -42,7 +44,7 @@ public class FhirDev implements IFhirVersion {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) {
|
||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
|
||||
Profile retVal = new Profile();
|
||||
|
||||
RuntimeResourceDefinition def = theRuntimeResourceDefinition;
|
||||
|
@ -58,7 +60,7 @@ public class FhirDev implements IFhirVersion {
|
|||
|
||||
@Override
|
||||
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
|
||||
return new ServerProfileProvider(theRestfulServer.getFhirContext());
|
||||
return new ServerProfileProvider(theRestfulServer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,13 +34,18 @@ import ca.uhn.fhir.rest.annotation.IdParam;
|
|||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class ServerProfileProvider implements IResourceProvider {
|
||||
|
||||
private FhirContext myContext;
|
||||
private final FhirContext myContext;
|
||||
private final RestfulServer myRestfulServer;
|
||||
|
||||
public ServerProfileProvider(FhirContext theCtx) {
|
||||
myContext = theCtx;
|
||||
public ServerProfileProvider(RestfulServer theServer) {
|
||||
myContext = theServer.getFhirContext();
|
||||
myRestfulServer = theServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,31 +54,36 @@ public class ServerProfileProvider implements IResourceProvider {
|
|||
}
|
||||
|
||||
@Read()
|
||||
public Profile getProfileById(@IdParam IdDt theId) {
|
||||
public Profile getProfileById(HttpServletRequest theRequest, @IdParam IdDt theId) {
|
||||
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getValue());
|
||||
if (retVal==null) {
|
||||
return null;
|
||||
}
|
||||
return (Profile) retVal.toProfile();
|
||||
String serverBase = getServerBase(theRequest);
|
||||
return (Profile) retVal.toProfile(serverBase);
|
||||
}
|
||||
|
||||
@Search()
|
||||
public List<Profile> getAllProfiles() {
|
||||
public List<Profile> getAllProfiles(HttpServletRequest theRequest) {
|
||||
final String serverBase = getServerBase(theRequest);
|
||||
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
|
||||
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
|
||||
@Override
|
||||
public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) {
|
||||
int cmp = theO1.getName().compareTo(theO2.getName());
|
||||
if (cmp==0) {
|
||||
cmp=theO1.getResourceProfile().compareTo(theO2.getResourceProfile());
|
||||
cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase));
|
||||
}
|
||||
return cmp;
|
||||
}});
|
||||
ArrayList<Profile> retVal = new ArrayList<Profile>();
|
||||
for (RuntimeResourceDefinition next : defs) {
|
||||
retVal.add((Profile) next.toProfile());
|
||||
retVal.add((Profile) next.toProfile(serverBase));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private String getServerBase(HttpServletRequest theHttpRequest) {
|
||||
return myRestfulServer.getServerBaseForRequest(theHttpRequest);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ import ca.uhn.fhir.rest.server.RestfulServer;
|
|||
import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider;
|
||||
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class FhirDstu1 implements IFhirVersion {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirDstu1.class);
|
||||
|
@ -128,7 +130,7 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
}
|
||||
}
|
||||
|
||||
private void fillName(StructureElement elem, BaseRuntimeElementDefinition<?> nextDef) {
|
||||
private void fillName(StructureElement elem, BaseRuntimeElementDefinition<?> nextDef, String theServerBase) {
|
||||
if (nextDef instanceof RuntimeResourceReferenceDefinition) {
|
||||
RuntimeResourceReferenceDefinition rr = (RuntimeResourceReferenceDefinition) nextDef;
|
||||
for (Class<? extends IResource> next : rr.getResourceTypes()) {
|
||||
|
@ -137,7 +139,7 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
|
||||
if (next != IResource.class) {
|
||||
RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType(next);
|
||||
type.getProfile().setValueAsString(resDef.getResourceProfile());
|
||||
type.getProfile().setValueAsString(resDef.getResourceProfile(theServerBase));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +155,7 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
type.setCode(fromCodeString);
|
||||
}
|
||||
|
||||
private void fillProfile(Structure theStruct, StructureElement theElement, BaseRuntimeElementDefinition<?> def, LinkedList<String> path, BaseRuntimeDeclaredChildDefinition theChild) {
|
||||
private void fillProfile(Structure theStruct, StructureElement theElement, BaseRuntimeElementDefinition<?> def, LinkedList<String> path, BaseRuntimeDeclaredChildDefinition theChild, String theServerBase) {
|
||||
|
||||
fillBasics(theElement, def, path, theChild);
|
||||
|
||||
|
@ -201,7 +203,7 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
|
||||
if (child instanceof RuntimeChildResourceBlockDefinition) {
|
||||
RuntimeResourceBlockDefinition nextDef = (RuntimeResourceBlockDefinition) child.getSingleChildOrThrow();
|
||||
fillProfile(theStruct, elem, nextDef, path, child);
|
||||
fillProfile(theStruct, elem, nextDef, path, child, theServerBase);
|
||||
} else if (child instanceof RuntimeChildContainedResources) {
|
||||
// ignore
|
||||
} else if (child instanceof RuntimeChildDeclaredExtensionDefinition) {
|
||||
|
@ -212,10 +214,10 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
String nextName = childNamesIter.next();
|
||||
BaseRuntimeElementDefinition<?> nextDef = child.getChildByName(nextName);
|
||||
fillBasics(elem, nextDef, path, child);
|
||||
fillName(elem, nextDef);
|
||||
fillName(elem, nextDef, theServerBase);
|
||||
while (childNamesIter.hasNext()) {
|
||||
nextDef = child.getChildByName(childNamesIter.next());
|
||||
fillName(elem, nextDef);
|
||||
fillName(elem, nextDef, theServerBase);
|
||||
}
|
||||
path.pollLast();
|
||||
} else {
|
||||
|
@ -231,7 +233,7 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) {
|
||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
|
||||
Profile retVal = new Profile();
|
||||
|
||||
RuntimeResourceDefinition def = theRuntimeResourceDefinition;
|
||||
|
@ -260,8 +262,7 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
StructureElement element = struct.addElement();
|
||||
element.getDefinition().setMin(1);
|
||||
element.getDefinition().setMax("1");
|
||||
|
||||
fillProfile(struct, element, def, path, null);
|
||||
fillProfile(struct, element, def, path, null, theServerBase);
|
||||
|
||||
retVal.getStructure().get(0).getElement().get(0).getDefinition().addType().getCode().setValue("Resource");
|
||||
|
||||
|
@ -318,7 +319,7 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
|
||||
@Override
|
||||
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
|
||||
return new ServerProfileProvider(theRestfulServer.getFhirContext());
|
||||
return new ServerProfileProvider(theRestfulServer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ import ca.uhn.fhir.rest.server.ResourceBinding;
|
|||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.util.ExtensionConstants;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Server FHIR Provider which serves the conformance statement for a RESTful server implementation
|
||||
*
|
||||
|
@ -95,7 +97,7 @@ public class ServerConformanceProvider {
|
|||
* See the class documentation for an important note if you are extending this class
|
||||
*/
|
||||
@Metadata
|
||||
public Conformance getServerConformance() {
|
||||
public Conformance getServerConformance(HttpServletRequest theRequest) {
|
||||
if (myConformance != null && myCache) {
|
||||
return myConformance;
|
||||
}
|
||||
|
@ -134,7 +136,7 @@ public class ServerConformanceProvider {
|
|||
String resourceName = next.getResourceName();
|
||||
RuntimeResourceDefinition def = myRestfulServer.getFhirContext().getResourceDefinition(resourceName);
|
||||
resource.getType().setValue(def.getName());
|
||||
resource.getProfile().setReference(new IdDt(def.getResourceProfile()));
|
||||
resource.getProfile().setReference(new IdDt(def.getResourceProfile(myRestfulServer.getServerBaseForRequest(theRequest))));
|
||||
|
||||
TreeSet<String> includes = new TreeSet<String>();
|
||||
|
||||
|
|
|
@ -34,13 +34,19 @@ import ca.uhn.fhir.rest.annotation.IdParam;
|
|||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import org.apache.http.HttpRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class ServerProfileProvider implements IResourceProvider {
|
||||
|
||||
private FhirContext myContext;
|
||||
private final FhirContext myContext;
|
||||
private final RestfulServer myRestfulServer;
|
||||
|
||||
public ServerProfileProvider(FhirContext theCtx) {
|
||||
myContext = theCtx;
|
||||
public ServerProfileProvider(RestfulServer theServer) {
|
||||
myContext = theServer.getFhirContext();
|
||||
myRestfulServer = theServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,31 +55,36 @@ public class ServerProfileProvider implements IResourceProvider {
|
|||
}
|
||||
|
||||
@Read()
|
||||
public Profile getProfileById(@IdParam IdDt theId) {
|
||||
public Profile getProfileById(HttpServletRequest theRequest, @IdParam IdDt theId) {
|
||||
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
|
||||
if (retVal==null) {
|
||||
return null;
|
||||
}
|
||||
return (Profile) retVal.toProfile();
|
||||
String serverBase = getServerBase(theRequest);
|
||||
return (Profile) retVal.toProfile(serverBase);
|
||||
}
|
||||
|
||||
@Search()
|
||||
public List<Profile> getAllProfiles() {
|
||||
public List<Profile> getAllProfiles(HttpServletRequest theRequest) {
|
||||
final String serverBase = getServerBase(theRequest);
|
||||
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
|
||||
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
|
||||
@Override
|
||||
public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) {
|
||||
int cmp = theO1.getName().compareTo(theO2.getName());
|
||||
if (cmp==0) {
|
||||
cmp=theO1.getResourceProfile().compareTo(theO2.getResourceProfile());
|
||||
cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase));
|
||||
}
|
||||
return cmp;
|
||||
}});
|
||||
ArrayList<Profile> retVal = new ArrayList<Profile>();
|
||||
for (RuntimeResourceDefinition next : defs) {
|
||||
retVal.add((Profile) next.toProfile());
|
||||
retVal.add((Profile) next.toProfile(serverBase));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private String getServerBase(HttpServletRequest theHttpRequest) {
|
||||
return myRestfulServer.getServerBaseForRequest(theHttpRequest);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,13 +25,13 @@ public class DuplicateExtensionTest extends TestCase {
|
|||
public void testScannerShouldAddProvidedResources() {
|
||||
FhirContext ctx = new FhirContext();
|
||||
RuntimeResourceDefinition patientDef = ctx.getResourceDefinition(CustomPatient.class);
|
||||
Profile profile = (Profile) patientDef.toProfile();
|
||||
Profile profile = (Profile) patientDef.toProfile("http://foo.org/fhir");
|
||||
|
||||
String res = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(profile);
|
||||
ourLog.info(res);
|
||||
|
||||
RuntimeResourceDefinition observationDef = ctx.getResourceDefinition(CustomObservation.class);
|
||||
profile = (Profile) observationDef.toProfile();
|
||||
profile = (Profile) observationDef.toProfile("http://foo.org/fhir");
|
||||
}
|
||||
|
||||
@ResourceDef(name = "Observation", id = "CustomObservation")
|
||||
|
|
|
@ -80,7 +80,7 @@ public class ExtensionTest {
|
|||
{
|
||||
FhirContext ctx2 = new FhirContext();
|
||||
RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient);
|
||||
System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile()));
|
||||
System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile("http://foo.org/fhir")));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package ca.uhn.fhir.context;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.resource.Profile;
|
||||
import ca.uhn.fhir.model.dstu.resource.Profile.ExtensionDefn;
|
||||
|
@ -13,6 +8,12 @@ import ca.uhn.fhir.model.dstu.resource.Profile.Structure;
|
|||
import ca.uhn.fhir.model.dstu.resource.Profile.StructureElement;
|
||||
import ca.uhn.fhir.model.dstu.resource.ValueSet;
|
||||
import ca.uhn.fhir.model.dstu.valueset.DataTypeEnum;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class RuntimeResourceDefinitionTest {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RuntimeResourceDefinitionTest.class);
|
||||
|
@ -22,7 +23,7 @@ public class RuntimeResourceDefinitionTest {
|
|||
FhirContext ctx = new FhirContext(Patient.class, Profile.class);
|
||||
RuntimeResourceDefinition def = ctx.getResourceDefinition(Patient.class);
|
||||
|
||||
Profile profile = (Profile) def.toProfile();
|
||||
Profile profile = (Profile) def.toProfile("http://foo.org/fhir");
|
||||
|
||||
ourLog.info(ctx.newXmlParser().encodeResourceToString(profile));
|
||||
|
||||
|
@ -41,7 +42,7 @@ public class RuntimeResourceDefinitionTest {
|
|||
FhirContext ctx = new FhirContext(ValueSet.class, Profile.class);
|
||||
RuntimeResourceDefinition def = ctx.getResourceDefinition(ValueSet.class);
|
||||
|
||||
Profile profile = (Profile) def.toProfile();
|
||||
Profile profile = (Profile) def.toProfile("http://foo.org/fhir");
|
||||
|
||||
String encoded = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(profile);
|
||||
ourLog.info(encoded);
|
||||
|
@ -56,9 +57,9 @@ public class RuntimeResourceDefinitionTest {
|
|||
FhirContext ctx = new FhirContext(ResourceWithExtensionsA.class, Profile.class);
|
||||
RuntimeResourceDefinition def = ctx.getResourceDefinition(ResourceWithExtensionsA.class);
|
||||
|
||||
Profile profile = (Profile) def.toProfile();
|
||||
Profile profile = (Profile) def.toProfile("http://foo.org/fhir");
|
||||
|
||||
ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(profile));
|
||||
ourLog.info(ctx.newXmlParser().encodeResourceToString(profile));
|
||||
|
||||
List<StructureElement> element = profile.getStructure().get(0).getElement();
|
||||
assertEquals(1, element.get(0).getDefinition().getType().size());
|
||||
|
@ -97,9 +98,53 @@ public class RuntimeResourceDefinitionTest {
|
|||
FhirContext ctx = new FhirContext(CustomObservation.class);
|
||||
RuntimeResourceDefinition def = ctx.getResourceDefinition(CustomObservation.class);
|
||||
|
||||
Profile profile = (Profile) def.toProfile();
|
||||
Profile profile = (Profile) def.toProfile("http://foo.org/fhir");
|
||||
|
||||
assertEquals("customobservation", profile.getId().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenResourceProfileNotSet_ProfileShouldBeConstructedFromServerBaseAndId() {
|
||||
FhirContext ctx = new FhirContext(PatientSansProfile.class);
|
||||
RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientSansProfile.class);
|
||||
assertEquals("http://foo.org/fhir/Profile/PatientSansProfile", def.getResourceProfile("http://foo.org/fhir"));
|
||||
}
|
||||
|
||||
@ResourceDef(name = "Patient", id = "PatientSansProfile")
|
||||
class PatientSansProfile extends Patient {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenResourceProfileHasNoUrl_ProfileShouldBeConstructedFromServerBaseAndProfile() {
|
||||
FhirContext ctx = new FhirContext(PatientWithShortProfile.class);
|
||||
RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithShortProfile.class);
|
||||
assertEquals("http://foo.org/fhir/Profile/PatientWithShortProfile", def.getResourceProfile("http://foo.org/fhir"));
|
||||
}
|
||||
|
||||
@ResourceDef(name = "Patient", id = "PatientWithShortProfileId", profile="PatientWithShortProfile")
|
||||
class PatientWithShortProfile extends Patient {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenResourceProfileHasUrl_ProfileShouldUseThat() {
|
||||
FhirContext ctx = new FhirContext(PatientWithFullProfile.class);
|
||||
RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithFullProfile.class);
|
||||
assertEquals("http://bar.org/Profile/PatientWithFullProfile", def.getResourceProfile("http://foo.org/fhir"));
|
||||
}
|
||||
|
||||
@ResourceDef(name = "Patient", id = "PatientWithFullProfileId", profile="http://bar.org/Profile/PatientWithFullProfile")
|
||||
class PatientWithFullProfile extends Patient {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenProfileAndIdAreBlank_ProfileShouldBeBlank() {
|
||||
FhirContext ctx = new FhirContext(PatientWithNoIdOrProfile.class);
|
||||
RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithNoIdOrProfile.class);
|
||||
assertEquals("", def.getResourceProfile("http://foo.org/fhir"));
|
||||
}
|
||||
|
||||
@ResourceDef(name = "Patient")
|
||||
class PatientWithNoIdOrProfile extends Patient {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package ca.uhn.fhir.rest.server;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -72,6 +74,8 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
|||
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
|
@ -997,10 +1001,19 @@ public class RestfulServerMethodTest {
|
|||
public void testServerProfileProviderFindsProfiles() {
|
||||
ServerProfileProvider profileProvider = (ServerProfileProvider)ourRestfulServer.getServerProfilesProvider();
|
||||
IdDt id = new IdDt("Profile", "observation");
|
||||
Profile profile = profileProvider.getProfileById(id);
|
||||
Profile profile = profileProvider.getProfileById(createHttpServletRequest(), id);
|
||||
assertNotNull(profile);
|
||||
}
|
||||
|
||||
private HttpServletRequest createHttpServletRequest() {
|
||||
HttpServletRequest req = mock(HttpServletRequest.class);
|
||||
when(req.getRequestURI()).thenReturn("/FhirStorm/fhir/Patient/_search");
|
||||
when(req.getServletPath()).thenReturn("/fhir");
|
||||
when(req.getRequestURL()).thenReturn(new StringBuffer().append("http://fhirstorm.dyndns.org:8080/FhirStorm/fhir/Patient/_search"));
|
||||
when(req.getContextPath()).thenReturn("/FhirStorm");
|
||||
return req;
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
|
@ -1013,12 +1026,14 @@ public class RestfulServerMethodTest {
|
|||
ourCtx = new FhirContext(Patient.class);
|
||||
|
||||
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
||||
ServerProfileProvider profProvider = new ServerProfileProvider(ourCtx);
|
||||
ourReportProvider = new DummyDiagnosticReportResourceProvider();
|
||||
DummyAdverseReactionResourceProvider adv = new DummyAdverseReactionResourceProvider();
|
||||
|
||||
ServletHandler proxyHandler = new ServletHandler();
|
||||
ourRestfulServer =new DummyRestfulServer(patientProvider, profProvider, ourReportProvider, adv);
|
||||
DummyRestfulServer dummyServer = new DummyRestfulServer(patientProvider, ourReportProvider, adv);
|
||||
ourRestfulServer = dummyServer;
|
||||
ServerProfileProvider profProvider = new ServerProfileProvider(ourRestfulServer);
|
||||
dummyServer.addResourceProvider(profProvider);
|
||||
ServletHolder servletHolder = new ServletHolder(ourRestfulServer);
|
||||
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
||||
ourServer.setHandler(proxyHandler);
|
||||
|
@ -1370,7 +1385,11 @@ public class RestfulServerMethodTest {
|
|||
private Collection<IResourceProvider> myResourceProviders;
|
||||
|
||||
public DummyRestfulServer(IResourceProvider... theResourceProviders) {
|
||||
myResourceProviders = Arrays.asList(theResourceProviders);
|
||||
myResourceProviders = new ArrayList<IResourceProvider>(Arrays.asList(theResourceProviders));
|
||||
}
|
||||
|
||||
public void addResourceProvider(IResourceProvider theResourceProvider) {
|
||||
myResourceProviders.add(theResourceProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -106,10 +106,10 @@ public class RestfulServerSelfReferenceTest {
|
|||
Server hServer = new Server(port);
|
||||
|
||||
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
||||
ServerProfileProvider profProvider = new ServerProfileProvider(ourCtx);
|
||||
|
||||
ServletHandler proxyHandler = new ServletHandler();
|
||||
RestfulServer server = new RestfulServer();
|
||||
ServerProfileProvider profProvider = new ServerProfileProvider(server);
|
||||
server.setFhirContext(ourCtx);
|
||||
server.setResourceProviders(patientProvider, profProvider);
|
||||
ServletHolder servletHolder = new ServletHolder(server);
|
||||
|
|
|
@ -4,6 +4,8 @@ import static org.hamcrest.Matchers.containsString;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -33,6 +35,9 @@ import ca.uhn.fhir.rest.param.DateRangeParam;
|
|||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
||||
import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class ServerConformanceProviderTest {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerConformanceProviderTest.class);
|
||||
|
@ -47,7 +52,7 @@ public class ServerConformanceProviderTest {
|
|||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(null);
|
||||
rs.init(createServletConfig());
|
||||
|
||||
boolean found=false;
|
||||
Collection<ResourceBinding> resourceBindings = rs.getResourceBindings();
|
||||
|
@ -61,7 +66,7 @@ public class ServerConformanceProviderTest {
|
|||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
Conformance conformance = sc.getServerConformance();
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
|
||||
String conf = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
@ -81,9 +86,9 @@ public class ServerConformanceProviderTest {
|
|||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(null);
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance();
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
|
||||
myCtx.newValidator().validate(conformance);
|
||||
}
|
||||
|
@ -99,7 +104,7 @@ public class ServerConformanceProviderTest {
|
|||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(null);
|
||||
rs.init(createServletConfig());
|
||||
|
||||
boolean found=false;
|
||||
Collection<ResourceBinding> resourceBindings = rs.getResourceBindings();
|
||||
|
@ -113,7 +118,7 @@ public class ServerConformanceProviderTest {
|
|||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
Conformance conformance = sc.getServerConformance();
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
|
@ -131,9 +136,9 @@ public class ServerConformanceProviderTest {
|
|||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(null);
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance();
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
|
@ -148,6 +153,20 @@ public class ServerConformanceProviderTest {
|
|||
assertEquals("DiagnosticReport.result", res.getSearchIncludeFirstRep().getValue());
|
||||
}
|
||||
|
||||
private HttpServletRequest createHttpServletRequest() {
|
||||
HttpServletRequest req = mock(HttpServletRequest.class);
|
||||
when(req.getRequestURI()).thenReturn("/FhirStorm/fhir/Patient/_search");
|
||||
when(req.getServletPath()).thenReturn("/fhir");
|
||||
when(req.getRequestURL()).thenReturn(new StringBuffer().append("http://fhirstorm.dyndns.org:8080/FhirStorm/fhir/Patient/_search"));
|
||||
when(req.getContextPath()).thenReturn("/FhirStorm");
|
||||
return req;
|
||||
}
|
||||
|
||||
private ServletConfig createServletConfig() {
|
||||
ServletConfig sc = mock(ServletConfig.class);
|
||||
when (sc.getServletContext()).thenReturn(null);
|
||||
return sc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
|
|
@ -6,6 +6,8 @@ import ca.uhn.fhir.model.api.IResource;
|
|||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class FhirDstu1 implements IFhirVersion {
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +21,7 @@ public class FhirDstu1 implements IFhirVersion {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) {
|
||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue