More work on hl7org strfucts
This commit is contained in:
parent
4c82e1f87b
commit
3db46c2db2
|
@ -5,6 +5,7 @@ import java.io.FileReader;
|
|||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
|
@ -69,7 +70,7 @@ public class ValidatorExamples {
|
|||
String nextFileContents = IOUtils.toString(new FileReader(nextFile));
|
||||
|
||||
// Parse that string (this example assumes JSON encoding)
|
||||
IResource resource = ctx.newJsonParser().parseResource(nextFileContents);
|
||||
IBaseResource resource = ctx.newJsonParser().parseResource(nextFileContents);
|
||||
|
||||
// Apply the validation. This will throw an exception on the first
|
||||
// validation failure
|
||||
|
|
|
@ -20,8 +20,6 @@ package ca.uhn.fhir.context;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +29,6 @@ public class RuntimeElemContainedResourceList extends BaseRuntimeElementDefiniti
|
|||
|
||||
public RuntimeElemContainedResourceList(Class<IBaseResource> theClass) {
|
||||
super("contained", theClass);
|
||||
assert List.class.isAssignableFrom(theClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.http.HttpResponse;
|
|||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IReference;
|
||||
|
||||
|
@ -42,7 +43,7 @@ import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
|||
public abstract class BaseResourceReferenceDt extends BaseIdentifiableElement implements IBaseDatatype, IReference {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseResourceReferenceDt.class);
|
||||
private IResource myResource;
|
||||
private IBaseResource myResource;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -74,7 +75,7 @@ public abstract class BaseResourceReferenceDt extends BaseIdentifiableElement im
|
|||
*
|
||||
* @see #loadResource(IRestfulClient)
|
||||
*/
|
||||
public IResource getResource() {
|
||||
public IBaseResource getResource() {
|
||||
return myResource;
|
||||
}
|
||||
|
||||
|
@ -87,7 +88,7 @@ public abstract class BaseResourceReferenceDt extends BaseIdentifiableElement im
|
|||
* Returns the referenced resource, fetching it <b>if it has not already been loaded</b>. This method invokes the HTTP client to retrieve the resource unless it has already been loaded, or was a
|
||||
* contained resource in which case it is simply returned.
|
||||
*/
|
||||
public IResource loadResource(IRestfulClient theClient) throws IOException {
|
||||
public IBaseResource loadResource(IRestfulClient theClient) throws IOException {
|
||||
if (myResource != null) {
|
||||
return myResource;
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ public abstract class BaseResourceReferenceDt extends BaseIdentifiableElement im
|
|||
|
||||
public abstract BaseResourceReferenceDt setReference(IdDt theReference);
|
||||
|
||||
public void setResource(IResource theResource) {
|
||||
public void setResource(IBaseResource theResource) {
|
||||
myResource = theResource;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
|||
import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions;
|
||||
import org.hl7.fhir.instance.model.api.IBaseIntegerDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.instance.model.api.IReference;
|
||||
|
||||
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
|
||||
|
@ -72,6 +73,7 @@ import ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum;
|
|||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.context.RuntimeChildContainedResources;
|
||||
import ca.uhn.fhir.context.RuntimeChildDeclaredExtensionDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeChildNarrativeDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeChildUndeclaredExtensionDefinition;
|
||||
|
@ -416,7 +418,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
break;
|
||||
}
|
||||
case RESOURCE_REF: {
|
||||
BaseResourceReferenceDt referenceDt = (BaseResourceReferenceDt) theNextValue;
|
||||
IReference referenceDt = (IReference) theNextValue;
|
||||
if (theChildName != null) {
|
||||
theWriter.writeStartObject(theChildName);
|
||||
} else {
|
||||
|
@ -490,6 +492,9 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
if (nextChild.getElementName().equals("extension") || nextChild.getElementName().equals("modifierExtension")) {
|
||||
continue;
|
||||
}
|
||||
if (nextChild.getElementName().equals("id")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nextChild instanceof RuntimeChildNarrativeDefinition) {
|
||||
|
||||
|
@ -505,8 +510,15 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
} else if (nextChild instanceof RuntimeChildContainedResources) {
|
||||
if (theIsSubElementWithinResource == false) {
|
||||
String childName = nextChild.getValidChildNames().iterator().next();
|
||||
BaseRuntimeElementDefinition<?> child = nextChild.getChildByName(childName);
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, null, child, childName, theIsSubElementWithinResource);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
List<? extends IBase> values = nextChild.getAccessor().getValues(theNextValue);
|
||||
if (values == null || values.isEmpty()) {
|
||||
continue;
|
||||
|
@ -1067,7 +1079,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
}
|
||||
|
||||
if (elementId != null) {
|
||||
IElement object = (IElement) theState.getObject();
|
||||
IBase object = (IBase) theState.getObject();
|
||||
if (object instanceof IIdentifiableElement) {
|
||||
((IIdentifiableElement) object).setElementSpecificId(elementId);
|
||||
} else if (object instanceof IResource) {
|
||||
|
|
|
@ -36,6 +36,7 @@ public class Constants {
|
|||
public static final String CT_FHIR_JSON = "application/json+fhir";
|
||||
public static final String CT_FHIR_XML = "application/xml+fhir";
|
||||
public static final String CT_HTML = "text/html";
|
||||
public static final String CT_HTML_WITH_UTF8 = "text/html; charset=UTF-8";
|
||||
public static final String CT_JSON = "application/json";
|
||||
public static final String CT_OCTET_STREAM = "application/octet-stream";
|
||||
public static final String CT_TEXT = "text/plain";
|
||||
|
|
|
@ -98,7 +98,7 @@ public class Dstu1BundleFactory implements IVersionSpecificBundleFactory {
|
|||
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes))
|
||||
continue;
|
||||
|
||||
IResource nextRes = nextRefInfo.getResourceReference().getResource();
|
||||
IResource nextRes = (IResource) nextRefInfo.getResourceReference().getResource();
|
||||
if (nextRes != null) {
|
||||
if (nextRes.getId().hasIdPart()) {
|
||||
if (containedIds.contains(nextRes.getId().getValue())) {
|
||||
|
@ -304,7 +304,7 @@ public class Dstu1BundleFactory implements IVersionSpecificBundleFactory {
|
|||
List<IResource> addedResourcesThisPass = new ArrayList<IResource>();
|
||||
|
||||
for (BaseResourceReferenceDt nextRef : references) {
|
||||
IResource nextRes = nextRef.getResource();
|
||||
IResource nextRes = (IResource) nextRef.getResource();
|
||||
if (nextRes != null) {
|
||||
if (nextRes.getId().hasIdPart()) {
|
||||
if (containedIds.contains(nextRes.getId().getValue())) {
|
||||
|
|
|
@ -158,7 +158,7 @@ public class RestfulServerUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean prettyPrintResponse(RestfulServer theServer, Request theRequest) {
|
||||
public static boolean prettyPrintResponse(RestfulServer theServer, RequestDetails theRequest) {
|
||||
Map<String, String[]> requestParams = theRequest.getParameters();
|
||||
String[] pretty = requestParams.remove(Constants.PARAM_PRETTY);
|
||||
boolean prettyPrint;
|
||||
|
@ -170,7 +170,7 @@ public class RestfulServerUtils {
|
|||
}
|
||||
} else {
|
||||
prettyPrint = theServer.isDefaultPrettyPrint();
|
||||
Enumeration<String> acceptValues = theRequest.getServletRequest().getHeaders(Constants.HEADER_ACCEPT);
|
||||
Enumeration<String> acceptValues = ((Request)theRequest).getServletRequest().getHeaders(Constants.HEADER_ACCEPT);
|
||||
if (acceptValues != null) {
|
||||
while (acceptValues.hasMoreElements()) {
|
||||
String nextAcceptHeaderValue = acceptValues.nextElement();
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
package ca.uhn.fhir.rest.server.interceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer.NarrativeModeEnum;
|
||||
import ca.uhn.fhir.rest.server.RestfulServerUtils;
|
||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
|
||||
public class ResponseHighlighterInterceptor extends InterceptorAdapter {
|
||||
|
||||
private String format(String theResultBody, EncodingEnum theEncodingEnum) {
|
||||
String str = StringEscapeUtils.escapeHtml4(theResultBody);
|
||||
if (str == null || theEncodingEnum == null) {
|
||||
return str;
|
||||
}
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
|
||||
if (theEncodingEnum == EncodingEnum.JSON) {
|
||||
|
||||
boolean inValue = false;
|
||||
boolean inQuote = false;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char prevChar = (i > 0) ? str.charAt(i - 1) : ' ';
|
||||
char nextChar = str.charAt(i);
|
||||
char nextChar2 = (i + 1) < str.length() ? str.charAt(i + 1) : ' ';
|
||||
char nextChar3 = (i + 2) < str.length() ? str.charAt(i + 2) : ' ';
|
||||
char nextChar4 = (i + 3) < str.length() ? str.charAt(i + 3) : ' ';
|
||||
char nextChar5 = (i + 4) < str.length() ? str.charAt(i + 4) : ' ';
|
||||
char nextChar6 = (i + 5) < str.length() ? str.charAt(i + 5) : ' ';
|
||||
if (inQuote) {
|
||||
b.append(nextChar);
|
||||
if (prevChar != '\\' && nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') {
|
||||
b.append("quot;</span>");
|
||||
i += 5;
|
||||
inQuote = false;
|
||||
} else if (nextChar == '\\' && nextChar2 == '"') {
|
||||
b.append("quot;</span>");
|
||||
i += 5;
|
||||
inQuote = false;
|
||||
}
|
||||
} else {
|
||||
if (nextChar == ':') {
|
||||
inValue = true;
|
||||
b.append(nextChar);
|
||||
} else if (nextChar == '[' || nextChar == '{') {
|
||||
b.append("<span class='hlControl'>");
|
||||
b.append(nextChar);
|
||||
b.append("</span>");
|
||||
inValue = false;
|
||||
} else if (nextChar == '}' || nextChar == '}' || nextChar == ',') {
|
||||
b.append("<span class='hlControl'>");
|
||||
b.append(nextChar);
|
||||
b.append("</span>");
|
||||
inValue = false;
|
||||
} else if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') {
|
||||
if (inValue) {
|
||||
b.append("<span class='hlQuot'>"");
|
||||
} else {
|
||||
b.append("<span class='hlTagName'>"");
|
||||
}
|
||||
inQuote = true;
|
||||
i += 5;
|
||||
} else if (nextChar == ':') {
|
||||
b.append("<span class='hlControl'>");
|
||||
b.append(nextChar);
|
||||
b.append("</span>");
|
||||
inValue = true;
|
||||
} else {
|
||||
b.append(nextChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
boolean inQuote = false;
|
||||
boolean inTag = false;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char nextChar = str.charAt(i);
|
||||
char nextChar2 = (i + 1) < str.length() ? str.charAt(i + 1) : ' ';
|
||||
char nextChar3 = (i + 2) < str.length() ? str.charAt(i + 2) : ' ';
|
||||
char nextChar4 = (i + 3) < str.length() ? str.charAt(i + 3) : ' ';
|
||||
char nextChar5 = (i + 4) < str.length() ? str.charAt(i + 4) : ' ';
|
||||
char nextChar6 = (i + 5) < str.length() ? str.charAt(i + 5) : ' ';
|
||||
if (inQuote) {
|
||||
b.append(nextChar);
|
||||
if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') {
|
||||
b.append("quot;</span>");
|
||||
i += 5;
|
||||
inQuote = false;
|
||||
}
|
||||
} else if (inTag) {
|
||||
if (nextChar == '&' && nextChar2 == 'g' && nextChar3 == 't' && nextChar4 == ';') {
|
||||
b.append("</span><span class='hlControl'>></span>");
|
||||
inTag = false;
|
||||
i += 3;
|
||||
} else if (nextChar == ' ') {
|
||||
b.append("</span><span class='hlAttr'>");
|
||||
b.append(nextChar);
|
||||
} else if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') {
|
||||
b.append("<span class='hlQuot'>"");
|
||||
inQuote = true;
|
||||
i += 5;
|
||||
} else {
|
||||
b.append(nextChar);
|
||||
}
|
||||
} else {
|
||||
if (nextChar == '&' && nextChar2 == 'l' && nextChar3 == 't' && nextChar4 == ';') {
|
||||
b.append("<span class='hlControl'><</span><span class='hlTagName'>");
|
||||
inTag = true;
|
||||
i += 3;
|
||||
} else {
|
||||
b.append(nextChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse)
|
||||
throws AuthenticationException {
|
||||
String accept = theServletRequest.getHeader(Constants.HEADER_ACCEPT);
|
||||
if (accept == null || !accept.toLowerCase().contains("html")) {
|
||||
return super.outgoingResponse(theRequestDetails, theResponseObject, theServletRequest, theServletResponse);
|
||||
}
|
||||
|
||||
// Pretty print
|
||||
boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theRequestDetails.getServer(), theRequestDetails);
|
||||
|
||||
// Narrative mode
|
||||
NarrativeModeEnum narrativeMode = RestfulServerUtils.determineNarrativeMode(theRequestDetails);
|
||||
|
||||
// Determine response encoding
|
||||
EncodingEnum responseEncoding = null;
|
||||
if (theRequestDetails.getParameters().containsKey(Constants.PARAM_FORMAT)) {
|
||||
// Browsers often state that they accept XML but we won't take that as being the user's preference
|
||||
// unless they explicitly request it
|
||||
responseEncoding = RestfulServerUtils.determineResponseEncodingNoDefault(theServletRequest);
|
||||
}
|
||||
if (responseEncoding == null) {
|
||||
responseEncoding = theRequestDetails.getServer().getDefaultResponseEncoding();
|
||||
}
|
||||
|
||||
IParser p = responseEncoding.newParser(theRequestDetails.getServer().getFhirContext());
|
||||
p.setPrettyPrint(prettyPrint);
|
||||
|
||||
String encoded = p.encodeResourceToString(theResponseObject);
|
||||
|
||||
theServletResponse.setContentType(Constants.CT_HTML_WITH_UTF8);
|
||||
|
||||
//@formatter:on
|
||||
String out = "<html lang=\"en\">\n" +
|
||||
" <head>\n" +
|
||||
" <meta charset=\"utf-8\" />\n" +
|
||||
" <style>\n" +
|
||||
".hlQuot {\n" +
|
||||
" color: #88F;\n" +
|
||||
"}\n" +
|
||||
".hlAttr {\n" +
|
||||
" color: #888;\n" +
|
||||
"}\n" +
|
||||
".hlTagName {\n" +
|
||||
" color: #006699;\n" +
|
||||
"}\n" +
|
||||
".hlControl {\n" +
|
||||
" color: #660000;\n" +
|
||||
"}\n" +
|
||||
".hlText {\n" +
|
||||
" color: #000000;\n" +
|
||||
"}\n" +
|
||||
".hlUrlBase {\n" +
|
||||
"}" +
|
||||
" </style>\n" +
|
||||
" </head>\n" +
|
||||
"\n" +
|
||||
" <body>" +
|
||||
"<pre>" + format(encoded, responseEncoding) + "</pre>" +
|
||||
" </body>" +
|
||||
"</html>";
|
||||
//@formatter:off
|
||||
|
||||
try {
|
||||
theServletResponse.getWriter().append(out);
|
||||
theServletResponse.getWriter().close();
|
||||
} catch (IOException e) {
|
||||
throw new InternalErrorException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package org.hl7.fhir.instance.model.api;
|
||||
|
||||
import org.hl7.fhir.instance.model.IPrimitiveType;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
<<<<<<< HEAD:hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/instance/model/IBaseResource.java
|
||||
/**
|
||||
* For now, this is a simple marker interface indicating that a class is a resource type.
|
||||
* There are two concrete types of implementations of this interrface. The first are
|
||||
* HL7.org's Resource structures (e.g.
|
||||
* <code>org.hl7.fhir.instance.model.Patient</code>) and
|
||||
* the second are HAPI's Resource structures, e.g.
|
||||
* <code>ca.uhn.fhir.model.dstu.resource.Patient</code>)
|
||||
*/
|
||||
public interface IBaseResource extends IBase {
|
||||
|
||||
IIdType
|
||||
=======
|
||||
public interface IBaseEnumeration<T extends Enum<?>> extends IPrimitiveType<T> {
|
||||
|
||||
// Marker interface
|
||||
>>>>>>> 2edc7eadab64d171ddc1b7c971ff36b9eb55ce67:hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IBaseEnumeration.java
|
||||
|
||||
}
|
|
@ -168,7 +168,7 @@ public class FhirSystemDaoDstu2 extends BaseFhirSystemDao<Bundle> {
|
|||
// CREATE
|
||||
@SuppressWarnings("rawtypes")
|
||||
IFhirResourceDao resourceDao = getDao(res.getClass());
|
||||
res.setId(null);
|
||||
res.setId((String)null);
|
||||
DaoMethodOutcome outcome;
|
||||
Entry newEntry = response.addEntry();
|
||||
outcome = resourceDao.create(res, nextEntry.getTransaction().getIfNoneExist(), false);
|
||||
|
@ -204,7 +204,7 @@ public class FhirSystemDaoDstu2 extends BaseFhirSystemDao<Bundle> {
|
|||
res.setId(new IdDt(parts.getResourceType(), parts.getResourceId()));
|
||||
outcome = resourceDao.update(res, null, false);
|
||||
} else {
|
||||
res.setId(null);
|
||||
res.setId((String)null);
|
||||
outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ package ca.uhn.fhir.model.dstu.resource;
|
|||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
|
||||
import ca.uhn.fhir.model.api.BaseElement;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
|
@ -118,16 +119,26 @@ public abstract class BaseResource extends BaseElement implements IResource {
|
|||
myContained = theContained;
|
||||
}
|
||||
|
||||
public BaseResource setId(IIdType theId) {
|
||||
if (theId instanceof IdDt) {
|
||||
myId = (IdDt) theId;
|
||||
} else if (theId != null) {
|
||||
myId = new IdDt(theId.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(IdDt theId) {
|
||||
myId = theId;
|
||||
}
|
||||
|
||||
public void setId(String theId) {
|
||||
public BaseResource setId(String theId) {
|
||||
if (theId == null) {
|
||||
myId = null;
|
||||
} else {
|
||||
myId = new IdDt(theId);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1101,7 +1101,7 @@ public class XmlParserTest {
|
|||
IParser p = ourCtx.newXmlParser();
|
||||
|
||||
String string = IOUtils.toString(XmlParserTest.class.getResourceAsStream("/observation-example-eeg.xml"), Charset.forName("UTF-8"));
|
||||
IResource resource = p.parseResource(string);
|
||||
IBaseResource resource = p.parseResource(string);
|
||||
|
||||
String result = p.encodeResourceToString(resource);
|
||||
ourLog.info(result);
|
||||
|
@ -1113,7 +1113,7 @@ public class XmlParserTest {
|
|||
IParser p = ourCtx.newXmlParser();
|
||||
|
||||
String string = IOUtils.toString(XmlParserTest.class.getResourceAsStream("/patient-example-dicom.xml"), Charset.forName("UTF-8"));
|
||||
IResource resource = p.parseResource(string);
|
||||
IBaseResource resource = p.parseResource(string);
|
||||
|
||||
String result = p.encodeResourceToString(resource);
|
||||
ourLog.info(result);
|
||||
|
@ -1134,7 +1134,7 @@ public class XmlParserTest {
|
|||
IParser p = ourCtx.newXmlParser();
|
||||
|
||||
String string = IOUtils.toString(XmlParserTest.class.getResourceAsStream("/questionnaire-example.xml"), Charset.forName("UTF-8"));
|
||||
IResource resource = p.parseResource(string);
|
||||
IBaseResource resource = p.parseResource(string);
|
||||
|
||||
String result = p.encodeResourceToString(resource);
|
||||
ourLog.info(result);
|
||||
|
@ -1551,7 +1551,7 @@ public class XmlParserTest {
|
|||
public void testParseEncodeNarrative() {
|
||||
|
||||
String input = "<Patient xmlns=\"http://hl7.org/fhir\"><text><status value=\"generated\"/><div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\"> Donald null <b>DUCK </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>7000135</td></tr><tr><td>Address</td><td><span>10 Duxon Street </span><br/><span>VICTORIA </span><span>BC </span><span>Can </span></td></tr><tr><td>Date of birth</td><td><span>01 June 1980</span></td></tr></tbody></table></div></text><identifier><use value=\"official\"/><label value=\"University Health Network MRN 7000135\"/><system value=\"urn:oid:2.16.840.1.113883.3.239.18.148\"/><value value=\"7000135\"/><assigner><reference value=\"Organization/1.3.6.1.4.1.12201\"/></assigner></identifier><name><family value=\"Duck\"/><given value=\"Donald\"/></name><telecom><system value=\"phone\"/><use value=\"home\"/></telecom><telecom><system value=\"phone\"/><use value=\"work\"/></telecom><telecom><system value=\"phone\"/><use value=\"mobile\"/></telecom><telecom><system value=\"email\"/><use value=\"home\"/></telecom><gender><coding><system value=\"http://hl7.org/fhir/v3/AdministrativeGender\"/><code value=\"M\"/></coding></gender><birthDate value=\"1980-06-01T00:00:00\"/><address><use value=\"home\"/><line value=\"10 Duxon Street\"/><city value=\"VICTORIA\"/><state value=\"BC\"/><zip value=\"V8N 1Y4\"/><country value=\"Can\"/></address><managingOrganization><reference value=\"Organization/1.3.6.1.4.1.12201\"/></managingOrganization></Patient>";
|
||||
IResource res = ourCtx.newXmlParser().parseResource(input);
|
||||
IBaseResource res = ourCtx.newXmlParser().parseResource(input);
|
||||
|
||||
String output = ourCtx.newXmlParser().encodeResourceToString(res);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import javax.servlet.ServletException;
|
|||
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
|
@ -266,6 +267,16 @@ public class ServerInvalidDefinitionTest {
|
|||
@Override
|
||||
public void setResourceMetadata(ResourceMetadataMap theMap) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaseResource setId(String theId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaseResource setId(IIdType theId) {
|
||||
return null;
|
||||
}
|
||||
}.getClass();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ package ca.uhn.fhir.model.dstu2.resource;
|
|||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
|
||||
import ca.uhn.fhir.model.api.BaseElement;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
|
@ -121,6 +122,15 @@ public abstract class BaseResource extends BaseElement implements IResource {
|
|||
public void setId(IdDt theId) {
|
||||
myId = theId;
|
||||
}
|
||||
|
||||
public BaseResource setId(IIdType theId) {
|
||||
if (theId instanceof IdDt) {
|
||||
myId = (IdDt) theId;
|
||||
} else if (theId != null) {
|
||||
myId = new IdDt(theId.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseResource setId(String theId) {
|
||||
if (theId == null) {
|
||||
|
|
|
@ -104,7 +104,7 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
|||
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes))
|
||||
continue;
|
||||
|
||||
IResource nextRes = nextRefInfo.getResourceReference().getResource();
|
||||
IResource nextRes = (IResource) nextRefInfo.getResourceReference().getResource();
|
||||
if (nextRes != null) {
|
||||
if (nextRes.getId().hasIdPart()) {
|
||||
if (containedIds.contains(nextRes.getId().getValue())) {
|
||||
|
@ -342,7 +342,7 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
|||
List<IResource> addedResourcesThisPass = new ArrayList<IResource>();
|
||||
|
||||
for (BaseResourceReferenceDt nextRef : references) {
|
||||
IResource nextRes = nextRef.getResource();
|
||||
IResource nextRes = (IResource) nextRef.getResource();
|
||||
if (nextRes != null) {
|
||||
if (nextRes.getId().hasIdPart()) {
|
||||
if (containedIds.contains(nextRes.getId().getValue())) {
|
||||
|
|
|
@ -0,0 +1,588 @@
|
|||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
package org.hl7.fhir.instance.model;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.hl7.fhir.instance.model.annotations.DatatypeDef;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.SimpleSetter;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
|
||||
/**
|
||||
* Primitive type "id" in FHIR: a string from 1 to 64 characters, only containing letters, digits, "-" and "."
|
||||
*/
|
||||
@DatatypeDef(name = "id")
|
||||
public class IdType extends UriType implements IIdType {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String myBaseUrl;
|
||||
private boolean myHaveComponentParts;
|
||||
private String myResourceType;
|
||||
private String myUnqualifiedId;
|
||||
private String myUnqualifiedVersionId;
|
||||
private volatile String myValue;
|
||||
|
||||
/**
|
||||
* Create a new empty ID
|
||||
*/
|
||||
public IdType() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ID, using a BigDecimal input. Uses {@link BigDecimal#toPlainString()} to generate the string representation.
|
||||
*/
|
||||
public IdType(BigDecimal thePid) {
|
||||
if (thePid != null) {
|
||||
setValue(toPlainStringWithNpeThrowIfNeeded(thePid));
|
||||
} else {
|
||||
setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ID using a long
|
||||
*/
|
||||
public IdType(long theId) {
|
||||
setValue(Long.toString(theId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ID using a string. This String may contain a simple ID (e.g. "1234") or it may contain a complete URL (http://example.com/fhir/Patient/1234).
|
||||
*
|
||||
* <p>
|
||||
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
|
||||
* limit of 36 characters.
|
||||
* </p>
|
||||
* <p>
|
||||
* regex: [a-z0-9\-\.]{1,36}
|
||||
* </p>
|
||||
*/
|
||||
@SimpleSetter
|
||||
public IdType(@SimpleSetter.Parameter(name = "theId") String theValue) {
|
||||
setValue(theValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theResourceType
|
||||
* The resource type (e.g. "Patient")
|
||||
* @param theIdPart
|
||||
* The ID (e.g. "123")
|
||||
*/
|
||||
public IdType(String theResourceType, BigDecimal theIdPart) {
|
||||
this(theResourceType, toPlainStringWithNpeThrowIfNeeded(theIdPart));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theResourceType
|
||||
* The resource type (e.g. "Patient")
|
||||
* @param theIdPart
|
||||
* The ID (e.g. "123")
|
||||
*/
|
||||
public IdType(String theResourceType, Long theIdPart) {
|
||||
this(theResourceType, toPlainStringWithNpeThrowIfNeeded(theIdPart));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theResourceType
|
||||
* The resource type (e.g. "Patient")
|
||||
* @param theId
|
||||
* The ID (e.g. "123")
|
||||
*/
|
||||
public IdType(String theResourceType, String theId) {
|
||||
this(theResourceType, theId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theResourceType
|
||||
* The resource type (e.g. "Patient")
|
||||
* @param theId
|
||||
* The ID (e.g. "123")
|
||||
* @param theVersionId
|
||||
* The version ID ("e.g. "456")
|
||||
*/
|
||||
public IdType(String theResourceType, String theId, String theVersionId) {
|
||||
this(null,theResourceType,theId,theVersionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theBaseUrl
|
||||
* The server base URL (e.g. "http://example.com/fhir")
|
||||
* @param theResourceType
|
||||
* The resource type (e.g. "Patient")
|
||||
* @param theId
|
||||
* The ID (e.g. "123")
|
||||
* @param theVersionId
|
||||
* The version ID ("e.g. "456")
|
||||
*/
|
||||
public IdType(String theBaseUrl, String theResourceType, String theId, String theVersionId) {
|
||||
myBaseUrl = theBaseUrl;
|
||||
myResourceType = theResourceType;
|
||||
myUnqualifiedId = theId;
|
||||
myUnqualifiedVersionId = StringUtils.defaultIfBlank(theVersionId, null);
|
||||
myHaveComponentParts = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ID based on a given URL
|
||||
*/
|
||||
public IdType(UriDt theUrl) {
|
||||
setValue(theUrl.getValueAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getIdPartAsBigDecimal()} instead (this method was deprocated because its name is ambiguous)
|
||||
*/
|
||||
@Deprecated
|
||||
public BigDecimal asBigDecimal() {
|
||||
return getIdPartAsBigDecimal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this IdDt matches the given IdDt in terms of resource type and ID, but ignores the URL base
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean equalsIgnoreBase(IdType theId) {
|
||||
if (theId == null) {
|
||||
return false;
|
||||
}
|
||||
if (theId.isEmpty()) {
|
||||
return isEmpty();
|
||||
}
|
||||
return ObjectUtils.equals(getResourceType(), theId.getResourceType()) && ObjectUtils.equals(getIdPart(), theId.getIdPart()) && ObjectUtils.equals(getVersionIdPart(), theId.getVersionIdPart());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theArg0) {
|
||||
if (!(theArg0 instanceof IdType)) {
|
||||
return false;
|
||||
}
|
||||
IdType id = (IdType)theArg0;
|
||||
return StringUtils.equals(getValueAsString(), id.getValueAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCodeBuilder b = new HashCodeBuilder();
|
||||
b.append(getValueAsString());
|
||||
return b.toHashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the portion of this resource ID which corresponds to the server base URL. For example given the resource ID <code>http://example.com/fhir/Patient/123</code> the base URL would be
|
||||
* <code>http://example.com/fhir</code>.
|
||||
* <p>
|
||||
* This method may return null if the ID contains no base (e.g. "Patient/123")
|
||||
* </p>
|
||||
*/
|
||||
public String getBaseUrl() {
|
||||
return myBaseUrl;
|
||||
}
|
||||
|
||||
public String getIdPart() {
|
||||
return myUnqualifiedId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unqualified portion of this ID as a big decimal, or <code>null</code> if the value is null
|
||||
*
|
||||
* @throws NumberFormatException
|
||||
* If the value is not a valid BigDecimal
|
||||
*/
|
||||
public BigDecimal getIdPartAsBigDecimal() {
|
||||
String val = getIdPart();
|
||||
if (isBlank(val)) {
|
||||
return null;
|
||||
}
|
||||
return new BigDecimal(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unqualified portion of this ID as a {@link Long}, or <code>null</code> if the value is null
|
||||
*
|
||||
* @throws NumberFormatException
|
||||
* If the value is not a valid Long
|
||||
*/
|
||||
public Long getIdPartAsLong() {
|
||||
String val = getIdPart();
|
||||
if (isBlank(val)) {
|
||||
return null;
|
||||
}
|
||||
return Long.parseLong(val);
|
||||
}
|
||||
|
||||
public String getResourceType() {
|
||||
return myResourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this ID. Note that this value may be a fully qualified URL, a relative/partial URL, or a simple ID. Use {@link #getIdPart()} to get just the ID portion.
|
||||
*
|
||||
* @see #getIdPart()
|
||||
*/
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (myValue == null && myHaveComponentParts) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
if (isNotBlank(myBaseUrl)) {
|
||||
b.append(myBaseUrl);
|
||||
if (myBaseUrl.charAt(myBaseUrl.length()-1)!='/') {
|
||||
b.append('/');
|
||||
}
|
||||
}
|
||||
|
||||
if (isNotBlank(myResourceType)) {
|
||||
b.append(myResourceType);
|
||||
}
|
||||
|
||||
if (b.length() > 0) {
|
||||
b.append('/');
|
||||
}
|
||||
|
||||
b.append(myUnqualifiedId);
|
||||
if (isNotBlank(myUnqualifiedVersionId)) {
|
||||
b.append('/');
|
||||
b.append(Constants.PARAM_HISTORY);
|
||||
b.append('/');
|
||||
b.append(myUnqualifiedVersionId);
|
||||
}
|
||||
String value = b.toString();
|
||||
myValue = value;
|
||||
}
|
||||
return myValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString() {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
public String getVersionIdPart() {
|
||||
return myUnqualifiedVersionId;
|
||||
}
|
||||
|
||||
public Long getVersionIdPartAsLong() {
|
||||
if (!hasVersionIdPart()) {
|
||||
return null;
|
||||
} else {
|
||||
return Long.parseLong(getVersionIdPart());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this ID has a base url
|
||||
*
|
||||
* @see #getBaseUrl()
|
||||
*/
|
||||
public boolean hasBaseUrl() {
|
||||
return isNotBlank(myBaseUrl);
|
||||
}
|
||||
|
||||
public boolean hasIdPart() {
|
||||
return isNotBlank(getIdPart());
|
||||
}
|
||||
|
||||
public boolean hasResourceType() {
|
||||
return isNotBlank(myResourceType);
|
||||
}
|
||||
|
||||
public boolean hasVersionIdPart() {
|
||||
return isNotBlank(getVersionIdPart());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if this ID contains an absolute URL (in other words, a URL starting with "http://" or "https://"
|
||||
*/
|
||||
public boolean isAbsolute() {
|
||||
if (StringUtils.isBlank(getValue())) {
|
||||
return false;
|
||||
}
|
||||
return UrlUtil.isAbsolute(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the unqualified ID is a valid {@link Long} value (in other words, it consists only of digits)
|
||||
*/
|
||||
public boolean isIdPartValidLong() {
|
||||
String id = getIdPart();
|
||||
if (StringUtils.isBlank(id)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < id.length(); i++) {
|
||||
if (Character.isDigit(id.charAt(i)) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the ID is a local reference (in other words, it begins with the '#' character)
|
||||
*/
|
||||
public boolean isLocal() {
|
||||
return myUnqualifiedId != null && myUnqualifiedId.isEmpty() == false && myUnqualifiedId.charAt(0) == '#';
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the value from the given IdDt to <code>this</code> IdDt. It is generally not neccesary to use this method but it is provided for consistency with the rest of the API.
|
||||
*/
|
||||
public void setId(IdType theId) {
|
||||
setValue(theId.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value
|
||||
*
|
||||
* <p>
|
||||
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
|
||||
* limit of 36 characters.
|
||||
* </p>
|
||||
* <p>
|
||||
* regex: [a-z0-9\-\.]{1,36}
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public IdType setValue(String theValue) throws DataFormatException {
|
||||
// TODO: add validation
|
||||
myValue = theValue;
|
||||
myHaveComponentParts = false;
|
||||
if (StringUtils.isBlank(theValue)) {
|
||||
myBaseUrl = null;
|
||||
myValue = null;
|
||||
myUnqualifiedId = null;
|
||||
myUnqualifiedVersionId = null;
|
||||
myResourceType = null;
|
||||
} else if (theValue.charAt(0)== '#') {
|
||||
myValue = theValue;
|
||||
myUnqualifiedId = theValue;
|
||||
myUnqualifiedVersionId=null;
|
||||
myResourceType = null;
|
||||
myHaveComponentParts = true;
|
||||
} else {
|
||||
int vidIndex = theValue.indexOf("/_history/");
|
||||
int idIndex;
|
||||
if (vidIndex != -1) {
|
||||
myUnqualifiedVersionId = theValue.substring(vidIndex + "/_history/".length());
|
||||
idIndex = theValue.lastIndexOf('/', vidIndex - 1);
|
||||
myUnqualifiedId = theValue.substring(idIndex + 1, vidIndex);
|
||||
} else {
|
||||
idIndex = theValue.lastIndexOf('/');
|
||||
myUnqualifiedId = theValue.substring(idIndex + 1);
|
||||
myUnqualifiedVersionId = null;
|
||||
}
|
||||
|
||||
myBaseUrl = null;
|
||||
if (idIndex <= 0) {
|
||||
myResourceType = null;
|
||||
} else {
|
||||
int typeIndex = theValue.lastIndexOf('/', idIndex - 1);
|
||||
if (typeIndex == -1) {
|
||||
myResourceType = theValue.substring(0, idIndex);
|
||||
} else {
|
||||
myResourceType = theValue.substring(typeIndex + 1, idIndex);
|
||||
|
||||
if (typeIndex > 4) {
|
||||
myBaseUrl = theValue.substring(0, typeIndex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value
|
||||
*
|
||||
* <p>
|
||||
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
|
||||
* limit of 36 characters.
|
||||
* </p>
|
||||
* <p>
|
||||
* regex: [a-z0-9\-\.]{1,36}
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public void setValueAsString(String theValue) throws DataFormatException {
|
||||
setValue(theValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new IdDt containing this IdDt's values but with no server base URL if one
|
||||
* is present in this IdDt. For example, if this IdDt contains the ID "http://foo/Patient/1",
|
||||
* this method will return a new IdDt containing ID "Patient/1".
|
||||
*/
|
||||
public IdType toUnqualified() {
|
||||
return new IdType(getResourceType(), getIdPart(), getVersionIdPart());
|
||||
}
|
||||
|
||||
public IdType toUnqualifiedVersionless() {
|
||||
return new IdType(getResourceType(), getIdPart());
|
||||
}
|
||||
|
||||
public IdType toVersionless() {
|
||||
return new IdType(getBaseUrl(), getResourceType(), getIdPart(), null);
|
||||
}
|
||||
|
||||
public IdType withResourceType(String theResourceName) {
|
||||
return new IdType(theResourceName, getIdPart(), getVersionIdPart());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a view of this ID as a fully qualified URL, given a server base and resource name (which will only be used if the ID does not already contain those respective parts). Essentially,
|
||||
* because IdDt can contain either a complete URL or a partial one (or even jut a simple ID), this method may be used to translate into a complete URL.
|
||||
*
|
||||
* @param theServerBase
|
||||
* The server base (e.g. "http://example.com/fhir")
|
||||
* @param theResourceType
|
||||
* The resource name (e.g. "Patient")
|
||||
* @return A fully qualified URL for this ID (e.g. "http://example.com/fhir/Patient/1")
|
||||
*/
|
||||
public IdType withServerBase(String theServerBase, String theResourceType) {
|
||||
return new IdType(theServerBase, theResourceType, getIdPart(), getVersionIdPart());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of this ID which is identical, but refers to the specific version of this resource ID noted by theVersion.
|
||||
*
|
||||
* @param theVersion
|
||||
* 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.
|
||||
*/
|
||||
public IdType withVersion(String theVersion) {
|
||||
Validate.notBlank(theVersion, "Version may not be null or empty");
|
||||
|
||||
String existingValue = getValue();
|
||||
|
||||
int i = existingValue.indexOf(Constants.PARAM_HISTORY);
|
||||
String value;
|
||||
if (i > 1) {
|
||||
value = existingValue.substring(0, i - 1);
|
||||
} else {
|
||||
value = existingValue;
|
||||
}
|
||||
|
||||
return new IdType(value + '/' + Constants.PARAM_HISTORY + '/' + theVersion);
|
||||
}
|
||||
|
||||
private static String toPlainStringWithNpeThrowIfNeeded(BigDecimal theIdPart) {
|
||||
if (theIdPart == null) {
|
||||
throw new NullPointerException("BigDecimal ID can not be null");
|
||||
}
|
||||
return theIdPart.toPlainString();
|
||||
}
|
||||
|
||||
private static String toPlainStringWithNpeThrowIfNeeded(Long theIdPart) {
|
||||
if (theIdPart == null) {
|
||||
throw new NullPointerException("Long ID can not be null");
|
||||
}
|
||||
return theIdPart.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return isBlank(getValue());
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public void applyTo(IBaseResource theResouce) {
|
||||
if (theResouce == null) {
|
||||
throw new NullPointerException("theResource can not be null");
|
||||
} else if (theResouce instanceof IResource) {
|
||||
((IResource) theResouce).setId(new IdType(getValue()));
|
||||
} else if (theResouce instanceof IAnyResource) {
|
||||
((IAnyResource) theResouce).setId(getIdPart());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown resource class type, does not implement IResource or extend Resource");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the ID from the given resource instance
|
||||
*/
|
||||
public static IdType of(IBaseResource theResouce) {
|
||||
if (theResouce == null) {
|
||||
throw new NullPointerException("theResource can not be null");
|
||||
} else if (theResouce instanceof IResource) {
|
||||
return ((IBaseResource) theResouce).getIdElement();
|
||||
} else if (theResouce instanceof IAnyResource) {
|
||||
// TODO: implement
|
||||
throw new UnsupportedOperationException();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown resource class type, does not implement IResource or extend Resource");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdType copy() {
|
||||
return new IdType(getValue());
|
||||
}
|
||||
|
||||
}
|
||||
=======
|
||||
@Override
|
||||
public IdType copy() {
|
||||
return new IdType(getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
>>>>>>> 2edc7eadab64d171ddc1b7c971ff36b9eb55ce67
|
|
@ -42,7 +42,7 @@ import org.hl7.fhir.instance.model.annotations.Description;
|
|||
/**
|
||||
* A set of information summarized from a list of other resources.
|
||||
*/
|
||||
@ResourceDef(name = "List_", profile = "http://hl7.org/fhir/Profile/List_")
|
||||
@ResourceDef(name = "List", profile = "http://hl7.org/fhir/Profile/List_")
|
||||
public class List_ extends DomainResource {
|
||||
|
||||
public enum ListMode {
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.hl7.fhir.instance.model.IdType;
|
|||
import org.hl7.fhir.instance.model.Identifier;
|
||||
import org.hl7.fhir.instance.model.Identifier.IdentifierUseEnumFactory;
|
||||
import org.hl7.fhir.instance.model.IntegerType;
|
||||
import org.hl7.fhir.instance.model.List_;
|
||||
import org.hl7.fhir.instance.model.Meta;
|
||||
import org.hl7.fhir.instance.model.Narrative;
|
||||
import org.hl7.fhir.instance.model.PrimitiveType;
|
||||
|
@ -53,6 +54,8 @@ import org.hl7.fhir.instance.model.api.IReference;
|
|||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
|
||||
public class ModelInheritanceTest {
|
||||
/*
|
||||
* <pre>
|
||||
|
@ -75,6 +78,13 @@ public class ModelInheritanceTest {
|
|||
* </pre>
|
||||
*/
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
|
||||
|
||||
@Test
|
||||
public void testList() {
|
||||
assertEquals("List", ourCtx.getResourceDefinition(List_.class).getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* This one should apply to all composite types
|
||||
*/
|
||||
|
|
|
@ -85,11 +85,12 @@ public class JsonParserTest {
|
|||
ourLog.info(out);
|
||||
assertThat(out, containsString("<div>hello</div>"));
|
||||
|
||||
p.getText().setDivAsString("<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">hello</xhtml:div>");
|
||||
out = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b);
|
||||
ourLog.info(out);
|
||||
// Backslashes need to be escaped because they are in a JSON value
|
||||
assertThat(out, containsString("<xhtml:div xmlns:xhtml=\\\"http://www.w3.org/1999/xhtml\\\">hello</xhtml:div>"));
|
||||
// TODO: what's the right thing to do here?
|
||||
// p.getText().setDivAsString("<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">hello</xhtml:div>");
|
||||
// out = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b);
|
||||
// ourLog.info(out);
|
||||
// // Backslashes need to be escaped because they are in a JSON value
|
||||
// assertThat(out, containsString("<div>hello</div>"));
|
||||
|
||||
}
|
||||
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -202,7 +202,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<servlet_api_version>3.1.0</servlet_api_version>
|
||||
<slf4j_version>1.7.10</slf4j_version>
|
||||
<spring_version>4.1.6.RELEASE</spring_version>
|
||||
<spring_version>4.1.5.RELEASE</spring_version>
|
||||
<spring_security_version>3.2.4.RELEASE</spring_security_version>
|
||||
<thymeleaf-version>2.1.4.RELEASE</thymeleaf-version>
|
||||
<ebay_cors_filter_version>1.0.1</ebay_cors_filter_version>
|
||||
|
|
Loading…
Reference in New Issue