Get all of the unit tests passing for DSTU1/DSTU2 split
This commit is contained in:
parent
96fe70de59
commit
18acda7be2
|
@ -20,6 +20,7 @@ package ca.uhn.fhir.context;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -173,6 +174,13 @@ public class FhirContext {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public RuntimeResourceDefinition getResourceDefinition(Class<? extends IBaseResource> theResourceType) {
|
||||
if (theResourceType == null) {
|
||||
throw new NullPointerException("theResourceType can not be null");
|
||||
}
|
||||
if (Modifier.isAbstract(theResourceType.getModifiers())) {
|
||||
throw new IllegalArgumentException("Can not scan abstract or interface class (resource definitions must be concrete classes): " + theResourceType.getName());
|
||||
}
|
||||
|
||||
RuntimeResourceDefinition retVal = (RuntimeResourceDefinition) myClassToElementDefinition.get(theResourceType);
|
||||
if (retVal == null) {
|
||||
retVal = scanResourceType((Class<? extends IResource>) theResourceType);
|
||||
|
@ -398,6 +406,9 @@ public class FhirContext {
|
|||
}
|
||||
|
||||
public void setNarrativeGenerator(INarrativeGenerator theNarrativeGenerator) {
|
||||
if (theNarrativeGenerator != null) {
|
||||
theNarrativeGenerator.setFhirContext(this);
|
||||
}
|
||||
myNarrativeGenerator = theNarrativeGenerator;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||
import ca.uhn.fhir.model.primitive.BoundCodeDt;
|
||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||
import ca.uhn.fhir.model.primitive.DecimalDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
||||
|
@ -45,7 +46,7 @@ public class BundleEntry extends BaseBundle {
|
|||
private StringDt myDeletedByEmail;
|
||||
private StringDt myDeletedByName;
|
||||
private StringDt myDeletedComment;
|
||||
private StringDt myDeletedResourceId;
|
||||
private IdDt myDeletedResourceId;
|
||||
private CodeDt myDeletedResourceType;
|
||||
private StringDt myDeletedResourceVersion;
|
||||
private StringDt myLinkAlternate;
|
||||
|
@ -61,7 +62,8 @@ public class BundleEntry extends BaseBundle {
|
|||
private InstantDt myUpdated;
|
||||
|
||||
/**
|
||||
* @deprecated Tags wil become immutable in a future release of HAPI, so {@link #addCategory(String, String, String)} should be used instead
|
||||
* @deprecated Tags wil become immutable in a future release of HAPI, so
|
||||
* {@link #addCategory(String, String, String)} should be used instead
|
||||
*/
|
||||
public Tag addCategory() {
|
||||
Tag retVal = new Tag();
|
||||
|
@ -115,9 +117,9 @@ public class BundleEntry extends BaseBundle {
|
|||
return myDeletedComment;
|
||||
}
|
||||
|
||||
public StringDt getDeletedResourceId() {
|
||||
public IdDt getDeletedResourceId() {
|
||||
if (myDeletedResourceId == null) {
|
||||
myDeletedResourceId = new StringDt();
|
||||
myDeletedResourceId = new IdDt();
|
||||
}
|
||||
return myDeletedResourceId;
|
||||
}
|
||||
|
@ -136,6 +138,16 @@ public class BundleEntry extends BaseBundle {
|
|||
return myDeletedResourceVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Setting IDs on bundle entries is redundant since resources already have an ID field. Instead of
|
||||
* providing an ID using this method, set the ID on the resource using {@link IResource#setId(IdDt)} or
|
||||
* if this entry represents a deleted resource, use {@link #setDeletedResourceId(IdDt)}.
|
||||
*/
|
||||
@Override
|
||||
public IdDt getId() {
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
public StringDt getLinkAlternate() {
|
||||
if (myLinkAlternate == null) {
|
||||
myLinkAlternate = new StringDt();
|
||||
|
@ -143,6 +155,9 @@ public class BundleEntry extends BaseBundle {
|
|||
return myLinkAlternate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use resource ID to determine base URL
|
||||
*/
|
||||
public StringDt getLinkBase() {
|
||||
if (myLinkBase == null) {
|
||||
myLinkBase = new StringDt();
|
||||
|
@ -204,8 +219,10 @@ public class BundleEntry extends BaseBundle {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated <b>DSTU2 Note:</b> As of DSTU2, bundle entries no longer have an updated time (this bit of metadata has been moved to the resource <meta/> element so it is redundant here). In
|
||||
* preparation for DSTU2, it is recommended that you migrate code away from using this method and over to using resource metadata instead.
|
||||
* @deprecated <b>DSTU2 Note:</b> As of DSTU2, bundle entries no longer have an updated time (this bit of metadata
|
||||
* has been moved to the resource <meta/> element so it is redundant here). In preparation for
|
||||
* DSTU2, it is recommended that you migrate code away from using this method and over to using resource
|
||||
* metadata instead.
|
||||
*/
|
||||
public InstantDt getUpdated() {
|
||||
if (myUpdated == null) {
|
||||
|
@ -224,7 +241,11 @@ public class BundleEntry extends BaseBundle {
|
|||
public boolean isEmpty() {
|
||||
//@formatter:off
|
||||
return super.isEmpty() &&
|
||||
ElementUtil.isEmpty(myDeletedResourceId, myDeletedResourceType, myDeletedResourceVersion, myScore,myStatus, myCategories, myDeletedAt, myLinkAlternate, myLinkSelf, myPublished, myResource, mySummary, myTitle, myUpdated, myDeletedByEmail, myDeletedByName, myDeletedComment);
|
||||
ElementUtil.isEmpty(
|
||||
myDeletedResourceId, myDeletedResourceType, myDeletedResourceVersion, myDeletedAt,
|
||||
myScore, myStatus, myCategories,
|
||||
myLinkAlternate, myLinkSelf, myPublished, myResource, mySummary,
|
||||
myTitle, myUpdated, myDeletedByEmail, myDeletedByName, myDeletedComment);
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
|
@ -250,7 +271,7 @@ public class BundleEntry extends BaseBundle {
|
|||
myDeletedComment = theDeletedComment;
|
||||
}
|
||||
|
||||
public void setDeletedResourceId(StringDt theDeletedResourceId) {
|
||||
public void setDeletedResourceId(IdDt theDeletedResourceId) {
|
||||
myDeletedResourceId = theDeletedResourceId;
|
||||
}
|
||||
|
||||
|
@ -262,10 +283,21 @@ public class BundleEntry extends BaseBundle {
|
|||
myDeletedResourceVersion = theDeletedResourceVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Bundle entries no longer have an ID in DSTU2, as ID is explicitly stated in the resource itself.
|
||||
*/
|
||||
@Override
|
||||
public void setId(IdDt theId) {
|
||||
super.setId(theId);
|
||||
}
|
||||
|
||||
public void setLinkAlternate(StringDt theLinkAlternate) {
|
||||
myLinkAlternate = theLinkAlternate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use resource ID to determine base URL
|
||||
*/
|
||||
public void setLinkBase(StringDt theLinkBase) {
|
||||
myLinkBase = theLinkBase;
|
||||
}
|
||||
|
@ -299,8 +331,10 @@ public class BundleEntry extends BaseBundle {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated <b>DSTU2 Note:</b> As of DSTU2, bundle entries no longer have an updated time (this bit of metadata has been moved to the resource <meta/> element so it is redundant here). In
|
||||
* preparation for DSTU2, it is recommended that you migrate code away from using this method and over to using resource metadata instead.
|
||||
* @deprecated <b>DSTU2 Note:</b> As of DSTU2, bundle entries no longer have an updated time (this bit of metadata
|
||||
* has been moved to the resource <meta/> element so it is redundant here). In preparation for
|
||||
* DSTU2, it is recommended that you migrate code away from using this method and over to using resource
|
||||
* metadata instead.
|
||||
*/
|
||||
public void setUpdated(InstantDt theUpdated) {
|
||||
Validate.notNull(theUpdated, "Updated may not be null");
|
||||
|
|
|
@ -61,6 +61,8 @@ import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
|
|||
import org.thymeleaf.templateresolver.TemplateResolver;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IDatatype;
|
||||
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
|
||||
import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum;
|
||||
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
||||
|
@ -70,7 +72,7 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseThymeleafNarrativeGenerator.class);
|
||||
private static final XhtmlAndHtml5NonValidatingSAXTemplateParser PARSER = new XhtmlAndHtml5NonValidatingSAXTemplateParser(1);
|
||||
|
||||
private Configuration configuration;
|
||||
private Configuration myThymeleafConfig;
|
||||
private boolean myApplyDefaultDatatypeTemplates = true;
|
||||
private HashMap<Class<?>, String> myClassToName;
|
||||
private boolean myCleanWhitespace = true;
|
||||
|
@ -84,16 +86,27 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
private TemplateEngine myTitleTemplateEngine;
|
||||
|
||||
public BaseThymeleafNarrativeGenerator() {
|
||||
configuration = new Configuration();
|
||||
configuration.addTemplateResolver(new ClassLoaderTemplateResolver());
|
||||
configuration.addMessageResolver(new StandardMessageResolver());
|
||||
configuration.setTemplateModeHandlers(StandardTemplateModeHandlers.ALL_TEMPLATE_MODE_HANDLERS);
|
||||
configuration.initialize();
|
||||
myThymeleafConfig = new Configuration();
|
||||
myThymeleafConfig.addTemplateResolver(new ClassLoaderTemplateResolver());
|
||||
myThymeleafConfig.addMessageResolver(new StandardMessageResolver());
|
||||
myThymeleafConfig.setTemplateModeHandlers(StandardTemplateModeHandlers.ALL_TEMPLATE_MODE_HANDLERS);
|
||||
myThymeleafConfig.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NarrativeDt generateNarrative(IBaseResource theResource) {
|
||||
return generateNarrative(null, theResource);
|
||||
return generateNarrative( null, theResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFhirContext(FhirContext theFhirContext) {
|
||||
if (theFhirContext == null) {
|
||||
throw new NullPointerException("Can not set theFhirContext to null");
|
||||
}
|
||||
if (myFhirContext != null && myFhirContext != theFhirContext) {
|
||||
throw new IllegalStateException("Narrative generators may not be reused/shared across multiple FhirContext instances");
|
||||
}
|
||||
myFhirContext = theFhirContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,6 +122,9 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
if (name == null) {
|
||||
name = myClassToName.get(theResource.getClass());
|
||||
}
|
||||
if (name == null) {
|
||||
name = myFhirContext.getResourceDefinition(theResource).getName().toLowerCase();
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
if (myIgnoreMissingTemplates) {
|
||||
|
@ -145,7 +161,7 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
|
||||
@Override
|
||||
public String generateTitle(IBaseResource theResource) {
|
||||
return generateTitle(null, theResource);
|
||||
return generateTitle( null, theResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,6 +179,9 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
if (name == null) {
|
||||
name = myClassToName.get(theResource.getClass());
|
||||
}
|
||||
if (name == null) {
|
||||
name = myFhirContext.getResourceDefinition(theResource).getName().toLowerCase();
|
||||
}
|
||||
|
||||
ourLog.trace("Template name is {}", name);
|
||||
|
||||
|
@ -235,7 +254,7 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
protected abstract List<String> getPropertyFile();
|
||||
|
||||
private Document getXhtmlDOMFor(final Reader source) {
|
||||
final Configuration configuration1 = configuration;
|
||||
final Configuration configuration1 = myThymeleafConfig;
|
||||
try {
|
||||
return PARSER.parseTemplate(configuration1, "input", source);
|
||||
} catch (final Exception e) {
|
||||
|
@ -371,32 +390,42 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
try {
|
||||
clazz = Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
ourLog.warn("Unknown datatype class '{}' identified in narrative file {}", name, propFileName);
|
||||
ourLog.debug("Unknown datatype class '{}' identified in narrative file {}", name, propFileName);
|
||||
clazz = null;
|
||||
}
|
||||
|
||||
// if (isBlank(narrativeName) && isBlank(titleName)) {
|
||||
// throw new ConfigurationException("Found property '" + nextKey + "' but no corresponding property '" + narrativePropName + "' or '" + titlePropName + "' in file " + propFileName);
|
||||
// }
|
||||
|
||||
if (clazz != null) {
|
||||
myClassToName.put(clazz, name);
|
||||
}
|
||||
|
||||
} else if (nextKey.endsWith(".narrative")) {
|
||||
String name = nextKey.substring(0, nextKey.indexOf(".narrative"));
|
||||
if (isBlank(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String narrativePropName = name + ".narrative";
|
||||
String narrativeName = file.getProperty(narrativePropName);
|
||||
String titlePropName = name + ".title";
|
||||
String titleName = file.getProperty(titlePropName);
|
||||
if (isBlank(narrativeName) && isBlank(titleName)) {
|
||||
throw new ConfigurationException("Found property '" + nextKey + "' but no corresponding property '" + narrativePropName + "' or '" + titlePropName + "' in file " + propFileName);
|
||||
}
|
||||
|
||||
myClassToName.put(clazz, name);
|
||||
|
||||
if (StringUtils.isNotBlank(narrativeName)) {
|
||||
String narrative = IOUtils.toString(loadResource(narrativeName));
|
||||
myNameToNarrativeTemplate.put(name, narrative);
|
||||
}
|
||||
continue;
|
||||
} else if (nextKey.endsWith(".title")) {
|
||||
String name = nextKey.substring(0, nextKey.indexOf(".title"));
|
||||
if (isBlank(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String titlePropName = name + ".title";
|
||||
String titleName = file.getProperty(titlePropName);
|
||||
if (StringUtils.isNotBlank(titleName)) {
|
||||
String title = IOUtils.toString(loadResource(titleName));
|
||||
myNameToTitleTemplate.put(name, title);
|
||||
}
|
||||
|
||||
} else if (nextKey.endsWith(".narrative")) {
|
||||
continue;
|
||||
} else if (nextKey.endsWith(".title")) {
|
||||
continue;
|
||||
} else {
|
||||
throw new ConfigurationException("Invalid property name: " + nextKey);
|
||||
|
@ -516,9 +545,12 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
private FhirContext myFhirContext;
|
||||
|
||||
public class NarrativeAttributeProcessor extends AbstractAttrProcessor {
|
||||
|
||||
|
||||
protected NarrativeAttributeProcessor() {
|
||||
super("narrative");
|
||||
}
|
||||
|
@ -555,6 +587,21 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
name = myClassToName.get(nextClass);
|
||||
nextClass = nextClass.getSuperclass();
|
||||
} while (name == null && nextClass.equals(Object.class) == false);
|
||||
|
||||
if (name == null) {
|
||||
if (value instanceof IBaseResource) {
|
||||
name = myFhirContext.getResourceDefinition((IBaseResource)value).getName();
|
||||
} else if (value instanceof IDatatype) {
|
||||
name = value.getClass().getSimpleName();
|
||||
name = name.substring(0, name.length() - 2);
|
||||
} else {
|
||||
throw new DataFormatException("Don't know how to determine name for type: " + value.getClass());
|
||||
}
|
||||
name = name.toLowerCase();
|
||||
if (!myNameToNarrativeTemplate.containsKey(name)) {
|
||||
name = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
|
@ -568,19 +615,23 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
|
|||
|
||||
String result = myProfileTemplateEngine.process(name, context);
|
||||
String trim = result.trim();
|
||||
Document dom = getXhtmlDOMFor(new StringReader(trim));
|
||||
|
||||
Element firstChild = (Element) dom.getFirstChild();
|
||||
for (int i = 0; i < firstChild.getChildren().size(); i++) {
|
||||
Node next = firstChild.getChildren().get(i);
|
||||
if (i == 0 && firstChild.getChildren().size() == 1) {
|
||||
if (next instanceof org.thymeleaf.dom.Text) {
|
||||
org.thymeleaf.dom.Text nextText = (org.thymeleaf.dom.Text) next;
|
||||
nextText.setContent(nextText.getContent().trim());
|
||||
if (!isBlank(trim + "AAA")) {
|
||||
Document dom = getXhtmlDOMFor(new StringReader(trim));
|
||||
|
||||
Element firstChild = (Element) dom.getFirstChild();
|
||||
for (int i = 0; i < firstChild.getChildren().size(); i++) {
|
||||
Node next = firstChild.getChildren().get(i);
|
||||
if (i == 0 && firstChild.getChildren().size() == 1) {
|
||||
if (next instanceof org.thymeleaf.dom.Text) {
|
||||
org.thymeleaf.dom.Text nextText = (org.thymeleaf.dom.Text) next;
|
||||
nextText.setContent(nextText.getContent().trim());
|
||||
}
|
||||
}
|
||||
theElement.addChild(next);
|
||||
}
|
||||
theElement.addChild(next);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return ProcessorResult.ok();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package ca.uhn.fhir.narrative;
|
|||
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
|
||||
|
@ -35,4 +36,9 @@ public interface INarrativeGenerator {
|
|||
|
||||
String generateTitle(String theProfile, IBaseResource theResource);
|
||||
|
||||
/**
|
||||
* This method is called automatically by the framework, you do not need to interact with this method.
|
||||
*/
|
||||
void setFhirContext(FhirContext theFhirContext);
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import ca.uhn.fhir.context.ConfigurationException;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeChildChoiceDefinition;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
|
||||
|
@ -68,6 +69,21 @@ public abstract class BaseParser implements IParser {
|
|||
return theValue;
|
||||
}
|
||||
|
||||
protected String determineResourceBaseUrl(String bundleBaseUrl, BundleEntry theEntry) {
|
||||
IResource resource = theEntry.getResource();
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String resourceBaseUrl = null;
|
||||
if (resource.getId() != null && resource.getId().hasBaseUrl()) {
|
||||
if (!resource.getId().getBaseUrl().equals(bundleBaseUrl)) {
|
||||
resourceBaseUrl = resource.getId().getBaseUrl();
|
||||
}
|
||||
}
|
||||
return resourceBaseUrl;
|
||||
}
|
||||
|
||||
private void containResourcesForEncoding(ContainedResources theContained, IBaseResource theResource, IBaseResource theTarget) {
|
||||
|
||||
Set<String> allIds = new HashSet<String>();
|
||||
|
|
|
@ -245,7 +245,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
|
||||
theEventWriter.write("resourceType", "Bundle");
|
||||
|
||||
writeTagWithTextNode(theEventWriter, "id", theBundle.getId().getIdPart());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "id", theBundle.getId().getIdPart());
|
||||
|
||||
if (!ElementUtil.isEmpty(theBundle.getId().getVersionIdPart(), theBundle.getUpdated())) {
|
||||
theEventWriter.writeStartObject("meta");
|
||||
|
@ -272,7 +272,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
for (BundleEntry nextEntry : theBundle.getEntries()) {
|
||||
theEventWriter.writeStartObject();
|
||||
|
||||
writeOptionalTagWithTextNode(theEventWriter, "base", nextEntry.getLinkBase());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "base", determineResourceBaseUrl(theBundle.getLinkBase().getValue(), nextEntry));
|
||||
writeOptionalTagWithTextNode(theEventWriter, "status", nextEntry.getStatus());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "search", nextEntry.getLinkSearch());
|
||||
writeOptionalTagWithDecimalNode(theEventWriter, "score", nextEntry.getScore());
|
||||
|
|
|
@ -170,8 +170,14 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
deleted = true;
|
||||
eventWriter.writeStartElement("at", "deleted-entry", TOMBSTONES_NS);
|
||||
eventWriter.writeNamespace("at", TOMBSTONES_NS);
|
||||
eventWriter.writeAttribute("ref", nextEntry.getId().getValueAsString());
|
||||
eventWriter.writeAttribute("when", nextEntry.getDeletedAt().getValueAsString());
|
||||
|
||||
if (nextEntry.getDeletedResourceId().isEmpty()) {
|
||||
writeOptionalAttribute(eventWriter, "ref", nextEntry.getId().getValueAsString());
|
||||
} else {
|
||||
writeOptionalAttribute(eventWriter, "ref", nextEntry.getDeletedResourceId().getValueAsString());
|
||||
}
|
||||
|
||||
writeOptionalAttribute(eventWriter, "when", nextEntry.getDeletedAt().getValueAsString());
|
||||
if (nextEntry.getDeletedByEmail().isEmpty() == false || nextEntry.getDeletedByName().isEmpty() == false) {
|
||||
eventWriter.writeStartElement(TOMBSTONES_NS, "by");
|
||||
if (nextEntry.getDeletedByName().isEmpty() == false) {
|
||||
|
@ -197,7 +203,11 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
|
||||
writeOptionalTagWithTextNode(eventWriter, "title", nextEntry.getTitle());
|
||||
if (!deleted) {
|
||||
writeTagWithTextNode(eventWriter, "id", nextEntry.getId());
|
||||
if (nextEntry.getId().isEmpty() == false) {
|
||||
writeTagWithTextNode(eventWriter, "id", nextEntry.getId());
|
||||
} else {
|
||||
writeTagWithTextNode(eventWriter, "id", nextEntry.getResource().getId());
|
||||
}
|
||||
}
|
||||
writeOptionalTagWithTextNode(eventWriter, "updated", nextEntry.getUpdated());
|
||||
writeOptionalTagWithTextNode(eventWriter, "published", nextEntry.getPublished());
|
||||
|
@ -240,6 +250,12 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
eventWriter.close();
|
||||
}
|
||||
|
||||
private void writeOptionalAttribute(XMLStreamWriter theEventWriter, String theName, String theValue) throws XMLStreamException {
|
||||
if (StringUtils.isNotBlank(theValue)) {
|
||||
theEventWriter.writeAttribute(theName, theValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void encodeBundleToWriterUsingBundleResource(Bundle theBundle, XMLStreamWriter theEventWriter) throws XMLStreamException {
|
||||
theEventWriter.writeStartElement("Bundle");
|
||||
theEventWriter.writeDefaultNamespace(FHIR_NS);
|
||||
|
@ -273,11 +289,7 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
theEventWriter.writeStartElement("entry");
|
||||
|
||||
IResource nextResource = nextEntry.getResource();
|
||||
if (nextResource.getId() != null && nextResource.getId().hasBaseUrl()) {
|
||||
if (!nextResource.getId().getBaseUrl().equals(bundleBaseUrl)) {
|
||||
writeOptionalTagWithValue(theEventWriter, "base", nextResource.getId().getBaseUrl());
|
||||
}
|
||||
}
|
||||
writeOptionalTagWithValue(theEventWriter, "base", determineResourceBaseUrl(bundleBaseUrl, nextEntry));
|
||||
|
||||
writeOptionalTagWithValue(theEventWriter, "status", nextEntry.getStatus().getValue());
|
||||
writeOptionalTagWithValue(theEventWriter, "search", nextEntry.getLinkSearch().getValue());
|
||||
|
|
|
@ -22,6 +22,7 @@ package ca.uhn.fhir.rest.method;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
|
@ -58,18 +59,22 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
|
|||
}
|
||||
|
||||
resourceParameter = (ResourceParameter) next;
|
||||
Class<? extends IResource> resourceType = resourceParameter.getResourceType();
|
||||
Class<? extends IResource> providerResourceType = resourceParameter.getResourceType();
|
||||
|
||||
if (theProvider instanceof IResourceProvider) {
|
||||
resourceType = ((IResourceProvider) theProvider).getResourceType();
|
||||
providerResourceType = ((IResourceProvider) theProvider).getResourceType();
|
||||
}
|
||||
|
||||
if (resourceType.isAssignableFrom(Binary.class)) {
|
||||
if (providerResourceType.isAssignableFrom(Binary.class)) {
|
||||
myBinary = true;
|
||||
}
|
||||
|
||||
myResourceType = resourceParameter.getResourceType();
|
||||
myResourceName = theContext.getResourceDefinition(myResourceType).getName();
|
||||
if (Modifier.isAbstract(myResourceType.getModifiers())) {
|
||||
myResourceType = providerResourceType;
|
||||
}
|
||||
|
||||
myResourceName = theContext.getResourceDefinition(providerResourceType).getName();
|
||||
|
||||
myResourceParameterIndex = index;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
|
|||
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeChildChoiceDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.model.api.ExtensionDt;
|
||||
import ca.uhn.fhir.model.api.IElement;
|
||||
|
@ -144,7 +145,18 @@ public class FhirTerser {
|
|||
List<Object> retVal = new ArrayList<Object>();
|
||||
|
||||
if (theSubList.size() == 1) {
|
||||
retVal.addAll(values);
|
||||
if (nextDef instanceof RuntimeChildChoiceDefinition) {
|
||||
for (IBase next : values) {
|
||||
if (next != null) {
|
||||
String childName = nextDef.getChildNameByDatatype(next.getClass());
|
||||
if (theSubList.get(0).equals(childName)) {
|
||||
retVal.add(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
retVal.addAll(values);
|
||||
}
|
||||
} else {
|
||||
for (IBase nextElement : values) {
|
||||
BaseRuntimeElementCompositeDefinition<?> nextChildDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(nextElement.getClass());
|
||||
|
|
|
@ -13,25 +13,25 @@
|
|||
display value on the first coding, and if that's missing too show a default "Untitled"
|
||||
value
|
||||
*/-->
|
||||
<th:block th:if="${not resource.name.text.empty}" th:text="${resource.name.text.value}"/>
|
||||
<th:block th:if=" ${resource.name.text.empty} and ${not resource.name.codingFirstRep.display.empty}" th:text="${resource.name.codingFirstRep.display}"/>
|
||||
<th:block th:if= "${resource.name.text.empty} and ${resource.name.codingFirstRep.display.empty}" th:text="Untitled Diagnostic Report"/>
|
||||
<th:block th:if="${not resource.name.textElement.empty}" th:text="${resource.name.textElement.value}"/>
|
||||
<th:block th:if=" ${resource.name.textElement.empty} and ${not resource.name.codingFirstRep.displayElement.empty}" th:text="${resource.name.codingFirstRep.display}"/>
|
||||
<th:block th:if= "${resource.name.textElement.empty} and ${resource.name.codingFirstRep.displayElement.empty}" th:text="Untitled Diagnostic Report"/>
|
||||
<!--/*--> Complete Blood Count <!--*/-->
|
||||
</div>
|
||||
|
||||
<table class="hapiPropertyTable">
|
||||
<tbody>
|
||||
<tr th:if="${not resource.status.empty}">
|
||||
<tr th:if="${not resource.statusElement.empty}">
|
||||
<td>Status</td>
|
||||
<td th:text="${resource.status.value}">Final</td>
|
||||
<td th:text="${resource.statusElement.value}">Final</td>
|
||||
</tr>
|
||||
<tr th:if="${not resource.issued.empty}">
|
||||
<tr th:if="${not resource.issuedElement.empty}">
|
||||
<td>Issued</td>
|
||||
<td th:narrative="${resource.issued}">22 March 2012</td>
|
||||
<td th:narrative="${resource.issuedElement}">22 March 2012</td>
|
||||
</tr>
|
||||
<tr th:if="${not resource.conclusion.empty}">
|
||||
<tr th:if="${not resource.conclusionElement.empty}">
|
||||
<td>Conclusion</td>
|
||||
<td th:narrative="${resource.conclusion}">This is the conclusion text</td>
|
||||
<td th:narrative="${resource.conclusionElement}">This is the conclusion text</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -50,15 +50,15 @@
|
|||
<th:block th:each="result,rowStat : ${resource.result}">
|
||||
<tr th:class="${rowStat.odd}? 'hapiTableOfValuesRowOdd' : 'hapiTableOfValuesRowEven'" class="hapiTableOfValuesRowOdd">
|
||||
<td>
|
||||
<th:block th:if="${not result.resource.name.text.empty}" th:text="${result.resource.name.text.value}"/>
|
||||
<th:block th:if="${result.resource.name.text.empty} and ${not #lists.isEmpty(result.resource.name.coding)} and ${not result.resource.name.coding[0].empty} and ${not result.resource.name.coding[0].display.empty}" th:text="${result.resource.name.coding[0].display}"/>
|
||||
<th:block th:if="${result.resource.name.text.empty} and ${not #lists.isEmpty(result.resource.name.coding)} and ${not result.resource.name.coding[0].empty} and ${result.resource.name.coding[0].display.empty}" th:text="'?'"/>
|
||||
<th:block th:if="${not result.resource.name.textElement.empty}" th:text="${result.resource.name.textElement.value}"/>
|
||||
<th:block th:if="${result.resource.name.textElement.empty} and ${not #lists.isEmpty(result.resource.name.coding)} and ${not result.resource.name.coding[0].empty} and ${not result.resource.name.coding[0].displayElement.empty}" th:text="${result.resource.name.coding[0].display}"/>
|
||||
<th:block th:if="${result.resource.name.textElement.empty} and ${not #lists.isEmpty(result.resource.name.coding)} and ${not result.resource.name.coding[0].empty} and ${result.resource.name.coding[0].displayElement.empty}" th:text="'?'"/>
|
||||
<!--/*--> Hb <!--*/-->
|
||||
</td>
|
||||
<td th:narrative="${result.resource.value}">2.2 g/L</td>
|
||||
<td>
|
||||
<th:block th:if="${not result.resource.interpretation.text.empty}" th:text="${result.resource.interpretation.text}"/>
|
||||
<th:block th:if="${result.resource.interpretation.text.empty} and ${not result.resource.interpretation.codingFirstRep.display.empty}" th:text="${result.resource.interpretation.codingFirstRep.display}"/>
|
||||
<th:block th:if="${not result.resource.interpretation.textElement.empty}" th:text="${result.resource.interpretation.text}"/>
|
||||
<th:block th:if="${result.resource.interpretation.textElement.empty} and ${not result.resource.interpretation.codingFirstRep.displayElement.empty}" th:text="${result.resource.interpretation.codingFirstRep.display}"/>
|
||||
<!--/*--> N <!--*/-->
|
||||
</td>
|
||||
<td>
|
||||
|
@ -68,10 +68,10 @@
|
|||
<th:block th:narrative="${result.resource.referenceRange[0].high}">2.9 g/L</th:block>
|
||||
</th:block>
|
||||
</td>
|
||||
<td th:text="${result.resource.status.value}">final</td>
|
||||
<td th:text="${result.resource.statusElement.value}">final</td>
|
||||
</tr>
|
||||
<tr th:if="${not result.resource.comments.empty}" th:class="${rowStat.odd}? 'hapiTableOfValuesRowOdd' : 'hapiTableOfValuesRowEven'" class="hapiTableOfValuesRowOdd">
|
||||
<td th:text="${result.resource.comments.value}" colspan="5">This is a comment</td>
|
||||
<tr th:if="${not result.resource.commentsElement.empty}" th:class="${rowStat.odd}? 'hapiTableOfValuesRowOdd' : 'hapiTableOfValuesRowEven'" class="hapiTableOfValuesRowOdd">
|
||||
<td th:text="${result.resource.commentsElement.value}" colspan="5">This is a comment</td>
|
||||
</tr>
|
||||
|
||||
<!--/* The following are just examples that don't appear in the generated narrative -->
|
||||
|
|
|
@ -11,7 +11,7 @@ a browser.
|
|||
<!--*/-->
|
||||
|
||||
<div>
|
||||
<div class="hapiHeaderText" th:if="${not resource.name.empty}" th:narrative="${resource.name}"></div>
|
||||
<div class="hapiHeaderText" th:if="${not resource.nameElement.empty}" th:narrative="${resource.name}"></div>
|
||||
</div>
|
||||
|
||||
<!--/*-->
|
||||
|
|
|
@ -11,20 +11,20 @@ a browser.
|
|||
<!--*/-->
|
||||
|
||||
<div>
|
||||
<div class="hapiHeaderText" th:if="${not resource.medication.resource.name.empty}" th:narrative="${resource.medication.resource.name}"></div>
|
||||
<div class="hapiHeaderText" th:if="${not resource.medication.resource.nameElement.empty}" th:narrative="${resource.medication.resource.nameElement}"></div>
|
||||
<table class="hapiPropertyTable">
|
||||
<tbody>
|
||||
<tr th:if="${not resource.id.empty}">
|
||||
<td>Id</td>
|
||||
<td th:text="${resource.id.value}"></td>
|
||||
</tr>
|
||||
<tr th:if="${not resource.dateWritten.empty}">
|
||||
<tr th:if="${not resource.dateWrittenElement.empty}">
|
||||
<td>Date</td>
|
||||
<td ><span th:text="${#dates.format(resource.dateWritten.value,'dd MMMM yyyy')}"></span></td>
|
||||
<td ><span th:text="${#dates.format(resource.dateWrittenElement.value,'dd MMMM yyyy')}"></span></td>
|
||||
</tr>
|
||||
<tr th:if="${not resource.status.empty}">
|
||||
<tr th:if="${not resource.statusElement.empty}">
|
||||
<td>Status</td>
|
||||
<td><span th:text="${resource.status.valueAsEnum}"></span></td>
|
||||
<td><span th:text="${resource.statusElement.valueAsEnum}"></span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<h1>Operation Outcome</h1>
|
||||
<table border="0">
|
||||
<tr th:each="issue : ${resource.issue}">
|
||||
<td th:text="${issue.severity.value}" style="font-weight: bold;"></td>
|
||||
<td th:text="${issue.severityElement.value}" style="font-weight: bold;"></td>
|
||||
<td th:text="${issue.location}"></td>
|
||||
<td><pre th:text="${issue.details}"/></td>
|
||||
</tr>
|
||||
|
|
|
@ -22,9 +22,9 @@ a browser.
|
|||
<td>Address</td>
|
||||
<td th:narrative="${resource.addressFirstRep}"></td>
|
||||
</tr>
|
||||
<tr th:if="${not resource.birthDate.empty}">
|
||||
<tr th:if="${not resource.birthDateElement.empty}">
|
||||
<td>Date of birth</td>
|
||||
<td><span th:text="${#dates.format(resource.birthDate.value,'dd MMMM yyyy')}"></span></td>
|
||||
<td><span th:text="${#dates.format(resource.birthDateElement.value,'dd MMMM yyyy')}"></span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<th:block th:each="line : ${resource.line}">
|
||||
<span th:text="${line} + ' '">123 Fake Street</span><br/>
|
||||
</th:block>
|
||||
<span th:if="${not resource.city.empty}" th:text="${resource.city} + ' '">Toronto</span>
|
||||
<span th:if="${not resource.state.empty}" th:text="${resource.state} + ' '">ON</span>
|
||||
<span th:if="${not resource.country.empty}" th:text="${resource.country}+ ' '">Canada</span>
|
||||
<span th:if="${not resource.cityElement.empty}" th:text="${resource.city} + ' '">Toronto</span>
|
||||
<span th:if="${not resource.stateElement.empty}" th:text="${resource.state} + ' '">ON</span>
|
||||
<span th:if="${not resource.countryElement.empty}" th:text="${resource.country}+ ' '">Canada</span>
|
||||
</div>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<div>
|
||||
<th:block th:if="${not resource.text.empty}" th:text="${resource.text.value}"/>
|
||||
<th:block th:if="${resource.text.empty}">
|
||||
<th:block th:if="${not resource.textElement.empty}" th:text="${resource.textElement.value}"/>
|
||||
<th:block th:if="${resource.textElement.empty}">
|
||||
<th:block th:if="${!resource.codingFirstRep.empty}">
|
||||
<th:block th:if="${!resource.codingFirstRep.display.empty}" th:text="${!resource.codingFirstRep.display.value}"/>
|
||||
<th:block th:if="${resource.codingFirstRep.display.empty}">
|
||||
<th:block th:if="${!resource.codingFirstRep.code.empty}">
|
||||
<th:block th:text="${resource.codingFirstRep.code.value}"/>
|
||||
<th:block th:if="${!resource.codingFirstRep.displayElement.empty}" th:text="${!resource.codingFirstRep.displayElement.value}"/>
|
||||
<th:block th:if="${resource.codingFirstRep.displayElement.empty}">
|
||||
<th:block th:if="${!resource.codingFirstRep.codeElement.empty}">
|
||||
<th:block th:text="${resource.codingFirstRep.codeElement.value}"/>
|
||||
</th:block>
|
||||
</th:block>
|
||||
</th:block>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div>
|
||||
<th:block th:if="${!resource.label.empty}" th:text="${resource.label.value}"/>
|
||||
<th:block th:if="${resource.label.empty}" th:text="${resource.value.valueAsString}"/>
|
||||
<th:block th:if="${!resource.labelElement.empty}" th:text="${resource.labelElement.value}"/>
|
||||
<th:block th:if="${resource.labelElement.empty}" th:text="${resource.valueElement.valueAsString}"/>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div>
|
||||
<th:block th:if="${!resource.start.empty} and ${!resource.end.empty}" th:text="${resource.start.value} + ' - ' + ${resource.end.value}"/>
|
||||
<th:block th:if="${!resource.start.empty} and ${resource.end.empty}" th:text="${resource.start.value} + ' - ?'"/>
|
||||
<th:block th:if="${resource.start.empty} and ${!resource.end.empty}" th:text="'? - ' + ${resource.end.value}"/>
|
||||
<th:block th:if="${!resource.startElement.empty} and ${!resource.endElement.empty}" th:text="${resource.startElement.value} + ' - ' + ${resource.endElement.value}"/>
|
||||
<th:block th:if="${!resource.startElement.empty} and ${resource.endElement.empty}" th:text="${resource.startElement.value} + ' - ?'"/>
|
||||
<th:block th:if="${resource.startElement.empty} and ${!resource.endElement.empty}" th:text="'? - ' + ${resource.endElement.value}"/>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div>
|
||||
<th:block th:if="${not resource.comparator.empty}" th:text="${resource.comparator.value}"/>
|
||||
<th:block th:if="${not resource.value.empty}" th:text="${resource.value.valueAsString}"/>
|
||||
<th:block th:if="${not resource.units.empty}" th:text="${resource.units.value}"/>
|
||||
<th:block th:if="${not resource.comparatorElement.empty}" th:text="${resource.comparatorElement.value}"/>
|
||||
<th:block th:if="${not resource.valueElement.empty}" th:text="${resource.valueElement.valueAsString}"/>
|
||||
<th:block th:if="${not resource.unitsElement.empty}" th:text="${resource.unitsElement.value}"/>
|
||||
</div>
|
||||
|
|
|
@ -25,6 +25,7 @@ address.narrative=classpath:ca/uhn/fhir/narrative/datatype/AddressDt.html
|
|||
|
||||
codeableconcept.class=ca.uhn.fhir.model.dstu.composite.CodeableConceptDt
|
||||
codeableconcept.narrative=classpath:ca/uhn/fhir/narrative/datatype/CodeableConceptDt.html
|
||||
boundcodeableconcept.narrative=classpath:ca/uhn/fhir/narrative/datatype/CodeableConceptDt.html
|
||||
|
||||
humanname.class=ca.uhn.fhir.model.dstu.composite.HumanNameDt
|
||||
humanname.narrative=classpath:ca/uhn/fhir/narrative/datatype/HumanNameDt.html
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<div>
|
||||
<th:block th:if="${not resource.name.text.empty}" th:text="${resource.name.text.value}"/>
|
||||
<th:block th:if=" ${resource.name.text.empty} and ${not resource.name.codingFirstRep.display.empty}" th:text="${resource.name.codingFirstRep.display}"/>
|
||||
<th:block th:if= "${resource.name.text.empty} and ${resource.name.codingFirstRep.display.empty}" th:text="Untitled Diagnostic Report"/>
|
||||
<th:block th:if="${not resource.name.textElement.empty}" th:text="${resource.name.textElement.value}"/>
|
||||
<th:block th:if=" ${resource.name.textElement.empty} and ${not resource.name.codingFirstRep.displayElement.empty}" th:text="${resource.name.codingFirstRep.display}"/>
|
||||
<th:block th:if= "${resource.name.textElement.empty} and ${resource.name.codingFirstRep.displayElement.empty}" th:text="Untitled Diagnostic Report"/>
|
||||
|
||||
<th:block th:if="${not resource.status.empty}" th:text="' - ' + ${resource.status.value}"/>
|
||||
<th:block th:if="${not resource.statusElement.empty}" th:text="' - ' + ${resource.statusElement.value}"/>
|
||||
<th:block th:text="' - ' + ${resource.result.size} + ' observations'"/>
|
||||
|
||||
</div>
|
|
@ -1,13 +1,13 @@
|
|||
<div>
|
||||
<th:block th:if="${!resource.identifierFirstRep.empty}" th:narrative="${resource.identifierFirstRep}" />
|
||||
<th:block th:if="${not resource.status.empty}">
|
||||
/ <th:block th:narrative="${resource.status}"/>
|
||||
<th:block th:if="${not resource.statusElement.empty}">
|
||||
/ <th:block th:narrative="${resource.statusElement}"/>
|
||||
</th:block>
|
||||
<th:block th:if="${not resource.typeFirstRep.empty}">
|
||||
/ <th:block th:narrative="${resource.typeFirstRep}"/>
|
||||
</th:block>
|
||||
<th:block th:if="${not resource.classElement.empty}">
|
||||
/ <th:block th:narrative="${resource.classElement}"/>
|
||||
<th:block th:if="${not resource.classElementElement.empty}">
|
||||
/ <th:block th:narrative="${resource.classElementElement}"/>
|
||||
</th:block>
|
||||
<th:block th:if="${not resource.period.empty}">
|
||||
/ <th:block th:narrative="${resource.period}"/>
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<div>
|
||||
<div class="hapiHeaderText" th:if="${not resource.medication.resource.name.empty}" th:narrative="${resource.medication.resource.name}"></div>
|
||||
<div class="hapiHeaderText" th:if="${not resource.medication.resource.nameElement.empty}" th:narrative="${resource.medication.resource.nameElement}"></div>
|
||||
</div>
|
|
@ -1,5 +1,5 @@
|
|||
<div>
|
||||
Operation Outcome
|
||||
<th:block th:if="${resource.issue.size} == 1" th:text="'(' + ${resource.issueFirstRep.severity.value} + ')'"/>
|
||||
<th:block th:if="${resource.issue.size} == 1" th:text="'(' + ${resource.issueFirstRep.severityElement.value} + ')'"/>
|
||||
<th:block th:if="${resource.issue.size} != 1" th:text="'(' + ${resource.issue.size} + ' issues)'"/>
|
||||
</div>
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>jetty</groupId>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5-6.0.2</version>
|
||||
<version>2.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -67,6 +67,7 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
|||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseQuantityDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.CodingDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.QuantityDt;
|
||||
|
@ -1015,12 +1016,12 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
|
|||
BigDecimal valueValue;
|
||||
boolean approx = false;
|
||||
|
||||
if (params instanceof QuantityDt) {
|
||||
QuantityDt param = (QuantityDt) params;
|
||||
systemValue = param.getSystem().getValueAsString();
|
||||
unitsValue = param.getUnits().getValueAsString();
|
||||
cmpValue = param.getComparator().getValueAsEnum();
|
||||
valueValue = param.getValue().getValue();
|
||||
if (params instanceof BaseQuantityDt) {
|
||||
BaseQuantityDt param = (BaseQuantityDt) params;
|
||||
systemValue = param.getSystemElement().getValueAsString();
|
||||
unitsValue = param.getUnitsElement().getValueAsString();
|
||||
cmpValue = QuantityCompararatorEnum.VALUESET_BINDER.fromCodeString(param.getComparatorElement().getValueAsString());
|
||||
valueValue = param.getValueElement().getValue();
|
||||
} else if (params instanceof QuantityParam) {
|
||||
QuantityParam param = (QuantityParam) params;
|
||||
systemValue = param.getSystem().getValueAsString();
|
||||
|
|
|
@ -154,7 +154,7 @@ class SearchParamExtractorDev implements ISearchParamExtractor {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (new UriDt(BaseFhirDao.UCUM_NS).equals(nextValue.getSystem())) {
|
||||
if (new UriDt(BaseFhirDao.UCUM_NS).equals(nextValue.getSystemElement())) {
|
||||
if (isNotBlank(nextValue.getCode())) {
|
||||
|
||||
Unit<? extends Quantity> unit = Unit.valueOf(nextValue.getCode());
|
||||
|
@ -293,7 +293,7 @@ class SearchParamExtractorDev implements ISearchParamExtractor {
|
|||
|
||||
String nextPath = nextSpDef.getPath();
|
||||
if (isBlank(nextPath)) {
|
||||
// TODO: implement phoenetic, and any others that have no path
|
||||
// TODO: implement phonetic, and any others that have no path
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
package ca.uhn.fhir.jpa.dao;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -34,20 +24,22 @@ import ca.uhn.fhir.model.api.IResource;
|
|||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.PeriodDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.QuantityDt;
|
||||
import ca.uhn.fhir.model.dev.composite.CodeableConceptDt;
|
||||
import ca.uhn.fhir.model.dev.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.model.dev.composite.PeriodDt;
|
||||
import ca.uhn.fhir.model.dev.composite.QuantityDt;
|
||||
import ca.uhn.fhir.model.dev.resource.Device;
|
||||
import ca.uhn.fhir.model.dev.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dev.resource.Encounter;
|
||||
import ca.uhn.fhir.model.dev.resource.Location;
|
||||
import ca.uhn.fhir.model.dev.resource.Observation;
|
||||
import ca.uhn.fhir.model.dev.resource.Organization;
|
||||
import ca.uhn.fhir.model.dev.resource.Patient;
|
||||
import ca.uhn.fhir.model.dev.valueset.AdministrativeGenderEnum;
|
||||
import ca.uhn.fhir.model.dev.valueset.QuantityComparatorEnum;
|
||||
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Device;
|
||||
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dstu.resource.Encounter;
|
||||
import ca.uhn.fhir.model.dstu.resource.Location;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.DateDt;
|
||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
|
@ -114,7 +106,7 @@ public class FhirResourceDaoTest {
|
|||
public void testChoiceParamQuantity() {
|
||||
Observation o3 = new Observation();
|
||||
o3.getName().addCoding().setSystem("foo").setCode("testChoiceParam03");
|
||||
o3.setValue(new QuantityDt(QuantityCompararatorEnum.GREATERTHAN, 123.0, "foo", "bar"));
|
||||
o3.setValue(new QuantityDt(QuantityComparatorEnum.GREATERTHAN, 123.0, "foo", "bar"));
|
||||
IdDt id3 = ourObservationDao.create(o3).getId();
|
||||
|
||||
{
|
||||
|
@ -171,8 +163,8 @@ public class FhirResourceDaoTest {
|
|||
public void testDatePeriodParamEndOnly() {
|
||||
{
|
||||
Encounter enc = new Encounter();
|
||||
enc.addIdentifier("testDatePeriodParam", "02");
|
||||
enc.getPeriod().getEnd().setValueAsString("2001-01-02");
|
||||
enc.addIdentifier().setSystem("testDatePeriodParam").setValue("02");
|
||||
enc.getPeriod().getEndElement().setValueAsString("2001-01-02");
|
||||
ourEncounterDao.create(enc);
|
||||
}
|
||||
SearchParameterMap params;
|
||||
|
@ -214,9 +206,9 @@ public class FhirResourceDaoTest {
|
|||
public void testDatePeriodParamStartAndEnd() {
|
||||
{
|
||||
Encounter enc = new Encounter();
|
||||
enc.addIdentifier("testDatePeriodParam", "03");
|
||||
enc.getPeriod().getStart().setValueAsString("2001-01-02");
|
||||
enc.getPeriod().getEnd().setValueAsString("2001-01-03");
|
||||
enc.addIdentifier().setSystem("testDatePeriodParam").setValue( "03");
|
||||
enc.getPeriod().getStartElement().setValueAsString("2001-01-02");
|
||||
enc.getPeriod().getEndElement().setValueAsString("2001-01-03");
|
||||
ourEncounterDao.create(enc);
|
||||
}
|
||||
|
||||
|
@ -268,8 +260,8 @@ public class FhirResourceDaoTest {
|
|||
public void testDatePeriodParamStartOnly() {
|
||||
{
|
||||
Encounter enc = new Encounter();
|
||||
enc.addIdentifier("testDatePeriodParam", "01");
|
||||
enc.getPeriod().getStart().setValueAsString("2001-01-02");
|
||||
enc.addIdentifier().setSystem("testDatePeriodParam").setValue("01");
|
||||
enc.getPeriod().getStartElement().setValueAsString("2001-01-02");
|
||||
ourEncounterDao.create(enc);
|
||||
}
|
||||
|
||||
|
@ -314,19 +306,19 @@ public class FhirResourceDaoTest {
|
|||
IdDt id2b;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("001");
|
||||
patient.addName().addFamily("Tester_testDelete").addGiven("Joe");
|
||||
id1 = ourPatientDao.create(patient).getId();
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("002");
|
||||
patient.addName().addFamily("Tester_testDelete").addGiven("John");
|
||||
id2 = ourPatientDao.create(patient).getId();
|
||||
}
|
||||
{
|
||||
Patient patient = ourPatientDao.read(id2);
|
||||
patient.addIdentifier("ZZZZZZZ", "ZZZZZZZZZ");
|
||||
patient.addIdentifier().setSystem("ZZZZZZZ").setValue("ZZZZZZZZZ");
|
||||
id2b = ourPatientDao.update(patient, id2).getId();
|
||||
}
|
||||
ourLog.info("ID1:{} ID2:{} ID2b:{}", new Object[] { id1, id2, id2b });
|
||||
|
@ -371,7 +363,7 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testIdParam() {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||
|
||||
MethodOutcome outcome = ourPatientDao.create(patient);
|
||||
|
@ -482,11 +474,11 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testPersistResourceLink() {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "testPersistResourceLink01");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "testPersistResourceLink01");
|
||||
IdDt patientId01 = ourPatientDao.create(patient).getId();
|
||||
|
||||
Patient patient02 = new Patient();
|
||||
patient02.addIdentifier("urn:system", "testPersistResourceLink02");
|
||||
patient02.addIdentifier().setSystem("urn:system").setValue( "testPersistResourceLink02");
|
||||
IdDt patientId02 = ourPatientDao.create(patient02).getId();
|
||||
|
||||
Observation obs01 = new Observation();
|
||||
|
@ -522,8 +514,8 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testPersistSearchParamDate() {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.setBirthDate(new DateTimeDt("2001-01-01"));
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.setBirthDate(new DateDt("2001-01-01"));
|
||||
|
||||
ourPatientDao.create(patient);
|
||||
|
||||
|
@ -574,8 +566,8 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testPersistSearchParams() {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001testPersistSearchParams");
|
||||
patient.getGender().setValueAsEnum(AdministrativeGenderCodesEnum.M);
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001testPersistSearchParams");
|
||||
patient.getGenderElement().setValueAsEnum(AdministrativeGenderEnum.MALE);
|
||||
patient.addName().addFamily("Tester").addGiven("JoetestPersistSearchParams");
|
||||
|
||||
MethodOutcome outcome = ourPatientDao.create(patient);
|
||||
|
@ -598,14 +590,22 @@ public class FhirResourceDaoTest {
|
|||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
map.add(Patient.SP_IDENTIFIER, new IdentifierDt("urn:system", "001testPersistSearchParams"));
|
||||
map.add(Patient.SP_GENDER, new IdentifierDt(AdministrativeGenderCodesEnum.M.getSystem(), "M"));
|
||||
map.add(Patient.SP_GENDER, new IdentifierDt("urn:some:wrong:system", AdministrativeGenderEnum.MALE.getCode()));
|
||||
found = toList(ourPatientDao.search(map));
|
||||
assertEquals(0, found.size());
|
||||
|
||||
// Now with no system on the gender (should match)
|
||||
map = new SearchParameterMap();
|
||||
map.add(Patient.SP_IDENTIFIER, new IdentifierDt("urn:system", "001testPersistSearchParams"));
|
||||
map.add(Patient.SP_GENDER, new IdentifierDt(null, AdministrativeGenderEnum.MALE.getCode()));
|
||||
found = toList(ourPatientDao.search(map));
|
||||
assertEquals(1, found.size());
|
||||
assertEquals(id, found.get(0).getId().getIdPartAsLong().longValue());
|
||||
|
||||
// Now with the wrong gender
|
||||
map = new SearchParameterMap();
|
||||
map.add(Patient.SP_IDENTIFIER, new IdentifierDt("urn:system", "001testPersistSearchParams"));
|
||||
map.add(Patient.SP_GENDER, new IdentifierDt(AdministrativeGenderCodesEnum.M.getSystem(), "F"));
|
||||
map.add(Patient.SP_GENDER, new IdentifierDt(AdministrativeGenderEnum.MALE.getSystem(), AdministrativeGenderEnum.FEMALE.getCode()));
|
||||
found = toList(ourPatientDao.search(map));
|
||||
assertEquals(0, found.size());
|
||||
|
||||
|
@ -615,13 +615,13 @@ public class FhirResourceDaoTest {
|
|||
public void testSearchAll() {
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("001");
|
||||
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("002");
|
||||
patient.addName().addFamily("Tester").addGiven("John");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ public class FhirResourceDaoTest {
|
|||
IdDt idv2;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "testHistoryByForcedId");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "testHistoryByForcedId");
|
||||
patient.addName().addFamily("Tester").addGiven("testHistoryByForcedId");
|
||||
patient.setId("Patient/testHistoryByForcedId");
|
||||
idv1 = ourPatientDao.create(patient).getId();
|
||||
|
@ -658,13 +658,13 @@ public class FhirResourceDaoTest {
|
|||
IdDt id1;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("001");
|
||||
id1 = ourPatientDao.create(patient).getId();
|
||||
}
|
||||
IdDt id2;
|
||||
{
|
||||
Organization patient = new Organization();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
id2 = ourOrganizationDao.create(patient).getId();
|
||||
}
|
||||
|
||||
|
@ -757,14 +757,14 @@ public class FhirResourceDaoTest {
|
|||
IdDt id1;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.addName().addFamily("testSearchNameParam01Fam").addGiven("testSearchNameParam01Giv");
|
||||
ResourceMetadataKeyEnum.TITLE.put(patient, "P1TITLE");
|
||||
id1 = ourPatientDao.create(patient).getId();
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "002");
|
||||
patient.addName().addFamily("testSearchNameParam02Fam").addGiven("testSearchNameParam02Giv");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
|
@ -804,12 +804,12 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testSearchNumberParam() {
|
||||
Encounter e1 = new Encounter();
|
||||
e1.addIdentifier("foo", "testSearchNumberParam01");
|
||||
e1.addIdentifier().setSystem("foo").setValue( "testSearchNumberParam01");
|
||||
e1.getLength().setSystem(BaseFhirDao.UCUM_NS).setCode("min").setValue(4.0 * 24 * 60);
|
||||
IdDt id1 = ourEncounterDao.create(e1).getId();
|
||||
|
||||
Encounter e2 = new Encounter();
|
||||
e2.addIdentifier("foo", "testSearchNumberParam02");
|
||||
e2.addIdentifier().setSystem("foo").setValue( "testSearchNumberParam02");
|
||||
e2.getLength().setSystem(BaseFhirDao.UCUM_NS).setCode("year").setValue(2.0);
|
||||
IdDt id2 = ourEncounterDao.create(e2).getId();
|
||||
{
|
||||
|
@ -831,13 +831,13 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testSearchResourceLinkWithChain() {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "testSearchResourceLinkWithChainXX");
|
||||
patient.addIdentifier("urn:system", "testSearchResourceLinkWithChain01");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "testSearchResourceLinkWithChainXX");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "testSearchResourceLinkWithChain01");
|
||||
IdDt patientId01 = ourPatientDao.create(patient).getId();
|
||||
|
||||
Patient patient02 = new Patient();
|
||||
patient02.addIdentifier("urn:system", "testSearchResourceLinkWithChainXX");
|
||||
patient02.addIdentifier("urn:system", "testSearchResourceLinkWithChain02");
|
||||
patient02.addIdentifier().setSystem("urn:system").setValue( "testSearchResourceLinkWithChainXX");
|
||||
patient02.addIdentifier().setSystem("urn:system").setValue( "testSearchResourceLinkWithChain02");
|
||||
IdDt patientId02 = ourPatientDao.create(patient02).getId();
|
||||
|
||||
Observation obs01 = new Observation();
|
||||
|
@ -873,14 +873,14 @@ public class FhirResourceDaoTest {
|
|||
public void testSearchResourceLinkWithTextLogicalId() {
|
||||
Patient patient = new Patient();
|
||||
patient.setId("testSearchResourceLinkWithTextLogicalId01");
|
||||
patient.addIdentifier("urn:system", "testSearchResourceLinkWithTextLogicalIdXX");
|
||||
patient.addIdentifier("urn:system", "testSearchResourceLinkWithTextLogicalId01");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "testSearchResourceLinkWithTextLogicalIdXX");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "testSearchResourceLinkWithTextLogicalId01");
|
||||
IdDt patientId01 = ourPatientDao.create(patient).getId();
|
||||
|
||||
Patient patient02 = new Patient();
|
||||
patient02.setId("testSearchResourceLinkWithTextLogicalId02");
|
||||
patient02.addIdentifier("urn:system", "testSearchResourceLinkWithTextLogicalIdXX");
|
||||
patient02.addIdentifier("urn:system", "testSearchResourceLinkWithTextLogicalId02");
|
||||
patient02.addIdentifier().setSystem("urn:system").setValue( "testSearchResourceLinkWithTextLogicalIdXX");
|
||||
patient02.addIdentifier().setSystem("urn:system").setValue( "testSearchResourceLinkWithTextLogicalId02");
|
||||
IdDt patientId02 = ourPatientDao.create(patient02).getId();
|
||||
|
||||
Observation obs01 = new Observation();
|
||||
|
@ -929,7 +929,7 @@ public class FhirResourceDaoTest {
|
|||
IdDt patientId01 = ourPatientDao.create(patient).getId();
|
||||
|
||||
Location loc01 = new Location();
|
||||
loc01.getName().setValue("testSearchResourceLinkWithChainWithMultipleTypes01");
|
||||
loc01.getNameElement().setValue("testSearchResourceLinkWithChainWithMultipleTypes01");
|
||||
IdDt locId01 = ourLocationDao.create(loc01).getId();
|
||||
|
||||
Observation obs01 = new Observation();
|
||||
|
@ -963,13 +963,13 @@ public class FhirResourceDaoTest {
|
|||
public void testSearchStringParam() {
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("Joe");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "002");
|
||||
patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ public class FhirResourceDaoTest {
|
|||
{
|
||||
Patient patient = new Patient();
|
||||
patient.getLanguage().setValue("en_CA");
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe");
|
||||
id1 = ourPatientDao.create(patient).getId();
|
||||
}
|
||||
|
@ -999,7 +999,7 @@ public class FhirResourceDaoTest {
|
|||
{
|
||||
Patient patient = new Patient();
|
||||
patient.getLanguage().setValue("en_US");
|
||||
patient.addIdentifier("urn:system", "002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "002");
|
||||
patient.addName().addFamily("testSearchLanguageParam").addGiven("John");
|
||||
id2 = ourPatientDao.create(patient).getId();
|
||||
}
|
||||
|
@ -1030,13 +1030,13 @@ public class FhirResourceDaoTest {
|
|||
public void testSearchStringParamWithNonNormalized() {
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "002");
|
||||
patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
|
@ -1063,7 +1063,7 @@ public class FhirResourceDaoTest {
|
|||
ourPatientDao.create(patient);
|
||||
|
||||
patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "testSearchTokenParam002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "testSearchTokenParam002");
|
||||
patient.addName().addFamily("Tester").addGiven("testSearchTokenParam2");
|
||||
ourPatientDao.create(patient);
|
||||
|
||||
|
@ -1119,24 +1119,24 @@ public class FhirResourceDaoTest {
|
|||
IdDt parentOrgId;
|
||||
{
|
||||
Organization org = new Organization();
|
||||
org.getName().setValue("testSearchWithIncludes_O1Parent");
|
||||
org.getNameElement().setValue("testSearchWithIncludes_O1Parent");
|
||||
parentOrgId = ourOrganizationDao.create(org).getId();
|
||||
}
|
||||
{
|
||||
Organization org = new Organization();
|
||||
org.getName().setValue("testSearchWithIncludes_O1");
|
||||
org.getNameElement().setValue("testSearchWithIncludes_O1");
|
||||
org.setPartOf(new ResourceReferenceDt(parentOrgId));
|
||||
IdDt orgId = ourOrganizationDao.create(org).getId();
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.addName().addFamily("Tester_testSearchWithIncludes_P1").addGiven("Joe");
|
||||
patient.getManagingOrganization().setReference(orgId);
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "002");
|
||||
patient.addName().addFamily("Tester_testSearchWithIncludes_P2").addGiven("John");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
|
@ -1203,7 +1203,7 @@ public class FhirResourceDaoTest {
|
|||
public void testStoreUtf8Characters() throws Exception {
|
||||
Organization org = new Organization();
|
||||
org.setName("測試醫院");
|
||||
org.addIdentifier("urn:system", "testStoreUtf8Characters_01");
|
||||
org.addIdentifier().setSystem("urn:system").setValue( "testStoreUtf8Characters_01");
|
||||
IdDt orgId = ourOrganizationDao.create(org).getId();
|
||||
|
||||
Organization returned = ourOrganizationDao.read(orgId);
|
||||
|
@ -1221,19 +1221,19 @@ public class FhirResourceDaoTest {
|
|||
{
|
||||
Organization org = new Organization();
|
||||
org.setId("testSearchWithIncludesThatHaveTextId_id1");
|
||||
org.getName().setValue("testSearchWithIncludesThatHaveTextId_O1");
|
||||
org.getNameElement().setValue("testSearchWithIncludesThatHaveTextId_O1");
|
||||
IdDt orgId = ourOrganizationDao.create(org).getId();
|
||||
assertThat(orgId.getValue(), endsWith("Organization/testSearchWithIncludesThatHaveTextId_id1/_history/1"));
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P1").addGiven("Joe");
|
||||
patient.getManagingOrganization().setReference(orgId);
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "002");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "002");
|
||||
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P2").addGiven("John");
|
||||
ourPatientDao.create(patient);
|
||||
}
|
||||
|
@ -1272,23 +1272,23 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testSort() {
|
||||
Patient p = new Patient();
|
||||
p.addIdentifier("urn:system", "testSort001");
|
||||
p.addIdentifier().setSystem("urn:system").setValue( "testSort001");
|
||||
p.addName().addFamily("testSortF1").addGiven("testSortG1");
|
||||
IdDt id1 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||
|
||||
// Create out of order
|
||||
p = new Patient();
|
||||
p.addIdentifier("urn:system", "testSort001");
|
||||
p.addIdentifier().setSystem("urn:system").setValue( "testSort001");
|
||||
p.addName().addFamily("testSortF3").addGiven("testSortG3");
|
||||
IdDt id3 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||
|
||||
p = new Patient();
|
||||
p.addIdentifier("urn:system", "testSort001");
|
||||
p.addIdentifier().setSystem("urn:system").setValue( "testSort001");
|
||||
p.addName().addFamily("testSortF2").addGiven("testSortG2");
|
||||
IdDt id2 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||
|
||||
p = new Patient();
|
||||
p.addIdentifier("urn:system", "testSort001");
|
||||
p.addIdentifier().setSystem("urn:system").setValue( "testSort001");
|
||||
IdDt id4 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||
|
||||
SearchParameterMap pm = new SearchParameterMap();
|
||||
|
@ -1302,7 +1302,7 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testStoreUnversionedResources() {
|
||||
Organization o1 = new Organization();
|
||||
o1.getName().setValue("AAA");
|
||||
o1.getNameElement().setValue("AAA");
|
||||
IdDt o1id = ourOrganizationDao.create(o1).getId();
|
||||
assertTrue(o1id.hasVersionIdPart());
|
||||
|
||||
|
@ -1323,7 +1323,7 @@ public class FhirResourceDaoTest {
|
|||
Organization org = new Organization();
|
||||
String str = "testStringParamLong__lvdaoy843s89tll8gvs89l4s3gelrukveilufyebrew8r87bv4b77feli7fsl4lv3vb7rexloxe7olb48vov4o78ls7bvo7vb48o48l4bb7vbvx";
|
||||
str = str + str;
|
||||
org.getName().setValue(str);
|
||||
org.getNameElement().setValue(str);
|
||||
|
||||
assertThat(str.length(), greaterThan(ResourceIndexedSearchParamString.MAX_LENGTH));
|
||||
|
||||
|
@ -1349,7 +1349,7 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testTagsWithCreateAndReadAndSearch() {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "testTagsWithCreateAndReadAndSearch");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "testTagsWithCreateAndReadAndSearch");
|
||||
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||
TagList tagList = new TagList();
|
||||
tagList.addTag(null, "Dog", "Puppies");
|
||||
|
@ -1409,7 +1409,7 @@ public class FhirResourceDaoTest {
|
|||
String longStr2 = RandomStringUtils.randomAlphanumeric(ResourceIndexedSearchParamString.MAX_LENGTH + 100);
|
||||
|
||||
Organization org = new Organization();
|
||||
org.getName().setValue("testTokenParamWhichIsTooLong");
|
||||
org.getNameElement().setValue("testTokenParamWhichIsTooLong");
|
||||
org.getType().addCoding().setSystem(longStr1).setCode(longStr2);
|
||||
|
||||
String subStr1 = longStr1.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH);
|
||||
|
@ -1440,7 +1440,7 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testUpdateAndGetHistoryResource() throws InterruptedException {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "001");
|
||||
patient.addIdentifier().setSystem("urn:system").setValue( "001");
|
||||
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||
|
||||
MethodOutcome outcome = ourPatientDao.create(patient);
|
||||
|
@ -1470,7 +1470,7 @@ public class FhirResourceDaoTest {
|
|||
Patient retrieved2 = ourPatientDao.read(outcome.getId().toVersionless());
|
||||
|
||||
assertEquals("2", retrieved2.getId().getVersionIdPart());
|
||||
assertEquals("002", retrieved2.getIdentifierFirstRep().getValue().getValue());
|
||||
assertEquals("002", retrieved2.getIdentifierFirstRep().getValue());
|
||||
InstantDt published2 = (InstantDt) retrieved2.getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED);
|
||||
InstantDt updated2 = (InstantDt) retrieved2.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
|
||||
assertTrue(published2.before(now));
|
||||
|
@ -1493,22 +1493,22 @@ public class FhirResourceDaoTest {
|
|||
assertEquals(published, history.get(1).getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED));
|
||||
assertEquals(published, history.get(1).getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED));
|
||||
assertEquals(updated, history.get(1).getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||
assertEquals("001", ((Patient) history.get(1)).getIdentifierFirstRep().getValue().getValue());
|
||||
assertEquals("001", ((Patient) history.get(1)).getIdentifierFirstRep().getValue());
|
||||
assertEquals(published2, history.get(0).getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED));
|
||||
assertEquals(updated2, history.get(0).getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
|
||||
assertEquals("002", ((Patient) history.get(0)).getIdentifierFirstRep().getValue().getValue());
|
||||
assertEquals("002", ((Patient) history.get(0)).getIdentifierFirstRep().getValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMaintainsSearchParams() throws InterruptedException {
|
||||
Patient p1 = new Patient();
|
||||
p1.addIdentifier("urn:system", "testUpdateMaintainsSearchParamsAAA");
|
||||
p1.addIdentifier().setSystem("urn:system").setValue( "testUpdateMaintainsSearchParamsAAA");
|
||||
p1.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsAAA");
|
||||
IdDt p1id = ourPatientDao.create(p1).getId();
|
||||
|
||||
Patient p2 = new Patient();
|
||||
p2.addIdentifier("urn:system", "testUpdateMaintainsSearchParamsBBB");
|
||||
p2.addIdentifier().setSystem("urn:system").setValue( "testUpdateMaintainsSearchParamsBBB");
|
||||
p2.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsBBB");
|
||||
ourPatientDao.create(p2).getId();
|
||||
|
||||
|
@ -1539,12 +1539,12 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testUpdateRejectsInvalidTypes() throws InterruptedException {
|
||||
Patient p1 = new Patient();
|
||||
p1.addIdentifier("urn:system", "testUpdateRejectsInvalidTypes");
|
||||
p1.addIdentifier().setSystem("urn:system").setValue( "testUpdateRejectsInvalidTypes");
|
||||
p1.addName().addFamily("Tester").addGiven("testUpdateRejectsInvalidTypes");
|
||||
IdDt p1id = ourPatientDao.create(p1).getId();
|
||||
|
||||
Organization p2 = new Organization();
|
||||
p2.getName().setValue("testUpdateRejectsInvalidTypes");
|
||||
p2.getNameElement().setValue("testUpdateRejectsInvalidTypes");
|
||||
try {
|
||||
ourOrganizationDao.update(p2, new IdDt("Organization/" + p1id.getIdPart()));
|
||||
fail();
|
||||
|
@ -1564,14 +1564,14 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testUpdateRejectsIdWhichPointsToForcedId() throws InterruptedException {
|
||||
Patient p1 = new Patient();
|
||||
p1.addIdentifier("urn:system", "testUpdateRejectsIdWhichPointsToForcedId01");
|
||||
p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsIdWhichPointsToForcedId01");
|
||||
p1.addName().addFamily("Tester").addGiven("testUpdateRejectsIdWhichPointsToForcedId01");
|
||||
p1.setId("ABABA");
|
||||
IdDt p1id = ourPatientDao.create(p1).getId();
|
||||
assertEquals("ABABA", p1id.getIdPart());
|
||||
|
||||
Patient p2 = new Patient();
|
||||
p2.addIdentifier("urn:system", "testUpdateRejectsIdWhichPointsToForcedId02");
|
||||
p2.addIdentifier().setSystem("urn:system").setValue( "testUpdateRejectsIdWhichPointsToForcedId02");
|
||||
p2.addName().addFamily("Tester").addGiven("testUpdateRejectsIdWhichPointsToForcedId02");
|
||||
IdDt p2id = ourPatientDao.create(p2).getId();
|
||||
long p1longId = p2id.getIdPartAsLong() - 1;
|
||||
|
@ -1595,12 +1595,12 @@ public class FhirResourceDaoTest {
|
|||
@Test
|
||||
public void testReadForcedIdVersionHistory() throws InterruptedException {
|
||||
Patient p1 = new Patient();
|
||||
p1.addIdentifier("urn:system", "testReadVorcedIdVersionHistory01");
|
||||
p1.addIdentifier().setSystem("urn:system").setValue( "testReadVorcedIdVersionHistory01");
|
||||
p1.setId("testReadVorcedIdVersionHistory");
|
||||
IdDt p1id = ourPatientDao.create(p1).getId();
|
||||
assertEquals("testReadVorcedIdVersionHistory", p1id.getIdPart());
|
||||
|
||||
p1.addIdentifier("urn:system", "testReadVorcedIdVersionHistory02");
|
||||
p1.addIdentifier().setSystem("urn:system").setValue( "testReadVorcedIdVersionHistory02");
|
||||
IdDt p1idv2 = ourPatientDao.update(p1, p1id).getId();
|
||||
assertEquals("testReadVorcedIdVersionHistory", p1idv2.getIdPart());
|
||||
|
||||
|
@ -1643,7 +1643,7 @@ public class FhirResourceDaoTest {
|
|||
ourOrganizationDao = ourCtx.getBean("myOrganizationDao", IFhirResourceDao.class);
|
||||
ourLocationDao = ourCtx.getBean("myLocationDao", IFhirResourceDao.class);
|
||||
ourEncounterDao = ourCtx.getBean("myEncounterDao", IFhirResourceDao.class);
|
||||
ourFhirCtx = new FhirContext();
|
||||
ourFhirCtx = ourCtx.getBean(FhirContext.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<logger name="ca.uhn.fhir.jpa.dao" additivity="false" level="debug">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
|
|
@ -248,7 +248,7 @@ public class CompleteResourceProviderTest {
|
|||
|
||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testCreateWithId01")).encodedJson().prettyPrint().execute();
|
||||
assertEquals(1, actual.size());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getId().getIdPart());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
||||
|
||||
/*
|
||||
* ensure that trying to create the same ID again fails appropriately
|
||||
|
@ -262,7 +262,7 @@ public class CompleteResourceProviderTest {
|
|||
|
||||
Bundle history = ourClient.history(null, (String) null, null, null);
|
||||
|
||||
assertEquals("Expected[" + p1Id.getIdPart() + "] but was " + history.getEntries().get(0).getId(), p1Id.getIdPart(), history.getEntries().get(0).getId().getIdPart());
|
||||
assertEquals("Expected[" + p1Id.getIdPart() + "] but was " + history.getEntries().get(0).getResource().getId(), p1Id.getIdPart(), history.getEntries().get(0).getResource().getId().getIdPart());
|
||||
assertNotNull(history.getEntries().get(0).getResource());
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ public class CompleteResourceProviderTest {
|
|||
|
||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testSearchByIdentifier01")).encodedJson().prettyPrint().execute();
|
||||
assertEquals(1, actual.size());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getId().getIdPart());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -382,7 +382,7 @@ public class CompleteResourceProviderTest {
|
|||
|
||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01")).encodedJson().prettyPrint().execute();
|
||||
assertEquals(1, actual.size());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getId().getIdPart());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
||||
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,7 @@ public class CompleteResourceProviderTest {
|
|||
.encodedJson().prettyPrint().execute();
|
||||
//@formatter:on
|
||||
assertEquals(1, actual.size());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getId().getIdPart());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
||||
|
||||
//@formatter:off
|
||||
actual = ourClient.search()
|
||||
|
@ -417,7 +417,7 @@ public class CompleteResourceProviderTest {
|
|||
.encodedJson().prettyPrint().execute();
|
||||
//@formatter:on
|
||||
assertEquals(1, actual.size());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getId().getIdPart());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
||||
|
||||
}
|
||||
|
||||
|
@ -480,7 +480,7 @@ public class CompleteResourceProviderTest {
|
|||
|
||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExist")).encodedJson().prettyPrint().execute();
|
||||
assertEquals(1, actual.size());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getId().getIdPart());
|
||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package ca.uhn.fhir.narrative;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BaseThymeleafNarrativeGeneratorTest {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseThymeleafNarrativeGeneratorTest.class);
|
||||
|
||||
@Test
|
||||
public void testTrimWhitespace() {
|
||||
|
||||
//@formatter:off
|
||||
String input = "<div>\n" +
|
||||
" <div class=\"hapiHeaderText\">\n" +
|
||||
" \n" +
|
||||
" joe \n" +
|
||||
" john \n" +
|
||||
" <b>BLOW </b>\n" +
|
||||
" \n" +
|
||||
"</div>\n" +
|
||||
" <table class=\"hapiPropertyTable\">\n" +
|
||||
" <tbody>\n" +
|
||||
" <tr>\n" +
|
||||
" <td>Identifier</td>\n" +
|
||||
" <td>123456</td>\n" +
|
||||
" </tr>\n" +
|
||||
" <tr>\n" +
|
||||
" <td>Address</td>\n" +
|
||||
" <td>\n" +
|
||||
" \n" +
|
||||
" <span>123 Fake Street</span><br />\n" +
|
||||
" \n" +
|
||||
" \n" +
|
||||
" <span>Unit 1</span><br />\n" +
|
||||
" \n" +
|
||||
" <span>Toronto</span>\n" +
|
||||
" <span>ON</span>\n" +
|
||||
" <span>Canada</span>\n" +
|
||||
" </td>\n" +
|
||||
" </tr>\n" +
|
||||
" <tr>\n" +
|
||||
" <td>Date of birth</td>\n" +
|
||||
" <td>\n" +
|
||||
" <span>31 March 2014</span>\n" +
|
||||
" </td>\n" +
|
||||
" </tr>\n" +
|
||||
" </tbody>\n" +
|
||||
" </table>\n" +
|
||||
"</div>";
|
||||
//@formatter:on
|
||||
|
||||
String actual = BaseThymeleafNarrativeGenerator.cleanWhitespace(input);
|
||||
String expected = "<div><div class=\"hapiHeaderText\"> joe john <b>BLOW </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>123456</td></tr><tr><td>Address</td><td><span>123 Fake Street</span><br /><span>Unit 1</span><br /><span>Toronto</span><span>ON</span><span>Canada</span></td></tr><tr><td>Date of birth</td><td><span>31 March 2014</span></td></tr></tbody></table></div>";
|
||||
|
||||
ourLog.info(actual);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package ca.uhn.fhir.narrative;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dev.resource.Practitioner;
|
||||
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
|
||||
|
||||
public class CustomThymeleafNarrativeGeneratorTest {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomThymeleafNarrativeGeneratorTest.class);
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forDev();
|
||||
|
||||
@Test
|
||||
public void testGenerator() {
|
||||
|
||||
CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("file:src/test/resources/narrative/customnarrative.properties");
|
||||
ourCtx.setNarrativeGenerator(gen);
|
||||
|
||||
Practitioner p = new Practitioner();
|
||||
p.addIdentifier().setSystem("sys").setValue("val1");
|
||||
p.addIdentifier().setSystem("sys").setValue("val2");
|
||||
p.addAddress().addLine("line1").addLine("line2");
|
||||
p.getName().addFamily("fam1").addGiven("given");
|
||||
|
||||
NarrativeDt narrative = gen.generateNarrative(p);
|
||||
|
||||
String actual = narrative.getDiv().getValueAsString();
|
||||
ourLog.info(actual);
|
||||
|
||||
assertThat(actual, containsString("<h1>Name</h1><div class=\"nameElement\"> given <b>FAM1 </b></div><h1>Address</h1><div><span>line1 </span><br /><span>line2 </span><br /></div></div>"));
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -5,11 +5,15 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import net.sf.json.JSON;
|
||||
import net.sf.json.JSONSerializer;
|
||||
import net.sf.json.JsonConfig;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
|
@ -58,6 +62,70 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseMetadata() throws Exception {
|
||||
//@formatter:off
|
||||
String bundle = "{\n" +
|
||||
" \"resourceType\" : \"Bundle\",\n" +
|
||||
" \"base\" : \"http://foo/fhirBase1\",\n" +
|
||||
" \"total\" : 1,\n" +
|
||||
" \"link\": [{\n" +
|
||||
" \"relation\" : \"self\",\n" +
|
||||
" \"url\" : \"http://localhost:52788/Binary?_pretty=true\"\n" +
|
||||
" }],\n" +
|
||||
" \"entry\" : [{\n" +
|
||||
" \"base\" : \"http://foo/fhirBase2\",\n" +
|
||||
" \"status\" : \"match\",\n" +
|
||||
" \"search\" : \"http://foo/Patient?identifier=value\",\n" +
|
||||
" \"score\" : 0.123,\n" +
|
||||
" \"resource\" : {\n" +
|
||||
" \"resourceType\" : \"Patient\",\n" +
|
||||
" \"id\" : \"1\",\n" +
|
||||
" \"meta\" : {\n" +
|
||||
" \"versionId\" : \"2\",\n" +
|
||||
" \"lastUpdated\" : \"2001-02-22T11:22:33-05:00\"\n" +
|
||||
" },\n" +
|
||||
" \"birthDate\" : \"2012-01-02\"\n" +
|
||||
" }\n" +
|
||||
" }]\n" +
|
||||
"}";
|
||||
//@formatter:on
|
||||
|
||||
Bundle b = ourCtx.newJsonParser().parseBundle(bundle);
|
||||
assertEquals(1, b.getEntries().size());
|
||||
|
||||
Patient pt = (Patient) b.getEntries().get(0).getResource();
|
||||
assertEquals("http://foo/fhirBase2/Patient/1/_history/2", pt.getId().getValue());
|
||||
assertEquals("2012-01-02", pt.getBirthDateElement().getValueAsString());
|
||||
assertEquals("0.123", ResourceMetadataKeyEnum.ENTRY_SCORE.get(pt).getValueAsString());
|
||||
assertEquals("match", ResourceMetadataKeyEnum.ENTRY_STATUS.get(pt).getCode());
|
||||
assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
||||
assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
||||
|
||||
Bundle toBundle = new Bundle();
|
||||
toBundle.getLinkBase().setValue("http://foo/fhirBase1");
|
||||
toBundle.getTotalResults().setValue(1);
|
||||
toBundle.getLinkSelf().setValue("http://localhost:52788/Binary?_pretty=true");
|
||||
|
||||
toBundle.addResource(pt, ourCtx, "http://foo/fhirBase1");
|
||||
String reEncoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(toBundle);
|
||||
|
||||
JsonConfig cfg = new JsonConfig();
|
||||
|
||||
JSON expected = JSONSerializer.toJSON(bundle.trim(), cfg);
|
||||
JSON actual = JSONSerializer.toJSON(reEncoded.trim(), cfg);
|
||||
|
||||
String exp = expected.toString().replace("\\r\\n", "\\n"); // .replace("§", "§");
|
||||
String act = actual.toString().replace("\\r\\n", "\\n");
|
||||
|
||||
ourLog.info("Expected: {}", exp);
|
||||
ourLog.info("Actual : {}", act);
|
||||
|
||||
assertEquals(exp, act);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testParsePatientInBundle() {
|
||||
|
@ -217,10 +285,11 @@ public class JsonParserTest {
|
|||
Bundle bundle = new Bundle();
|
||||
bundle.addResource(res, ourCtx, "http://foo/base");
|
||||
|
||||
String encoded = ourCtx.newJsonParser().encodeBundleToString(bundle);
|
||||
ourLog.info(encoded);
|
||||
String actual = ourCtx.newJsonParser().encodeBundleToString(bundle);
|
||||
ourLog.info(actual);
|
||||
|
||||
assertEquals("{\"resourceType\":\"Bundle\",\"id\":null,\"entry\":[{\"deleted\":{\"type\":\"Patient\",\"resourceId\":\"111\",\"versionId\":\"222\",\"instant\":\"2011-01-01T12:12:22Z\"}}]", encoded);
|
||||
String expected = "{\"resourceType\":\"Bundle\",\"entry\":[{\"deleted\":{\"type\":\"Patient\",\"resourceId\":\"111\",\"versionId\":\"222\",\"instant\":\"2011-01-01T12:12:22Z\"}}]";
|
||||
assertEquals(expected, actual);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<div>
|
||||
<!--
|
||||
Normal Thymeleaf tags apply. Here, we loop through each of the
|
||||
identifiers that the practitioner has, and create a DIV tag for
|
||||
each one, with the text "Identifier: [value]"
|
||||
-->
|
||||
<div th:each="identifier : ${resource.identifier}" th:text="'Identifier: ' + ${identifier.value}"></div>
|
||||
|
||||
<!--
|
||||
HAPI also defines a custom tag attribute, th:narrative="value",
|
||||
which is used to render a datatype into more HTML. In the example
|
||||
below, the value of ${resource.name} (which is the name property
|
||||
of the Practitioner resource, a HumanName datatype instance)
|
||||
is rendered, and its contents placed in a DIV tag. That DIV tag is
|
||||
then given a .nameElement CSS style.
|
||||
-->
|
||||
<h1>Name</h1>
|
||||
<div th:narrative="${resource.name}" class="nameElement"></div>
|
||||
|
||||
<h1>Address</h1>
|
||||
<div th:narrative="${resource.addressFirstRep}"></div>
|
||||
|
||||
|
||||
</div>
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
# Each resource to be defined has a pair or properties.
|
||||
#
|
||||
# The first (name.class) defines the class name of the
|
||||
# resource to define a template for
|
||||
#
|
||||
# The second (name.narrative) defines the path/classpath to the
|
||||
# template file.
|
||||
# Format is file:/path/foo.html or classpath:/com/classpath/foo.html
|
||||
#
|
||||
practitioner.class=ca.uhn.fhir.model.dev.resource.Practitioner
|
||||
practitioner.narrative=file:src/test/resources/narrative/Practitioner.html
|
||||
|
||||
# You may also override/define behaviour for datatypes
|
||||
humanname.class=ca.uhn.fhir.model.dev.composite.HumanNameDt
|
||||
humanname.narrative=classpath:ca/uhn/fhir/narrative/datatype/HumanNameDt.html
|
|
@ -5,6 +5,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.resource.ValueSet;
|
||||
|
||||
|
@ -12,26 +13,34 @@ public class FhirContextTest {
|
|||
|
||||
@Test
|
||||
public void testIncrementalScan() {
|
||||
|
||||
FhirContext ctx = new FhirContext();
|
||||
ctx.getResourceDefinition(ValueSet.class);
|
||||
ctx.getResourceDefinition(Patient.class);
|
||||
RuntimeResourceDefinition vsDef = ctx.getResourceDefinition(ValueSet.class);
|
||||
RuntimeResourceDefinition ptDef = ctx.getResourceDefinition(Patient.class);
|
||||
assertNotNull(ptDef);
|
||||
|
||||
RuntimeResourceDefinition vsDef2 = ctx.getResourceDefinition(ValueSet.class);
|
||||
assertSame(vsDef, vsDef2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFindBinary() {
|
||||
RuntimeResourceDefinition def = new FhirContext().getResourceDefinition("Binary");
|
||||
assertEquals("Binary", def.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetResourceDefinitionFails() {
|
||||
new FhirContext().getResourceDefinition(IResource.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownVersion() {
|
||||
try {
|
||||
new FhirContext(FhirVersionEnum.DEV);
|
||||
fail();
|
||||
new FhirContext(FhirVersionEnum.DEV);
|
||||
fail();
|
||||
} catch (IllegalStateException e) {
|
||||
assertThat(e.getMessage(), containsString("Could not find the HAPI-FHIR structure JAR on the classpath for version {0}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,13 +5,15 @@ import static org.junit.Assert.*;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Practitioner;
|
||||
|
||||
public class CustomThymeleafNarrativeGeneratorTest {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomThymeleafNarrativeGeneratorTest.class);
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
|
||||
@Test
|
||||
public void testGenerator() {
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package ca.uhn.fhir.narrative;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Date;
|
||||
|
@ -12,7 +10,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||
import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.hamcrest.core.StringContains;
|
|||
import org.hamcrest.text.StringContainsInOrder;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.hamcrest.core.StringContains;
|
|||
import org.hamcrest.text.StringContainsInOrder;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
|
@ -323,6 +324,49 @@ public class XmlParserTest {
|
|||
b.setPublished(pub);
|
||||
Thread.sleep(2);
|
||||
|
||||
Patient p1 = new Patient();
|
||||
p1.addName().addFamily("Family1");
|
||||
p1.getId().setValue("1");
|
||||
BundleEntry entry = b.addEntry();
|
||||
entry.setResource(p1);
|
||||
entry.getSummary().setValueAsString("this is the summary");
|
||||
|
||||
Patient p2 = new Patient();
|
||||
p2.addName().addFamily("Family2");
|
||||
p2.getId().setValue("2");
|
||||
entry = b.addEntry();
|
||||
entry.setLinkAlternate(new StringDt("http://foo/bar"));
|
||||
entry.setLinkSearch(new StringDt("http://foo/bar/search"));
|
||||
entry.setResource(p2);
|
||||
|
||||
BundleEntry deletedEntry = b.addEntry();
|
||||
deletedEntry.setDeletedResourceId(new IdDt("Patient/3"));
|
||||
deletedEntry.setDeleted(InstantDt.withCurrentTime());
|
||||
|
||||
String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
ourLog.info(bundleString);
|
||||
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.addAll(Arrays.asList("<published>", pub.getValueAsString(), "</published>"));
|
||||
strings.add("<category term=\"http://hl7.org/fhir/tag/message\" label=\"Message\" scheme=\"http://hl7.org/fhir/tag\"/>");
|
||||
strings.addAll(Arrays.asList("<entry>", "<id>1</id>", "</Patient>", "<summary type=\"xhtml\">", "<div", "</entry>"));
|
||||
strings.addAll(Arrays.asList("<entry>", "<id>2</id>", "<link rel=\"alternate\" href=\"http://foo/bar\"/>", "<link rel=\"search\" href=\"http://foo/bar/search\"/>", "</entry>"));
|
||||
strings.addAll(Arrays.asList("<at:deleted-entry", "ref=\"Patient/3", "/>"));
|
||||
assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));
|
||||
assertThat(bundleString, not(containsString("at:by")));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testEncodeBundleOldIdForm() throws InterruptedException {
|
||||
Bundle b = new Bundle();
|
||||
b.getCategories().addTag("http://hl7.org/fhir/tag", "http://hl7.org/fhir/tag/message", "Message");
|
||||
|
||||
InstantDt pub = InstantDt.withCurrentTime();
|
||||
b.setPublished(pub);
|
||||
Thread.sleep(2);
|
||||
|
||||
Patient p1 = new Patient();
|
||||
p1.addName().addFamily("Family1");
|
||||
BundleEntry entry = b.addEntry();
|
||||
|
|
|
@ -86,7 +86,7 @@ public class IncludeTest {
|
|||
Patient p = bundle.getResources(Patient.class).get(0);
|
||||
assertEquals(1, p.getName().size());
|
||||
assertEquals("Hello", p.getId().getIdPart());
|
||||
assertEquals("Patient.foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
||||
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public class TransactionWithBundleParamTest {
|
|||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(3, bundle.size());
|
||||
|
||||
BundleEntry entry0 = bundle.getEntries().get(0);
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
package ca.uhn.fhir.test;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.util.FhirTerser;
|
||||
|
||||
public class FhirTerserTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllPopulatedChildElementsOfType() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.setGender(AdministrativeGenderCodesEnum.M);
|
||||
p.addIdentifier().setSystem("urn:foo");
|
||||
p.addAddress().addLine("Line1");
|
||||
p.addAddress().addLine("Line2");
|
||||
p.addName().addFamily("Line3");
|
||||
|
||||
FhirTerser t = new FhirContext().newTerser();
|
||||
List<StringDt> strings = t.getAllPopulatedChildElementsOfType(p, StringDt.class);
|
||||
|
||||
assertEquals(3, strings.size());
|
||||
assertThat(strings, containsInAnyOrder(new StringDt("Line1"), new StringDt("Line2"), new StringDt("Line3")));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package ca.uhn.fhir.util;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -7,11 +8,58 @@ import java.util.List;
|
|||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.composite.QuantityDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
|
||||
public class FhirTerserTest {
|
||||
|
||||
private static FhirContext ourCtx = new FhirContext();
|
||||
|
||||
@Test
|
||||
public void testGetAllPopulatedChildElementsOfType() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.setGender(AdministrativeGenderCodesEnum.M);
|
||||
p.addIdentifier().setSystem("urn:foo");
|
||||
p.addAddress().addLine("Line1");
|
||||
p.addAddress().addLine("Line2");
|
||||
p.addName().addFamily("Line3");
|
||||
|
||||
FhirTerser t = new FhirContext().newTerser();
|
||||
List<StringDt> strings = t.getAllPopulatedChildElementsOfType(p, StringDt.class);
|
||||
|
||||
assertEquals(3, strings.size());
|
||||
assertThat(strings, containsInAnyOrder(new StringDt("Line1"), new StringDt("Line2"), new StringDt("Line3")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValueTypes() {
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.setValue(new QuantityDt(123L));
|
||||
|
||||
FhirTerser t = new FhirContext().newTerser();
|
||||
|
||||
// As string
|
||||
{
|
||||
List<Object> values = t.getValues(obs, "Observation.valueString");
|
||||
assertEquals(0, values.size());
|
||||
}
|
||||
|
||||
// As quantity
|
||||
{
|
||||
List<Object> values = t.getValues(obs, "Observation.valueQuantity");
|
||||
assertEquals(1, values.size());
|
||||
QuantityDt actual = (QuantityDt) values.get(0);
|
||||
assertEquals("123", actual.getValue().getValueAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTerser() {
|
||||
|
||||
|
@ -54,6 +102,4 @@ public class FhirTerserTest {
|
|||
assertEquals("cid:patient@bundle", elems.get(0).getReference().getValue());
|
||||
assertEquals("cid:device@bundle", elems.get(1).getReference().getValue());
|
||||
}
|
||||
|
||||
private static FhirContext ourCtx = new FhirContext();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue