Squashed commit of the following:

commit 1ab9b58e9f
Author: James Agnew <jamesagnew@gmail.com>
Date:   Tue Jan 24 10:46:56 2017 -0500

    Changes working now

commit 5c752cdace
Author: James <jamesagnew@gmail.com>
Date:   Tue Jan 24 08:43:04 2017 -0500

    Get JPA working with new uuid: logic

commit 127b76884a
Author: James Agnew <jamesagnew@gmail.com>
Date:   Mon Jan 23 21:11:18 2017 -0500

    Fix test

commit 599bbe236c
Author: James Agnew <jamesagnew@gmail.com>
Date:   Mon Jan 23 18:42:46 2017 -0500

    Work on #544
This commit is contained in:
James Agnew 2017-01-24 10:47:24 -05:00
parent a63b42d08f
commit 344e324929
22 changed files with 953 additions and 519 deletions

View File

@ -1,5 +1,6 @@
package ca.uhn.fhir.model.primitive; package ca.uhn.fhir.model.primitive;
import static org.apache.commons.lang3.StringUtils.defaultString;
/* /*
* #%L * #%L
* HAPI FHIR - Core Library * HAPI FHIR - Core Library
@ -202,34 +203,6 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
return getIdPartAsBigDecimal(); return getIdPartAsBigDecimal();
} }
private String determineLocalPrefix(String theValue) {
if (theValue == null || theValue.isEmpty()) {
return null;
}
if (theValue.startsWith("#")) {
return "#";
}
int lastPrefix = -1;
for (int i = 0; i < theValue.length(); i++) {
char nextChar = theValue.charAt(i);
if (nextChar == ':') {
lastPrefix = i;
} else if (!Character.isLetter(nextChar) || !Character.isLowerCase(nextChar)) {
break;
}
}
if (lastPrefix != -1) {
String candidate = theValue.substring(0, lastPrefix + 1);
if (candidate.startsWith("cid:") || candidate.startsWith("urn:")) {
return candidate;
} else {
return null;
}
} else {
return null;
}
}
@Override @Override
public boolean equals(Object theArg0) { public boolean equals(Object theArg0) {
if (!(theArg0 instanceof IdDt)) { if (!(theArg0 instanceof IdDt)) {
@ -316,8 +289,8 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
public String getValue() { public String getValue() {
if (super.getValue() == null && myHaveComponentParts) { if (super.getValue() == null && myHaveComponentParts) {
if (determineLocalPrefix(myBaseUrl) != null && myResourceType == null && myUnqualifiedVersionId == null) { if (isLocal() || isUrn()) {
return myBaseUrl + myUnqualifiedId; return myUnqualifiedId;
} }
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
@ -448,11 +421,16 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
} }
/** /**
* Returns <code>true</code> if the ID is a local reference (in other words, it begins with the '#' character) * Returns <code>true</code> if the ID is a local reference (in other words,
* it begins with the '#' character)
*/ */
@Override @Override
public boolean isLocal() { public boolean isLocal() {
return "#".equals(myBaseUrl); return defaultString(myUnqualifiedId).startsWith("#");
}
private boolean isUrn() {
return defaultString(myUnqualifiedId).startsWith("urn:");
} }
@Override @Override
@ -468,6 +446,27 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
setValue(theId.getValue()); setValue(theId.getValue());
} }
@Override
public IIdType setParts(String theBaseUrl, String theResourceType, String theIdPart, String theVersionIdPart) {
if (isNotBlank(theVersionIdPart)) {
Validate.notBlank(theResourceType, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated");
Validate.notBlank(theIdPart, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated");
}
if (isNotBlank(theBaseUrl) && isNotBlank(theIdPart)) {
Validate.notBlank(theResourceType, "If theBaseUrl is populated and theIdPart is populated, theResourceType must be populated");
}
setValue(null);
myBaseUrl = theBaseUrl;
myResourceType = theResourceType;
myUnqualifiedId = theIdPart;
myUnqualifiedVersionId = StringUtils.defaultIfBlank(theVersionIdPart, null);
myHaveComponentParts = true;
return this;
}
/** /**
* Set the value * Set the value
* *
@ -485,8 +484,6 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
super.setValue(theValue); super.setValue(theValue);
myHaveComponentParts = false; myHaveComponentParts = false;
String localPrefix = determineLocalPrefix(theValue);
if (StringUtils.isBlank(theValue)) { if (StringUtils.isBlank(theValue)) {
myBaseUrl = null; myBaseUrl = null;
super.setValue(null); super.setValue(null);
@ -495,14 +492,14 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
myResourceType = null; myResourceType = null;
} else if (theValue.charAt(0) == '#' && theValue.length() > 1) { } else if (theValue.charAt(0) == '#' && theValue.length() > 1) {
super.setValue(theValue); super.setValue(theValue);
myBaseUrl = "#"; myBaseUrl = null;
myUnqualifiedId = theValue.substring(1); myUnqualifiedId = theValue;
myUnqualifiedVersionId = null; myUnqualifiedVersionId = null;
myResourceType = null; myResourceType = null;
myHaveComponentParts = true; myHaveComponentParts = true;
} else if (localPrefix != null) { } else if (theValue.startsWith("urn:")) {
myBaseUrl = localPrefix; myBaseUrl = null;
myUnqualifiedId = theValue.substring(localPrefix.length()); myUnqualifiedId = theValue;
myUnqualifiedVersionId = null; myUnqualifiedVersionId = null;
myResourceType = null; myResourceType = null;
myHaveComponentParts = true; myHaveComponentParts = true;
@ -567,24 +564,33 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
*/ */
@Override @Override
public IdDt toUnqualified() { public IdDt toUnqualified() {
if (isLocal() || isUrn()) {
return new IdDt(getValueAsString());
}
return new IdDt(getResourceType(), getIdPart(), getVersionIdPart()); return new IdDt(getResourceType(), getIdPart(), getVersionIdPart());
} }
@Override @Override
public IdDt toUnqualifiedVersionless() { public IdDt toUnqualifiedVersionless() {
if (isLocal()) { if (isLocal() || isUrn()) {
return toVersionless(); return new IdDt(getValueAsString());
} }
return new IdDt(getResourceType(), getIdPart()); return new IdDt(getResourceType(), getIdPart());
} }
@Override @Override
public IdDt toVersionless() { public IdDt toVersionless() {
if (isLocal() || isUrn()) {
return new IdDt(getValueAsString());
}
return new IdDt(getBaseUrl(), getResourceType(), getIdPart(), null); return new IdDt(getBaseUrl(), getResourceType(), getIdPart(), null);
} }
@Override @Override
public IdDt withResourceType(String theResourceName) { public IdDt withResourceType(String theResourceName) {
if (isLocal() || isUrn()) {
return new IdDt(getValueAsString());
}
return new IdDt(theResourceName, getIdPart(), getVersionIdPart()); return new IdDt(theResourceName, getIdPart(), getVersionIdPart());
} }
@ -600,6 +606,9 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
*/ */
@Override @Override
public IdDt withServerBase(String theServerBase, String theResourceType) { public IdDt withServerBase(String theServerBase, String theResourceType) {
if (isLocal() || isUrn()) {
return new IdDt(getValueAsString());
}
return new IdDt(theServerBase, theResourceType, getIdPart(), getVersionIdPart()); return new IdDt(theServerBase, theResourceType, getIdPart(), getVersionIdPart());
} }
@ -610,9 +619,14 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
* The actual version string, e.g. "1" * The actual version string, e.g. "1"
* @return A new instance of IdDt which is identical, but refers to the specific version of this resource ID noted by theVersion. * @return A new instance of IdDt which is identical, but refers to the specific version of this resource ID noted by theVersion.
*/ */
@Override
public IdDt withVersion(String theVersion) { public IdDt withVersion(String theVersion) {
Validate.notBlank(theVersion, "Version may not be null or empty"); Validate.notBlank(theVersion, "Version may not be null or empty");
if (isLocal() || isUrn()) {
return new IdDt(getValueAsString());
}
String existingValue = getValue(); String existingValue = getValue();
int i = existingValue.indexOf(Constants.PARAM_HISTORY); int i = existingValue.indexOf(Constants.PARAM_HISTORY);
@ -678,25 +692,4 @@ public class IdDt extends UriDt implements IPrimitiveDatatype<String>, IIdType {
return theIdPart.toString(); return theIdPart.toString();
} }
@Override
public IIdType setParts(String theBaseUrl, String theResourceType, String theIdPart, String theVersionIdPart) {
if (isNotBlank(theVersionIdPart)) {
Validate.notBlank(theResourceType, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated");
Validate.notBlank(theIdPart, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated");
}
if (isNotBlank(theBaseUrl) && isNotBlank(theIdPart)) {
Validate.notBlank(theResourceType, "If theBaseUrl is populated and theIdPart is populated, theResourceType must be populated");
}
setValue(null);
myBaseUrl = theBaseUrl;
myResourceType = theResourceType;
myUnqualifiedId = theIdPart;
myUnqualifiedVersionId = StringUtils.defaultIfBlank(theVersionIdPart, null);
myHaveComponentParts = true;
return this;
}
} }

View File

@ -347,7 +347,7 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
for (BundleEntry nextEntry : theBundle.getEntries()) { for (BundleEntry nextEntry : theBundle.getEntries()) {
theEventWriter.beginObject(); theEventWriter.beginObject();
if (nextEntry.getResource() != null && nextEntry.getResource().getId().getBaseUrl() != null) { if (nextEntry.getResource() != null && isNotBlank(nextEntry.getResource().getIdElement().getValue()) && (nextEntry.getResource().getId().getBaseUrl() != null || nextEntry.getResource().getId().getValueAsString().startsWith("urn:"))) {
writeOptionalTagWithTextNode(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue()); writeOptionalTagWithTextNode(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue());
} }

View File

@ -721,7 +721,6 @@ class ParserState<T> {
myInstance = theInstance; myInstance = theInstance;
} }
@SuppressWarnings("unchecked")
@Override @Override
public void wereBack() { public void wereBack() {
@ -2090,17 +2089,32 @@ class ParserState<T> {
final boolean bundle = "Bundle".equals(myContext.getResourceDefinition(myInstance).getName()); final boolean bundle = "Bundle".equals(myContext.getResourceDefinition(myInstance).getName());
if (bundle) { if (bundle) {
FhirTerser t = myContext.newTerser();
Map<String, IBaseResource> idToResource = new HashMap<String, IBaseResource>();
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
List<IBase> entries = t.getValues(myInstance, "Bundle.entry", IBase.class);
for (IBase nextEntry : entries) {
IPrimitiveType<?> fullUrl = t.getSingleValueOrNull(nextEntry, "fullUrl", IPrimitiveType.class);
if (fullUrl != null && isNotBlank(fullUrl.getValueAsString())) {
IBaseResource resource = t.getSingleValueOrNull(nextEntry, "resource", IBaseResource.class);
if (resource != null) {
idToResource.put(fullUrl.getValueAsString(), resource);
}
}
}
}
/* /*
* Stitch together resource references * Stitch together resource references
*/ */
Map<IIdType, IBaseResource> idToResource = new HashMap<IIdType, IBaseResource>();
FhirTerser t = myContext.newTerser();
List<IBaseResource> resources = t.getAllPopulatedChildElementsOfType(myInstance, IBaseResource.class); List<IBaseResource> resources = t.getAllPopulatedChildElementsOfType(myInstance, IBaseResource.class);
for (IBaseResource next : resources) { for (IBaseResource next : resources) {
IIdType id = next.getIdElement(); IIdType id = next.getIdElement();
if (id != null && id.isEmpty() == false) { if (id != null && id.isEmpty() == false) {
String resName = myContext.getResourceDefinition(next).getName(); String resName = myContext.getResourceDefinition(next).getName();
idToResource.put(id.withResourceType(resName).toUnqualifiedVersionless(), next); IIdType idType = id.withResourceType(resName).toUnqualifiedVersionless();
idToResource.put(idType.getValueAsString(), next);
} }
} }
@ -2108,7 +2122,8 @@ class ParserState<T> {
List<IBaseReference> refs = myContext.newTerser().getAllPopulatedChildElementsOfType(next, IBaseReference.class); List<IBaseReference> refs = myContext.newTerser().getAllPopulatedChildElementsOfType(next, IBaseReference.class);
for (IBaseReference nextRef : refs) { for (IBaseReference nextRef : refs) {
if (nextRef.isEmpty() == false && nextRef.getReferenceElement() != null) { if (nextRef.isEmpty() == false && nextRef.getReferenceElement() != null) {
IBaseResource target = idToResource.get(nextRef.getReferenceElement().toUnqualifiedVersionless()); IIdType unqualifiedVersionless = nextRef.getReferenceElement().toUnqualifiedVersionless();
IBaseResource target = idToResource.get(unqualifiedVersionless.getValueAsString());
if (target != null) { if (target != null) {
nextRef.setResource(target); nextRef.setResource(target);
} }

View File

@ -446,7 +446,7 @@ public class XmlParser extends BaseParser implements IParser {
writeBundleResourceLink(theEventWriter, "alternate", nextEntry.getLinkAlternate()); writeBundleResourceLink(theEventWriter, "alternate", nextEntry.getLinkAlternate());
if (nextEntry.getResource() != null && nextEntry.getResource().getId().getBaseUrl() != null) { if (nextEntry.getResource() != null && isNotBlank(nextEntry.getResource().getIdElement().getValue()) && (nextEntry.getResource().getId().getBaseUrl() != null || nextEntry.getResource().getId().getValueAsString().startsWith("urn:"))) {
writeOptionalTagWithValue(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue()); writeOptionalTagWithValue(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue());
} }

View File

@ -130,10 +130,41 @@ public interface IIdType extends IPrimitiveType<String> {
IIdType toVersionless(); IIdType toVersionless();
/**
* Returns a copy of this object, but with a different {@link #getResourceType() resource type}
* (or if this object does not have a resource type currently, returns a copy of this object with
* the given resource type).
* <p>
* Note that if this object represents a local reference (e.g. <code>#foo</code>) or
* a URN (e.g. <code>urn:oid:1.2.3.4</code>) this method will simply return a copy
* of this object with no modifications.
* </p>
*/
IIdType withResourceType(String theResName); IIdType withResourceType(String theResName);
/**
* Returns a copy of this object, but with a different {@link #getResourceType() resource type}
* and {@link #getBaseUrl() base URL}
* (or if this object does not have a resource type currently, returns a copy of this object with
* the given server base and resource type).
* <p>
* Note that if this object represents a local reference (e.g. <code>#foo</code>) or
* a URN (e.g. <code>urn:oid:1.2.3.4</code>) this method will simply return a copy
* of this object with no modifications.
* </p>
*/
IIdType withServerBase(String theServerBase, String theResourceName); IIdType withServerBase(String theServerBase, String theResourceName);
/**
* Returns a copy of this object, but with a different {@link #getVersionIdPart() version ID}
* (or if this object does not have a resource type currently, returns a copy of this object with
* the given version).
* <p>
* Note that if this object represents a local reference (e.g. <code>#foo</code>) or
* a URN (e.g. <code>urn:oid:1.2.3.4</code>) this method will simply return a copy
* of this object with no modifications.
* </p>
*/
IIdType withVersion(String theVersion); IIdType withVersion(String theVersion);
/** /**

View File

@ -164,7 +164,7 @@ public class FhirSystemDaoDstu1 extends BaseHapiFhirSystemDao<List<IResource>, M
entity = toEntity(nextResource); entity = toEntity(nextResource);
entity.setUpdated(updateTime); entity.setUpdated(updateTime);
entity.setPublished(updateTime); entity.setPublished(updateTime);
if (nextId.isEmpty() == false && "cid:".equals(nextId.getBaseUrl())) { if (nextId.getIdPart() != null && nextId.getIdPart().startsWith("cid:")) {
ourLog.debug("Resource in transaction has ID[{}], will replace with server assigned ID", nextId.getIdPart()); ourLog.debug("Resource in transaction has ID[{}], will replace with server assigned ID", nextId.getIdPart());
} else if (nextResouceOperationIn == BundleEntryTransactionMethodEnum.POST) { } else if (nextResouceOperationIn == BundleEntryTransactionMethodEnum.POST) {
if (nextId.isEmpty() == false) { if (nextId.isEmpty() == false) {
@ -282,7 +282,7 @@ public class FhirSystemDaoDstu1 extends BaseHapiFhirSystemDao<List<IResource>, M
} }
private static boolean isPlaceholder(IdDt theId) { private static boolean isPlaceholder(IdDt theId) {
if ("cid:".equals(theId.getBaseUrl())) { if (theId.getIdPart() != null && theId.getIdPart().startsWith("cid:")) {
return true; return true;
} }
return false; return false;

View File

@ -40,7 +40,6 @@ import java.util.Set;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -634,9 +633,11 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
} }
private static boolean isPlaceholder(IdDt theId) { private static boolean isPlaceholder(IdDt theId) {
if ("urn:oid:".equals(theId.getBaseUrl()) || "urn:uuid:".equals(theId.getBaseUrl())) { if (theId.getValue() != null) {
if (theId.getValue().startsWith("urn:oid:") || theId.getValue().startsWith("urn:uuid:")) {
return true; return true;
} }
}
return false; return false;
} }

View File

@ -627,9 +627,11 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
} }
private static boolean isPlaceholder(IdType theId) { private static boolean isPlaceholder(IdType theId) {
if ("urn:oid:".equals(theId.getBaseUrl()) || "urn:uuid:".equals(theId.getBaseUrl())) { if (theId.getValue() != null) {
if (theId.getValue().startsWith("urn:oid:") || theId.getValue().startsWith("urn:uuid:")) {
return true; return true;
} }
}
return false; return false;
} }

View File

@ -1615,13 +1615,11 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Patient"); res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Patient");
Observation o1 = new Observation(); Observation o1 = new Observation();
o1.setId("cid:observation1");
o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02"); o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02");
o1.setSubject(new ResourceReferenceDt("urn:oid:0.1.2.3")); o1.setSubject(new ResourceReferenceDt("urn:oid:0.1.2.3"));
res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Observation"); res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Observation");
Observation o2 = new Observation(); Observation o2 = new Observation();
o2.setId("cid:observation2");
o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03"); o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03");
o2.setSubject(new ResourceReferenceDt("urn:oid:0.1.2.3")); o2.setSubject(new ResourceReferenceDt("urn:oid:0.1.2.3"));
res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Observation"); res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Observation");
@ -1760,13 +1758,11 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Patient"); res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Patient");
Observation o1 = new Observation(); Observation o1 = new Observation();
o1.setId("cid:observation1");
o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02"); o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02");
o1.setSubject(new ResourceReferenceDt("Patient/urn:oid:0.1.2.3")); o1.setSubject(new ResourceReferenceDt("Patient/urn:oid:0.1.2.3"));
res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Observation"); res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Observation");
Observation o2 = new Observation(); Observation o2 = new Observation();
o2.setId("cid:observation2");
o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03"); o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03");
o2.setSubject(new ResourceReferenceDt("Patient/urn:oid:0.1.2.3")); o2.setSubject(new ResourceReferenceDt("Patient/urn:oid:0.1.2.3"));
res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Observation"); res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Observation");

View File

@ -93,7 +93,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
return null; return null;
} }
/** /**
* See #410 * See #410
*/ */
@ -363,7 +362,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
} }
@Test @Test
public void testTransactionCreateInlineMatchUrlWithNoMatches() { public void testTransactionCreateInlineMatchUrlWithNoMatches() {
String methodName = "testTransactionCreateInlineMatchUrlWithNoMatches"; String methodName = "testTransactionCreateInlineMatchUrlWithNoMatches";
@ -371,7 +369,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
myDaoConfig.setAllowInlineMatchUrlReferences(true); myDaoConfig.setAllowInlineMatchUrlReferences(true);
Observation o = new Observation(); Observation o = new Observation();
o.getCode().setText("Some Observation"); o.getCode().setText("Some Observation");
o.getSubject().setReference("Patient?identifier=urn%3Asystem%7C" + methodName); o.getSubject().setReference("Patient?identifier=urn%3Asystem%7C" + methodName);
@ -385,7 +382,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
} }
} }
@Test @Test
public void testTransactionCreateInlineMatchUrlWithOneMatch() { public void testTransactionCreateInlineMatchUrlWithOneMatch() {
String methodName = "testTransactionCreateInlineMatchUrlWithOneMatch"; String methodName = "testTransactionCreateInlineMatchUrlWithOneMatch";
@ -768,7 +764,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
mySystemDao.transaction(mySrd, request); mySystemDao.transaction(mySrd, request);
fail(); fail();
} catch (InvalidRequestException e) { } catch (InvalidRequestException e) {
assertEquals(e.getMessage(), "Unable to process Transaction - Request would cause multiple resources to match URL: \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateWithDuplicateMatchUrl01\". Does transaction request contain duplicates?"); assertEquals(e.getMessage(),
"Unable to process Transaction - Request would cause multiple resources to match URL: \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateWithDuplicateMatchUrl01\". Does transaction request contain duplicates?");
} }
} }
@ -790,7 +787,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
mySystemDao.transaction(mySrd, request); mySystemDao.transaction(mySrd, request);
fail(); fail();
} catch (InvalidRequestException e) { } catch (InvalidRequestException e) {
assertEquals(e.getMessage(), "Unable to process Transaction - Request would cause multiple resources to match URL: \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateWithDuplicateMatchUrl02\". Does transaction request contain duplicates?"); assertEquals(e.getMessage(),
"Unable to process Transaction - Request would cause multiple resources to match URL: \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateWithDuplicateMatchUrl02\". Does transaction request contain duplicates?");
} }
} }
@ -1145,7 +1143,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
} }
} }
@Test @Test
public void testTransactionDeleteMatchUrlWithZeroMatch() { public void testTransactionDeleteMatchUrlWithZeroMatch() {
String methodName = "testTransactionDeleteMatchUrlWithZeroMatch"; String methodName = "testTransactionDeleteMatchUrlWithZeroMatch";
@ -1947,6 +1944,24 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertNotEquals(medOrderId1, medOrderId2); assertNotEquals(medOrderId1, medOrderId2);
} }
@Test
public void testTransactionWIthInvalidPlaceholder() throws Exception {
Bundle res = new Bundle();
res.setType(BundleType.TRANSACTION);
Observation o1 = new Observation();
o1.setId("cid:observation1");
o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02");
res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");
try {
mySystemDao.transaction(mySrd, res);
fail();
} catch (InvalidRequestException e) {
assertEquals("Invalid placeholder ID found: cid:observation1 - Must be of the form 'urn:uuid:[uuid]' or 'urn:oid:[oid]'", e.getMessage());
}
}
@Test @Test
public void testTransactionWithRelativeOidIds() throws Exception { public void testTransactionWithRelativeOidIds() throws Exception {
Bundle res = new Bundle(); Bundle res = new Bundle();
@ -1958,13 +1973,11 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient"); res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient");
Observation o1 = new Observation(); Observation o1 = new Observation();
o1.setId("cid:observation1");
o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02"); o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02");
o1.setSubject(new Reference("urn:oid:0.1.2.3")); o1.setSubject(new Reference("urn:oid:0.1.2.3"));
res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation"); res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");
Observation o2 = new Observation(); Observation o2 = new Observation();
o2.setId("cid:observation2");
o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03"); o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03");
o2.setSubject(new Reference("urn:oid:0.1.2.3")); o2.setSubject(new Reference("urn:oid:0.1.2.3"));
res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation"); res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");
@ -2103,13 +2116,11 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient"); res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient");
Observation o1 = new Observation(); Observation o1 = new Observation();
o1.setId("cid:observation1");
o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02"); o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02");
o1.setSubject(new Reference("Patient/urn:oid:0.1.2.3")); o1.setSubject(new Reference("Patient/urn:oid:0.1.2.3"));
res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation"); res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");
Observation o2 = new Observation(); Observation o2 = new Observation();
o2.setId("cid:observation2");
o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03"); o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03");
o2.setSubject(new Reference("Patient/urn:oid:0.1.2.3")); o2.setSubject(new Reference("Patient/urn:oid:0.1.2.3"));
res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation"); res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");

