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; 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, * 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.
* Resource References, etc. to represent a specific instance of a resource.
* *
* <p> * <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 * <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
* other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters. * limit of 36 characters.
* </p> * </p>
* <p> * <p>
* regex: [a-z0-9\-\.]{1,36} * 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 * Create a new ID, using a BigDecimal input. Uses {@link BigDecimal#toPlainString()} to generate the string representation.
* representation.
*/ */
public IdDt(BigDecimal thePid) { public IdDt(BigDecimal thePid) {
if (thePid != null) { if (thePid != null) {
setValue(thePid.toPlainString()); setValue(toPlainStringWithNpeThrowIfNeeded(thePid));
} else { } else {
setValue(null); 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 * 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).
* URL (http://example.com/fhir/Patient/1234).
* *
* <p> * <p>
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or * <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
* any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters. * limit of 36 characters.
* </p> * </p>
* <p> * <p>
* regex: [a-z0-9\-\.]{1,36} * regex: [a-z0-9\-\.]{1,36}
@ -107,7 +104,14 @@ public class IdDt extends BasePrimitive<String> {
* The ID (e.g. "123") * The ID (e.g. "123")
*/ */
public IdDt(String theResourceType, BigDecimal theIdPart) { 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") * The version ID ("e.g. "456")
*/ */
public IdDt(String theResourceType, String theId, String theVersionId) { 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"); Validate.notBlank(theId, "ID must not be blank");
myResourceType = theResourceType; myResourceType = theResourceType;
@ -149,14 +152,6 @@ public class IdDt extends BasePrimitive<String> {
return getIdPartAsBigDecimal(); 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 * 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 * 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.
* provided for consistency with the rest of the API.
*/ */
@Override @Override
public IdDt getId() { 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 * 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.
* simple ID. Use {@link #getIdPart()} to get just the ID portion.
* *
* @see #getIdPart() * @see #getIdPart()
*/ */
@Override @Override
public String getValue() { public String getValue() {
if (myValue == null && myHaveComponentParts) { if (myValue == null && myHaveComponentParts) {
if (myUnqualifiedVersionId != null) { if (myUnqualifiedVersionId != null) {
myValue = myResourceType + '/' + myUnqualifiedId + '/' + Constants.PARAM_HISTORY + '/' + myUnqualifiedVersionId; myValue = myResourceType + '/' + myUnqualifiedId + '/' + Constants.PARAM_HISTORY + '/' + myUnqualifiedVersionId;
} else { } else {
myValue = myResourceType + '/' + myUnqualifiedId; myValue = myResourceType + '/' + myUnqualifiedId;
} }
} }
return myValue; return myValue;
} }
@ -259,16 +252,12 @@ public class IdDt extends BasePrimitive<String> {
return isNotBlank(myResourceType); return isNotBlank(myResourceType);
} }
<<<<<<< HEAD
=======
public boolean hasVersionIdPart() { public boolean hasVersionIdPart() {
return isNotBlank(getVersionIdPart()); return isNotBlank(getVersionIdPart());
} }
>>>>>>> 4d517aa76fc28af9fc4f0fa298ea3ee313a533a7
/** /**
* Returns <code>true</code> if the unqualified ID is a valid {@link Long} value (in other words, it consists only * Returns <code>true</code> if the unqualified ID is a valid {@link Long} value (in other words, it consists only of digits)
* of digits)
*/ */
public boolean isIdPartValidLong() { public boolean isIdPartValidLong() {
String id = getIdPart(); 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 * 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.
* but it is provided for consistency with the rest of the API.
*/ */
@Override @Override
public void setId(IdDt theId) { public void setId(IdDt theId) {
@ -303,8 +291,8 @@ public class IdDt extends BasePrimitive<String> {
* Set the value * Set the value
* *
* <p> * <p>
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or * <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
* any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters. * limit of 36 characters.
* </p> * </p>
* <p> * <p>
* regex: [a-z0-9\-\.]{1,36} * regex: [a-z0-9\-\.]{1,36}
@ -314,6 +302,7 @@ public class IdDt extends BasePrimitive<String> {
public void setValue(String theValue) throws DataFormatException { public void setValue(String theValue) throws DataFormatException {
// TODO: add validation // TODO: add validation
myValue = theValue; myValue = theValue;
myHaveComponentParts=false;
if (StringUtils.isBlank(theValue)) { if (StringUtils.isBlank(theValue)) {
myValue = null; myValue = null;
myUnqualifiedId = null; myUnqualifiedId = null;
@ -350,8 +339,8 @@ public class IdDt extends BasePrimitive<String> {
* Set the value * Set the value
* *
* <p> * <p>
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or * <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
* any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters. * limit of 36 characters.
* </p> * </p>
* <p> * <p>
* regex: [a-z0-9\-\.]{1,36} * regex: [a-z0-9\-\.]{1,36}
@ -364,7 +353,7 @@ public class IdDt extends BasePrimitive<String> {
@Override @Override
public String toString() { public String toString() {
return myValue; return getValue();
} }
public IdDt toUnqualified() { public IdDt toUnqualified() {
@ -376,19 +365,18 @@ public class IdDt extends BasePrimitive<String> {
} }
public IdDt toVersionless() { public IdDt toVersionless() {
int i = myValue.indexOf(Constants.PARAM_HISTORY); String value = getValue();
int i = value.indexOf(Constants.PARAM_HISTORY);
if (i > 1) { if (i > 1) {
return new IdDt(myValue.substring(0, i - 1)); return new IdDt(value.substring(0, i - 1));
} else { } else {
return this; return this;
} }
} }
/** /**
* Returns a view of this ID as a fully qualified URL, given a server base and resource name (which will only be * 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,
* used if the ID does not already contain those respective parts). Essentially, because IdDt can contain either a * 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.
* 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 * @param theServerBase
* The server base (e.g. "http://example.com/fhir") * 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 * Creates a new instance of this ID which is identical, but refers to the specific version of this resource ID noted by theVersion.
* noted by theVersion.
* *
* @param theVersion * @param theVersion
* The actual version string, e.g. "1" * 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 * @return A new instance of IdDt which is identical, but refers to the specific version of this resource ID noted by theVersion.
* by theVersion.
*/ */
public IdDt withVersion(String theVersion) { public IdDt withVersion(String theVersion) {
Validate.notBlank(theVersion, "Version may not be null or empty"); 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; String value;
if (i > 1) { if (i > 1) {
value = myValue.substring(0, i - 1); value = existingValue.substring(0, i - 1);
} else { } else {
value = myValue; value = existingValue;
} }
<<<<<<< HEAD
=======
return new IdDt(value + '/' + Constants.PARAM_HISTORY + '/' + theVersion); 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 { public class ReferenceParam extends IdDt implements IQueryParameterType {
private String myChain; private String myChain;
private String myResourceType;
public ReferenceParam() { public ReferenceParam() {
} }
@ -44,8 +43,11 @@ public class ReferenceParam extends IdDt implements IQueryParameterType {
} }
public ReferenceParam(String theResourceType, String theChain, String theValue) { public ReferenceParam(String theResourceType, String theChain, String theValue) {
setResourceType(theResourceType); if (isNotBlank(theResourceType)) {
setValueAsQueryToken(null, theValue); setValue(theResourceType + "/" + theValue);
} else {
setValue(theValue);
}
setChain(theChain); setChain(theChain);
} }
@ -56,9 +58,9 @@ public class ReferenceParam extends IdDt implements IQueryParameterType {
@Override @Override
public String getQueryParameterQualifier() { public String getQueryParameterQualifier() {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
if (isNotBlank(myResourceType)) { if (isNotBlank(getResourceType())) {
b.append(':'); b.append(':');
b.append(myResourceType); b.append(getResourceType());
} }
if (isNotBlank(myChain)) { if (isNotBlank(myChain)) {
b.append('.'); b.append('.');
@ -70,13 +72,9 @@ public class ReferenceParam extends IdDt implements IQueryParameterType {
return null; return null;
} }
public String getResourceType() {
return myResourceType;
}
@Override @Override
public String getValueAsQueryToken() { public String getValueAsQueryToken() {
return getValue(); return getIdPart();
} }
public void setChain(String theChain) { public void setChain(String theChain) {
@ -84,35 +82,35 @@ public class ReferenceParam extends IdDt implements IQueryParameterType {
} }
public Class<? extends IResource> getResourceType(FhirContext theCtx) { public Class<? extends IResource> getResourceType(FhirContext theCtx) {
if (isBlank(myResourceType)) { if (isBlank(getResourceType())) {
return null; return null;
} }
return theCtx.getResourceDefinition(myResourceType).getImplementingClass(); return theCtx.getResourceDefinition(getResourceType()).getImplementingClass();
}
public void setResourceType(String theResourceType) {
myResourceType = theResourceType;
} }
@Override @Override
public void setValueAsQueryToken(String theQualifier, String theValue) { public void setValueAsQueryToken(String theQualifier, String theValue) {
String q = theQualifier; String q = theQualifier;
String resourceType=null;
if (isNotBlank(q)) { if (isNotBlank(q)) {
if (q.startsWith(":")) { if (q.startsWith(":")) {
int nextIdx = q.indexOf('.'); int nextIdx = q.indexOf('.');
if (nextIdx != -1) { if (nextIdx != -1) {
myResourceType = q.substring(1, nextIdx); resourceType = q.substring(1, nextIdx);
myChain = q.substring(nextIdx + 1); myChain = q.substring(nextIdx + 1);
} else { } else {
myResourceType = q.substring(1); resourceType = q.substring(1);
} }
} else if (q.startsWith(".")) { } else if (q.startsWith(".")) {
myChain = q.substring(1); 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("_")) { if (nextString.startsWith("_")) {
operation = nextString; operation = nextString;
} else { } 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?throw404=true");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -130,7 +131,6 @@ public class ResfulServerMethodTest {
} }
@Test @Test
public void testCreateJson() throws Exception { public void testCreateJson() throws Exception {
@ -143,7 +143,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost); 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); ourLog.info("Response was:\n{}", responseContent);
@ -151,7 +152,7 @@ public class ResfulServerMethodTest {
assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue());
} }
@Test @Test
public void testCreateWithUnprocessableEntity() throws Exception { public void testCreateWithUnprocessableEntity() throws Exception {
@ -163,7 +164,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost); 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); 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?dateRange=%3E%3D2011-01-01&dateRange=%3C%3D2021-01-01");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -203,14 +206,15 @@ public class ResfulServerMethodTest {
HttpDelete httpGet = new HttpDelete("http://localhost:" + ourPort + "/Patient/1234"); HttpDelete httpGet = new HttpDelete("http://localhost:" + ourPort + "/Patient/1234");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
OperationOutcome patient = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent); 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1&_include=include2&_include=include3");
HttpResponse status = ourClient.execute(httpGet); 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()); assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); 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"); httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1&_include=include2&_include=include3&_format=json");
status = ourClient.execute(httpGet); 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()); assertEquals(200, status.getStatusLine().getStatusCode());
ourLog.info(responseContent); ourLog.info(responseContent);
@ -266,7 +272,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_format=json"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_format=json");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -291,7 +298,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_format=xml"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_format=xml");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -312,7 +320,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -327,7 +336,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2"); httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2");
status = ourClient.execute(httpGet); 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); ourLog.debug("Response was:\n{}", responseContent);
@ -342,7 +352,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/9999999"); httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/9999999");
status = ourClient.execute(httpGet); 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); ourLog.debug("Response was:\n{}", responseContent);
@ -361,7 +372,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1/_history/999"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1/_history/999");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -378,7 +390,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata");
HttpResponse status = ourClient.execute(httpGet); 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); // ourLog.info("Response was:\n{}", responseContent);
@ -414,7 +427,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/999/_history"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/999/_history");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -424,7 +438,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/998/_history"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/998/_history");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -452,7 +467,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/222/_history"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/222/_history");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -502,7 +518,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_history"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_history");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -546,15 +563,14 @@ public class ResfulServerMethodTest {
} }
@Test @Test
public void testReadOnTypeThatDoesntSupportRead() throws Exception { public void testReadOnTypeThatDoesntSupportRead() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/AdverseReaction/223"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/AdverseReaction/223");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -568,7 +584,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/AdverseReaction"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/AdverseReaction");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -580,7 +597,8 @@ public class ResfulServerMethodTest {
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/AdverseReaction/_search"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/AdverseReaction/_search");
status = ourClient.execute(httpPost); 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); ourLog.info("Response was:\n{}", responseContent);
@ -597,7 +615,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Profile?"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Profile?");
HttpResponse status = ourClient.execute(httpGet); 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); // 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?dob=2011-01-02");
HttpResponse status = ourClient.execute(httpGet); 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); 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"); httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?dob=%3E%3D2011-01-02");
status = ourClient.execute(httpGet); 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); 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_search?dob=2011-01-02");
HttpResponse status = ourClient.execute(httpGet); 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); 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"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?dob=2011-01-02");
status = ourClient.execute(httpPost); 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); ourLog.info("Response was:\n{}", responseContent);
@ -695,7 +718,8 @@ public class ResfulServerMethodTest {
httpPost.setEntity(new UrlEncodedFormEntity(urlParameters)); httpPost.setEntity(new UrlEncodedFormEntity(urlParameters));
status = ourClient.execute(httpPost); 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); 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?ids=urn:aaa%7Caaa,urn:bbb%7Cbbb");
HttpResponse status = ourClient.execute(httpGet); 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); 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier=urn:hapitest:mrns%7C00001");
HttpResponse status = ourClient.execute(httpGet); 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); 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"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?identifier=urn:hapitest:mrns%7C00001");
status = ourClient.execute(httpPost); 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); 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"); httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_search?identifier=urn:hapitest:mrns%7C00001");
status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -791,7 +819,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?_query=someQueryNoParams"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?_query=someQueryNoParams");
HttpResponse status = ourClient.execute(httpGet); 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); 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?_query=someQueryOneParam&param1=AAAA");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -824,7 +854,7 @@ public class ResfulServerMethodTest {
assertEquals("AAAA", patient.getName().get(1).getFamilyAsSingleString()); assertEquals("AAAA", patient.getName().get(1).getFamilyAsSingleString());
} }
@Test @Test
public void testSearchQuantityParam() throws Exception { public void testSearchQuantityParam() throws Exception {
@ -836,7 +866,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?quantityParam=%3E%3D123%7Cfoo%7Cbar"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?quantityParam=%3E%3D123%7Cfoo%7Cbar");
HttpResponse status = ourClient.execute(httpGet); 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); 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1&_include=include2&_include=include3");
HttpResponse status = ourClient.execute(httpGet); 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); 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"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1&_include=include2&_include=include4");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -888,7 +921,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?withIncludes=include1");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -902,7 +936,8 @@ public class ResfulServerMethodTest {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name1=AAA"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name1=AAA");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -922,7 +957,8 @@ public class ResfulServerMethodTest {
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name1=AAA&name2=BBB"); httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name1=AAA&name2=BBB");
status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
@ -948,7 +984,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost); 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); 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"))); httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
ourClient.execute(httpPost); ourClient.execute(httpPost);
assertEquals(2, ourReportProvider.getLastTags().size()); assertEquals(2, ourReportProvider.getLastTags().size());
assertEquals(new Tag((String)null, "Dog", "aa"), ourReportProvider.getLastTags().get(0)); 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, "Cat", "bb"), ourReportProvider.getLastTags().get(1));
} }
@ -1012,7 +1049,7 @@ public class ResfulServerMethodTest {
ourClient.execute(httpPost); ourClient.execute(httpPost);
assertEquals(1, ourReportProvider.getLastTags().size()); assertEquals(1, ourReportProvider.getLastTags().size());
assertEquals(new Tag("Dog"), ourReportProvider.getLastTags().get(0)); assertEquals(new Tag("Dog"), ourReportProvider.getLastTags().get(0));
} }
@Test @Test
@ -1059,7 +1096,6 @@ public class ResfulServerMethodTest {
} }
@Test @Test
public void testUpdateWithVersion() throws Exception { public void testUpdateWithVersion() throws Exception {
@ -1126,7 +1162,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost); 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); ourLog.info("Response was:\n{}", responseContent);
assertThat(responseContent, not(containsString("\n "))); assertThat(responseContent, not(containsString("\n ")));
@ -1145,7 +1182,8 @@ public class ResfulServerMethodTest {
status = ourClient.execute(httpPost); 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); ourLog.info("Response was:\n{}", responseContent);
@ -1183,7 +1221,8 @@ public class ResfulServerMethodTest {
HttpResponse status = ourClient.execute(httpPost); 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); ourLog.info("Response was:\n{}", responseContent);
assertThat(responseContent, containsString("\n ")); assertThat(responseContent, containsString("\n "));
@ -1195,14 +1234,15 @@ public class ResfulServerMethodTest {
HttpDelete httpGet = new HttpDelete("http://localhost:" + ourPort + "/Patient/1234?_pretty=true"); HttpDelete httpGet = new HttpDelete("http://localhost:" + ourPort + "/Patient/1234?_pretty=true");
HttpResponse status = ourClient.execute(httpGet); 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); ourLog.info("Response was:\n{}", responseContent);
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
OperationOutcome patient = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent); OperationOutcome patient = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent);
assertEquals("1234", patient.getIssueFirstRep().getDetails().getValue()); assertEquals("Patient/1234", patient.getIssueFirstRep().getDetails().getValue());
} }
@ -1252,15 +1292,15 @@ public class ResfulServerMethodTest {
IdDt version = new IdDt(thePatient.getIdentifier().get(1).getValue().getValue()); IdDt version = new IdDt(thePatient.getIdentifier().get(1).getValue().getValue());
return new MethodOutcome(id, version); return new MethodOutcome(id, version);
} }
@Search() @Search()
public Collection<AdverseReaction> getAllResources() { public Collection<AdverseReaction> getAllResources() {
ArrayList<AdverseReaction> retVal = new ArrayList<AdverseReaction>(); ArrayList<AdverseReaction> retVal = new ArrayList<AdverseReaction>();
AdverseReaction ar1 = new AdverseReaction(); AdverseReaction ar1 = new AdverseReaction();
ar1.setId("1"); ar1.setId("1");
retVal.add(ar1); retVal.add(ar1);
AdverseReaction ar2 = new AdverseReaction(); AdverseReaction ar2 = new AdverseReaction();
ar2.setId("2"); ar2.setId("2");
retVal.add(ar2); retVal.add(ar2);
@ -1268,7 +1308,6 @@ public class ResfulServerMethodTest {
return retVal; return retVal;
} }
@Override @Override
public Class<? extends IResource> getResourceType() { public Class<? extends IResource> getResourceType() {
return AdverseReaction.class; return AdverseReaction.class;
@ -1347,8 +1386,8 @@ public class ResfulServerMethodTest {
return retVal; 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) public List<Patient> findDiagnosticReportsByPatient(@RequiredParam(name = "Patient.identifier") IdentifierDt thePatientId,
throws Exception { @RequiredParam(name = DiagnosticReport.SP_NAME) CodingListParam theNames, @OptionalParam(name = DiagnosticReport.SP_DATE) DateRangeParam theDateRange) throws Exception {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -1357,7 +1396,7 @@ public class ResfulServerMethodTest {
ArrayList<Patient> retVal = new ArrayList<Patient>(); ArrayList<Patient> retVal = new ArrayList<Patient>();
IdDt id = theId; IdDt id = theId;
if (id.getValue().equals("999")) { if (id.getIdPart().equals("999")) {
id = null; // to test the error when no ID is present 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.VERSION_ID, "1");
older.getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, new Date(10000L)); older.getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, new Date(10000L));
older.getResourceMetadata().put(ResourceMetadataKeyEnum.UPDATED, new InstantDt(new Date(20000L))); 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"); older.getResourceMetadata().put(ResourceMetadataKeyEnum.VERSION_ID, "1");
} }
retVal.add(older); retVal.add(older);
@ -1375,7 +1414,7 @@ public class ResfulServerMethodTest {
Patient newer = createPatient1(); Patient newer = createPatient1();
newer.setId(theId); newer.setId(theId);
newer.getNameFirstRep().getFamilyFirstRep().setValue("NewerFamily"); 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.VERSION_ID, "2");
} }
newer.getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, new Date(10000L)); newer.getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, new Date(10000L));
@ -1477,14 +1516,12 @@ public class ResfulServerMethodTest {
next.addName().addFamily(theParam.getValue()); next.addName().addFamily(theParam.getValue());
return next; return next;
} }
@Search() @Search()
public Patient getPatientQuantityParam(@RequiredParam(name = "quantityParam") QuantityDt theParam) { public Patient getPatientQuantityParam(@RequiredParam(name = "quantityParam") QuantityDt theParam) {
Patient next = getIdToPatient().get("1"); Patient next = getIdToPatient().get("1");
next.addName().addFamily(theParam.getComparator().getValueAsString()) next.addName().addFamily(theParam.getComparator().getValueAsString()).addFamily(theParam.getValue().getValueAsString()).addFamily(theParam.getSystem().getValueAsString())
.addFamily(theParam.getValue().getValueAsString()) .addFamily(theParam.getUnits().getValueAsString());
.addFamily(theParam.getSystem().getValueAsString())
.addFamily(theParam.getUnits().getValueAsString());
return next; return next;
} }
@ -1501,7 +1538,8 @@ public class ResfulServerMethodTest {
} }
@Search() @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"); Patient next = getIdToPatient().get("1");
next.addCommunication().setText(theString.getValue()); next.addCommunication().setText(theString.getValue());
@ -1551,7 +1589,7 @@ public class ResfulServerMethodTest {
*/ */
@Read() @Read()
public Patient getResourceById(@IdParam IdDt theId) { public Patient getResourceById(@IdParam IdDt theId) {
return getIdToPatient().get(theId.getValue()); return getIdToPatient().get(theId.getIdPart());
} }
@Read() @Read()
@ -1572,9 +1610,7 @@ public class ResfulServerMethodTest {
@Update() @Update()
public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersionId, @ResourceParam DiagnosticOrder thePatient) { public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersionId, @ResourceParam DiagnosticOrder thePatient) {
/* /*
* TODO: THIS METHOD IS NOT USED. It's the wrong type * 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
* (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 * update/create/etc method
*/ */
IdDt id = theId; IdDt id = theId;

View File

@ -279,7 +279,9 @@ public class ServerFeaturesTest {
*/ */
@Read() @Read()
public Patient getResourceById(@IdParam IdDt theId) { 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"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </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"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>

View File

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

View File

@ -2,4 +2,5 @@ eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8 encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8 encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=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="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <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/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"> <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> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>

31
pom.xml
View File

@ -137,6 +137,37 @@
<addSvnKeyWords>false</addSvnKeyWords> <addSvnKeyWords>false</addSvnKeyWords>
</configuration> </configuration>
</plugin> </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> </plugins>
</pluginManagement> </pluginManagement>