reference params should handle resource types properly

This commit is contained in:
James Agnew 2014-07-10 18:17:44 -04:00
parent 4ddaaf0406
commit 1346802403
11 changed files with 240 additions and 157 deletions

View File

@ -35,12 +35,11 @@ import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.server.Constants;
/**
* Represents the FHIR ID type. This is the actual resource ID, meaning the ID that will be used in RESTful URLs,
* Resource References, etc. to represent a specific instance of a resource.
* Represents the FHIR ID type. This is the actual resource ID, meaning the ID that will be used in RESTful URLs, Resource References, etc. to represent a specific instance of a resource.
*
* <p>
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any
* other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
* limit of 36 characters.
* </p>
* <p>
* regex: [a-z0-9\-\.]{1,36}
@ -63,12 +62,11 @@ public class IdDt extends BasePrimitive<String> {
}
/**
* Create a new ID, using a BigDecimal input. Uses {@link BigDecimal#toPlainString()} to generate the string
* representation.
* Create a new ID, using a BigDecimal input. Uses {@link BigDecimal#toPlainString()} to generate the string representation.
*/
public IdDt(BigDecimal thePid) {
if (thePid != null) {
setValue(thePid.toPlainString());
setValue(toPlainStringWithNpeThrowIfNeeded(thePid));
} else {
setValue(null);
}
@ -82,12 +80,11 @@ public class IdDt extends BasePrimitive<String> {
}
/**
* Create a new ID using a string. This String may contain a simple ID (e.g. "1234") or it may contain a complete
* URL (http://example.com/fhir/Patient/1234).
* Create a new ID using a string. This String may contain a simple ID (e.g. "1234") or it may contain a complete URL (http://example.com/fhir/Patient/1234).
*
* <p>
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or
* any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
* limit of 36 characters.
* </p>
* <p>
* regex: [a-z0-9\-\.]{1,36}
@ -107,7 +104,14 @@ public class IdDt extends BasePrimitive<String> {
* The ID (e.g. "123")
*/
public IdDt(String theResourceType, BigDecimal theIdPart) {
this(theResourceType, theIdPart.toPlainString());
this(theResourceType, toPlainStringWithNpeThrowIfNeeded(theIdPart));
}
private static String toPlainStringWithNpeThrowIfNeeded(BigDecimal theIdPart) {
if (theIdPart==null) {
throw new NullPointerException("BigDecimal ID can not be null");
}
return theIdPart.toPlainString();
}
/**
@ -133,7 +137,6 @@ public class IdDt extends BasePrimitive<String> {
* The version ID ("e.g. "456")
*/
public IdDt(String theResourceType, String theId, String theVersionId) {
Validate.notBlank(theResourceType, "Resource type must not be blank");
Validate.notBlank(theId, "ID must not be blank");
myResourceType = theResourceType;
@ -149,14 +152,6 @@ public class IdDt extends BasePrimitive<String> {
return getIdPartAsBigDecimal();
}
/**
* @deprecated Use {@link #getIdPartAsBigDecimal()} instead (this method was deprocated because its name is
* ambiguous)
*/
public BigDecimal asBigDecimal() {
return getIdPartAsBigDecimal();
}
/**
* Returns true if this IdDt matches the given IdDt in terms of resource type and ID, but ignores the URL base
*/
@ -172,8 +167,7 @@ public class IdDt extends BasePrimitive<String> {
}
/**
* Returns a reference to <code>this</code> IdDt. It is generally not neccesary to use this method but it is
* provided for consistency with the rest of the API.
* Returns a reference to <code>this</code> IdDt. It is generally not neccesary to use this method but it is provided for consistency with the rest of the API.
*/
@Override
public IdDt getId() {
@ -217,19 +211,18 @@ public class IdDt extends BasePrimitive<String> {
}
/**
* Returns the value of this ID. Note that this value may be a fully qualified URL, a relative/partial URL, or a
* simple ID. Use {@link #getIdPart()} to get just the ID portion.
* Returns the value of this ID. Note that this value may be a fully qualified URL, a relative/partial URL, or a simple ID. Use {@link #getIdPart()} to get just the ID portion.
*
* @see #getIdPart()
*/
@Override
public String getValue() {
if (myValue == null && myHaveComponentParts) {
if (myUnqualifiedVersionId != null) {
myValue = myResourceType + '/' + myUnqualifiedId + '/' + Constants.PARAM_HISTORY + '/' + myUnqualifiedVersionId;
} else {
myValue = myResourceType + '/' + myUnqualifiedId;
}
if (myUnqualifiedVersionId != null) {
myValue = myResourceType + '/' + myUnqualifiedId + '/' + Constants.PARAM_HISTORY + '/' + myUnqualifiedVersionId;
} else {
myValue = myResourceType + '/' + myUnqualifiedId;
}
}
return myValue;
}
@ -259,16 +252,12 @@ public class IdDt extends BasePrimitive<String> {
return isNotBlank(myResourceType);
}
<<<<<<< HEAD
=======
public boolean hasVersionIdPart() {
return isNotBlank(getVersionIdPart());
}
>>>>>>> 4d517aa76fc28af9fc4f0fa298ea3ee313a533a7
/**
* Returns <code>true</code> if the unqualified ID is a valid {@link Long} value (in other words, it consists only
* of digits)
* Returns <code>true</code> if the unqualified ID is a valid {@link Long} value (in other words, it consists only of digits)
*/
public boolean isIdPartValidLong() {
String id = getIdPart();
@ -291,8 +280,7 @@ public class IdDt extends BasePrimitive<String> {
}
/**
* Copies the value from the given IdDt to <code>this</code> IdDt. It is generally not neccesary to use this method
* but it is provided for consistency with the rest of the API.
* Copies the value from the given IdDt to <code>this</code> IdDt. It is generally not neccesary to use this method but it is provided for consistency with the rest of the API.
*/
@Override
public void setId(IdDt theId) {
@ -303,8 +291,8 @@ public class IdDt extends BasePrimitive<String> {
* Set the value
*
* <p>
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or
* any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
* limit of 36 characters.
* </p>
* <p>
* regex: [a-z0-9\-\.]{1,36}
@ -314,6 +302,7 @@ public class IdDt extends BasePrimitive<String> {
public void setValue(String theValue) throws DataFormatException {
// TODO: add validation
myValue = theValue;
myHaveComponentParts=false;
if (StringUtils.isBlank(theValue)) {
myValue = null;
myUnqualifiedId = null;
@ -350,8 +339,8 @@ public class IdDt extends BasePrimitive<String> {
* Set the value
*
* <p>
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or
* any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
* limit of 36 characters.
* </p>
* <p>
* regex: [a-z0-9\-\.]{1,36}
@ -364,7 +353,7 @@ public class IdDt extends BasePrimitive<String> {
@Override
public String toString() {
return myValue;
return getValue();
}
public IdDt toUnqualified() {
@ -376,19 +365,18 @@ public class IdDt extends BasePrimitive<String> {
}
public IdDt toVersionless() {
int i = myValue.indexOf(Constants.PARAM_HISTORY);
String value = getValue();
int i = value.indexOf(Constants.PARAM_HISTORY);
if (i > 1) {
return new IdDt(myValue.substring(0, i - 1));
return new IdDt(value.substring(0, i - 1));
} else {
return this;
}
}
/**
* Returns a view of this ID as a fully qualified URL, given a server base and resource name (which will only be
* used if the ID does not already contain those respective parts). Essentially, because IdDt can contain either a
* complete URL or a partial one (or even jut a simple ID), this method may be used to translate into a complete
* URL.
* Returns a view of this ID as a fully qualified URL, given a server base and resource name (which will only be used if the ID does not already contain those respective parts). Essentially,
* because IdDt can contain either a complete URL or a partial one (or even jut a simple ID), this method may be used to translate into a complete URL.
*
* @param theServerBase
* The server base (e.g. "http://example.com/fhir")
@ -416,29 +404,26 @@ public class IdDt extends BasePrimitive<String> {
}
/**
* Creates a new instance of this ID which is identical, but refers to the specific version of this resource ID
* noted by theVersion.
* Creates a new instance of this ID which is identical, but refers to the specific version of this resource ID noted by theVersion.
*
* @param theVersion
* The actual version string, e.g. "1"
* @return A new instance of IdDt which is identical, but refers to the specific version of this resource ID noted
* by theVersion.
* @return A new instance of IdDt which is identical, but refers to the specific version of this resource ID noted by theVersion.
*/
public IdDt withVersion(String theVersion) {
Validate.notBlank(theVersion, "Version may not be null or empty");
int i = myValue.indexOf(Constants.PARAM_HISTORY);
String existingValue = getValue();
int i = existingValue.indexOf(Constants.PARAM_HISTORY);
String value;
if (i > 1) {
value = myValue.substring(0, i - 1);
value = existingValue.substring(0, i - 1);
} else {
value = myValue;
value = existingValue;
}
<<<<<<< HEAD
=======
return new IdDt(value + '/' + Constants.PARAM_HISTORY + '/' + theVersion);
}
>>>>>>> 4d517aa76fc28af9fc4f0fa298ea3ee313a533a7
}

View File

@ -29,7 +29,6 @@ import ca.uhn.fhir.model.primitive.IdDt;
public class ReferenceParam extends IdDt implements IQueryParameterType {
private String myChain;
private String myResourceType;
public ReferenceParam() {
}
@ -44,8 +43,11 @@ public class ReferenceParam extends IdDt implements IQueryParameterType {
}
public ReferenceParam(String theResourceType, String theChain, String theValue) {
setResourceType(theResourceType);
setValueAsQueryToken(null, theValue);
if (isNotBlank(theResourceType)) {
setValue(theResourceType + "/" + theValue);
} else {
setValue(theValue);
}
setChain(theChain);
}
@ -56,9 +58,9 @@ public class ReferenceParam extends IdDt implements IQueryParameterType {
@Override
public String getQueryParameterQualifier() {
StringBuilder b = new StringBuilder();
if (isNotBlank(myResourceType)) {
if (isNotBlank(getResourceType())) {
b.append(':');
b.append(myResourceType);
b.append(getResourceType());
}
if (isNotBlank(myChain)) {
b.append('.');
@ -70,13 +72,9 @@ public class ReferenceParam extends IdDt implements IQueryParameterType {
return null;
}
public String getResourceType() {
return myResourceType;
}
@Override
public String getValueAsQueryToken() {
return getValue();
return getIdPart();
}
public void setChain(String theChain) {
@ -84,35 +82,35 @@ public class ReferenceParam extends IdDt implements IQueryParameterType {
}
public Class<? extends IResource> getResourceType(FhirContext theCtx) {
if (isBlank(myResourceType)) {
if (isBlank(getResourceType())) {
return null;
}
return theCtx.getResourceDefinition(myResourceType).getImplementingClass();
}
public void setResourceType(String theResourceType) {
myResourceType = theResourceType;
return theCtx.getResourceDefinition(getResourceType()).getImplementingClass();
}
@Override
public void setValueAsQueryToken(String theQualifier, String theValue) {
String q = theQualifier;
String resourceType=null;
if (isNotBlank(q)) {
if (q.startsWith(":")) {
int nextIdx = q.indexOf('.');
if (nextIdx != -1) {
myResourceType = q.substring(1, nextIdx);
resourceType = q.substring(1, nextIdx);
myChain = q.substring(nextIdx + 1);
} else {
myResourceType = q.substring(1);
resourceType = q.substring(1);
}
} else if (q.startsWith(".")) {
myChain = q.substring(1);
}
}
setValue(theValue);
if (isNotBlank(resourceType)) {
setValue(resourceType + '/' + theValue);
} else {
setValue(theValue);
}
}
}

View File

@ -434,7 +434,7 @@ public class RestfulServer extends HttpServlet {
if (nextString.startsWith("_")) {
operation = nextString;
} else {
id = new IdDt(nextString);
id = new IdDt(resourceName, nextString);
}
}

View File

@ -0,0 +1,29 @@
package ca.uhn.fhir.rest.param;
import static org.junit.Assert.*;
import org.junit.Test;
public class ReferenceParamTest {
@Test
public void testWithResourceTypeAsQualifier() {
ReferenceParam rp = new ReferenceParam();
rp.setValueAsQueryToken(":Location", "123");
assertEquals("Location", rp.getResourceType());
assertEquals("123", rp.getIdPart());
}
@Test
public void testWithResourceType() {
ReferenceParam rp = new ReferenceParam();
rp.setValueAsQueryToken(null, "Location/123");
assertEquals("Location", rp.getResourceType());
assertEquals("123", rp.getIdPart());
}
}

View File

@ -101,7 +101,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?throw404=true");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -130,7 +131,6 @@ public class ResfulServerMethodTest {
}
@Test
public void testCreateJson() throws Exception {
@ -143,7 +143,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -163,7 +164,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -185,7 +187,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?dateRange=%3E%3D2011-01-01&dateRange=%3C%3D2021-01-01");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -203,14 +206,15 @@ public class ResfulServerMethodTest {
HttpDelete httpGet = new HttpDelete("http://localhost:" + ourPort + "/Patient/1234");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertEquals(200, status.getStatusLine().getStatusCode());
OperationOutcome patient = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent);
assertEquals("1234", patient.getIssueFirstRep().getDetails().getValue());
assertEquals("Patient/1234", patient.getIssueFirstRep().getDetails().getValue());
}
@ -234,7 +238,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1&_include=include2&_include=include3");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
@ -244,7 +249,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1&_include=include2&_include=include3&_format=json");
status = ourClient.execute(httpGet);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
ourLog.info(responseContent);
@ -266,7 +272,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_format=json");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -291,7 +298,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_format=xml");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -312,7 +320,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -327,7 +336,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2");
status = ourClient.execute(httpGet);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.debug("Response was:\n{}", responseContent);
@ -342,7 +352,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/9999999");
status = ourClient.execute(httpGet);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.debug("Response was:\n{}", responseContent);
@ -361,7 +372,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1/_history/999");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -378,7 +390,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
// ourLog.info("Response was:\n{}", responseContent);
@ -414,7 +427,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/999/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -424,7 +438,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/998/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -452,7 +467,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/222/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -502,7 +518,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -546,15 +563,14 @@ public class ResfulServerMethodTest {
}
@Test
public void testReadOnTypeThatDoesntSupportRead() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/AdverseReaction/223");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -568,7 +584,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/AdverseReaction");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -580,7 +597,8 @@ public class ResfulServerMethodTest {
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/AdverseReaction/_search");
status = ourClient.execute(httpPost);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -597,7 +615,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Profile?");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
// ourLog.info("Response was:\n{}", responseContent);
@ -615,7 +634,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?dob=2011-01-02");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -635,7 +655,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?dob=%3E%3D2011-01-02");
status = ourClient.execute(httpGet);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -656,7 +677,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_search?dob=2011-01-02");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -674,7 +696,8 @@ public class ResfulServerMethodTest {
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?dob=2011-01-02");
status = ourClient.execute(httpPost);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -695,7 +718,8 @@ public class ResfulServerMethodTest {
httpPost.setEntity(new UrlEncodedFormEntity(urlParameters));
status = ourClient.execute(httpPost);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -716,7 +740,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?ids=urn:aaa%7Caaa,urn:bbb%7Cbbb");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -736,7 +761,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier=urn:hapitest:mrns%7C00001");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -754,7 +780,8 @@ public class ResfulServerMethodTest {
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?identifier=urn:hapitest:mrns%7C00001");
status = ourClient.execute(httpPost);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -772,7 +799,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_search?identifier=urn:hapitest:mrns%7C00001");
status = ourClient.execute(httpGet);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -791,7 +819,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?_query=someQueryNoParams");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -815,7 +844,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?_query=someQueryOneParam&param1=AAAA");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -836,7 +866,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?quantityParam=%3E%3D123%7Cfoo%7Cbar");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -855,7 +886,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1&_include=include2&_include=include3");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -875,7 +907,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1&_include=include2&_include=include4");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -888,7 +921,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -902,7 +936,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name1=AAA");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -922,7 +957,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name1=AAA&name2=BBB");
status = ourClient.execute(httpGet);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -948,7 +984,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -995,8 +1032,8 @@ public class ResfulServerMethodTest {
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
ourClient.execute(httpPost);
assertEquals(2, ourReportProvider.getLastTags().size());
assertEquals(new Tag((String)null, "Dog", "aa"), ourReportProvider.getLastTags().get(0));
assertEquals(new Tag((String)null, "Cat", "bb"), ourReportProvider.getLastTags().get(1));
assertEquals(new Tag((String) null, "Dog", "aa"), ourReportProvider.getLastTags().get(0));
assertEquals(new Tag((String) null, "Cat", "bb"), ourReportProvider.getLastTags().get(1));
}
@ -1059,7 +1096,6 @@ public class ResfulServerMethodTest {
}
@Test
public void testUpdateWithVersion() throws Exception {
@ -1126,7 +1162,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertThat(responseContent, not(containsString("\n ")));
@ -1145,7 +1182,8 @@ public class ResfulServerMethodTest {
status = ourClient.execute(httpPost);
responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
@ -1183,7 +1221,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertThat(responseContent, containsString("\n "));
@ -1195,14 +1234,15 @@ public class ResfulServerMethodTest {
HttpDelete httpGet = new HttpDelete("http://localhost:" + ourPort + "/Patient/1234?_pretty=true");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertEquals(200, status.getStatusLine().getStatusCode());
OperationOutcome patient = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent);
assertEquals("1234", patient.getIssueFirstRep().getDetails().getValue());
assertEquals("Patient/1234", patient.getIssueFirstRep().getDetails().getValue());
}
@ -1268,7 +1308,6 @@ public class ResfulServerMethodTest {
return retVal;
}
@Override
public Class<? extends IResource> getResourceType() {
return AdverseReaction.class;
@ -1347,8 +1386,8 @@ public class ResfulServerMethodTest {
return retVal;
}
public List<Patient> findDiagnosticReportsByPatient(@RequiredParam(name = "Patient.identifier") IdentifierDt thePatientId, @RequiredParam(name = DiagnosticReport.SP_NAME) CodingListParam theNames, @OptionalParam(name = DiagnosticReport.SP_DATE) DateRangeParam theDateRange)
throws Exception {
public List<Patient> findDiagnosticReportsByPatient(@RequiredParam(name = "Patient.identifier") IdentifierDt thePatientId,
@RequiredParam(name = DiagnosticReport.SP_NAME) CodingListParam theNames, @OptionalParam(name = DiagnosticReport.SP_DATE) DateRangeParam theDateRange) throws Exception {
return Collections.emptyList();
}
@ -1357,7 +1396,7 @@ public class ResfulServerMethodTest {
ArrayList<Patient> retVal = new ArrayList<Patient>();
IdDt id = theId;
if (id.getValue().equals("999")) {
if (id.getIdPart().equals("999")) {
id = null; // to test the error when no ID is present
}
@ -1367,7 +1406,7 @@ public class ResfulServerMethodTest {
older.getResourceMetadata().put(ResourceMetadataKeyEnum.VERSION_ID, "1");
older.getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, new Date(10000L));
older.getResourceMetadata().put(ResourceMetadataKeyEnum.UPDATED, new InstantDt(new Date(20000L)));
if (id != null && !id.getValue().equals("998")) {
if (id != null && !id.getIdPart().equals("998")) {
older.getResourceMetadata().put(ResourceMetadataKeyEnum.VERSION_ID, "1");
}
retVal.add(older);
@ -1375,7 +1414,7 @@ public class ResfulServerMethodTest {
Patient newer = createPatient1();
newer.setId(theId);
newer.getNameFirstRep().getFamilyFirstRep().setValue("NewerFamily");
if (id != null && !id.getValue().equals("998")) {
if (id != null && !id.getIdPart().equals("998")) {
newer.getResourceMetadata().put(ResourceMetadataKeyEnum.VERSION_ID, "2");
}
newer.getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, new Date(10000L));
@ -1481,10 +1520,8 @@ public class ResfulServerMethodTest {
@Search()
public Patient getPatientQuantityParam(@RequiredParam(name = "quantityParam") QuantityDt theParam) {
Patient next = getIdToPatient().get("1");
next.addName().addFamily(theParam.getComparator().getValueAsString())
.addFamily(theParam.getValue().getValueAsString())
.addFamily(theParam.getSystem().getValueAsString())
.addFamily(theParam.getUnits().getValueAsString());
next.addName().addFamily(theParam.getComparator().getValueAsString()).addFamily(theParam.getValue().getValueAsString()).addFamily(theParam.getSystem().getValueAsString())
.addFamily(theParam.getUnits().getValueAsString());
return next;
}
@ -1501,7 +1538,8 @@ public class ResfulServerMethodTest {
}
@Search()
public Patient getPatientWithIncludes(@RequiredParam(name = "withIncludes") StringDt theString, @IncludeParam(allow = { "include1", "include2", "include3" }) List<PathSpecification> theIncludes) {
public Patient getPatientWithIncludes(@RequiredParam(name = "withIncludes") StringDt theString,
@IncludeParam(allow = { "include1", "include2", "include3" }) List<PathSpecification> theIncludes) {
Patient next = getIdToPatient().get("1");
next.addCommunication().setText(theString.getValue());
@ -1551,7 +1589,7 @@ public class ResfulServerMethodTest {
*/
@Read()
public Patient getResourceById(@IdParam IdDt theId) {
return getIdToPatient().get(theId.getValue());
return getIdToPatient().get(theId.getIdPart());
}
@Read()
@ -1572,9 +1610,7 @@ public class ResfulServerMethodTest {
@Update()
public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersionId, @ResourceParam DiagnosticOrder thePatient) {
/*
* TODO: THIS METHOD IS NOT USED. It's the wrong type
* (DiagnosticOrder), so it should cause an exception on startup.
* Also we should detect if there are multiple resource params on an
* TODO: THIS METHOD IS NOT USED. It's the wrong type (DiagnosticOrder), so it should cause an exception on startup. Also we should detect if there are multiple resource params on an
* update/create/etc method
*/
IdDt id = theId;

View File

@ -279,7 +279,9 @@ public class ServerFeaturesTest {
*/
@Read()
public Patient getResourceById(@IdParam IdDt theId) {
return getIdToPatient().get(theId.getValue());
String key = theId.getIdPart();
Patient retVal = getIdToPatient().get(key);
return retVal;
}
/**

View File

@ -12,7 +12,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry excluding="**/moment*.*" kind="src" path="src/main/webapp"/>
<classpathentry excluding="**/moment*.*" kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>

View File

@ -2,4 +2,5 @@ eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -3,6 +3,7 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
<dependent-module archiveName="hapi-fhir-base-0.4-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/hapi-fhir-base/hapi-fhir-base">
<dependency-type>uses</dependency-type>
</dependent-module>

31
pom.xml
View File

@ -137,6 +137,37 @@
<addSvnKeyWords>false</addSvnKeyWords>
</configuration>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-antrun-plugin
</artifactId>
<versionRange>
[1.7,)
</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>