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();
|
||||||
|
|
|
@ -152,7 +152,7 @@ public IdType(long 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
|
||||||
|
@ -169,10 +169,8 @@ public IdType(String 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));
|
||||||
|
@ -181,10 +179,8 @@ public IdType(String theResourceType, BigDecimal 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));
|
||||||
|
@ -193,10 +189,8 @@ public IdType(String theResourceType, Long 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);
|
||||||
|
@ -205,12 +199,9 @@ public IdType(String theResourceType, String theId) {
|
||||||
/**
|
/**
|
||||||
* 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);
|
||||||
|
@ -219,14 +210,10 @@ public IdType(String theResourceType, String theId, String 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;
|
||||||
|
@ -321,8 +308,7 @@ public String getIdPart() {
|
||||||
* 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();
|
||||||
|
@ -336,8 +322,7 @@ public BigDecimal getIdPartAsBigDecimal() {
|
||||||
* 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() {
|
||||||
|
@ -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");
|
||||||
|
@ -521,7 +511,7 @@ public boolean isVersionIdPartValidLong() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -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);
|
||||||
|
@ -592,7 +596,7 @@ public IdType setValue(String theValue) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -657,10 +661,8 @@ public IdType withResourceType(String theResourceName) {
|
||||||
* 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")
|
||||||
*/
|
*/
|
||||||
|
@ -676,8 +678,7 @@ public IdType withServerBase(String theServerBase, String theResourceType) {
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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