commit
7c39a47852
|
@ -301,11 +301,16 @@ public class IdDt extends UriDt implements /*IPrimitiveDatatype<String>, */IIdTy
|
||||||
b.append(myResourceType);
|
b.append(myResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.length() > 0) {
|
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNotBlank(myUnqualifiedId)) {
|
||||||
b.append(myUnqualifiedId);
|
b.append(myUnqualifiedId);
|
||||||
|
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
|
b.append('/');
|
||||||
|
}
|
||||||
|
|
||||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
b.append(Constants.PARAM_HISTORY);
|
b.append(Constants.PARAM_HISTORY);
|
||||||
|
@ -522,8 +527,22 @@ public class IdDt extends UriDt implements /*IPrimitiveDatatype<String>, */IIdTy
|
||||||
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
||||||
if (typeIndex == -1) {
|
if (typeIndex == -1) {
|
||||||
myResourceType = theValue.substring(0, idIndex);
|
myResourceType = theValue.substring(0, idIndex);
|
||||||
|
} else {
|
||||||
|
if (typeIndex > 0 && '/' == theValue.charAt(typeIndex - 1)) {
|
||||||
|
typeIndex = theValue.indexOf('/', typeIndex + 1);
|
||||||
|
}
|
||||||
|
if (typeIndex >= idIndex) {
|
||||||
|
// e.g. http://example.org/foo
|
||||||
|
// 'foo' was the id but we're making that the resource type. Nullify the id part because we don't have an id.
|
||||||
|
// Also set null value to the super.setValue() and enable myHaveComponentParts so it forces getValue() to properly
|
||||||
|
// recreate the url
|
||||||
|
myResourceType = myUnqualifiedId;
|
||||||
|
myUnqualifiedId = null;
|
||||||
|
super.setValue(null);
|
||||||
|
myHaveComponentParts = true;
|
||||||
} else {
|
} else {
|
||||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeIndex > 4) {
|
if (typeIndex > 4) {
|
||||||
myBaseUrl = theValue.substring(0, typeIndex);
|
myBaseUrl = theValue.substring(0, typeIndex);
|
||||||
|
|
|
@ -28,20 +28,20 @@ public interface IBaseBundle extends IBaseResource {
|
||||||
* link.type field to indicate that the given link is for
|
* link.type field to indicate that the given link is for
|
||||||
* the next page of results.
|
* the next page of results.
|
||||||
*/
|
*/
|
||||||
public static final String LINK_NEXT = "next";
|
String LINK_NEXT = "next";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constant for links provided in the bundle. This constant is used in the
|
* Constant for links provided in the bundle. This constant is used in the
|
||||||
* link.type field to indicate that the given link is for
|
* link.type field to indicate that the given link is for
|
||||||
* the previous page of results.
|
* the previous page of results.
|
||||||
*/
|
*/
|
||||||
public static final String LINK_PREV = "previous";
|
String LINK_PREV = "previous";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constant for links provided in the bundle. This constant is used in the
|
* Constant for links provided in the bundle. This constant is used in the
|
||||||
* link.type field to indicate that the given link is for
|
* link.type field to indicate that the given link is for
|
||||||
* this bundle.
|
* this bundle.
|
||||||
*/
|
*/
|
||||||
public static final String LINK_SELF = "self";
|
String LINK_SELF = "self";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1681,7 +1681,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OUTPUT execute() {
|
public OUTPUT execute() {
|
||||||
Validate.notNull(myReturnBundleType, "Return bundle type mustbe specified");
|
|
||||||
|
|
||||||
Map<String, List<String>> params = getParamMap();
|
Map<String, List<String>> params = getParamMap();
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,15 @@ public class ResourceLink implements Serializable {
|
||||||
public void setTargetResourceUrl(IIdType theTargetResourceUrl) {
|
public void setTargetResourceUrl(IIdType theTargetResourceUrl) {
|
||||||
Validate.isTrue(theTargetResourceUrl.hasBaseUrl());
|
Validate.isTrue(theTargetResourceUrl.hasBaseUrl());
|
||||||
Validate.isTrue(theTargetResourceUrl.hasResourceType());
|
Validate.isTrue(theTargetResourceUrl.hasResourceType());
|
||||||
Validate.isTrue(theTargetResourceUrl.hasIdPart());
|
|
||||||
|
if (theTargetResourceUrl.hasIdPart()) {
|
||||||
|
// do nothing
|
||||||
|
} else {
|
||||||
|
// Must have set an url like http://example.org/something
|
||||||
|
// We treat 'something' as the resource type because of fix for #659. Prior to #659 fix, 'something' was
|
||||||
|
// treated as the id and 'example.org' was treated as the resource type
|
||||||
|
// TODO: log a warning?
|
||||||
|
}
|
||||||
|
|
||||||
myTargetResourceType = theTargetResourceUrl.getResourceType();
|
myTargetResourceType = theTargetResourceUrl.getResourceType();
|
||||||
myTargetResourceUrl = theTargetResourceUrl.getValue();
|
myTargetResourceUrl = theTargetResourceUrl.getValue();
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.client.ClientProtocolException;
|
import org.apache.http.client.ClientProtocolException;
|
||||||
import org.apache.http.client.methods.*;
|
import org.apache.http.client.methods.*;
|
||||||
import org.apache.http.entity.*;
|
import org.apache.http.entity.*;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
@ -2059,7 +2060,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
Observation o = new Observation();
|
Observation o = new Observation();
|
||||||
o.getCode().setText("testSearchWithInvalidSort");
|
o.getCode().setText("testSearchWithInvalidSort");
|
||||||
myObservationDao.create(o, mySrd);
|
myObservationDao.create(o, mySrd);
|
||||||
ourClient
|
IBaseBundle bundle = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Observation.class)
|
.forResource(Observation.class)
|
||||||
.sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet
|
.sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet
|
||||||
|
|
|
@ -84,6 +84,37 @@ public class IdDtTest {
|
||||||
assertEquals("foo/_history/2", id.withVersion("2").getValue());
|
assertEquals("foo/_history/2", id.withVersion("2").getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo1() {
|
||||||
|
IdDt id = new IdDt("http://my.org/foo");
|
||||||
|
assertEquals("http://my.org/foo", id.getValueAsString());
|
||||||
|
assertEquals(null, id.getIdPart());
|
||||||
|
assertEquals("foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("foo", id.getResourceType());
|
||||||
|
assertEquals("http://my.org", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/foo//_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo2() {
|
||||||
|
IdDt id = new IdDt("http://my.org/a/b/c/foo");
|
||||||
|
assertEquals("http://my.org/a/b/c/foo", id.getValueAsString());
|
||||||
|
assertEquals("foo", id.getIdPart());
|
||||||
|
assertEquals("c/foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("c/foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("c", id.getResourceType());
|
||||||
|
assertEquals("http://my.org/a/b", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient/foo", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient/foo", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/a/b/c/foo/_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDetectIsIdPartValid() {
|
public void testDetectIsIdPartValid() {
|
||||||
|
|
|
@ -358,11 +358,16 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
||||||
b.append(myResourceType);
|
b.append(myResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.length() > 0) {
|
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNotBlank(myUnqualifiedId)) {
|
||||||
b.append(myUnqualifiedId);
|
b.append(myUnqualifiedId);
|
||||||
|
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
|
b.append('/');
|
||||||
|
}
|
||||||
|
|
||||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
b.append("_history");
|
b.append("_history");
|
||||||
|
@ -553,8 +558,22 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
||||||
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
||||||
if (typeIndex == -1) {
|
if (typeIndex == -1) {
|
||||||
myResourceType = theValue.substring(0, idIndex);
|
myResourceType = theValue.substring(0, idIndex);
|
||||||
|
} else {
|
||||||
|
if (typeIndex > 0 && '/' == theValue.charAt(typeIndex - 1)) {
|
||||||
|
typeIndex = theValue.indexOf('/', typeIndex + 1);
|
||||||
|
}
|
||||||
|
if (typeIndex >= idIndex) {
|
||||||
|
// e.g. http://example.org/foo
|
||||||
|
// 'foo' was the id but we're making that the resource type. Nullify the id part because we don't have an id.
|
||||||
|
// Also set null value to the super.setValue() and enable myHaveComponentParts so it forces getValue() to properly
|
||||||
|
// recreate the url
|
||||||
|
myResourceType = myUnqualifiedId;
|
||||||
|
myUnqualifiedId = null;
|
||||||
|
super.setValue(null);
|
||||||
|
myHaveComponentParts = true;
|
||||||
} else {
|
} else {
|
||||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeIndex > 4) {
|
if (typeIndex > 4) {
|
||||||
myBaseUrl = theValue.substring(0, typeIndex);
|
myBaseUrl = theValue.substring(0, typeIndex);
|
||||||
|
|
|
@ -92,6 +92,37 @@ public class IdTypeDstu2_1Test {
|
||||||
assertEquals("foo/_history/2", id.withVersion("2").getValue());
|
assertEquals("foo/_history/2", id.withVersion("2").getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo1() {
|
||||||
|
IdType id = new IdType("http://my.org/foo");
|
||||||
|
assertEquals("http://my.org/foo", id.getValueAsString());
|
||||||
|
assertEquals(null, id.getIdPart());
|
||||||
|
assertEquals("foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("foo", id.getResourceType());
|
||||||
|
assertEquals("http://my.org", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/foo//_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo2() {
|
||||||
|
IdType id = new IdType("http://my.org/a/b/c/foo");
|
||||||
|
assertEquals("http://my.org/a/b/c/foo", id.getValueAsString());
|
||||||
|
assertEquals("foo", id.getIdPart());
|
||||||
|
assertEquals("c/foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("c/foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("c", id.getResourceType());
|
||||||
|
assertEquals("http://my.org/a/b", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient/foo", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient/foo", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/a/b/c/foo/_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDetectLocal() {
|
public void testDetectLocal() {
|
||||||
|
|
|
@ -1873,6 +1873,26 @@ public class JsonParserDstu2_1Test {
|
||||||
Assert.assertThat(message, containsString("contained"));
|
Assert.assertThat(message, containsString("contained"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
|
||||||
|
String refVal = "http://my.org/FooBar";
|
||||||
|
|
||||||
|
Patient fhirPat = new Patient();
|
||||||
|
fhirPat.addExtension().setUrl("x1").setValue(new Reference(refVal));
|
||||||
|
|
||||||
|
IParser parser = ourCtx.newJsonParser();
|
||||||
|
|
||||||
|
String output = parser.encodeResourceToString(fhirPat);
|
||||||
|
System.out.println("output: " + output);
|
||||||
|
|
||||||
|
// Deserialize then check that valueReference value is still correct
|
||||||
|
fhirPat = parser.parseResource(Patient.class, output);
|
||||||
|
|
||||||
|
List<Extension> extlst = fhirPat.getExtensionsByUrl("x1");
|
||||||
|
Assert.assertEquals(1, extlst.size());
|
||||||
|
Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
package ca.uhn.fhir.parser;
|
package ca.uhn.fhir.parser;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import static org.hamcrest.Matchers.contains;
|
import ca.uhn.fhir.model.api.annotation.Child;
|
||||||
import static org.junit.Assert.*;
|
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||||
import static org.mockito.Matchers.any;
|
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||||
import static org.mockito.Mockito.*;
|
import ca.uhn.fhir.parser.FooMessageHeaderWithExplicitField.FooMessageSourceComponent;
|
||||||
|
import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation;
|
||||||
import java.io.IOException;
|
import ca.uhn.fhir.parser.PatientWithCustomCompositeExtension.FooParentExtension;
|
||||||
import java.nio.charset.StandardCharsets;
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
import java.util.*;
|
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||||
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.hamcrest.collection.IsEmptyCollection;
|
import org.hamcrest.collection.IsEmptyCollection;
|
||||||
import org.hamcrest.core.StringContains;
|
import org.hamcrest.core.StringContains;
|
||||||
import org.hamcrest.text.StringContainsInOrder;
|
import org.hamcrest.text.StringContainsInOrder;
|
||||||
import org.hl7.fhir.dstu2016may.model.*;
|
|
||||||
import org.hl7.fhir.dstu2016may.model.Address.AddressUse;
|
import org.hl7.fhir.dstu2016may.model.Address.AddressUse;
|
||||||
|
import org.hl7.fhir.dstu2016may.model.*;
|
||||||
import org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent;
|
import org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent;
|
||||||
import org.hl7.fhir.dstu2016may.model.Bundle.BundleType;
|
import org.hl7.fhir.dstu2016may.model.Bundle.BundleType;
|
||||||
import org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem;
|
import org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem;
|
||||||
|
@ -32,20 +33,20 @@ import org.junit.*;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.xmlunit.builder.DiffBuilder;
|
import org.xmlunit.builder.DiffBuilder;
|
||||||
import org.xmlunit.builder.Input;
|
import org.xmlunit.builder.Input;
|
||||||
import org.xmlunit.diff.*;
|
import org.xmlunit.diff.ComparisonControllers;
|
||||||
|
import org.xmlunit.diff.DefaultNodeMatcher;
|
||||||
|
import org.xmlunit.diff.Diff;
|
||||||
|
import org.xmlunit.diff.ElementSelectors;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import static org.hamcrest.Matchers.contains;
|
||||||
import ca.uhn.fhir.model.api.annotation.Child;
|
import static org.hamcrest.Matchers.*;
|
||||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
import static org.junit.Assert.*;
|
||||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
import static org.mockito.Matchers.any;
|
||||||
import ca.uhn.fhir.parser.FooMessageHeaderWithExplicitField.FooMessageSourceComponent;
|
import static org.mockito.Mockito.*;
|
||||||
import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation;
|
|
||||||
import ca.uhn.fhir.parser.PatientWithCustomCompositeExtension.FooParentExtension;
|
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
|
||||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
|
||||||
|
|
||||||
public class XmlParserDstu2_1Test {
|
public class XmlParserDstu2_1Test {
|
||||||
private static FhirContext ourCtx = FhirContext.forDstu2_1();
|
private static FhirContext ourCtx = FhirContext.forDstu2_1();
|
||||||
|
@ -2662,6 +2663,26 @@ public class XmlParserDstu2_1Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
|
||||||
|
String refVal = "http://my.org/FooBar";
|
||||||
|
|
||||||
|
Patient fhirPat = new Patient();
|
||||||
|
fhirPat.addExtension().setUrl("x1").setValue(new Reference(refVal));
|
||||||
|
|
||||||
|
IParser parser = ourCtx.newXmlParser();
|
||||||
|
|
||||||
|
String output = parser.encodeResourceToString(fhirPat);
|
||||||
|
System.out.println("output: " + output);
|
||||||
|
|
||||||
|
// Deserialize then check that valueReference value is still correct
|
||||||
|
fhirPat = parser.parseResource(Patient.class, output);
|
||||||
|
|
||||||
|
List<Extension> extlst = fhirPat.getExtensionsByUrl("x1");
|
||||||
|
Assert.assertEquals(1, extlst.size());
|
||||||
|
Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference());
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
public static void afterClassClearContext() {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class BaseResourceReferenceDtTest {
|
||||||
new ResourceReferenceDt("http://foo/123123").loadResource(client);
|
new ResourceReferenceDt("http://foo/123123").loadResource(client);
|
||||||
fail();
|
fail();
|
||||||
} catch (DataFormatException e) {
|
} catch (DataFormatException e) {
|
||||||
assertEquals("Unknown resource name \"foo\" (this name is not known in FHIR version \"DSTU2\")", e.getMessage());
|
assertEquals("Unknown resource name \"123123\" (this name is not known in FHIR version \"DSTU2\")", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1948,4 +1948,24 @@ public class JsonParserDstu2Test {
|
||||||
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
|
||||||
|
String refVal = "http://my.org/FooBar";
|
||||||
|
|
||||||
|
Patient fhirPat = new Patient();
|
||||||
|
fhirPat.addUndeclaredExtension(false, "x1").setValue(new ResourceReferenceDt(refVal));
|
||||||
|
|
||||||
|
IParser parser = ourCtx.newJsonParser();
|
||||||
|
|
||||||
|
String output = parser.encodeResourceToString(fhirPat);
|
||||||
|
System.out.println("output: " + output);
|
||||||
|
|
||||||
|
// Deserialize then check that valueReference value is still correct
|
||||||
|
fhirPat = parser.parseResource(Patient.class, output);
|
||||||
|
|
||||||
|
List<ExtensionDt> extlst = fhirPat.getUndeclaredExtensionsByUrl("x1");
|
||||||
|
Assert.assertEquals(1, extlst.size());
|
||||||
|
Assert.assertEquals(refVal, ((ResourceReferenceDt) extlst.get(0).getValue()).getReference().getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.hamcrest.text.StringContainsInOrder;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
@ -2790,6 +2791,26 @@ public class XmlParserDstu2Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
|
||||||
|
String refVal = "http://my.org/FooBar";
|
||||||
|
|
||||||
|
Patient fhirPat = new Patient();
|
||||||
|
fhirPat.addUndeclaredExtension(false, "x1").setValue(new ResourceReferenceDt(refVal));
|
||||||
|
|
||||||
|
IParser parser = ourCtx.newXmlParser();
|
||||||
|
|
||||||
|
String output = parser.encodeResourceToString(fhirPat);
|
||||||
|
System.out.println("output: " + output);
|
||||||
|
|
||||||
|
// Deserialize then check that valueReference value is still correct
|
||||||
|
fhirPat = parser.parseResource(Patient.class, output);
|
||||||
|
|
||||||
|
List<ExtensionDt> extlst = fhirPat.getUndeclaredExtensionsByUrl("x1");
|
||||||
|
Assert.assertEquals(1, extlst.size());
|
||||||
|
Assert.assertEquals(refVal, ((ResourceReferenceDt) extlst.get(0).getValue()).getReference().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
public static void afterClassClearContext() {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
|
|
@ -351,11 +351,16 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
||||||
b.append(myResourceType);
|
b.append(myResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.length() > 0) {
|
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNotBlank(myUnqualifiedId)) {
|
||||||
b.append(myUnqualifiedId);
|
b.append(myUnqualifiedId);
|
||||||
|
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
|
b.append('/');
|
||||||
|
}
|
||||||
|
|
||||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
b.append("_history");
|
b.append("_history");
|
||||||
|
@ -546,8 +551,22 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
||||||
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
||||||
if (typeIndex == -1) {
|
if (typeIndex == -1) {
|
||||||
myResourceType = theValue.substring(0, idIndex);
|
myResourceType = theValue.substring(0, idIndex);
|
||||||
|
} else {
|
||||||
|
if (typeIndex > 0 && '/' == theValue.charAt(typeIndex - 1)) {
|
||||||
|
typeIndex = theValue.indexOf('/', typeIndex + 1);
|
||||||
|
}
|
||||||
|
if (typeIndex >= idIndex) {
|
||||||
|
// e.g. http://example.org/foo
|
||||||
|
// 'foo' was the id but we're making that the resource type. Nullify the id part because we don't have an id.
|
||||||
|
// Also set null value to the super.setValue() and enable myHaveComponentParts so it forces getValue() to properly
|
||||||
|
// recreate the url
|
||||||
|
myResourceType = myUnqualifiedId;
|
||||||
|
myUnqualifiedId = null;
|
||||||
|
super.setValue(null);
|
||||||
|
myHaveComponentParts = true;
|
||||||
} else {
|
} else {
|
||||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeIndex > 4) {
|
if (typeIndex > 4) {
|
||||||
myBaseUrl = theValue.substring(0, typeIndex);
|
myBaseUrl = theValue.substring(0, typeIndex);
|
||||||
|
|
|
@ -92,6 +92,38 @@ public class IdTypeDstu3Test {
|
||||||
assertEquals("foo/_history/2", id.withVersion("2").getValue());
|
assertEquals("foo/_history/2", id.withVersion("2").getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo1() {
|
||||||
|
IdType id = new IdType("http://my.org/foo");
|
||||||
|
assertEquals("http://my.org/foo", id.getValueAsString());
|
||||||
|
assertEquals(null, id.getIdPart());
|
||||||
|
assertEquals("foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("foo", id.getResourceType());
|
||||||
|
assertEquals("http://my.org", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/foo//_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo2() {
|
||||||
|
IdType id = new IdType("http://my.org/a/b/c/foo");
|
||||||
|
assertEquals("http://my.org/a/b/c/foo", id.getValueAsString());
|
||||||
|
assertEquals("foo", id.getIdPart());
|
||||||
|
assertEquals("c/foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("c/foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("c", id.getResourceType());
|
||||||
|
assertEquals("http://my.org/a/b", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient/foo", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient/foo", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/a/b/c/foo/_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDetectLocal() {
|
public void testDetectLocal() {
|
||||||
IdType id;
|
IdType id;
|
||||||
|
|
|
@ -2414,6 +2414,26 @@ public class JsonParserDstu3Test {
|
||||||
assertTrue(result.isSuccessful());
|
assertTrue(result.isSuccessful());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
|
||||||
|
String refVal = "http://my.org/FooBar";
|
||||||
|
|
||||||
|
Patient fhirPat = new Patient();
|
||||||
|
fhirPat.addExtension().setUrl("x1").setValue(new Reference(refVal));
|
||||||
|
|
||||||
|
IParser parser = ourCtx.newJsonParser();
|
||||||
|
|
||||||
|
String output = parser.encodeResourceToString(fhirPat);
|
||||||
|
System.out.println("output: " + output);
|
||||||
|
|
||||||
|
// Deserialize then check that valueReference value is still correct
|
||||||
|
fhirPat = parser.parseResource(Patient.class, output);
|
||||||
|
|
||||||
|
List<Extension> extlst = fhirPat.getExtensionsByUrl("x1");
|
||||||
|
Assert.assertEquals(1, extlst.size());
|
||||||
|
Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference());
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
public static void afterClassClearContext() {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
|
|
@ -3334,6 +3334,26 @@ public class XmlParserDstu3Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
|
||||||
|
String refVal = "http://my.org/FooBar";
|
||||||
|
|
||||||
|
Patient fhirPat = new Patient();
|
||||||
|
fhirPat.addExtension().setUrl("x1").setValue(new Reference(refVal));
|
||||||
|
|
||||||
|
IParser parser = ourCtx.newXmlParser();
|
||||||
|
|
||||||
|
String output = parser.encodeResourceToString(fhirPat);
|
||||||
|
System.out.println("output: " + output);
|
||||||
|
|
||||||
|
// Deserialize then check that valueReference value is still correct
|
||||||
|
fhirPat = parser.parseResource(Patient.class, output);
|
||||||
|
|
||||||
|
List<Extension> extlst = fhirPat.getExtensionsByUrl("x1");
|
||||||
|
Assert.assertEquals(1, extlst.size());
|
||||||
|
Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference());
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
public static void afterClassClearContext() {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
|
|
@ -380,11 +380,16 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
||||||
b.append(myResourceType);
|
b.append(myResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.length() > 0) {
|
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNotBlank(myUnqualifiedId)) {
|
||||||
b.append(myUnqualifiedId);
|
b.append(myUnqualifiedId);
|
||||||
|
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
|
b.append('/');
|
||||||
|
}
|
||||||
|
|
||||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
b.append("_history");
|
b.append("_history");
|
||||||
|
@ -570,8 +575,22 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
||||||
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
||||||
if (typeIndex == -1) {
|
if (typeIndex == -1) {
|
||||||
myResourceType = theValue.substring(0, idIndex);
|
myResourceType = theValue.substring(0, idIndex);
|
||||||
|
} else {
|
||||||
|
if (typeIndex > 0 && '/' == theValue.charAt(typeIndex - 1)) {
|
||||||
|
typeIndex = theValue.indexOf('/', typeIndex + 1);
|
||||||
|
}
|
||||||
|
if (typeIndex >= idIndex) {
|
||||||
|
// e.g. http://example.org/foo
|
||||||
|
// 'foo' was the id but we're making that the resource type. Nullify the id part because we don't have an id.
|
||||||
|
// Also set null value to the super.setValue() and enable myHaveComponentParts so it forces getValue() to properly
|
||||||
|
// recreate the url
|
||||||
|
myResourceType = myUnqualifiedId;
|
||||||
|
myUnqualifiedId = null;
|
||||||
|
super.setValue(null);
|
||||||
|
myHaveComponentParts = true;
|
||||||
} else {
|
} else {
|
||||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeIndex > 4) {
|
if (typeIndex > 4) {
|
||||||
myBaseUrl = theValue.substring(0, typeIndex);
|
myBaseUrl = theValue.substring(0, typeIndex);
|
||||||
|
|
|
@ -84,6 +84,54 @@ public class IdTypeTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNormal() {
|
||||||
|
IdType id = new IdType("foo");
|
||||||
|
assertEquals("foo", id.getValueAsString());
|
||||||
|
assertEquals("foo", id.getIdPart());
|
||||||
|
assertEquals("foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals(null, id.getResourceType());
|
||||||
|
assertEquals(null, id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient/foo", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient/foo", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("foo/_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo1() {
|
||||||
|
IdType id = new IdType("http://my.org/foo");
|
||||||
|
assertEquals("http://my.org/foo", id.getValueAsString());
|
||||||
|
assertEquals(null, id.getIdPart());
|
||||||
|
assertEquals("foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("foo", id.getResourceType());
|
||||||
|
assertEquals("http://my.org", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/foo//_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo2() {
|
||||||
|
IdType id = new IdType("http://my.org/a/b/c/foo");
|
||||||
|
assertEquals("http://my.org/a/b/c/foo", id.getValueAsString());
|
||||||
|
assertEquals("foo", id.getIdPart());
|
||||||
|
assertEquals("c/foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("c/foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("c", id.getResourceType());
|
||||||
|
assertEquals("http://my.org/a/b", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient/foo", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient/foo", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/a/b/c/foo/_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDetermineBase() {
|
public void testDetermineBase() {
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package ca.uhn.fhir.parser;
|
package ca.uhn.fhir.parser;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import static org.junit.Assert.*;
|
import ca.uhn.fhir.model.api.annotation.Child;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||||
import java.io.*;
|
import ca.uhn.fhir.narrative.INarrativeGenerator;
|
||||||
import java.nio.charset.Charset;
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
import java.util.Arrays;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
import java.util.List;
|
import net.sf.json.JSON;
|
||||||
|
import net.sf.json.JSONSerializer;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.hamcrest.core.IsNot;
|
import org.hamcrest.core.IsNot;
|
||||||
import org.hamcrest.core.StringContains;
|
import org.hamcrest.core.StringContains;
|
||||||
|
@ -22,19 +22,23 @@ import org.hl7.fhir.instance.model.Narrative.NarrativeStatus;
|
||||||
import org.hl7.fhir.instance.model.Patient.ContactComponent;
|
import org.hl7.fhir.instance.model.Patient.ContactComponent;
|
||||||
import org.hl7.fhir.instance.model.ValueSet.ConceptDefinitionComponent;
|
import org.hl7.fhir.instance.model.ValueSet.ConceptDefinitionComponent;
|
||||||
import org.hl7.fhir.instance.model.ValueSet.ValueSetCodeSystemComponent;
|
import org.hl7.fhir.instance.model.ValueSet.ValueSetCodeSystemComponent;
|
||||||
import org.hl7.fhir.instance.model.api.*;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
import org.hl7.fhir.instance.model.api.INarrative;
|
||||||
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import java.io.IOException;
|
||||||
import ca.uhn.fhir.model.api.annotation.Child;
|
import java.io.OutputStreamWriter;
|
||||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
import java.io.StringReader;
|
||||||
import ca.uhn.fhir.narrative.INarrativeGenerator;
|
import java.nio.charset.Charset;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
import java.util.Arrays;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import java.util.List;
|
||||||
import net.sf.json.JSON;
|
|
||||||
import net.sf.json.JSONSerializer;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class JsonParserHl7OrgDstu2Test {
|
public class JsonParserHl7OrgDstu2Test {
|
||||||
private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
|
private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
|
||||||
|
@ -1274,6 +1278,26 @@ public class JsonParserHl7OrgDstu2Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
|
||||||
|
String refVal = "http://my.org/FooBar";
|
||||||
|
|
||||||
|
Patient fhirPat = new Patient();
|
||||||
|
fhirPat.addExtension().setUrl("x1").setValue(new Reference(refVal));
|
||||||
|
|
||||||
|
IParser parser = ourCtx.newJsonParser();
|
||||||
|
|
||||||
|
String output = parser.encodeResourceToString(fhirPat);
|
||||||
|
System.out.println("output: " + output);
|
||||||
|
|
||||||
|
// Deserialize then check that valueReference value is still correct
|
||||||
|
fhirPat = parser.parseResource(Patient.class, output);
|
||||||
|
|
||||||
|
List<Extension> extlst = fhirPat.getExtension();
|
||||||
|
Assert.assertEquals(1, extlst.size());
|
||||||
|
Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference());
|
||||||
|
}
|
||||||
|
|
||||||
@ResourceDef(name = "Patient")
|
@ResourceDef(name = "Patient")
|
||||||
public static class MyPatientWithOneDeclaredAddressExtension extends Patient {
|
public static class MyPatientWithOneDeclaredAddressExtension extends Patient {
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,24 @@ import org.hl7.fhir.instance.model.Identifier.IdentifierUse;
|
||||||
import org.hl7.fhir.instance.model.Narrative.NarrativeStatus;
|
import org.hl7.fhir.instance.model.Narrative.NarrativeStatus;
|
||||||
import org.hl7.fhir.instance.model.api.*;
|
import org.hl7.fhir.instance.model.api.*;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
import org.hl7.fhir.instance.model.Observation;
|
||||||
|
import org.hl7.fhir.instance.model.Organization;
|
||||||
|
import org.hl7.fhir.instance.model.Patient;
|
||||||
|
import org.hl7.fhir.instance.model.PrimitiveType;
|
||||||
|
import org.hl7.fhir.instance.model.Reference;
|
||||||
|
import org.hl7.fhir.instance.model.Resource;
|
||||||
|
import org.hl7.fhir.instance.model.SimpleQuantity;
|
||||||
|
import org.hl7.fhir.instance.model.Specimen;
|
||||||
|
import org.hl7.fhir.instance.model.StringType;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
import org.hl7.fhir.instance.model.api.INarrative;
|
||||||
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xmlunit.builder.DiffBuilder;
|
import org.xmlunit.builder.DiffBuilder;
|
||||||
import org.xmlunit.builder.Input;
|
import org.xmlunit.builder.Input;
|
||||||
|
@ -1738,6 +1756,26 @@ public class XmlParserHl7OrgDstu2Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFooResourceCorrectlySerializedInExtensionValueReference() {
|
||||||
|
String refVal = "http://my.org/FooBar";
|
||||||
|
|
||||||
|
Patient fhirPat = new Patient();
|
||||||
|
fhirPat.addExtension().setUrl("x1").setValue(new Reference(refVal));
|
||||||
|
|
||||||
|
IParser parser = ourCtx.newXmlParser();
|
||||||
|
|
||||||
|
String output = parser.encodeResourceToString(fhirPat);
|
||||||
|
System.out.println("output: " + output);
|
||||||
|
|
||||||
|
// Deserialize then check that valueReference value is still correct
|
||||||
|
fhirPat = parser.parseResource(Patient.class, output);
|
||||||
|
|
||||||
|
List<Extension> extlst = fhirPat.getExtension();
|
||||||
|
Assert.assertEquals(1, extlst.size());
|
||||||
|
Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference());
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
ourCtx = FhirContext.forDstu2Hl7Org();
|
ourCtx = FhirContext.forDstu2Hl7Org();
|
||||||
|
|
|
@ -70,89 +70,89 @@ import org.hl7.fhir.instance.model.api.*;
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the logical identity for a resource, or as much of that
|
* This class represents the logical identity for a resource, or as much of that
|
||||||
* identity is known. In FHIR, every resource must have a "logical ID" which is
|
* identity is known. In FHIR, every resource must have a "logical ID" which is
|
||||||
* defined by the FHIR specification as:
|
* defined by the FHIR specification as:
|
||||||
* <p>
|
* <p>
|
||||||
* <code>A whole number in the range 0 to 2^64-1 (optionally represented in hex),
|
* <code>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, "-"
|
* a uuid, an oid, or any other combination of lowercase letters, numerals, "-"
|
||||||
* and ".", with a length limit of 36 characters</code>
|
* and ".", with a length limit of 36 characters</code>
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* This class contains that logical ID, and can optionally also contain a
|
* This class contains that logical ID, and can optionally also contain a
|
||||||
* relative or absolute URL representing the resource identity. For example, the
|
* relative or absolute URL representing the resource identity. For example, the
|
||||||
* following are all valid values for IdType, and all might represent the same
|
* following are all valid values for IdType, and all might represent the same
|
||||||
* resource:
|
* resource:
|
||||||
* </p>
|
* </p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><code>123</code> (just a resource's ID)</li>
|
* <li><code>123</code> (just a resource's ID)</li>
|
||||||
* <li><code>Patient/123</code> (a relative identity)</li>
|
* <li><code>Patient/123</code> (a relative identity)</li>
|
||||||
* <li><code>http://example.com/Patient/123 (an absolute identity)</code></li>
|
* <li><code>http://example.com/Patient/123 (an absolute identity)</code></li>
|
||||||
* <li>
|
* <li>
|
||||||
* <code>http://example.com/Patient/123/_history/1 (an absolute identity with a version id)</code>
|
* <code>http://example.com/Patient/123/_history/1 (an absolute identity with a version id)</code>
|
||||||
* </li>
|
* </li>
|
||||||
* <li>
|
* <li>
|
||||||
* <code>Patient/123/_history/1 (a relative identity with a version id)</code>
|
* <code>Patient/123/_history/1 (a relative identity with a version id)</code>
|
||||||
* </li>
|
* </li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
* In most situations, you only need to populate the resource's ID (e.g.
|
* In most situations, you only need to populate the resource's ID (e.g.
|
||||||
* <code>123</code>) in resources you are constructing and the encoder will
|
* <code>123</code>) in resources you are constructing and the encoder will
|
||||||
* infer the rest from the context in which the object is being used. On the
|
* infer the rest from the context in which the object is being used. On the
|
||||||
* other hand, the parser will always try to populate the complete absolute
|
* other hand, the parser will always try to populate the complete absolute
|
||||||
* identity on objects it creates as a convenience.
|
* identity on objects it creates as a convenience.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* Regex for ID: [a-z0-9\-\.]{1,36}
|
* Regex for ID: [a-z0-9\-\.]{1,36}
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@DatatypeDef(name = "id", profileOf=StringType.class)
|
@DatatypeDef(name = "id", profileOf = StringType.class)
|
||||||
public final class IdType extends UriType implements IPrimitiveType<String>, IIdType {
|
public final class IdType extends UriType implements IPrimitiveType<String>, IIdType {
|
||||||
public static final String URN_PREFIX = "urn:";
|
public static final String URN_PREFIX = "urn:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the maximum length for the ID
|
* This is the maximum length for the ID
|
||||||
*/
|
*/
|
||||||
public static final int MAX_LENGTH = 64; // maximum length
|
public static final int MAX_LENGTH = 64; // maximum length
|
||||||
|
|
||||||
private static final long serialVersionUID = 2L;
|
private static final long serialVersionUID = 2L;
|
||||||
private String myBaseUrl;
|
private String myBaseUrl;
|
||||||
private boolean myHaveComponentParts;
|
private boolean myHaveComponentParts;
|
||||||
private String myResourceType;
|
private String myResourceType;
|
||||||
private String myUnqualifiedId;
|
private String myUnqualifiedId;
|
||||||
private String myUnqualifiedVersionId;
|
private String myUnqualifiedVersionId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new empty ID
|
* Create a new empty ID
|
||||||
*/
|
*/
|
||||||
public IdType() {
|
public IdType() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ID, using a BigDecimal input. Uses
|
* Create a new ID, using a BigDecimal input. Uses
|
||||||
* {@link BigDecimal#toPlainString()} to generate the string representation.
|
* {@link BigDecimal#toPlainString()} to generate the string representation.
|
||||||
*/
|
*/
|
||||||
public IdType(BigDecimal thePid) {
|
public IdType(BigDecimal thePid) {
|
||||||
if (thePid != null) {
|
if (thePid != null) {
|
||||||
setValue(toPlainStringWithNpeThrowIfNeeded(thePid));
|
setValue(toPlainStringWithNpeThrowIfNeeded(thePid));
|
||||||
} else {
|
} else {
|
||||||
setValue(null);
|
setValue(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ID using a long
|
* Create a new ID using a long
|
||||||
*/
|
*/
|
||||||
public IdType(long theId) {
|
public IdType(long theId) {
|
||||||
setValue(Long.toString(theId));
|
setValue(Long.toString(theId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ID using a string. This String may contain a simple ID (e.g.
|
* Create a new ID using a string. This String may contain a simple ID (e.g.
|
||||||
* "1234") or it may contain a complete URL
|
* "1234") or it may contain a complete URL
|
||||||
* (http://example.com/fhir/Patient/1234).
|
* (http://example.com/fhir/Patient/1234).
|
||||||
*
|
* <p>
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally
|
* <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
|
* represented in hex), a uuid, an oid, or any other combination of lowercase
|
||||||
|
@ -162,73 +162,60 @@ public IdType(long theId) {
|
||||||
* regex: [a-z0-9\-\.]{1,36}
|
* regex: [a-z0-9\-\.]{1,36}
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public IdType(String theValue) {
|
public IdType(String theValue) {
|
||||||
setValue(theValue);
|
setValue(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param theResourceType
|
* @param theResourceType The resource type (e.g. "Patient")
|
||||||
* The resource type (e.g. "Patient")
|
* @param theIdPart The ID (e.g. "123")
|
||||||
* @param theIdPart
|
|
||||||
* The ID (e.g. "123")
|
|
||||||
*/
|
*/
|
||||||
public IdType(String theResourceType, BigDecimal theIdPart) {
|
public IdType(String theResourceType, BigDecimal theIdPart) {
|
||||||
this(theResourceType, toPlainStringWithNpeThrowIfNeeded(theIdPart));
|
this(theResourceType, toPlainStringWithNpeThrowIfNeeded(theIdPart));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param theResourceType
|
* @param theResourceType The resource type (e.g. "Patient")
|
||||||
* The resource type (e.g. "Patient")
|
* @param theIdPart The ID (e.g. "123")
|
||||||
* @param theIdPart
|
|
||||||
* The ID (e.g. "123")
|
|
||||||
*/
|
*/
|
||||||
public IdType(String theResourceType, Long theIdPart) {
|
public IdType(String theResourceType, Long theIdPart) {
|
||||||
this(theResourceType, toPlainStringWithNpeThrowIfNeeded(theIdPart));
|
this(theResourceType, toPlainStringWithNpeThrowIfNeeded(theIdPart));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param theResourceType
|
* @param theResourceType The resource type (e.g. "Patient")
|
||||||
* The resource type (e.g. "Patient")
|
* @param theId The ID (e.g. "123")
|
||||||
* @param theId
|
|
||||||
* The ID (e.g. "123")
|
|
||||||
*/
|
*/
|
||||||
public IdType(String theResourceType, String theId) {
|
public IdType(String theResourceType, String theId) {
|
||||||
this(theResourceType, theId, null);
|
this(theResourceType, theId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param theResourceType
|
* @param theResourceType The resource type (e.g. "Patient")
|
||||||
* The resource type (e.g. "Patient")
|
* @param theId The ID (e.g. "123")
|
||||||
* @param theId
|
* @param theVersionId The version ID ("e.g. "456")
|
||||||
* The ID (e.g. "123")
|
|
||||||
* @param theVersionId
|
|
||||||
* The version ID ("e.g. "456")
|
|
||||||
*/
|
*/
|
||||||
public IdType(String theResourceType, String theId, String theVersionId) {
|
public IdType(String theResourceType, String theId, String theVersionId) {
|
||||||
this(null, theResourceType, theId, theVersionId);
|
this(null, theResourceType, theId, theVersionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param theBaseUrl
|
* @param theBaseUrl The server base URL (e.g. "http://example.com/fhir")
|
||||||
* The server base URL (e.g. "http://example.com/fhir")
|
* @param theResourceType The resource type (e.g. "Patient")
|
||||||
* @param theResourceType
|
* @param theId The ID (e.g. "123")
|
||||||
* The resource type (e.g. "Patient")
|
* @param theVersionId The version ID ("e.g. "456")
|
||||||
* @param theId
|
|
||||||
* The ID (e.g. "123")
|
|
||||||
* @param theVersionId
|
|
||||||
* The version ID ("e.g. "456")
|
|
||||||
*/
|
*/
|
||||||
public IdType(String theBaseUrl, String theResourceType, String theId, String theVersionId) {
|
public IdType(String theBaseUrl, String theResourceType, String theId, String theVersionId) {
|
||||||
myBaseUrl = theBaseUrl;
|
myBaseUrl = theBaseUrl;
|
||||||
myResourceType = theResourceType;
|
myResourceType = theResourceType;
|
||||||
myUnqualifiedId = theId;
|
myUnqualifiedId = theId;
|
||||||
|
@ -237,51 +224,51 @@ public IdType(String theBaseUrl, String theResourceType, String theId, String th
|
||||||
if (isBlank(myBaseUrl) && isBlank(myResourceType) && isBlank(myUnqualifiedId) && isBlank(myUnqualifiedVersionId)) {
|
if (isBlank(myBaseUrl) && isBlank(myResourceType) && isBlank(myUnqualifiedId) && isBlank(myUnqualifiedVersionId)) {
|
||||||
myHaveComponentParts = false;
|
myHaveComponentParts = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an ID based on a given URL
|
* Creates an ID based on a given URL
|
||||||
*/
|
*/
|
||||||
public IdType(UriType theUrl) {
|
public IdType(UriType theUrl) {
|
||||||
setValue(theUrl.getValueAsString());
|
setValue(theUrl.getValueAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyTo(IBaseResource theResouce) {
|
public void applyTo(IBaseResource theResouce) {
|
||||||
if (theResouce == null) {
|
if (theResouce == null) {
|
||||||
throw new NullPointerException("theResource can not be null");
|
throw new NullPointerException("theResource can not be null");
|
||||||
} else {
|
} else {
|
||||||
theResouce.setId(new IdType(getValue()));
|
theResouce.setId(new IdType(getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link #getIdPartAsBigDecimal()} instead (this method was
|
* @deprecated Use {@link #getIdPartAsBigDecimal()} instead (this method was
|
||||||
* deprocated because its name is ambiguous)
|
* deprocated because its name is ambiguous)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public BigDecimal asBigDecimal() {
|
public BigDecimal asBigDecimal() {
|
||||||
return getIdPartAsBigDecimal();
|
return getIdPartAsBigDecimal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdType copy() {
|
public IdType copy() {
|
||||||
return new IdType(getValue());
|
return new IdType(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object theArg0) {
|
public boolean equals(Object theArg0) {
|
||||||
if (!(theArg0 instanceof IdType)) {
|
if (!(theArg0 instanceof IdType)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return StringUtils.equals(getValueAsString(), ((IdType)theArg0).getValueAsString());
|
return StringUtils.equals(getValueAsString(), ((IdType) theArg0).getValueAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this IdType matches the given IdType in terms of resource
|
* Returns true if this IdType matches the given IdType in terms of resource
|
||||||
* type and ID, but ignores the URL base
|
* type and ID, but ignores the URL base
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public boolean equalsIgnoreBase(IdType theId) {
|
public boolean equalsIgnoreBase(IdType theId) {
|
||||||
if (theId == null) {
|
if (theId == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -291,9 +278,9 @@ public boolean equalsIgnoreBase(IdType theId) {
|
||||||
return ObjectUtils.equals(getResourceType(), theId.getResourceType())
|
return ObjectUtils.equals(getResourceType(), theId.getResourceType())
|
||||||
&& ObjectUtils.equals(getIdPart(), theId.getIdPart())
|
&& ObjectUtils.equals(getIdPart(), theId.getIdPart())
|
||||||
&& ObjectUtils.equals(getVersionIdPart(), theId.getVersionIdPart());
|
&& ObjectUtils.equals(getVersionIdPart(), theId.getVersionIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the portion of this resource ID which corresponds to the server
|
* Returns the portion of this resource ID which corresponds to the server
|
||||||
* base URL. For example given the resource ID
|
* base URL. For example given the resource ID
|
||||||
* <code>http://example.com/fhir/Patient/123</code> the base URL would be
|
* <code>http://example.com/fhir/Patient/123</code> the base URL would be
|
||||||
|
@ -302,66 +289,64 @@ public boolean equalsIgnoreBase(IdType theId) {
|
||||||
* This method may return null if the ID contains no base (e.g. "Patient/123")
|
* This method may return null if the ID contains no base (e.g. "Patient/123")
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getBaseUrl() {
|
public String getBaseUrl() {
|
||||||
return myBaseUrl;
|
return myBaseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns only the logical ID part of this ID. For example, given the ID
|
* Returns only the logical ID part of this ID. For example, given the ID
|
||||||
* "http://example,.com/fhir/Patient/123/_history/456", this method would
|
* "http://example,.com/fhir/Patient/123/_history/456", this method would
|
||||||
* return "123".
|
* return "123".
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getIdPart() {
|
public String getIdPart() {
|
||||||
return myUnqualifiedId;
|
return myUnqualifiedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the unqualified portion of this ID as a big decimal, or
|
* Returns the unqualified portion of this ID as a big decimal, or
|
||||||
* <code>null</code> if the value is null
|
* <code>null</code> if the value is null
|
||||||
*
|
*
|
||||||
* @throws NumberFormatException
|
* @throws NumberFormatException If the value is not a valid BigDecimal
|
||||||
* If the value is not a valid BigDecimal
|
|
||||||
*/
|
*/
|
||||||
public BigDecimal getIdPartAsBigDecimal() {
|
public BigDecimal getIdPartAsBigDecimal() {
|
||||||
String val = getIdPart();
|
String val = getIdPart();
|
||||||
if (isBlank(val)) {
|
if (isBlank(val)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new BigDecimal(val);
|
return new BigDecimal(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the unqualified portion of this ID as a {@link Long}, or
|
* Returns the unqualified portion of this ID as a {@link Long}, or
|
||||||
* <code>null</code> if the value is null
|
* <code>null</code> if the value is null
|
||||||
*
|
*
|
||||||
* @throws NumberFormatException
|
* @throws NumberFormatException If the value is not a valid Long
|
||||||
* If the value is not a valid Long
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long getIdPartAsLong() {
|
public Long getIdPartAsLong() {
|
||||||
String val = getIdPart();
|
String val = getIdPart();
|
||||||
if (isBlank(val)) {
|
if (isBlank(val)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Long.parseLong(val);
|
return Long.parseLong(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getResourceType() {
|
public String getResourceType() {
|
||||||
return myResourceType;
|
return myResourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of this ID. Note that this value may be a fully qualified
|
* 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
|
* URL, a relative/partial URL, or a simple ID. Use {@link #getIdPart()} to
|
||||||
* get just the ID portion.
|
* get just the ID portion.
|
||||||
*
|
*
|
||||||
* @see #getIdPart()
|
* @see #getIdPart()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
String retVal = super.getValue();
|
String retVal = super.getValue();
|
||||||
if (retVal == null && myHaveComponentParts) {
|
if (retVal == null && myHaveComponentParts) {
|
||||||
|
|
||||||
|
@ -381,11 +366,16 @@ public String getValue() {
|
||||||
b.append(myResourceType);
|
b.append(myResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.length() > 0) {
|
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNotBlank(myUnqualifiedId)) {
|
||||||
b.append(myUnqualifiedId);
|
b.append(myUnqualifiedId);
|
||||||
|
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
|
b.append('/');
|
||||||
|
}
|
||||||
|
|
||||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||||
b.append('/');
|
b.append('/');
|
||||||
b.append("_history");
|
b.append("_history");
|
||||||
|
@ -396,76 +386,76 @@ public String getValue() {
|
||||||
super.setValue(retVal);
|
super.setValue(retVal);
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
return getValue();
|
return getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersionIdPart() {
|
public String getVersionIdPart() {
|
||||||
return myUnqualifiedVersionId;
|
return myUnqualifiedVersionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getVersionIdPartAsLong() {
|
public Long getVersionIdPartAsLong() {
|
||||||
if (!hasVersionIdPart()) {
|
if (!hasVersionIdPart()) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return Long.parseLong(getVersionIdPart());
|
return Long.parseLong(getVersionIdPart());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this ID has a base url
|
* Returns true if this ID has a base url
|
||||||
*
|
*
|
||||||
* @see #getBaseUrl()
|
* @see #getBaseUrl()
|
||||||
*/
|
*/
|
||||||
public boolean hasBaseUrl() {
|
public boolean hasBaseUrl() {
|
||||||
return isNotBlank(myBaseUrl);
|
return isNotBlank(myBaseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
HashCodeBuilder b = new HashCodeBuilder();
|
HashCodeBuilder b = new HashCodeBuilder();
|
||||||
b.append(getValueAsString());
|
b.append(getValueAsString());
|
||||||
return b.toHashCode();
|
return b.toHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasIdPart() {
|
public boolean hasIdPart() {
|
||||||
return isNotBlank(getIdPart());
|
return isNotBlank(getIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasResourceType() {
|
public boolean hasResourceType() {
|
||||||
return isNotBlank(myResourceType);
|
return isNotBlank(myResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasVersionIdPart() {
|
public boolean hasVersionIdPart() {
|
||||||
return isNotBlank(getVersionIdPart());
|
return isNotBlank(getVersionIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if this ID contains an absolute URL (in other
|
* Returns <code>true</code> if this ID contains an absolute URL (in other
|
||||||
* words, a URL starting with "http://" or "https://"
|
* words, a URL starting with "http://" or "https://"
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isAbsolute() {
|
public boolean isAbsolute() {
|
||||||
if (StringUtils.isBlank(getValue())) {
|
if (StringUtils.isBlank(getValue())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return isUrlAbsolute(getValue());
|
return isUrlAbsolute(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return isBlank(getValue());
|
return isBlank(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isIdPartValid() {
|
public boolean isIdPartValid() {
|
||||||
String id = getIdPart();
|
String id = getIdPart();
|
||||||
if (StringUtils.isBlank(id)) {
|
if (StringUtils.isBlank(id)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -490,38 +480,38 @@ public boolean isIdPartValid() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the unqualified ID is a valid {@link Long}
|
* Returns <code>true</code> if the unqualified ID is a valid {@link Long}
|
||||||
* value (in other words, it consists only of digits)
|
* value (in other words, it consists only of digits)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isIdPartValidLong() {
|
public boolean isIdPartValidLong() {
|
||||||
return isValidLong(getIdPart());
|
return isValidLong(getIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the ID is a local reference (in other words,
|
* Returns <code>true</code> if the ID is a local reference (in other words,
|
||||||
* it begins with the '#' character)
|
* it begins with the '#' character)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isLocal() {
|
public boolean isLocal() {
|
||||||
return defaultString(myUnqualifiedId).startsWith("#");
|
return defaultString(myUnqualifiedId).startsWith("#");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUrn() {
|
public boolean isUrn() {
|
||||||
return defaultString(myUnqualifiedId).startsWith(URN_PREFIX);
|
return defaultString(myUnqualifiedId).startsWith(URN_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVersionIdPartValidLong() {
|
public boolean isVersionIdPartValidLong() {
|
||||||
return isValidLong(getVersionIdPart());
|
return isValidLong(getVersionIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value
|
* Set the value
|
||||||
*
|
* <p>
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally
|
* <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
|
* represented in hex), a uuid, an oid, or any other combination of lowercase
|
||||||
|
@ -531,8 +521,8 @@ public boolean isVersionIdPartValidLong() {
|
||||||
* regex: [a-z0-9\-\.]{1,36}
|
* regex: [a-z0-9\-\.]{1,36}
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IdType setValue(String theValue) {
|
public IdType setValue(String theValue) {
|
||||||
// TODO: add validation
|
// TODO: add validation
|
||||||
super.setValue(theValue);
|
super.setValue(theValue);
|
||||||
myHaveComponentParts = false;
|
myHaveComponentParts = false;
|
||||||
|
@ -576,8 +566,22 @@ public IdType setValue(String theValue) {
|
||||||
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
||||||
if (typeIndex == -1) {
|
if (typeIndex == -1) {
|
||||||
myResourceType = theValue.substring(0, idIndex);
|
myResourceType = theValue.substring(0, idIndex);
|
||||||
|
} else {
|
||||||
|
if (typeIndex > 0 && '/' == theValue.charAt(typeIndex - 1)) {
|
||||||
|
typeIndex = theValue.indexOf('/', typeIndex + 1);
|
||||||
|
}
|
||||||
|
if (typeIndex >= idIndex) {
|
||||||
|
// e.g. http://example.org/foo
|
||||||
|
// 'foo' was the id but we're making that the resource type. Nullify the id part because we don't have an id.
|
||||||
|
// Also set null value to the super.setValue() and enable myHaveComponentParts so it forces getValue() to properly
|
||||||
|
// recreate the url
|
||||||
|
myResourceType = myUnqualifiedId;
|
||||||
|
myUnqualifiedId = null;
|
||||||
|
super.setValue(null);
|
||||||
|
myHaveComponentParts = true;
|
||||||
} else {
|
} else {
|
||||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeIndex > 4) {
|
if (typeIndex > 4) {
|
||||||
myBaseUrl = theValue.substring(0, typeIndex);
|
myBaseUrl = theValue.substring(0, typeIndex);
|
||||||
|
@ -588,11 +592,11 @@ public IdType setValue(String theValue) {
|
||||||
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value
|
* Set the value
|
||||||
*
|
* <p>
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally
|
* <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
|
* represented in hex), a uuid, an oid, or any other combination of lowercase
|
||||||
|
@ -602,87 +606,84 @@ public IdType setValue(String theValue) {
|
||||||
* regex: [a-z0-9\-\.]{1,36}
|
* regex: [a-z0-9\-\.]{1,36}
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setValueAsString(String theValue) {
|
public void setValueAsString(String theValue) {
|
||||||
setValue(theValue);
|
setValue(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getValue();
|
return getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new IdType containing this IdType's values but with no server
|
* Returns a new IdType containing this IdType's values but with no server
|
||||||
* base URL if one is present in this IdType. For example, if this IdType
|
* base URL if one is present in this IdType. For example, if this IdType
|
||||||
* contains the ID "http://foo/Patient/1", this method will return a new
|
* contains the ID "http://foo/Patient/1", this method will return a new
|
||||||
* IdType containing ID "Patient/1".
|
* IdType containing ID "Patient/1".
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IdType toUnqualified() {
|
public IdType toUnqualified() {
|
||||||
if (isLocal() || isUrn()) {
|
if (isLocal() || isUrn()) {
|
||||||
return new IdType(getValueAsString());
|
return new IdType(getValueAsString());
|
||||||
}
|
}
|
||||||
return new IdType(getResourceType(), getIdPart(), getVersionIdPart());
|
return new IdType(getResourceType(), getIdPart(), getVersionIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdType toUnqualifiedVersionless() {
|
public IdType toUnqualifiedVersionless() {
|
||||||
if (isLocal() || isUrn()) {
|
if (isLocal() || isUrn()) {
|
||||||
return new IdType(getValueAsString());
|
return new IdType(getValueAsString());
|
||||||
}
|
}
|
||||||
return new IdType(getResourceType(), getIdPart());
|
return new IdType(getResourceType(), getIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdType toVersionless() {
|
public IdType toVersionless() {
|
||||||
if (isLocal() || isUrn()) {
|
if (isLocal() || isUrn()) {
|
||||||
return new IdType(getValueAsString());
|
return new IdType(getValueAsString());
|
||||||
}
|
}
|
||||||
return new IdType(getBaseUrl(), getResourceType(), getIdPart(), null);
|
return new IdType(getBaseUrl(), getResourceType(), getIdPart(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdType withResourceType(String theResourceName) {
|
public IdType withResourceType(String theResourceName) {
|
||||||
if (isLocal() || isUrn()) {
|
if (isLocal() || isUrn()) {
|
||||||
return new IdType(getValueAsString());
|
return new IdType(getValueAsString());
|
||||||
}
|
}
|
||||||
return new IdType(theResourceName, getIdPart(), getVersionIdPart());
|
return new IdType(theResourceName, getIdPart(), getVersionIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view of this ID as a fully qualified URL, given a server base and
|
* 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
|
* resource name (which will only be used if the ID does not already contain
|
||||||
* those respective parts). Essentially, because IdType can contain either a
|
* those respective parts). Essentially, because IdType can contain either a
|
||||||
* complete URL or a partial one (or even jut a simple ID), this method may be
|
* complete URL or a partial one (or even jut a simple ID), this method may be
|
||||||
* used to translate into a complete URL.
|
* 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")
|
* @param theResourceType The resource name (e.g. "Patient")
|
||||||
* @param theResourceType
|
|
||||||
* The resource name (e.g. "Patient")
|
|
||||||
* @return A fully qualified URL for this ID (e.g.
|
* @return A fully qualified URL for this ID (e.g.
|
||||||
* "http://example.com/fhir/Patient/1")
|
* "http://example.com/fhir/Patient/1")
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IdType withServerBase(String theServerBase, String theResourceType) {
|
public IdType withServerBase(String theServerBase, String theResourceType) {
|
||||||
if (isLocal() || isUrn()) {
|
if (isLocal() || isUrn()) {
|
||||||
return new IdType(getValueAsString());
|
return new IdType(getValueAsString());
|
||||||
}
|
}
|
||||||
return new IdType(theServerBase, theResourceType, getIdPart(), getVersionIdPart());
|
return new IdType(theServerBase, theResourceType, getIdPart(), getVersionIdPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of this ID which is identical, but refers to the
|
* Creates a new instance of this ID which is identical, but refers to the
|
||||||
* specific version of this resource ID noted by theVersion.
|
* specific version of this resource ID 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 IdType which is identical, but refers to the
|
* @return A new instance of IdType which is identical, but refers to the
|
||||||
* specific version of this resource ID noted by theVersion.
|
* specific version of this resource ID noted by theVersion.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IdType withVersion(String theVersion) {
|
public IdType withVersion(String theVersion) {
|
||||||
Validate.notBlank(theVersion, "Version may not be null or empty");
|
Validate.notBlank(theVersion, "Version may not be null or empty");
|
||||||
|
|
||||||
if (isLocal() || isUrn()) {
|
if (isLocal() || isUrn()) {
|
||||||
|
@ -700,14 +701,14 @@ public IdType withVersion(String theVersion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new IdType(value + '/' + "_history" + '/' + theVersion);
|
return new IdType(value + '/' + "_history" + '/' + theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isUrlAbsolute(String theValue) {
|
private static boolean isUrlAbsolute(String theValue) {
|
||||||
String value = theValue.toLowerCase();
|
String value = theValue.toLowerCase();
|
||||||
return value.startsWith("http://") || value.startsWith("https://");
|
return value.startsWith("http://") || value.startsWith("https://");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isValidLong(String id) {
|
private static boolean isValidLong(String id) {
|
||||||
if (StringUtils.isBlank(id)) {
|
if (StringUtils.isBlank(id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -717,20 +718,20 @@ private static boolean isValidLong(String id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new ID with with form "urn:uuid:[UUID]" where [UUID] is a new,
|
* Construct a new ID with with form "urn:uuid:[UUID]" where [UUID] is a new,
|
||||||
* randomly created UUID generated by {@link UUID#randomUUID()}
|
* randomly created UUID generated by {@link UUID#randomUUID()}
|
||||||
*/
|
*/
|
||||||
public static IdType newRandomUuid() {
|
public static IdType newRandomUuid() {
|
||||||
return new IdType("urn:uuid:" + UUID.randomUUID().toString());
|
return new IdType("urn:uuid:" + UUID.randomUUID().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the ID from the given resource instance
|
* Retrieves the ID from the given resource instance
|
||||||
*/
|
*/
|
||||||
public static IdType of(IBaseResource theResouce) {
|
public static IdType of(IBaseResource theResouce) {
|
||||||
if (theResouce == null) {
|
if (theResouce == null) {
|
||||||
throw new NullPointerException("theResource can not be null");
|
throw new NullPointerException("theResource can not be null");
|
||||||
} else {
|
} else {
|
||||||
|
@ -743,21 +744,21 @@ public static IdType of(IBaseResource theResouce) {
|
||||||
return new IdType(retVal.getValue());
|
return new IdType(retVal.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toPlainStringWithNpeThrowIfNeeded(BigDecimal theIdPart) {
|
private static String toPlainStringWithNpeThrowIfNeeded(BigDecimal theIdPart) {
|
||||||
if (theIdPart == null) {
|
if (theIdPart == null) {
|
||||||
throw new NullPointerException("BigDecimal ID can not be null");
|
throw new NullPointerException("BigDecimal ID can not be null");
|
||||||
}
|
}
|
||||||
return theIdPart.toPlainString();
|
return theIdPart.toPlainString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toPlainStringWithNpeThrowIfNeeded(Long theIdPart) {
|
private static String toPlainStringWithNpeThrowIfNeeded(Long theIdPart) {
|
||||||
if (theIdPart == null) {
|
if (theIdPart == null) {
|
||||||
throw new NullPointerException("Long ID can not be null");
|
throw new NullPointerException("Long ID can not be null");
|
||||||
}
|
}
|
||||||
return theIdPart.toString();
|
return theIdPart.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fhirType() {
|
public String fhirType() {
|
||||||
return "id";
|
return "id";
|
||||||
|
|
|
@ -1216,7 +1216,7 @@ public class ClientR4Test {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPatientFeedWithOneResult() {
|
static String getPatientFeedWithOneResult() {
|
||||||
return getPatientFeedWithOneResult(ourCtx);
|
return getPatientFeedWithOneResult(ourCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,30 @@ public class GenericClientR4Test {
|
||||||
return capt;
|
return capt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchWithNoExplicitBundleReturnType() throws Exception {
|
||||||
|
|
||||||
|
String msg = ClientR4Test.getPatientFeedWithOneResult();
|
||||||
|
|
||||||
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||||
|
|
||||||
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||||
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||||
|
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||||
|
|
||||||
|
// httpResponse = new BasicHttpResponse(statusline, catalog, locale)
|
||||||
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||||
|
|
||||||
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://foo");
|
||||||
|
Bundle response = (Bundle) client.search().forResource(Patient.class).execute();
|
||||||
|
|
||||||
|
assertEquals("http://foo/Patient", capt.getValue().getURI().toString());
|
||||||
|
Patient patient = (Patient) response.getEntry().get(0).getResource();
|
||||||
|
assertEquals("PRP1660", patient.getIdentifier().get(0).getValueElement().getValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptHeaderWithEncodingSpecified() throws Exception {
|
public void testAcceptHeaderWithEncodingSpecified() throws Exception {
|
||||||
final String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
final String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||||
|
|
|
@ -0,0 +1,336 @@
|
||||||
|
package org.hl7.fhir.r4.model;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class IdTypeR4Test {
|
||||||
|
|
||||||
|
private static FhirContext ourCtx;
|
||||||
|
|
||||||
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IdTypeR4Test.class);
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClassClearContext() {
|
||||||
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo1() {
|
||||||
|
IdType id = new IdType("http://my.org/foo");
|
||||||
|
assertEquals("http://my.org/foo", id.getValueAsString());
|
||||||
|
assertEquals(null, id.getIdPart());
|
||||||
|
assertEquals("foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("foo", id.getResourceType());
|
||||||
|
assertEquals("http://my.org", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/foo//_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseUrlFoo2() {
|
||||||
|
IdType id = new IdType("http://my.org/a/b/c/foo");
|
||||||
|
assertEquals("http://my.org/a/b/c/foo", id.getValueAsString());
|
||||||
|
assertEquals("foo", id.getIdPart());
|
||||||
|
assertEquals("c/foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("c/foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals("c", id.getResourceType());
|
||||||
|
assertEquals("http://my.org/a/b", id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient/foo", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient/foo", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("http://my.org/a/b/c/foo/_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUuid() {
|
||||||
|
IdType id = new IdType("urn:uuid:1234-5678");
|
||||||
|
assertEquals("urn:uuid:1234-5678", id.getValueAsString());
|
||||||
|
assertEquals("urn:uuid:1234-5678", id.getIdPart());
|
||||||
|
assertEquals("urn:uuid:1234-5678", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("urn:uuid:1234-5678", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals(null, id.getResourceType());
|
||||||
|
assertEquals(null, id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("urn:uuid:1234-5678", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("urn:uuid:1234-5678", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("urn:uuid:1234-5678", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOid() {
|
||||||
|
IdType id = new IdType("urn:oid:1.2.3.4");
|
||||||
|
assertEquals("urn:oid:1.2.3.4", id.getValueAsString());
|
||||||
|
assertEquals("urn:oid:1.2.3.4", id.getIdPart());
|
||||||
|
assertEquals("urn:oid:1.2.3.4", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("urn:oid:1.2.3.4", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals(null, id.getResourceType());
|
||||||
|
assertEquals(null, id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("urn:oid:1.2.3.4", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("urn:oid:1.2.3.4", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("urn:oid:1.2.3.4", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLocal() {
|
||||||
|
IdType id = new IdType("#foo");
|
||||||
|
assertEquals("#foo", id.getValueAsString());
|
||||||
|
assertEquals("#foo", id.getIdPart());
|
||||||
|
assertEquals("#foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("#foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals(null, id.getResourceType());
|
||||||
|
assertEquals(null, id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("#foo", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("#foo", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("#foo", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNormal() {
|
||||||
|
IdType id = new IdType("foo");
|
||||||
|
assertEquals("foo", id.getValueAsString());
|
||||||
|
assertEquals("foo", id.getIdPart());
|
||||||
|
assertEquals("foo", id.toUnqualified().getValueAsString());
|
||||||
|
assertEquals("foo", id.toUnqualifiedVersionless().getValueAsString());
|
||||||
|
assertEquals(null, id.getVersionIdPart());
|
||||||
|
assertEquals(null, id.getResourceType());
|
||||||
|
assertEquals(null, id.getBaseUrl());
|
||||||
|
|
||||||
|
assertEquals("Patient/foo", id.withResourceType("Patient").getValue());
|
||||||
|
assertEquals("http://foo/Patient/foo", id.withServerBase("http://foo", "Patient").getValue());
|
||||||
|
assertEquals("foo/_history/2", id.withVersion("2").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDetectLocal() {
|
||||||
|
IdType id;
|
||||||
|
|
||||||
|
id = new IdType("#123");
|
||||||
|
assertEquals("#123", id.getValue());
|
||||||
|
assertTrue(id.isLocal());
|
||||||
|
|
||||||
|
id = new IdType("#Medication/499059CE-CDD4-48BC-9014-528A35D15CED/_history/1");
|
||||||
|
assertEquals("#Medication/499059CE-CDD4-48BC-9014-528A35D15CED/_history/1", id.getValue());
|
||||||
|
assertTrue(id.isLocal());
|
||||||
|
|
||||||
|
id = new IdType("http://example.com/Patient/33#123");
|
||||||
|
assertEquals("http://example.com/Patient/33#123", id.getValue());
|
||||||
|
assertFalse(id.isLocal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConstructorsWithNullArguments() {
|
||||||
|
IdType id = new IdType(null, null, null);
|
||||||
|
assertEquals(null, id.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDetectLocalBase() {
|
||||||
|
assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
|
||||||
|
assertEquals(null, new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
|
||||||
|
assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart());
|
||||||
|
|
||||||
|
assertEquals("cid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
|
||||||
|
assertEquals(null, new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
|
||||||
|
assertEquals("cid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart());
|
||||||
|
|
||||||
|
assertEquals("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
|
||||||
|
assertEquals(null, new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
|
||||||
|
assertEquals("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See #67
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testComplicatedLocal() {
|
||||||
|
IdType id = new IdType("#Patient/cid:Patient-72/_history/1");
|
||||||
|
assertTrue(id.isLocal());
|
||||||
|
assertEquals(null, id.getBaseUrl());
|
||||||
|
assertNull(id.getResourceType());
|
||||||
|
assertNull(id.getVersionIdPart());
|
||||||
|
assertEquals("#Patient/cid:Patient-72/_history/1", id.getIdPart());
|
||||||
|
|
||||||
|
IdType id2 = new IdType("#Patient/cid:Patient-72/_history/1");
|
||||||
|
assertEquals(id, id2);
|
||||||
|
|
||||||
|
id2 = id2.toUnqualified();
|
||||||
|
assertTrue(id2.isLocal());
|
||||||
|
assertNull(id2.getBaseUrl());
|
||||||
|
assertNull(id2.getResourceType());
|
||||||
|
assertNull(id2.getVersionIdPart());
|
||||||
|
assertEquals("#Patient/cid:Patient-72/_history/1", id2.getIdPart());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDetermineBase() {
|
||||||
|
|
||||||
|
IdType rr;
|
||||||
|
|
||||||
|
rr = new IdType("http://foo/fhir/Organization/123");
|
||||||
|
assertEquals("http://foo/fhir", rr.getBaseUrl());
|
||||||
|
|
||||||
|
rr = new IdType("http://foo/fhir/Organization/123/_history/123");
|
||||||
|
assertEquals("http://foo/fhir", rr.getBaseUrl());
|
||||||
|
|
||||||
|
rr = new IdType("Organization/123/_history/123");
|
||||||
|
assertEquals(null, rr.getBaseUrl());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseValueAbsolute() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
IdType rr = new IdType();
|
||||||
|
rr.setValue("http://foo/fhir/Organization/123");
|
||||||
|
|
||||||
|
patient.setManagingOrganization(new Reference(rr));
|
||||||
|
|
||||||
|
Patient actual = parseAndEncode(patient);
|
||||||
|
Reference ref = actual.getManagingOrganization();
|
||||||
|
assertEquals("Organization", ref.getReferenceElement().getResourceType());
|
||||||
|
assertEquals("123", ref.getReferenceElement().getIdPart());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBigDecimalIds() {
|
||||||
|
|
||||||
|
IdType id = new IdType(new BigDecimal("123"));
|
||||||
|
assertEquals(id.getIdPartAsBigDecimal(), new BigDecimal("123"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseValueAbsoluteWithVersion() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
IdType rr = new IdType();
|
||||||
|
rr.setValue("http://foo/fhir/Organization/123/_history/999");
|
||||||
|
patient.setManagingOrganization(new Reference(rr));
|
||||||
|
|
||||||
|
Patient actual = parseAndEncode(patient);
|
||||||
|
Reference ref = actual.getManagingOrganization();
|
||||||
|
assertEquals("Organization", ref.getReferenceElement().getResourceType());
|
||||||
|
assertEquals("123", ref.getReferenceElement().getIdPart());
|
||||||
|
assertEquals(null, ref.getReferenceElement().getVersionIdPart());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testViewMethods() {
|
||||||
|
IdType i = new IdType("http://foo/fhir/Organization/123/_history/999");
|
||||||
|
assertEquals("Organization/123/_history/999", i.toUnqualified().getValue());
|
||||||
|
assertEquals("http://foo/fhir/Organization/123", i.toVersionless().getValue());
|
||||||
|
assertEquals("Organization/123", i.toUnqualifiedVersionless().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseValueWithVersion() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
IdType rr = new IdType();
|
||||||
|
rr.setValue("/123/_history/999");
|
||||||
|
patient.setManagingOrganization(new Reference(rr));
|
||||||
|
|
||||||
|
Patient actual = parseAndEncode(patient);
|
||||||
|
Reference ref = actual.getManagingOrganization();
|
||||||
|
assertEquals(null, ref.getReferenceElement().getResourceType());
|
||||||
|
assertEquals("123", ref.getReferenceElement().getIdPart());
|
||||||
|
assertEquals(null, ref.getReferenceElement().getVersionIdPart());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseValueMissingType1() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
IdType rr = new IdType();
|
||||||
|
rr.setValue("/123");
|
||||||
|
patient.setManagingOrganization(new Reference(rr));
|
||||||
|
|
||||||
|
Patient actual = parseAndEncode(patient);
|
||||||
|
Reference ref = actual.getManagingOrganization();
|
||||||
|
assertEquals(null, ref.getReferenceElement().getResourceType());
|
||||||
|
assertEquals("123", ref.getReferenceElement().getIdPart());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseValueMissingType2() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
IdType rr = new IdType();
|
||||||
|
rr.setValue("123");
|
||||||
|
patient.setManagingOrganization(new Reference(rr));
|
||||||
|
|
||||||
|
Patient actual = parseAndEncode(patient);
|
||||||
|
Reference ref = actual.getManagingOrganization();
|
||||||
|
assertEquals(null, ref.getReferenceElement().getResourceType());
|
||||||
|
assertEquals("123", ref.getReferenceElement().getIdPart());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseValueRelative1() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
IdType rr = new IdType();
|
||||||
|
rr.setValue("Organization/123");
|
||||||
|
patient.setManagingOrganization(new Reference(rr));
|
||||||
|
|
||||||
|
Patient actual = parseAndEncode(patient);
|
||||||
|
Reference ref = actual.getManagingOrganization();
|
||||||
|
assertEquals("Organization", ref.getReferenceElement().getResourceType());
|
||||||
|
assertEquals("123", ref.getReferenceElement().getIdPart());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncodeParts() {
|
||||||
|
IdType id = new IdType("http://foo", "Patient", "123", "456");
|
||||||
|
assertEquals("http://foo/Patient/123/_history/456", id.getValue());
|
||||||
|
assertEquals("http://foo/Patient/123/_history/9", id.withVersion("9").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseValueRelative2() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
IdType rr = new IdType();
|
||||||
|
rr.setValue("/Organization/123");
|
||||||
|
patient.setManagingOrganization(new Reference(rr));
|
||||||
|
|
||||||
|
Patient actual = parseAndEncode(patient);
|
||||||
|
Reference ref = actual.getManagingOrganization();
|
||||||
|
assertEquals("Organization", ref.getReferenceElement().getResourceType());
|
||||||
|
assertEquals("123", ref.getReferenceElement().getIdPart());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Patient parseAndEncode(Patient patient) {
|
||||||
|
String encoded = ourCtx.newXmlParser().encodeResourceToString(patient);
|
||||||
|
ourLog.info("\n" + encoded);
|
||||||
|
return ourCtx.newXmlParser().parseResource(Patient.class, encoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
ourCtx = FhirContext.forR4();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,30 +0,0 @@
|
||||||
<configuration>
|
|
||||||
|
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] - %msg%n
|
|
||||||
</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<logger name="org.eclipse" additivity="false" level="info">
|
|
||||||
<appender-ref ref="STDOUT" />
|
|
||||||
</logger>
|
|
||||||
<logger name="org.apache" additivity="false" level="info">
|
|
||||||
<appender-ref ref="STDOUT" />
|
|
||||||
</logger>
|
|
||||||
<logger name="org.thymeleaf" additivity="false" level="warn">
|
|
||||||
<appender-ref ref="STDOUT" />
|
|
||||||
</logger>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<logger name="ca.uhn.fhir.rest.client" additivity="false" level="trace">
|
|
||||||
<appender-ref ref="STDOUT" />
|
|
||||||
</logger>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="STDOUT" />
|
|
||||||
</root>
|
|
||||||
|
|
||||||
</configuration>
|
|
Loading…
Reference in New Issue