commit
7c39a47852
|
@ -301,11 +301,16 @@ public class IdDt extends UriDt implements /*IPrimitiveDatatype<String>, */IIdTy
|
|||
b.append(myResourceType);
|
||||
}
|
||||
|
||||
if (b.length() > 0) {
|
||||
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
if (isNotBlank(myUnqualifiedId)) {
|
||||
b.append(myUnqualifiedId);
|
||||
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
b.append(myUnqualifiedId);
|
||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
b.append(Constants.PARAM_HISTORY);
|
||||
|
@ -523,7 +528,21 @@ public class IdDt extends UriDt implements /*IPrimitiveDatatype<String>, */IIdTy
|
|||
if (typeIndex == -1) {
|
||||
myResourceType = theValue.substring(0, idIndex);
|
||||
} else {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
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 {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
}
|
||||
|
||||
if (typeIndex > 4) {
|
||||
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
|
||||
* 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
|
||||
* link.type field to indicate that the given link is for
|
||||
* 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
|
||||
* link.type field to indicate that the given link is for
|
||||
* 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
|
||||
public OUTPUT execute() {
|
||||
Validate.notNull(myReturnBundleType, "Return bundle type mustbe specified");
|
||||
|
||||
Map<String, List<String>> params = getParamMap();
|
||||
|
||||
|
|
|
@ -197,7 +197,15 @@ public class ResourceLink implements Serializable {
|
|||
public void setTargetResourceUrl(IIdType theTargetResourceUrl) {
|
||||
Validate.isTrue(theTargetResourceUrl.hasBaseUrl());
|
||||
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();
|
||||
myTargetResourceUrl = theTargetResourceUrl.getValue();
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.methods.*;
|
||||
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.IIdType;
|
||||
import org.junit.*;
|
||||
|
@ -2059,12 +2060,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
Observation o = new Observation();
|
||||
o.getCode().setText("testSearchWithInvalidSort");
|
||||
myObservationDao.create(o, mySrd);
|
||||
ourClient
|
||||
.search()
|
||||
.forResource(Observation.class)
|
||||
.sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet
|
||||
.prettyPrint()
|
||||
.execute();
|
||||
IBaseBundle bundle = ourClient
|
||||
.search()
|
||||
.forResource(Observation.class)
|
||||
.sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet
|
||||
.prettyPrint()
|
||||
.execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -84,6 +84,37 @@ public class IdDtTest {
|
|||
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
|
||||
public void testDetectIsIdPartValid() {
|
||||
|
|
|
@ -358,11 +358,16 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
|||
b.append(myResourceType);
|
||||
}
|
||||
|
||||
if (b.length() > 0) {
|
||||
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
if (isNotBlank(myUnqualifiedId)) {
|
||||
b.append(myUnqualifiedId);
|
||||
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
b.append(myUnqualifiedId);
|
||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
b.append("_history");
|
||||
|
@ -554,7 +559,21 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
|||
if (typeIndex == -1) {
|
||||
myResourceType = theValue.substring(0, idIndex);
|
||||
} else {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
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 {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
}
|
||||
|
||||
if (typeIndex > 4) {
|
||||
myBaseUrl = theValue.substring(0, typeIndex);
|
||||
|
|
|
@ -92,6 +92,37 @@ public class IdTypeDstu2_1Test {
|
|||
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
|
||||
public void testDetectLocal() {
|
||||
|
|
|
@ -1873,6 +1873,26 @@ public class JsonParserDstu2_1Test {
|
|||
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
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package ca.uhn.fhir.parser;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||
import ca.uhn.fhir.parser.FooMessageHeaderWithExplicitField.FooMessageSourceComponent;
|
||||
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;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hamcrest.collection.IsEmptyCollection;
|
||||
import org.hamcrest.core.StringContains;
|
||||
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.*;
|
||||
import org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent;
|
||||
import org.hl7.fhir.dstu2016may.model.Bundle.BundleType;
|
||||
import org.hl7.fhir.dstu2016may.model.ContactPoint.ContactPointSystem;
|
||||
|
@ -32,20 +33,20 @@ import org.junit.*;
|
|||
import org.mockito.ArgumentCaptor;
|
||||
import org.xmlunit.builder.DiffBuilder;
|
||||
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 ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||
import ca.uhn.fhir.parser.FooMessageHeaderWithExplicitField.FooMessageSourceComponent;
|
||||
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;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class XmlParserDstu2_1Test {
|
||||
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
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
|
|
|
@ -136,7 +136,7 @@ public class BaseResourceReferenceDtTest {
|
|||
new ResourceReferenceDt("http://foo/123123").loadResource(client);
|
||||
fail();
|
||||
} 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 {
|
||||
|
|
|
@ -1948,4 +1948,24 @@ public class JsonParserDstu2Test {
|
|||
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.IIdType;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
|
|
|
@ -351,11 +351,16 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
|||
b.append(myResourceType);
|
||||
}
|
||||
|
||||
if (b.length() > 0) {
|
||||
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
if (isNotBlank(myUnqualifiedId)) {
|
||||
b.append(myUnqualifiedId);
|
||||
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
b.append(myUnqualifiedId);
|
||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
b.append("_history");
|
||||
|
@ -547,7 +552,21 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
|||
if (typeIndex == -1) {
|
||||
myResourceType = theValue.substring(0, idIndex);
|
||||
} else {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
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 {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
}
|
||||
|
||||
if (typeIndex > 4) {
|
||||
myBaseUrl = theValue.substring(0, typeIndex);
|
||||
|
|
|
@ -92,6 +92,38 @@ public class IdTypeDstu3Test {
|
|||
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
|
||||
public void testDetectLocal() {
|
||||
IdType id;
|
||||
|
|
|
@ -2414,6 +2414,26 @@ public class JsonParserDstu3Test {
|
|||
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
|
||||
public static void afterClassClearContext() {
|
||||
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
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
|
|
|
@ -380,11 +380,16 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
|||
b.append(myResourceType);
|
||||
}
|
||||
|
||||
if (b.length() > 0) {
|
||||
if (b.length() > 0 && isNotBlank(myUnqualifiedId)) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
if (isNotBlank(myUnqualifiedId)) {
|
||||
b.append(myUnqualifiedId);
|
||||
} else if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
b.append(myUnqualifiedId);
|
||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
b.append("_history");
|
||||
|
@ -571,7 +576,21 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
|
|||
if (typeIndex == -1) {
|
||||
myResourceType = theValue.substring(0, idIndex);
|
||||
} else {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
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 {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
}
|
||||
|
||||
if (typeIndex > 4) {
|
||||
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
|
||||
public void testDetermineBase() {
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package ca.uhn.fhir.parser;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.narrative.INarrativeGenerator;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import net.sf.json.JSON;
|
||||
import net.sf.json.JSONSerializer;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hamcrest.core.IsNot;
|
||||
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.ValueSet.ConceptDefinitionComponent;
|
||||
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.junit.*;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.narrative.INarrativeGenerator;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import net.sf.json.JSON;
|
||||
import net.sf.json.JSONSerializer;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class JsonParserHl7OrgDstu2Test {
|
||||
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")
|
||||
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.api.*;
|
||||
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.xmlunit.builder.DiffBuilder;
|
||||
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
|
||||
public static void beforeClass() {
|
||||
ourCtx = FhirContext.forDstu2Hl7Org();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1216,7 +1216,7 @@ public class ClientR4Test {
|
|||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
private static String getPatientFeedWithOneResult() {
|
||||
static String getPatientFeedWithOneResult() {
|
||||
return getPatientFeedWithOneResult(ourCtx);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,31 @@ public class GenericClientR4Test {
|
|||
return capt;
|
||||
}
|
||||
|
||||
@Test
|
||||
@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
|
||||
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\"}]}}]}";
|
||||
|
||||
|
|
|
@ -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