View File

@ -20,6 +20,71 @@ public class IdDtTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IdDtTest.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IdDtTest.class);
@Test
public void testUuid() {
IdDt id = new IdDt("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() {
IdDt id = new IdDt("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() {
IdDt id = new IdDt("#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() {
IdDt id = new IdDt("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 @Test
public void testDetectIsIdPartValid() { public void testDetectIsIdPartValid() {
assertTrue(new IdDt("0").isIdPartValid()); assertTrue(new IdDt("0").isIdPartValid());
@ -60,16 +125,16 @@ public class IdDtTest {
@Test @Test
public void testDetectLocalBase() { public void testDetectLocalBase() {
assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("urn:uuid:", new IdDt("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdDt("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart());
assertEquals("cid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue()); assertEquals("cid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("cid:", new IdDt("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdDt("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); assertEquals("cid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart());
assertEquals("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("#180f219f-97a8-486d-99d9-ed631fe4fc57").getValue()); assertEquals("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("#180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("#", new IdDt("#180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdDt("#180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("#180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); assertEquals("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdDt("#180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart());
} }
@ -80,10 +145,10 @@ public class IdDtTest {
public void testComplicatedLocal() { public void testComplicatedLocal() {
IdDt id = new IdDt("#Patient/cid:Patient-72/_history/1"); IdDt id = new IdDt("#Patient/cid:Patient-72/_history/1");
assertTrue(id.isLocal()); assertTrue(id.isLocal());
assertEquals("#", id.getBaseUrl()); assertEquals(null, id.getBaseUrl());
assertNull(id.getResourceType()); assertNull(id.getResourceType());
assertNull(id.getVersionIdPart()); assertNull(id.getVersionIdPart());
assertEquals("Patient/cid:Patient-72/_history/1", id.getIdPart()); assertEquals("#Patient/cid:Patient-72/_history/1", id.getIdPart());
} }

View File

@ -561,8 +561,8 @@ public class XmlParserTest {
// Re-parse the bundle // Re-parse the bundle
patient = (Patient) xmlParser.parseResource(xmlParser.encodeResourceToString(patient)); patient = (Patient) xmlParser.parseResource(xmlParser.encodeResourceToString(patient));
assertEquals("#1", patient.getManagingOrganization().getReference().getValue()); assertEquals("#1", patient.getManagingOrganization().getReference().getValue());
assertEquals("#", patient.getManagingOrganization().getReference().getBaseUrl()); assertEquals(null, patient.getManagingOrganization().getReference().getBaseUrl());
assertEquals("1", patient.getManagingOrganization().getReference().getIdPart()); assertEquals("#1", patient.getManagingOrganization().getReference().getIdPart());
assertNotNull(patient.getManagingOrganization().getResource()); assertNotNull(patient.getManagingOrganization().getResource());
org = (Organization) patient.getManagingOrganization().getResource(); org = (Organization) patient.getManagingOrganization().getResource();

View File

@ -1,5 +1,7 @@
package org.hl7.fhir.dstu2016may.model; package org.hl7.fhir.dstu2016may.model;
import static org.apache.commons.lang3.StringUtils.defaultString;
/* /*
Copyright (c) 2011+, HL7, Inc. Copyright (c) 2011+, HL7, Inc.
All rights reserved. All rights reserved.
@ -242,34 +244,6 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
return new IdType(getValue()); return new IdType(getValue());
} }
private String determineLocalPrefix(String theValue) {
if (theValue == null || theValue.isEmpty()) {
return null;
}
if (theValue.startsWith("#")) {
return "#";
}
int lastPrefix = -1;
for (int i = 0; i < theValue.length(); i++) {
char nextChar = theValue.charAt(i);
if (nextChar == ':') {
lastPrefix = i;
} else if (!Character.isLetter(nextChar) || !Character.isLowerCase(nextChar)) {
break;
}
}
if (lastPrefix != -1) {
String candidate = theValue.substring(0, lastPrefix + 1);
if (candidate.startsWith("cid:") || candidate.startsWith("urn:")) {
return candidate;
} else {
return null;
}
} else {
return null;
}
}
@Override @Override
public boolean equals(Object theArg0) { public boolean equals(Object theArg0) {
if (!(theArg0 instanceof IdType)) { if (!(theArg0 instanceof IdType)) {
@ -368,8 +342,8 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
String retVal = super.getValue(); String retVal = super.getValue();
if (retVal == null && myHaveComponentParts) { if (retVal == null && myHaveComponentParts) {
if (determineLocalPrefix(myBaseUrl) != null && myResourceType == null && myUnqualifiedVersionId == null) { if (isLocal() || isUrn()) {
return myBaseUrl + myUnqualifiedId; return myUnqualifiedId;
} }
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
@ -510,7 +484,11 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
*/ */
@Override @Override
public boolean isLocal() { public boolean isLocal() {
return "#".equals(myBaseUrl); return defaultString(myUnqualifiedId).startsWith("#");
}
private boolean isUrn() {
return defaultString(myUnqualifiedId).startsWith("urn:");
} }
@Override @Override
@ -536,8 +514,6 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
super.setValue(theValue); super.setValue(theValue);
myHaveComponentParts = false; myHaveComponentParts = false;
String localPrefix = determineLocalPrefix(theValue);
if (StringUtils.isBlank(theValue)) { if (StringUtils.isBlank(theValue)) {
myBaseUrl = null; myBaseUrl = null;
super.setValue(null); super.setValue(null);
@ -546,14 +522,17 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
myResourceType = null; myResourceType = null;
} else if (theValue.charAt(0) == '#' && theValue.length() > 1) { } else if (theValue.charAt(0) == '#' && theValue.length() > 1) {
super.setValue(theValue); super.setValue(theValue);
myBaseUrl = "#"; myBaseUrl = null;
myUnqualifiedId = theValue.substring(1); myUnqualifiedId = theValue;
myUnqualifiedVersionId = null;
myResourceType = null;
myHaveComponentParts = true;
} else if (theValue.startsWith("urn:")) {
myBaseUrl = null;
myUnqualifiedId = theValue;
myUnqualifiedVersionId = null; myUnqualifiedVersionId = null;
myResourceType = null; myResourceType = null;
myHaveComponentParts = true; myHaveComponentParts = true;
} else if (localPrefix != null) {
myBaseUrl = localPrefix;
myUnqualifiedId = theValue.substring(localPrefix.length());
} else { } else {
int vidIndex = theValue.indexOf("/_history/"); int vidIndex = theValue.indexOf("/_history/");
int idIndex; int idIndex;
@ -618,21 +597,33 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
*/ */
@Override @Override
public IdType toUnqualified() { public IdType toUnqualified() {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(getResourceType(), getIdPart(), getVersionIdPart()); return new IdType(getResourceType(), getIdPart(), getVersionIdPart());
} }
@Override @Override
public IdType toUnqualifiedVersionless() { public IdType toUnqualifiedVersionless() {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(getResourceType(), getIdPart()); return new IdType(getResourceType(), getIdPart());
} }
@Override @Override
public IdType toVersionless() { public IdType toVersionless() {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(getBaseUrl(), getResourceType(), getIdPart(), null); return new IdType(getBaseUrl(), getResourceType(), getIdPart(), null);
} }
@Override @Override
public IdType withResourceType(String theResourceName) { public IdType withResourceType(String theResourceName) {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(theResourceName, getIdPart(), getVersionIdPart()); return new IdType(theResourceName, getIdPart(), getVersionIdPart());
} }
@ -652,6 +643,9 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
*/ */
@Override @Override
public IdType withServerBase(String theServerBase, String theResourceType) { public IdType withServerBase(String theServerBase, String theResourceType) {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(theServerBase, theResourceType, getIdPart(), getVersionIdPart()); return new IdType(theServerBase, theResourceType, getIdPart(), getVersionIdPart());
} }
@ -667,6 +661,10 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
public IdType withVersion(String theVersion) { public IdType withVersion(String theVersion) {
Validate.notBlank(theVersion, "Version may not be null or empty"); Validate.notBlank(theVersion, "Version may not be null or empty");
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
String existingValue = getValue(); String existingValue = getValue();
int i = existingValue.indexOf("_history"); int i = existingValue.indexOf("_history");

View File

@ -28,6 +28,70 @@ public class IdTypeDstu2_1Test {
TestUtil.clearAllStaticFieldsForUnitTest(); TestUtil.clearAllStaticFieldsForUnitTest();
} }
@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 @Test
public void testDetectLocal() { public void testDetectLocal() {
@ -55,16 +119,16 @@ public class IdTypeDstu2_1Test {
@Test @Test
public void testDetectLocalBase() { public void testDetectLocalBase() {
assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("urn:uuid:", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); 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("cid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("cid:", new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); 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("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("#", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); assertEquals("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart());
} }
@ -75,20 +139,20 @@ public class IdTypeDstu2_1Test {
public void testComplicatedLocal() { public void testComplicatedLocal() {
IdType id = new IdType("#Patient/cid:Patient-72/_history/1"); IdType id = new IdType("#Patient/cid:Patient-72/_history/1");
assertTrue(id.isLocal()); assertTrue(id.isLocal());
assertEquals("#", id.getBaseUrl()); assertEquals(null, id.getBaseUrl());
assertNull(id.getResourceType()); assertNull(id.getResourceType());
assertNull(id.getVersionIdPart()); assertNull(id.getVersionIdPart());
assertEquals("Patient/cid:Patient-72/_history/1", id.getIdPart()); assertEquals("#Patient/cid:Patient-72/_history/1", id.getIdPart());
IdType id2 = new IdType("#Patient/cid:Patient-72/_history/1"); IdType id2 = new IdType("#Patient/cid:Patient-72/_history/1");
assertEquals(id, id2); assertEquals(id, id2);
id2 = id2.toUnqualified(); id2 = id2.toUnqualified();
assertFalse(id2.isLocal()); assertTrue(id2.isLocal());
assertNull(id2.getBaseUrl()); assertNull(id2.getBaseUrl());
assertNull(id2.getResourceType()); assertNull(id2.getResourceType());
assertNull(id2.getVersionIdPart()); assertNull(id2.getVersionIdPart());
assertEquals("Patient/cid:Patient-72/_history/1", id2.getIdPart()); assertEquals("#Patient/cid:Patient-72/_history/1", id2.getIdPart());
} }

View File

@ -1,6 +1,5 @@
package ca.uhn.fhir.parser; package ca.uhn.fhir.parser;
import static org.apache.commons.lang3.StringUtils.countMatches;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
@ -15,79 +14,31 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull; import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.hamcrest.core.StringContains; import org.hamcrest.core.StringContains;
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.Address.AddressUseEnumFactory; import org.hl7.fhir.dstu2016may.model.Address.AddressUseEnumFactory;
import org.hl7.fhir.dstu2016may.model.Attachment;
import org.hl7.fhir.dstu2016may.model.AuditEvent;
import org.hl7.fhir.dstu2016may.model.Basic;
import org.hl7.fhir.dstu2016may.model.Binary;
import org.hl7.fhir.dstu2016may.model.Bundle;
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.Claim;
import org.hl7.fhir.dstu2016may.model.Coding;
import org.hl7.fhir.dstu2016may.model.Communication;
import org.hl7.fhir.dstu2016may.model.Condition;
import org.hl7.fhir.dstu2016may.model.Condition.ConditionVerificationStatus; import org.hl7.fhir.dstu2016may.model.Condition.ConditionVerificationStatus;
import org.hl7.fhir.dstu2016may.model.Conformance;
import org.hl7.fhir.dstu2016may.model.Conformance.UnknownContentCode; import org.hl7.fhir.dstu2016may.model.Conformance.UnknownContentCode;
import org.hl7.fhir.dstu2016may.model.Coverage;
import org.hl7.fhir.dstu2016may.model.DateTimeType;
import org.hl7.fhir.dstu2016may.model.DateType;
import org.hl7.fhir.dstu2016may.model.DecimalType;
import org.hl7.fhir.dstu2016may.model.DiagnosticReport;
import org.hl7.fhir.dstu2016may.model.EnumFactory;
import org.hl7.fhir.dstu2016may.model.Enumeration; import org.hl7.fhir.dstu2016may.model.Enumeration;
import org.hl7.fhir.dstu2016may.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu2016may.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu2016may.model.ExplanationOfBenefit;
import org.hl7.fhir.dstu2016may.model.Extension;
import org.hl7.fhir.dstu2016may.model.HumanName;
import org.hl7.fhir.dstu2016may.model.IdType;
import org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse; import org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse;
import org.hl7.fhir.dstu2016may.model.Linkage;
import org.hl7.fhir.dstu2016may.model.Medication;
import org.hl7.fhir.dstu2016may.model.MedicationOrder;
import org.hl7.fhir.dstu2016may.model.Observation;
import org.hl7.fhir.dstu2016may.model.Observation.ObservationStatus; import org.hl7.fhir.dstu2016may.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu2016may.model.Parameters;
import org.hl7.fhir.dstu2016may.model.Patient;
import org.hl7.fhir.dstu2016may.model.PrimitiveType;
import org.hl7.fhir.dstu2016may.model.Quantity;
import org.hl7.fhir.dstu2016may.model.QuestionnaireResponse;
import org.hl7.fhir.dstu2016may.model.Reference;
import org.hl7.fhir.dstu2016may.model.RelatedPerson;
import org.hl7.fhir.dstu2016may.model.SampledData;
import org.hl7.fhir.dstu2016may.model.SimpleQuantity;
import org.hl7.fhir.dstu2016may.model.StringType;
import org.hl7.fhir.dstu2016may.model.UriType;
import org.hl7.fhir.dstu2016may.model.ValueSet;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.After; import org.junit.*;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -96,11 +47,8 @@ import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation; import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation;
import ca.uhn.fhir.parser.PatientWithExtendedContactDstu3.CustomContactComponent; import ca.uhn.fhir.parser.PatientWithExtendedContactDstu3.CustomContactComponent;
import ca.uhn.fhir.parser.XmlParserDstu2_1Test.TestPatientFor327; import ca.uhn.fhir.parser.XmlParserDstu2_1Test.TestPatientFor327;
import ca.uhn.fhir.parser.json.JsonLikeValue.ValueType;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ValidationResult;
import net.sf.json.JSON; import net.sf.json.JSON;
import net.sf.json.JSONSerializer; import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig; import net.sf.json.JsonConfig;
@ -1430,8 +1378,8 @@ public class JsonParserDstu2_1Test {
ourLog.info(encoded); ourLog.info(encoded);
assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getIdElement().getValue()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getIdElement().getValue());
assertEquals("urn:uuid:", parsed.getEntry().get(0).getResource().getIdElement().getBaseUrl()); assertEquals(null, parsed.getEntry().get(0).getResource().getIdElement().getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getIdElement().getIdPart()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getIdElement().getIdPart());
assertThat(encoded, not(containsString("\"id\":\"180f219f-97a8-486d-99d9-ed631fe4fc57\""))); assertThat(encoded, not(containsString("\"id\":\"180f219f-97a8-486d-99d9-ed631fe4fc57\"")));
} }

View File

@ -67,6 +67,34 @@ public class JsonParserDstu2Test {
private static FhirContext ourCtx = FhirContext.forDstu2(); private static FhirContext ourCtx = FhirContext.forDstu2();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserDstu2Test.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserDstu2Test.class);
/**
* See #544
*/
@Test
public void testBundleStitchReferencesByUuid() throws Exception {
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
DocumentManifest dm = new DocumentManifest();
dm.getSubject().setReference("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
bundle.addEntry().setResource(dm);
Patient patient = new Patient();
patient.addName().addFamily("FAMILY");
bundle.addEntry().setResource(patient).setFullUrl("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
ourLog.info(encoded);
bundle = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, encoded);
dm = (DocumentManifest) bundle.getEntry().get(0).getResource();
assertEquals("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3", dm.getSubject().getReference());
Patient subject = (Patient) dm.getSubject().getResource();
assertNotNull(subject);
assertEquals("FAMILY", subject.getNameFirstRep().getFamilyAsSingleString());
}
@Test @Test
public void testContainedResourceInExtensionUndeclared() { public void testContainedResourceInExtensionUndeclared() {
Patient p = new Patient(); Patient p = new Patient();
@ -89,6 +117,21 @@ public class JsonParserDstu2Test {
assertEquals("ORG", o.getName()); assertEquals("ORG", o.getName());
} }
@Test
public void testEncodeBundleOldStyleContainingResourceWithUuidBase() {
Patient p = new Patient();
p.setId(IdDt.newRandomUuid());
p.addName().addFamily("PATIENT");
Bundle b = new Bundle();
b.addEntry().setResource(p);
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder("fullUrl", p.getId().getValue(), "Patient"));
}
/** /**
* See #308 * See #308
*/ */
@ -1242,8 +1285,8 @@ public class JsonParserDstu2Test {
ourLog.info(encoded); ourLog.info(encoded);
assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getId().getValue()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getId().getValue());
assertEquals("urn:uuid:", parsed.getEntry().get(0).getResource().getId().getBaseUrl()); assertEquals(null, parsed.getEntry().get(0).getResource().getId().getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getId().getIdPart()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getId().getIdPart());
assertThat(encoded, not(containsString("\"id\":\"180f219f-97a8-486d-99d9-ed631fe4fc57\""))); assertThat(encoded, not(containsString("\"id\":\"180f219f-97a8-486d-99d9-ed631fe4fc57\"")));
} }

View File

@ -1,5 +1,7 @@
package org.hl7.fhir.dstu3.model; package org.hl7.fhir.dstu3.model;
import static org.apache.commons.lang3.StringUtils.defaultString;
/* /*
Copyright (c) 2011+, HL7, Inc. Copyright (c) 2011+, HL7, Inc.
All rights reserved. All rights reserved.
@ -242,41 +244,12 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
return new IdType(getValue()); return new IdType(getValue());
} }
private String determineLocalPrefix(String theValue) {
if (theValue == null || theValue.isEmpty()) {
return null;
}
if (theValue.startsWith("#")) {
return "#";
}
int lastPrefix = -1;
for (int i = 0; i < theValue.length(); i++) {
char nextChar = theValue.charAt(i);
if (nextChar == ':') {
lastPrefix = i;
} else if (!Character.isLetter(nextChar) || !Character.isLowerCase(nextChar)) {
break;
}
}
if (lastPrefix != -1) {
String candidate = theValue.substring(0, lastPrefix + 1);
if (candidate.startsWith("cid:") || candidate.startsWith("urn:")) {
return candidate;
} else {
return null;
}
} else {
return null;
}
}
@Override @Override
public boolean equals(Object theArg0) { public boolean equals(Object theArg0) {
if (!(theArg0 instanceof IdType)) { if (!(theArg0 instanceof IdType)) {
return false; return false;
} }
IdType id = (IdType) theArg0; return StringUtils.equals(getValueAsString(), ((IdType)theArg0).getValueAsString());
return StringUtils.equals(getValueAsString(), id.getValueAsString());
} }
/** /**
@ -368,8 +341,8 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
String retVal = super.getValue(); String retVal = super.getValue();
if (retVal == null && myHaveComponentParts) { if (retVal == null && myHaveComponentParts) {
if (determineLocalPrefix(myBaseUrl) != null && myResourceType == null && myUnqualifiedVersionId == null) { if (isLocal() || isUrn()) {
return myBaseUrl + myUnqualifiedId; return myUnqualifiedId;
} }
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
@ -510,7 +483,11 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
*/ */
@Override @Override
public boolean isLocal() { public boolean isLocal() {
return "#".equals(myBaseUrl); return defaultString(myUnqualifiedId).startsWith("#");
}
private boolean isUrn() {
return defaultString(myUnqualifiedId).startsWith("urn:");
} }
@Override @Override
@ -536,8 +513,6 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
super.setValue(theValue); super.setValue(theValue);
myHaveComponentParts = false; myHaveComponentParts = false;
String localPrefix = determineLocalPrefix(theValue);
if (StringUtils.isBlank(theValue)) { if (StringUtils.isBlank(theValue)) {
myBaseUrl = null; myBaseUrl = null;
super.setValue(null); super.setValue(null);
@ -546,14 +521,17 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
myResourceType = null; myResourceType = null;
} else if (theValue.charAt(0) == '#' && theValue.length() > 1) { } else if (theValue.charAt(0) == '#' && theValue.length() > 1) {
super.setValue(theValue); super.setValue(theValue);
myBaseUrl = "#"; myBaseUrl = null;
myUnqualifiedId = theValue.substring(1); myUnqualifiedId = theValue;
myUnqualifiedVersionId = null;
myResourceType = null;
myHaveComponentParts = true;
} else if (theValue.startsWith("urn:")) {
myBaseUrl = null;
myUnqualifiedId = theValue;
myUnqualifiedVersionId = null; myUnqualifiedVersionId = null;
myResourceType = null; myResourceType = null;
myHaveComponentParts = true; myHaveComponentParts = true;
} else if (localPrefix != null) {
myBaseUrl = localPrefix;
myUnqualifiedId = theValue.substring(localPrefix.length());
} else { } else {
int vidIndex = theValue.indexOf("/_history/"); int vidIndex = theValue.indexOf("/_history/");
int idIndex; int idIndex;
@ -618,21 +596,33 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
*/ */
@Override @Override
public IdType toUnqualified() { public IdType toUnqualified() {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(getResourceType(), getIdPart(), getVersionIdPart()); return new IdType(getResourceType(), getIdPart(), getVersionIdPart());
} }
@Override @Override
public IdType toUnqualifiedVersionless() { public IdType toUnqualifiedVersionless() {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(getResourceType(), getIdPart()); return new IdType(getResourceType(), getIdPart());
} }
@Override @Override
public IdType toVersionless() { public IdType toVersionless() {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(getBaseUrl(), getResourceType(), getIdPart(), null); return new IdType(getBaseUrl(), getResourceType(), getIdPart(), null);
} }
@Override @Override
public IdType withResourceType(String theResourceName) { public IdType withResourceType(String theResourceName) {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(theResourceName, getIdPart(), getVersionIdPart()); return new IdType(theResourceName, getIdPart(), getVersionIdPart());
} }
@ -652,6 +642,9 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
*/ */
@Override @Override
public IdType withServerBase(String theServerBase, String theResourceType) { public IdType withServerBase(String theServerBase, String theResourceType) {
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
return new IdType(theServerBase, theResourceType, getIdPart(), getVersionIdPart()); return new IdType(theServerBase, theResourceType, getIdPart(), getVersionIdPart());
} }
@ -664,9 +657,14 @@ public final class IdType extends UriType implements IPrimitiveType<String>, IId
* @return A new instance of IdType which is identical, but refers to the * @return A new instance of IdType which is identical, but refers to the
* specific version of this resource ID noted by theVersion. * specific version of this resource ID noted by theVersion.
*/ */
@Override
public IdType withVersion(String theVersion) { public IdType withVersion(String theVersion) {
Validate.notBlank(theVersion, "Version may not be null or empty"); Validate.notBlank(theVersion, "Version may not be null or empty");
if (isLocal() || isUrn()) {
return new IdType(getValueAsString());
}
String existingValue = getValue(); String existingValue = getValue();
int i = existingValue.indexOf("_history"); int i = existingValue.indexOf("_history");

View File

@ -28,6 +28,69 @@ public class IdTypeDstu3Test {
TestUtil.clearAllStaticFieldsForUnitTest(); TestUtil.clearAllStaticFieldsForUnitTest();
} }
@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 @Test
public void testDetectLocal() { public void testDetectLocal() {
@ -55,16 +118,16 @@ public class IdTypeDstu3Test {
@Test @Test
public void testDetectLocalBase() { public void testDetectLocalBase() {
assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("urn:uuid:", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); 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("cid:180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("cid:", new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("cid:180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); 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("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getValue());
assertEquals("#", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl()); assertEquals(null, new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart()); assertEquals("#180f219f-97a8-486d-99d9-ed631fe4fc57", new IdType("#180f219f-97a8-486d-99d9-ed631fe4fc57").getIdPart());
} }
@ -75,20 +138,20 @@ public class IdTypeDstu3Test {
public void testComplicatedLocal() { public void testComplicatedLocal() {
IdType id = new IdType("#Patient/cid:Patient-72/_history/1"); IdType id = new IdType("#Patient/cid:Patient-72/_history/1");
assertTrue(id.isLocal()); assertTrue(id.isLocal());
assertEquals("#", id.getBaseUrl()); assertEquals(null, id.getBaseUrl());
assertNull(id.getResourceType()); assertNull(id.getResourceType());
assertNull(id.getVersionIdPart()); assertNull(id.getVersionIdPart());
assertEquals("Patient/cid:Patient-72/_history/1", id.getIdPart()); assertEquals("#Patient/cid:Patient-72/_history/1", id.getIdPart());
IdType id2 = new IdType("#Patient/cid:Patient-72/_history/1"); IdType id2 = new IdType("#Patient/cid:Patient-72/_history/1");
assertEquals(id, id2); assertEquals(id, id2);
id2 = id2.toUnqualified(); id2 = id2.toUnqualified();
assertFalse(id2.isLocal()); assertTrue(id2.isLocal());
assertNull(id2.getBaseUrl()); assertNull(id2.getBaseUrl());
assertNull(id2.getResourceType()); assertNull(id2.getResourceType());
assertNull(id2.getVersionIdPart()); assertNull(id2.getVersionIdPart());
assertEquals("Patient/cid:Patient-72/_history/1", id2.getIdPart()); assertEquals("#Patient/cid:Patient-72/_history/1", id2.getIdPart());
} }

View File

@ -34,52 +34,16 @@ import java.util.UUID;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.hamcrest.core.StringContains; import org.hamcrest.core.StringContains;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Address.AddressUse; import org.hl7.fhir.dstu3.model.Address.AddressUse;
import org.hl7.fhir.dstu3.model.Address.AddressUseEnumFactory; import org.hl7.fhir.dstu3.model.Address.AddressUseEnumFactory;
import org.hl7.fhir.dstu3.model.Attachment;
import org.hl7.fhir.dstu3.model.AuditEvent;
import org.hl7.fhir.dstu3.model.Basic;
import org.hl7.fhir.dstu3.model.Binary;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.Bundle.BundleType; import org.hl7.fhir.dstu3.model.Bundle.BundleType;
import org.hl7.fhir.dstu3.model.Claim;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Communication;
import org.hl7.fhir.dstu3.model.Condition;
import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus; import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus;
import org.hl7.fhir.dstu3.model.Conformance;
import org.hl7.fhir.dstu3.model.Conformance.UnknownContentCode; import org.hl7.fhir.dstu3.model.Conformance.UnknownContentCode;
import org.hl7.fhir.dstu3.model.Coverage;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.DateType;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.DiagnosticReport;
import org.hl7.fhir.dstu3.model.EnumFactory;
import org.hl7.fhir.dstu3.model.Enumeration;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu3.model.ExplanationOfBenefit;
import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.dstu3.model.HumanName;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse; import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
import org.hl7.fhir.dstu3.model.Linkage;
import org.hl7.fhir.dstu3.model.Medication;
import org.hl7.fhir.dstu3.model.MedicationRequest;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.PrimitiveType;
import org.hl7.fhir.dstu3.model.Quantity;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.RelatedPerson;
import org.hl7.fhir.dstu3.model.SampledData;
import org.hl7.fhir.dstu3.model.SimpleQuantity;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -115,6 +79,35 @@ public class JsonParserDstu3Test {
ourCtx.setNarrativeGenerator(null); ourCtx.setNarrativeGenerator(null);
} }
/**
* See #544
*/
@Test
public void testBundleStitchReferencesByUuid() throws Exception {
Bundle bundle = new Bundle();
DocumentManifest dm = new DocumentManifest();
dm.getSubject().setReference("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
bundle.addEntry().setResource(dm);
Patient patient = new Patient();
patient.addName().setFamily("FAMILY");
bundle.addEntry().setResource(patient).setFullUrl("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
ourLog.info(encoded);
bundle = ourCtx.newJsonParser().parseResource(Bundle.class, encoded);
dm = (DocumentManifest) bundle.getEntry().get(0).getResource();
assertEquals("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3", dm.getSubject().getReference());
Patient subject = (Patient) dm.getSubject().getResource();
assertNotNull(subject);
assertEquals("FAMILY", subject.getNameFirstRep().getFamily());
}
@Test @Test
public void testIncorrectJsonTypesIdAndArray() { public void testIncorrectJsonTypesIdAndArray() {
@ -1660,8 +1653,8 @@ public class JsonParserDstu3Test {
ourLog.info(encoded); ourLog.info(encoded);
assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getIdElement().getValue()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getIdElement().getValue());
assertEquals("urn:uuid:", parsed.getEntry().get(0).getResource().getIdElement().getBaseUrl()); assertEquals(null, parsed.getEntry().get(0).getResource().getIdElement().getBaseUrl());
assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getIdElement().getIdPart()); assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getIdElement().getIdPart());
assertThat(encoded, not(containsString("\"id\":\"180f219f-97a8-486d-99d9-ed631fe4fc57\""))); assertThat(encoded, not(containsString("\"id\":\"180f219f-97a8-486d-99d9-ed631fe4fc57\"")));
} }

View File

@ -77,153 +77,31 @@ public class XmlParserDstu3Test {
} }
/** /**
* See #414 * See #544
*/ */
@Test @Test
public void testParseXmlExtensionWithoutUrl() { public void testBundleStitchReferencesByUuid() throws Exception {
//@formatter:off Bundle bundle = new Bundle();
String input = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
" <extension>\n" +
" <valueDateTime value=\"2011-01-02T11:13:15\"/>\n" +
" </extension>\n" +
"</Patient>";
//@formatter:on
IParser parser = ourCtx.newXmlParser(); DocumentManifest dm = new DocumentManifest();
parser.setParserErrorHandler(new LenientErrorHandler()); dm.getSubject().setReference("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
Patient parsed = (Patient) parser.parseResource(input); bundle.addEntry().setResource(dm);
assertEquals(1, parsed.getExtension().size());
assertEquals(null, parsed.getExtension().get(0).getUrl());
assertEquals("2011-01-02T11:13:15", parsed.getExtension().get(0).getValueAsPrimitive().getValueAsString());
try {
parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(input);
fail();
} catch (DataFormatException e) {
assertEquals("Resource is missing required element 'url' in parent element 'extension'", e.getCause().getMessage());
}
}
/**
* See #414
*/
@Test
public void testParseXmlModifierExtensionWithoutUrl() {
//@formatter:off
String input = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
" <modifierExtension>\n" +
" <valueDateTime value=\"2011-01-02T11:13:15\"/>\n" +
" </modifierExtension>\n" +
"</Patient>";
//@formatter:on
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
Patient parsed = (Patient) parser.parseResource(input);
assertEquals(1, parsed.getModifierExtension().size());
assertEquals(null, parsed.getModifierExtension().get(0).getUrl());
assertEquals("2011-01-02T11:13:15", parsed.getModifierExtension().get(0).getValueAsPrimitive().getValueAsString());
try {
parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(input);
fail();
} catch (DataFormatException e) {
assertEquals("Resource is missing required element 'url' in parent element 'modifierExtension'", e.getCause().getMessage());
}
}
@Test
public void testEncodeChainedContainedResourcer() {
Organization gp = new Organization();
gp.setName("grandparent");
Organization parent = new Organization();
parent.setName("parent");
parent.getPartOf().setResource(gp);
Organization child = new Organization();
child.setName("child");
child.getPartOf().setResource(parent);
Patient patient = new Patient(); Patient patient = new Patient();
patient.getManagingOrganization().setResource(child); patient.addName().setFamily("FAMILY");
bundle.addEntry().setResource(patient).setFullUrl("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle);
ourLog.info(encoded); ourLog.info(encoded);
patient = ourCtx.newXmlParser().parseResource(Patient.class, encoded); bundle = ourCtx.newXmlParser().parseResource(Bundle.class, encoded);
dm = (DocumentManifest) bundle.getEntry().get(0).getResource();
child = (Organization) patient.getManagingOrganization().getResource(); assertEquals("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3", dm.getSubject().getReference());
assertEquals("child", child.getName());
parent = (Organization) child.getPartOf().getResource(); Patient subject = (Patient) dm.getSubject().getResource();
assertEquals("parent", parent.getName()); assertNotNull(subject);
assertEquals("FAMILY", subject.getNameFirstRep().getFamily());
gp = (Organization) parent.getPartOf().getResource();
assertEquals("grandparent", gp.getName());
}
/**
* If a contained resource refers to a contained resource that comes after it, it should still be successfully
* woven together.
*/
@Test
public void testParseWovenContainedResources() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_woven_obs.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
org.hl7.fhir.dstu3.model.Bundle bundle = parser.parseResource(Bundle.class, string);
DiagnosticReport resource = (DiagnosticReport) bundle.getEntry().get(0).getResource();
Observation obs = (Observation) resource.getResult().get(1).getResource();
assertEquals("#2", obs.getId());
Reference performerFirstRep = obs.getPerformerFirstRep();
Practitioner performer = (Practitioner) performerFirstRep.getResource();
assertEquals("#3", performer.getId());
}
@Test(expected = DataFormatException.class)
public void testContainedResourceWithNoId() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(Bundle.class, string);
}
@Test()
public void testContainedResourceWithNoIdLenient() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
parser.parseResource(Bundle.class, string);
}
@Test(expected = DataFormatException.class)
public void testParseWithInvalidLocalRef() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(Bundle.class, string);
}
@Test()
public void testParseWithInvalidLocalRefLenient() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
parser.parseResource(Bundle.class, string);
} }
@Test @Test
@ -257,6 +135,7 @@ public class XmlParserDstu3Test {
} }
@Test @Test
public void testContainedResourceInExtensionUndeclared() { public void testContainedResourceInExtensionUndeclared() {
Patient p = new Patient(); Patient p = new Patient();
@ -279,6 +158,24 @@ public class XmlParserDstu3Test {
assertEquals("ORG", o.getName()); assertEquals("ORG", o.getName());
} }
@Test(expected = DataFormatException.class)
public void testContainedResourceWithNoId() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(Bundle.class, string);
}
@Test()
public void testContainedResourceWithNoIdLenient() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
parser.parseResource(Bundle.class, string);
}
@Test @Test
public void testDuration() { public void testDuration() {
Encounter enc = new Encounter(); Encounter enc = new Encounter();
@ -1023,6 +920,37 @@ public class XmlParserDstu3Test {
assertThat(encoded, not(stringContainsInOrder("<DiagnosticReport", "<contained", "<Observation", "<contained", "<Observation", "</DiagnosticReport"))); assertThat(encoded, not(stringContainsInOrder("<DiagnosticReport", "<contained", "<Observation", "<contained", "<Observation", "</DiagnosticReport")));
} }
@Test
public void testEncodeChainedContainedResourcer() {
Organization gp = new Organization();
gp.setName("grandparent");
Organization parent = new Organization();
parent.setName("parent");
parent.getPartOf().setResource(gp);
Organization child = new Organization();
child.setName("child");
child.getPartOf().setResource(parent);
Patient patient = new Patient();
patient.getManagingOrganization().setResource(child);
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
ourLog.info(encoded);
patient = ourCtx.newXmlParser().parseResource(Patient.class, encoded);
child = (Organization) patient.getManagingOrganization().getResource();
assertEquals("child", child.getName());
parent = (Organization) child.getPartOf().getResource();
assertEquals("parent", parent.getName());
gp = (Organization) parent.getPartOf().getResource();
assertEquals("grandparent", gp.getName());
}
/** /**
* See #326 * See #326
*/ */
@ -1929,8 +1857,6 @@ public class XmlParserDstu3Test {
assertThat(output, containsString("<text><status value=\"generated\"/><div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\">John <b>SMITH </b>")); assertThat(output, containsString("<text><status value=\"generated\"/><div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\">John <b>SMITH </b>"));
} }
@Test @Test
public void testMoreExtensions() throws Exception { public void testMoreExtensions() throws Exception {
@ -2176,6 +2102,8 @@ public class XmlParserDstu3Test {
} }
@Test @Test
public void testParseAndEncodeCommentsOnExtensions() { public void testParseAndEncodeCommentsOnExtensions() {
//@formatter:off //@formatter:off
@ -3105,6 +3033,106 @@ public class XmlParserDstu3Test {
} }
} }
@Test(expected = DataFormatException.class)
public void testParseWithInvalidLocalRef() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(Bundle.class, string);
}
@Test()
public void testParseWithInvalidLocalRefLenient() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
parser.parseResource(Bundle.class, string);
}
/**
* If a contained resource refers to a contained resource that comes after it, it should still be successfully
* woven together.
*/
@Test
public void testParseWovenContainedResources() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_woven_obs.xml"), StandardCharsets.UTF_8);
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
org.hl7.fhir.dstu3.model.Bundle bundle = parser.parseResource(Bundle.class, string);
DiagnosticReport resource = (DiagnosticReport) bundle.getEntry().get(0).getResource();
Observation obs = (Observation) resource.getResult().get(1).getResource();
assertEquals("#2", obs.getId());
Reference performerFirstRep = obs.getPerformerFirstRep();
Practitioner performer = (Practitioner) performerFirstRep.getResource();
assertEquals("#3", performer.getId());
}
/**
* See #414
*/
@Test
public void testParseXmlExtensionWithoutUrl() {
//@formatter:off
String input = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
" <extension>\n" +
" <valueDateTime value=\"2011-01-02T11:13:15\"/>\n" +
" </extension>\n" +
"</Patient>";
//@formatter:on
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
Patient parsed = (Patient) parser.parseResource(input);
assertEquals(1, parsed.getExtension().size());
assertEquals(null, parsed.getExtension().get(0).getUrl());
assertEquals("2011-01-02T11:13:15", parsed.getExtension().get(0).getValueAsPrimitive().getValueAsString());
try {
parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(input);
fail();
} catch (DataFormatException e) {
assertEquals("Resource is missing required element 'url' in parent element 'extension'", e.getCause().getMessage());
}
}
/**
* See #414
*/
@Test
public void testParseXmlModifierExtensionWithoutUrl() {
//@formatter:off
String input = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
" <modifierExtension>\n" +
" <valueDateTime value=\"2011-01-02T11:13:15\"/>\n" +
" </modifierExtension>\n" +
"</Patient>";
//@formatter:on
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
Patient parsed = (Patient) parser.parseResource(input);
assertEquals(1, parsed.getModifierExtension().size());
assertEquals(null, parsed.getModifierExtension().get(0).getUrl());
assertEquals("2011-01-02T11:13:15", parsed.getModifierExtension().get(0).getValueAsPrimitive().getValueAsString());
try {
parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(input);
fail();
} catch (DataFormatException e) {
assertEquals("Resource is missing required element 'url' in parent element 'modifierExtension'", e.getCause().getMessage());
}
}
/** /**
* See #339 * See #339
* *

File diff suppressed because one or more lines are too long

View File

@ -222,6 +222,17 @@
return an HTTP 404 and not a 400, per the HTTP spec. Thanks to return an HTTP 404 and not a 400, per the HTTP spec. Thanks to
GitHub user @CarthageKing for the pull request! GitHub user @CarthageKing for the pull request!
</action> </action>
<action type="fix" issue="544">
When parsing a Bundle containing placeholder fullUrls and references
(e.g. "urn:uuid:0000-0000") the resource reference targets did not get
populated with the given resources. Note that as a part of this
change, <![CDATA[<code>IdType</code> and <code>IdDt</code>]]> have been modified
so that when parsing a placeholder ID, the complete placeholder including the
"urn:uuid:" or "urn:oid:" prefix will be placed into the ID part. Previously,
the prefix was treated as the base URL, which led to strange behaviour
like the placeholder being treated as a real IDs. Thanks to GitHub
user @jodue for reporting!
</action>
</release> </release>
<release version="2.1" date="2016-11-11"> <release version="2.1" date="2016-11-11">
<action type="add"> <action type="add">