Merge branch 'tags-set'
This commit is contained in:
commit
3eeea9b0fc
|
@ -7,6 +7,12 @@
|
||||||
</properties>
|
</properties>
|
||||||
<body>
|
<body>
|
||||||
<release version="0.7" date="TBD">
|
<release version="0.7" date="TBD">
|
||||||
|
<action type="add" issue="30">
|
||||||
|
<![CDATA[<b>API CHANGE:</b>]]> The TagList class previously implemented ArrayList semantics,
|
||||||
|
but this has been replaced with LinkedHashMap semantics. This means that the list of
|
||||||
|
tags will no longer accept duplicate tags, but that tag order will still be
|
||||||
|
preserved. Thanks to Bill de Beaubien for reporting!
|
||||||
|
</action>
|
||||||
<action type="add" dev="suranga">
|
<action type="add" dev="suranga">
|
||||||
Documentation fixes
|
Documentation fixes
|
||||||
</action>
|
</action>
|
||||||
|
|
|
@ -59,12 +59,20 @@ public class Bundle extends BaseBundle /* implements IElement */{
|
||||||
private IntegerDt myTotalResults;
|
private IntegerDt myTotalResults;
|
||||||
private InstantDt myUpdated;
|
private InstantDt myUpdated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Tags wil become immutable in a future release of HAPI, so {@link #addCategory(String, String, String)} should be used instead
|
||||||
|
*/
|
||||||
public Tag addCategory() {
|
public Tag addCategory() {
|
||||||
Tag retVal = new Tag();
|
Tag retVal = new Tag();
|
||||||
getCategories().add(retVal);
|
getCategories().add(retVal);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addCategory(String theScheme, String theTerm, String theLabel) {
|
||||||
|
getCategories().add(new Tag(theScheme, theTerm, theLabel));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addCategory(Tag theTag) {
|
public void addCategory(Tag theTag) {
|
||||||
getCategories().add(theTag);
|
getCategories().add(theTag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,19 @@ public class BundleEntry extends BaseBundle {
|
||||||
private StringDt myTitle;
|
private StringDt myTitle;
|
||||||
private InstantDt myUpdated;
|
private InstantDt myUpdated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Tags wil become immutable in a future release of HAPI, so {@link #addCategory(String, String, String)} should be used instead
|
||||||
|
*/
|
||||||
public Tag addCategory() {
|
public Tag addCategory() {
|
||||||
Tag retVal = new Tag();
|
Tag retVal = new Tag();
|
||||||
getCategories().add(retVal);
|
getCategories().add(retVal);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addCategory(String theScheme, String theTerm, String theLabel) {
|
||||||
|
getCategories().add(new Tag(theScheme, theTerm, theLabel));
|
||||||
|
}
|
||||||
|
|
||||||
public void addCategory(Tag theTag) {
|
public void addCategory(Tag theTag) {
|
||||||
getCategories().add(theTag);
|
getCategories().add(theTag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,38 +28,52 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single tag
|
||||||
|
* <p>
|
||||||
|
* Note on equality- When computing hashCode or equals values for this class, only the
|
||||||
|
* {@link #getScheme() scheme} and
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
public class Tag extends BaseElement implements IElement {
|
public class Tag extends BaseElement implements IElement {
|
||||||
/**
|
|
||||||
* Convenience constant containing the "http://hl7.org/fhir/tag" scheme
|
|
||||||
* value
|
|
||||||
*/
|
|
||||||
public static final String HL7_ORG_FHIR_TAG = "http://hl7.org/fhir/tag";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience constant containing the "http://hl7.org/fhir/tag/security" scheme
|
|
||||||
* value
|
|
||||||
*/
|
|
||||||
public static final String HL7_ORG_SECURITY_TAG = "http://hl7.org/fhir/tag/security";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience constant containing the "http://hl7.org/fhir/tag/profile" scheme
|
|
||||||
* value
|
|
||||||
*/
|
|
||||||
public static final String HL7_ORG_PROFILE_TAG = "http://hl7.org/fhir/tag/profile";
|
|
||||||
|
|
||||||
public static final String ATTR_TERM = "term";
|
|
||||||
public static final String ATTR_LABEL = "label";
|
public static final String ATTR_LABEL = "label";
|
||||||
public static final String ATTR_SCHEME = "scheme";
|
public static final String ATTR_SCHEME = "scheme";
|
||||||
|
public static final String ATTR_TERM = "term";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience constant containing the "http://hl7.org/fhir/tag" scheme value
|
||||||
|
*/
|
||||||
|
public static final String HL7_ORG_FHIR_TAG = "http://hl7.org/fhir/tag";
|
||||||
|
/**
|
||||||
|
* Convenience constant containing the "http://hl7.org/fhir/tag/profile" scheme value
|
||||||
|
*/
|
||||||
|
public static final String HL7_ORG_PROFILE_TAG = "http://hl7.org/fhir/tag/profile";
|
||||||
|
/**
|
||||||
|
* Convenience constant containing the "http://hl7.org/fhir/tag/security" scheme value
|
||||||
|
*/
|
||||||
|
public static final String HL7_ORG_SECURITY_TAG = "http://hl7.org/fhir/tag/security";
|
||||||
|
|
||||||
private String myLabel;
|
private String myLabel;
|
||||||
private String myScheme;
|
private String myScheme;
|
||||||
private String myTerm;
|
private String myTerm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Tags will become immutable in a future release, so this constructor should not be used.
|
||||||
|
*/
|
||||||
public Tag() {
|
public Tag() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated There is no reason to create a tag with a term and not a scheme, so this constructor will be removed
|
||||||
|
*/
|
||||||
public Tag(String theTerm) {
|
public Tag(String theTerm) {
|
||||||
this((String)null, theTerm, null);
|
this((String) null, theTerm, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag(String theScheme, String theTerm) {
|
||||||
|
myScheme = theScheme;
|
||||||
|
myTerm = theTerm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag(String theScheme, String theTerm, String theLabel) {
|
public Tag(String theScheme, String theTerm, String theLabel) {
|
||||||
|
@ -78,32 +92,6 @@ public class Tag extends BaseElement implements IElement {
|
||||||
myLabel = theLabel;
|
myLabel = theLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
Tag other = (Tag) obj;
|
|
||||||
if (myLabel == null) {
|
|
||||||
if (other.myLabel != null)
|
|
||||||
return false;
|
|
||||||
} else if (!myLabel.equals(other.myLabel))
|
|
||||||
return false;
|
|
||||||
if (myScheme == null) {
|
|
||||||
if (other.myScheme != null)
|
|
||||||
return false;
|
|
||||||
} else if (!myScheme.equals(other.myScheme))
|
|
||||||
return false;
|
|
||||||
if (myTerm == null) {
|
|
||||||
if (other.myTerm != null)
|
|
||||||
return false;
|
|
||||||
} else if (!myTerm.equals(other.myTerm))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return myLabel;
|
return myLabel;
|
||||||
|
@ -117,11 +105,32 @@ public class Tag extends BaseElement implements IElement {
|
||||||
return myTerm;
|
return myTerm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
Tag other = (Tag) obj;
|
||||||
|
if (myScheme == null) {
|
||||||
|
if (other.myScheme != null)
|
||||||
|
return false;
|
||||||
|
} else if (!myScheme.equals(other.myScheme))
|
||||||
|
return false;
|
||||||
|
if (myTerm == null) {
|
||||||
|
if (other.myTerm != null)
|
||||||
|
return false;
|
||||||
|
} else if (!myTerm.equals(other.myTerm))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((myLabel == null) ? 0 : myLabel.hashCode());
|
|
||||||
result = prime * result + ((myScheme == null) ? 0 : myScheme.hashCode());
|
result = prime * result + ((myScheme == null) ? 0 : myScheme.hashCode());
|
||||||
result = prime * result + ((myTerm == null) ? 0 : myTerm.hashCode());
|
result = prime * result + ((myTerm == null) ? 0 : myTerm.hashCode());
|
||||||
return result;
|
return result;
|
||||||
|
@ -132,16 +141,31 @@ public class Tag extends BaseElement implements IElement {
|
||||||
return StringUtils.isBlank(myLabel) && StringUtils.isBlank(myScheme) && StringUtils.isBlank(myTerm);
|
return StringUtils.isBlank(myLabel) && StringUtils.isBlank(myScheme) && StringUtils.isBlank(myTerm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Tags will become immutable in a future release of HAPI in order to facilitate
|
||||||
|
* ensuring that the TagList acts as an unordered set. Use the constructor to set this field when creating a new
|
||||||
|
* tag object
|
||||||
|
*/
|
||||||
public Tag setLabel(String theLabel) {
|
public Tag setLabel(String theLabel) {
|
||||||
myLabel = theLabel;
|
myLabel = theLabel;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Tags will become immutable in a future release of HAPI in order to facilitate
|
||||||
|
* ensuring that the TagList acts as an unordered set. Use the constructor to set this field when creating a new
|
||||||
|
* tag object
|
||||||
|
*/
|
||||||
public Tag setScheme(String theScheme) {
|
public Tag setScheme(String theScheme) {
|
||||||
myScheme = theScheme;
|
myScheme = theScheme;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Tags will become immutable in a future release of HAPI in order to facilitate
|
||||||
|
* ensuring that the TagList acts as an unordered set. Use the constructor to set this field when creating a new
|
||||||
|
* tag object
|
||||||
|
*/
|
||||||
public Tag setTerm(String theTerm) {
|
public Tag setTerm(String theTerm) {
|
||||||
myTerm = theTerm;
|
myTerm = theTerm;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -20,24 +20,146 @@ package ca.uhn.fhir.model.api;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class TagList extends ArrayList<Tag> {
|
/**
|
||||||
|
* A collection of tags present on a single resource. TagList is backed by a {@link LinkedHashSet}, so the order of added tags will be consistent, but duplicates will not be preserved.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* <b>Thread safety:</b> This class is not thread safe
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public class TagList implements Set<Tag>, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
public static final String ATTR_CATEGORY = "category";
|
public static final String ATTR_CATEGORY = "category";
|
||||||
public static final String ELEMENT_NAME = "TagList";
|
public static final String ELEMENT_NAME = "TagList";
|
||||||
public static final String ELEMENT_NAME_LC = ELEMENT_NAME.toLowerCase();
|
|
||||||
|
|
||||||
public Tag addTag(String theScheme, String theTerm, String theLabel) {
|
public static final String ELEMENT_NAME_LC = ELEMENT_NAME.toLowerCase();
|
||||||
Tag retVal = new Tag(theScheme, theTerm, theLabel);
|
private static final long serialVersionUID = 1L;
|
||||||
|
private transient List<Tag> myOrderedTags;
|
||||||
|
private LinkedHashSet<Tag> myTagSet = new LinkedHashSet<Tag>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public TagList() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
b.append("TagList[").append(size()).append(" tag(s)]");
|
||||||
|
for (Tag next : this) {
|
||||||
|
b.append("\n * ").append(next.toString());
|
||||||
|
}
|
||||||
|
return b.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(Tag theE) {
|
||||||
|
myOrderedTags = null;
|
||||||
|
return myTagSet.add(theE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAll(Collection<? extends Tag> theC) {
|
||||||
|
myOrderedTags = null;
|
||||||
|
return myTagSet.addAll(theC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Tags wil become immutable in a future release of HAPI, so {@link #addTag(String, String, String)} should be used instead
|
||||||
|
*/
|
||||||
|
public Tag addTag() {
|
||||||
|
myOrderedTags = null;
|
||||||
|
return addTag(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new tag instance
|
||||||
|
*
|
||||||
|
* @param theScheme
|
||||||
|
* The tag scheme
|
||||||
|
* @param theTerm
|
||||||
|
* The tag term
|
||||||
|
* @return Returns the newly created tag instance. Note that the tag is added to the list by this method, so you generally do not need to interact directly with the added tag.
|
||||||
|
*/
|
||||||
|
public Tag addTag(String theScheme, String theTerm) {
|
||||||
|
Tag retVal = new Tag(theScheme, theTerm);
|
||||||
add(retVal);
|
add(retVal);
|
||||||
|
myOrderedTags = null;
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag addTag() {
|
/**
|
||||||
return addTag(null, null, null);
|
* Add a new tag instance
|
||||||
|
*
|
||||||
|
* @param theScheme
|
||||||
|
* The tag scheme
|
||||||
|
* @param theTerm
|
||||||
|
* The tag term
|
||||||
|
* @param theLabel
|
||||||
|
* The tag label
|
||||||
|
* @return Returns the newly created tag instance. Note that the tag is added to the list by this method, so you generally do not need to interact directly with the added tag.
|
||||||
|
*/
|
||||||
|
public Tag addTag(String theScheme, String theTerm, String theLabel) {
|
||||||
|
Tag retVal = new Tag(theScheme, theTerm, theLabel);
|
||||||
|
add(retVal);
|
||||||
|
myOrderedTags = null;
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
myOrderedTags = null;
|
||||||
|
myTagSet.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Object theO) {
|
||||||
|
return myTagSet.contains(theO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsAll(Collection<?> theC) {
|
||||||
|
return myTagSet.containsAll(theC);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
TagList other = (TagList) obj;
|
||||||
|
if (myTagSet == null) {
|
||||||
|
if (other.myTagSet != null)
|
||||||
|
return false;
|
||||||
|
} else if (!myTagSet.equals(other.myTagSet))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the tag at a given index - Note that the TagList is backed by a {@link LinkedHashSet}, so the order of added tags will be consistent, but duplicates will not be preserved.
|
||||||
|
*/
|
||||||
|
public Tag get(int theIndex) {
|
||||||
|
if (myOrderedTags == null) {
|
||||||
|
myOrderedTags = new ArrayList<Tag>();
|
||||||
|
for (Tag next : myTagSet) {
|
||||||
|
myOrderedTags.add(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return myOrderedTags.get(theIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag getTag(String theScheme, String theTerm) {
|
public Tag getTag(String theScheme, String theTerm) {
|
||||||
|
@ -59,4 +181,52 @@ public class TagList extends ArrayList<Tag> {
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return myTagSet.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return myTagSet.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<Tag> iterator() {
|
||||||
|
return myTagSet.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object theO) {
|
||||||
|
myOrderedTags = null;
|
||||||
|
return myTagSet.remove(theO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(Collection<?> theC) {
|
||||||
|
myOrderedTags = null;
|
||||||
|
return myTagSet.removeAll(theC);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(Collection<?> theC) {
|
||||||
|
myOrderedTags = null;
|
||||||
|
return myTagSet.retainAll(theC);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return myTagSet.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] toArray() {
|
||||||
|
return myTagSet.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T[] toArray(T[] theA) {
|
||||||
|
return myTagSet.toArray(theA);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,8 +158,7 @@ class ParserState<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically
|
* Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically intended for embedded XHTML content
|
||||||
* intended for embedded XHTML content
|
|
||||||
*/
|
*/
|
||||||
public void xmlEvent(XMLEvent theNextEvent) {
|
public void xmlEvent(XMLEvent theNextEvent) {
|
||||||
myState.xmlEvent(theNextEvent);
|
myState.xmlEvent(theNextEvent);
|
||||||
|
@ -222,35 +221,37 @@ class ParserState<T> {
|
||||||
private static final int STATE_TERM = 1;
|
private static final int STATE_TERM = 1;
|
||||||
|
|
||||||
private int myCatState = STATE_NONE;
|
private int myCatState = STATE_NONE;
|
||||||
private Tag myInstance;
|
private TagList myTagList;
|
||||||
|
private String myTerm;
|
||||||
|
private String myLabel;
|
||||||
|
private String myScheme;
|
||||||
|
|
||||||
public AtomCategoryState(Tag theEntry) {
|
public AtomCategoryState(TagList theTagList) {
|
||||||
super(null);
|
super(null);
|
||||||
myInstance = theEntry;
|
myTagList = theTagList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||||
if ("term".equals(theName)) {
|
if ("term".equals(theName)) {
|
||||||
myInstance.setTerm(theValue);
|
myTerm = theValue;
|
||||||
} else if ("label".equals(theName)) {
|
} else if ("label".equals(theName)) {
|
||||||
myInstance.setLabel(theValue);
|
myLabel = theValue;
|
||||||
} else if ("scheme".equals(theName)) {
|
} else if ("scheme".equals(theName)) {
|
||||||
myInstance.setScheme(theValue);
|
myScheme = theValue;
|
||||||
} else if ("value".equals(theName)) {
|
} else if ("value".equals(theName)) {
|
||||||
/*
|
/*
|
||||||
* This handles XML parsing, which is odd for this quasi-resource type, since the tag has three values
|
* This handles XML parsing, which is odd for this quasi-resource type, since the tag has three values instead of one like everything else.
|
||||||
* instead of one like everything else.
|
|
||||||
*/
|
*/
|
||||||
switch (myCatState) {
|
switch (myCatState) {
|
||||||
case STATE_LABEL:
|
case STATE_LABEL:
|
||||||
myInstance.setLabel(theValue);
|
myLabel = theValue;
|
||||||
break;
|
break;
|
||||||
case STATE_TERM:
|
case STATE_TERM:
|
||||||
myInstance.setTerm(theValue);
|
myTerm = theValue;
|
||||||
break;
|
break;
|
||||||
case STATE_SCHEME:
|
case STATE_SCHEME:
|
||||||
myInstance.setScheme(theValue);
|
myScheme = theValue;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
super.string(theValue);
|
super.string(theValue);
|
||||||
|
@ -265,6 +266,9 @@ class ParserState<T> {
|
||||||
if (myCatState != STATE_NONE) {
|
if (myCatState != STATE_NONE) {
|
||||||
myCatState = STATE_NONE;
|
myCatState = STATE_NONE;
|
||||||
} else {
|
} else {
|
||||||
|
if (isNotEmpty(myScheme) || isNotBlank(myTerm) || isNotBlank(myLabel)) {
|
||||||
|
myTagList.addTag(myScheme, myTerm, myLabel);
|
||||||
|
}
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,7 +426,7 @@ class ParserState<T> {
|
||||||
} else if ("summary".equals(theLocalPart)) {
|
} else if ("summary".equals(theLocalPart)) {
|
||||||
push(new XhtmlState(getPreResourceState(), myEntry.getSummary(), false));
|
push(new XhtmlState(getPreResourceState(), myEntry.getSummary(), false));
|
||||||
} else if ("category".equals(theLocalPart)) {
|
} else if ("category".equals(theLocalPart)) {
|
||||||
push(new AtomCategoryState(myEntry.addCategory()));
|
push(new AtomCategoryState(myEntry.getCategories()));
|
||||||
} else if ("deleted".equals(theLocalPart) && myJsonMode) {
|
} else if ("deleted".equals(theLocalPart) && myJsonMode) {
|
||||||
// JSON and XML deleted entries are completely different for some reason
|
// JSON and XML deleted entries are completely different for some reason
|
||||||
myDeleted = true;
|
myDeleted = true;
|
||||||
|
@ -629,7 +633,7 @@ class ParserState<T> {
|
||||||
} else if ("author".equals(theLocalPart)) {
|
} else if ("author".equals(theLocalPart)) {
|
||||||
push(new AtomAuthorState(myInstance));
|
push(new AtomAuthorState(myInstance));
|
||||||
} else if ("category".equals(theLocalPart)) {
|
} else if ("category".equals(theLocalPart)) {
|
||||||
push(new AtomCategoryState(myInstance.getCategories().addTag()));
|
push(new AtomCategoryState(myInstance.getCategories()));
|
||||||
} else if ("deleted-entry".equals(theLocalPart) && verifyNamespace(XmlParser.TOMBSTONES_NS, theNamespaceURI)) {
|
} else if ("deleted-entry".equals(theLocalPart) && verifyNamespace(XmlParser.TOMBSTONES_NS, theNamespaceURI)) {
|
||||||
push(new AtomDeletedEntryState(myInstance, myResourceType));
|
push(new AtomDeletedEntryState(myInstance, myResourceType));
|
||||||
} else {
|
} else {
|
||||||
|
@ -707,7 +711,8 @@ class ParserState<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param theData The string value
|
* @param theData
|
||||||
|
* The string value
|
||||||
*/
|
*/
|
||||||
public void string(String theData) {
|
public void string(String theData) {
|
||||||
// ignore by default
|
// ignore by default
|
||||||
|
@ -718,7 +723,8 @@ class ParserState<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param theNextEvent The XML event
|
* @param theNextEvent
|
||||||
|
* The XML event
|
||||||
*/
|
*/
|
||||||
public void xmlEvent(XMLEvent theNextEvent) {
|
public void xmlEvent(XMLEvent theNextEvent) {
|
||||||
// ignore
|
// ignore
|
||||||
|
@ -1275,7 +1281,8 @@ class ParserState<T> {
|
||||||
myContext.newTerser().visit(myInstance, new IModelVisitor() {
|
myContext.newTerser().visit(myInstance, new IModelVisitor() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition, ExtensionDt theNextExt) {
|
public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition,
|
||||||
|
ExtensionDt theNextExt) {
|
||||||
acceptElement(theNextExt.getValue(), null, null);
|
acceptElement(theNextExt.getValue(), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1508,7 +1515,7 @@ class ParserState<T> {
|
||||||
@Override
|
@Override
|
||||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||||
if (TagList.ATTR_CATEGORY.equals(theLocalPart)) {
|
if (TagList.ATTR_CATEGORY.equals(theLocalPart)) {
|
||||||
push(new TagState(myTagList.addTag()));
|
push(new TagState(myTagList));
|
||||||
} else {
|
} else {
|
||||||
throw new DataFormatException("Unexpected element: " + theLocalPart);
|
throw new DataFormatException("Unexpected element: " + theLocalPart);
|
||||||
}
|
}
|
||||||
|
@ -1524,11 +1531,14 @@ class ParserState<T> {
|
||||||
private static final int SCHEME = 3;
|
private static final int SCHEME = 3;
|
||||||
private static final int TERM = 1;
|
private static final int TERM = 1;
|
||||||
private int mySubState = 0;
|
private int mySubState = 0;
|
||||||
private Tag myTag;
|
private TagList myTagList;
|
||||||
|
private String myTerm;
|
||||||
|
private String myLabel;
|
||||||
|
private String myScheme;
|
||||||
|
|
||||||
public TagState(Tag theTag) {
|
public TagState(TagList theTagList) {
|
||||||
super(null);
|
super(null);
|
||||||
myTag = theTag;
|
myTagList = theTagList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1537,13 +1547,13 @@ class ParserState<T> {
|
||||||
|
|
||||||
switch (mySubState) {
|
switch (mySubState) {
|
||||||
case TERM:
|
case TERM:
|
||||||
myTag.setTerm(value);
|
myTerm = (value);
|
||||||
break;
|
break;
|
||||||
case LABEL:
|
case LABEL:
|
||||||
myTag.setLabel(value);
|
myLabel = (value);
|
||||||
break;
|
break;
|
||||||
case SCHEME:
|
case SCHEME:
|
||||||
myTag.setScheme(value);
|
myScheme = (value);
|
||||||
break;
|
break;
|
||||||
case NONE:
|
case NONE:
|
||||||
// This handles JSON encoding, which is a bit weird
|
// This handles JSON encoding, which is a bit weird
|
||||||
|
@ -1559,6 +1569,9 @@ class ParserState<T> {
|
||||||
if (mySubState != NONE) {
|
if (mySubState != NONE) {
|
||||||
mySubState = NONE;
|
mySubState = NONE;
|
||||||
} else {
|
} else {
|
||||||
|
if (isNotEmpty(myScheme) || isNotBlank(myTerm) || isNotBlank(myLabel)) {
|
||||||
|
myTagList.addTag(myScheme, myTerm, myLabel);
|
||||||
|
}
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,10 +214,6 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding<Void>
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((myVersionIdParamIndex != null) != (theRequest.getId() != null && theRequest.getId().hasVersionIdPart())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDelete()) {
|
if (isDelete()) {
|
||||||
if (Constants.PARAM_DELETE.equals(theRequest.getSecondaryOperation()) == false) {
|
if (Constants.PARAM_DELETE.equals(theRequest.getSecondaryOperation()) == false) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -20,7 +20,7 @@ package ca.uhn.fhir.rest.method;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.*;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
@ -66,7 +66,6 @@ import ca.uhn.fhir.rest.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.server.IDynamicSearchResourceProvider;
|
import ca.uhn.fhir.rest.server.IDynamicSearchResourceProvider;
|
||||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||||
import ca.uhn.fhir.rest.server.SearchParameterMap;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package ca.uhn.fhir.model.api;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||||
|
|
||||||
|
public class TagListTest {
|
||||||
|
|
||||||
|
private FhirContext myCtx = new FhirContext();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEquals() {
|
||||||
|
TagList tagList1 = new TagList();
|
||||||
|
tagList1.addTag(null, "Dog", "Puppies");
|
||||||
|
tagList1.addTag("http://foo", "Cat", "Kittens");
|
||||||
|
|
||||||
|
TagList tagList2 = new TagList();
|
||||||
|
tagList2.addTag(null, "Dog", "Puppies");
|
||||||
|
tagList2.addTag("http://foo", "Cat", "Kittens");
|
||||||
|
|
||||||
|
assertEquals(tagList1,tagList2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEqualsIgnoresLabel() {
|
||||||
|
TagList tagList1 = new TagList();
|
||||||
|
tagList1.addTag(null, "Dog", "AAAA");
|
||||||
|
tagList1.addTag("http://foo", "Cat", "BBBB");
|
||||||
|
|
||||||
|
TagList tagList2 = new TagList();
|
||||||
|
tagList2.addTag(null, "Dog", "Puppies");
|
||||||
|
tagList2.addTag("http://foo", "Cat", "Kittens");
|
||||||
|
|
||||||
|
assertEquals(tagList1,tagList2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEqualsIgnoresOrder() {
|
||||||
|
TagList tagList1 = new TagList();
|
||||||
|
tagList1.addTag(null, "Dog", "Puppies");
|
||||||
|
tagList1.addTag("http://foo", "Cat", "Kittens");
|
||||||
|
|
||||||
|
TagList tagList2 = new TagList();
|
||||||
|
tagList2.addTag("http://foo", "Cat", "Kittens");
|
||||||
|
tagList2.addTag(null, "Dog", "Puppies");
|
||||||
|
|
||||||
|
assertEquals(tagList1,tagList2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPreventDuplication() {
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addIdentifier("urn:system", "testTagsWithCreateAndReadAndSearch");
|
||||||
|
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||||
|
TagList tagList = new TagList();
|
||||||
|
tagList.addTag(null, "Dog", "Puppies");
|
||||||
|
// Add this twice
|
||||||
|
tagList.addTag("http://foo", "Cat", "Kittens");
|
||||||
|
tagList.addTag("http://foo", "Cat", "Kittens");
|
||||||
|
|
||||||
|
patient.getResourceMetadata().put(ResourceMetadataKeyEnum.TAG_LIST, tagList);
|
||||||
|
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.addResource(patient, myCtx, "http://foo");
|
||||||
|
|
||||||
|
String encoded = myCtx.newXmlParser().encodeBundleToString(b);
|
||||||
|
assertThat(encoded, stringContainsInOrder(Arrays.asList("Cat", "Kittens")));
|
||||||
|
assertThat(encoded, not(stringContainsInOrder(Arrays.asList("Cat", "Kittens", "Cat", "Kittens"))));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -63,7 +63,6 @@ public class JsonParserTest {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserTest.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserTest.class);
|
||||||
private static FhirContext ourCtx;
|
private static FhirContext ourCtx;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeNarrativeBlockInBundle() {
|
public void testEncodeNarrativeBlockInBundle() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
@ -87,7 +86,6 @@ public class JsonParserTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodingNullExtension() {
|
public void testEncodingNullExtension() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
@ -164,13 +162,11 @@ public class JsonParserTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeExtensionInResourceElement() {
|
public void testEncodeExtensionInResourceElement() {
|
||||||
|
|
||||||
Conformance c = new Conformance();
|
Conformance c = new Conformance();
|
||||||
// c.addRest().getSecurity().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
// c.addRest().getSecurity().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||||
c.addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
c.addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||||
|
|
||||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||||
|
@ -187,10 +183,10 @@ public class JsonParserTest {
|
||||||
|
|
||||||
Binary patient = new Binary();
|
Binary patient = new Binary();
|
||||||
patient.setContentType("foo");
|
patient.setContentType("foo");
|
||||||
patient.setContent(new byte[] {1,2,3,4});
|
patient.setContent(new byte[] { 1, 2, 3, 4 });
|
||||||
|
|
||||||
String val = ourCtx.newJsonParser().encodeResourceToString(patient);
|
String val = ourCtx.newJsonParser().encodeResourceToString(patient);
|
||||||
assertEquals("{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}",val);
|
assertEquals("{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}", val);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,8 +213,6 @@ public class JsonParserTest {
|
||||||
assertNull(value);
|
assertNull(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNestedContainedResources() {
|
public void testNestedContainedResources() {
|
||||||
|
|
||||||
|
@ -240,39 +234,27 @@ public class JsonParserTest {
|
||||||
|
|
||||||
// Only one (outer) contained block
|
// Only one (outer) contained block
|
||||||
int idx0 = str.indexOf("\"contained\"");
|
int idx0 = str.indexOf("\"contained\"");
|
||||||
int idx1 = str.indexOf("\"contained\"",idx0+1);
|
int idx1 = str.indexOf("\"contained\"", idx0 + 1);
|
||||||
|
|
||||||
assertNotEquals(-1, idx0);
|
assertNotEquals(-1, idx0);
|
||||||
assertEquals(-1, idx1);
|
assertEquals(-1, idx1);
|
||||||
|
|
||||||
Observation obs = ourCtx.newJsonParser().parseResource(Observation.class, str);
|
Observation obs = ourCtx.newJsonParser().parseResource(Observation.class, str);
|
||||||
assertEquals("A",obs.getName().getText().getValue());
|
assertEquals("A", obs.getName().getText().getValue());
|
||||||
|
|
||||||
Observation obsB = (Observation) obs.getRelatedFirstRep().getTarget().getResource();
|
Observation obsB = (Observation) obs.getRelatedFirstRep().getTarget().getResource();
|
||||||
assertEquals("B",obsB.getName().getText().getValue());
|
assertEquals("B", obsB.getName().getText().getValue());
|
||||||
|
|
||||||
Observation obsC = (Observation) obsB.getRelatedFirstRep().getTarget().getResource();
|
Observation obsC = (Observation) obsB.getRelatedFirstRep().getTarget().getResource();
|
||||||
assertEquals("C",obsC.getName().getText().getValue());
|
assertEquals("C", obsC.getName().getText().getValue());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseQuery() {
|
public void testParseQuery() {
|
||||||
String msg = "{\n" +
|
String msg = "{\n" + " \"resourceType\": \"Query\",\n" + " \"text\": {\n" + " \"status\": \"generated\",\n" + " \"div\": \"<div>[Put rendering here]</div>\"\n" + " },\n"
|
||||||
" \"resourceType\": \"Query\",\n" +
|
+ " \"identifier\": \"urn:uuid:42b253f5-fa17-40d0-8da5-44aeb4230376\",\n" + " \"parameter\": [\n" + " {\n" + " \"url\": \"http://hl7.org/fhir/query#_query\",\n"
|
||||||
" \"text\": {\n" +
|
+ " \"valueString\": \"example\"\n" + " }\n" + " ]\n" + "}";
|
||||||
" \"status\": \"generated\",\n" +
|
|
||||||
" \"div\": \"<div>[Put rendering here]</div>\"\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"identifier\": \"urn:uuid:42b253f5-fa17-40d0-8da5-44aeb4230376\",\n" +
|
|
||||||
" \"parameter\": [\n" +
|
|
||||||
" {\n" +
|
|
||||||
" \"url\": \"http://hl7.org/fhir/query#_query\",\n" +
|
|
||||||
" \"valueString\": \"example\"\n" +
|
|
||||||
" }\n" +
|
|
||||||
" ]\n" +
|
|
||||||
"}";
|
|
||||||
Query query = ourCtx.newJsonParser().parseResource(Query.class, msg);
|
Query query = ourCtx.newJsonParser().parseResource(Query.class, msg);
|
||||||
|
|
||||||
assertEquals("urn:uuid:42b253f5-fa17-40d0-8da5-44aeb4230376", query.getIdentifier().getValueAsString());
|
assertEquals("urn:uuid:42b253f5-fa17-40d0-8da5-44aeb4230376", query.getIdentifier().getValueAsString());
|
||||||
|
@ -287,7 +269,6 @@ public class JsonParserTest {
|
||||||
ExtensionDt parameter = q.addParameter();
|
ExtensionDt parameter = q.addParameter();
|
||||||
parameter.setUrl("http://hl7.org/fhir/query#_query").setValue(new StringDt("example"));
|
parameter.setUrl("http://hl7.org/fhir/query#_query").setValue(new StringDt("example"));
|
||||||
|
|
||||||
|
|
||||||
String val = new FhirContext().newJsonParser().encodeResourceToString(q);
|
String val = new FhirContext().newJsonParser().encodeResourceToString(q);
|
||||||
ourLog.info(val);
|
ourLog.info(val);
|
||||||
|
|
||||||
|
@ -315,7 +296,7 @@ public class JsonParserTest {
|
||||||
|
|
||||||
Binary val = ourCtx.newJsonParser().parseResource(Binary.class, "{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}");
|
Binary val = ourCtx.newJsonParser().parseResource(Binary.class, "{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}");
|
||||||
assertEquals("foo", val.getContentType());
|
assertEquals("foo", val.getContentType());
|
||||||
assertArrayEquals(new byte[] {1,2,3,4}, val.getContent());
|
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, val.getContent());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +363,7 @@ public class JsonParserTest {
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
String encoded = new FhirContext().newJsonParser().encodeTagListToString(tagList);
|
String encoded = new FhirContext().newJsonParser().encodeTagListToString(tagList);
|
||||||
assertEquals(expected,encoded);
|
assertEquals(expected, encoded);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +373,7 @@ public class JsonParserTest {
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
BundleEntry e = b.addEntry();
|
BundleEntry e = b.addEntry();
|
||||||
e.setResource(new Patient());
|
e.setResource(new Patient());
|
||||||
b.addCategory().setLabel("label").setTerm("term").setScheme("scheme");
|
b.addCategory("scheme", "term", "label");
|
||||||
|
|
||||||
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
||||||
ourLog.info(val);
|
ourLog.info(val);
|
||||||
|
@ -400,8 +381,8 @@ public class JsonParserTest {
|
||||||
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
||||||
|
|
||||||
b = new FhirContext().newJsonParser().parseBundle(val);
|
b = new FhirContext().newJsonParser().parseBundle(val);
|
||||||
assertEquals(1,b.getEntries().size());
|
assertEquals(1, b.getEntries().size());
|
||||||
assertEquals(1,b.getCategories().size());
|
assertEquals(1, b.getCategories().size());
|
||||||
assertEquals("term", b.getCategories().get(0).getTerm());
|
assertEquals("term", b.getCategories().get(0).getTerm());
|
||||||
assertEquals("label", b.getCategories().get(0).getLabel());
|
assertEquals("label", b.getCategories().get(0).getLabel());
|
||||||
assertEquals("scheme", b.getCategories().get(0).getScheme());
|
assertEquals("scheme", b.getCategories().get(0).getScheme());
|
||||||
|
@ -415,16 +396,16 @@ public class JsonParserTest {
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
BundleEntry e = b.addEntry();
|
BundleEntry e = b.addEntry();
|
||||||
e.setResource(new Patient());
|
e.setResource(new Patient());
|
||||||
e.addCategory().setLabel("label").setTerm("term").setScheme("scheme");
|
e.addCategory("scheme", "term", "label");
|
||||||
|
|
||||||
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
||||||
ourLog.info(val);
|
ourLog.info(val);
|
||||||
|
|
||||||
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
||||||
|
|
||||||
b = new FhirContext().newJsonParser().parseBundle(val);
|
b = ourCtx.newJsonParser().parseBundle(val);
|
||||||
assertEquals(1,b.getEntries().size());
|
assertEquals(1, b.getEntries().size());
|
||||||
assertEquals(1,b.getEntries().get(0).getCategories().size());
|
assertEquals(1, b.getEntries().get(0).getCategories().size());
|
||||||
assertEquals("term", b.getEntries().get(0).getCategories().get(0).getTerm());
|
assertEquals("term", b.getEntries().get(0).getCategories().get(0).getTerm());
|
||||||
assertEquals("label", b.getEntries().get(0).getCategories().get(0).getLabel());
|
assertEquals("label", b.getEntries().get(0).getCategories().get(0).getLabel());
|
||||||
assertEquals("scheme", b.getEntries().get(0).getCategories().get(0).getScheme());
|
assertEquals("scheme", b.getEntries().get(0).getCategories().get(0).getScheme());
|
||||||
|
@ -450,7 +431,6 @@ public class JsonParserTest {
|
||||||
parseAndEncode("/alert.profile.json");
|
parseAndEncode("/alert.profile.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void parseAndEncode(String name) throws IOException {
|
private void parseAndEncode(String name) throws IOException {
|
||||||
String msg = IOUtils.toString(XmlParser.class.getResourceAsStream(name));
|
String msg = IOUtils.toString(XmlParser.class.getResourceAsStream(name));
|
||||||
ourLog.info(msg);
|
ourLog.info(msg);
|
||||||
|
@ -465,7 +445,7 @@ public class JsonParserTest {
|
||||||
JSON actual = JSONSerializer.toJSON(encoded.trim());
|
JSON actual = JSONSerializer.toJSON(encoded.trim());
|
||||||
|
|
||||||
String exp = expected.toString().replace("\\r\\n", "\\n").replace("§", "§");
|
String exp = expected.toString().replace("\\r\\n", "\\n").replace("§", "§");
|
||||||
String act = actual.toString().replace("\\r\\n","\\n");
|
String act = actual.toString().replace("\\r\\n", "\\n");
|
||||||
|
|
||||||
ourLog.info("Expected: {}", exp);
|
ourLog.info("Expected: {}", exp);
|
||||||
ourLog.info("Actual : {}", act);
|
ourLog.info("Actual : {}", act);
|
||||||
|
@ -473,8 +453,6 @@ public class JsonParserTest {
|
||||||
assertEquals(exp, act);
|
assertEquals(exp, act);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeContainedResourcesMore() {
|
public void testEncodeContainedResourcesMore() {
|
||||||
|
|
||||||
|
@ -518,7 +496,6 @@ public class JsonParserTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeDeclaredExtensionWithResourceContent() {
|
public void testEncodeDeclaredExtensionWithResourceContent() {
|
||||||
IParser parser = new FhirContext().newJsonParser();
|
IParser parser = new FhirContext().newJsonParser();
|
||||||
|
@ -549,8 +526,6 @@ public class JsonParserTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeExt() throws Exception {
|
public void testEncodeExt() throws Exception {
|
||||||
|
|
||||||
|
@ -567,11 +542,12 @@ public class JsonParserTest {
|
||||||
ourLog.info(encoded);
|
ourLog.info(encoded);
|
||||||
|
|
||||||
assertThat(encoded, not(containsString("123456")));
|
assertThat(encoded, not(containsString("123456")));
|
||||||
assertEquals("{\"resourceType\":\"ValueSet\",\"define\":{\"concept\":[{\"extension\":[{\"url\":\"urn:alt\",\"valueString\":\"alt name\"}],\"code\":\"someCode\",\"display\":\"someDisplay\"}]}}", encoded);
|
assertEquals(
|
||||||
|
"{\"resourceType\":\"ValueSet\",\"define\":{\"concept\":[{\"extension\":[{\"url\":\"urn:alt\",\"valueString\":\"alt name\"}],\"code\":\"someCode\",\"display\":\"someDisplay\"}]}}",
|
||||||
|
encoded);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeExtensionWithResourceContent() {
|
public void testEncodeExtensionWithResourceContent() {
|
||||||
IParser parser = new FhirContext().newJsonParser();
|
IParser parser = new FhirContext().newJsonParser();
|
||||||
|
@ -593,7 +569,6 @@ public class JsonParserTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeInvalidChildGoodException() {
|
public void testEncodeInvalidChildGoodException() {
|
||||||
Observation obs = new Observation();
|
Observation obs = new Observation();
|
||||||
|
@ -793,7 +768,6 @@ public class JsonParserTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This sample has extra elements in <searchParam> that are not actually a part of the spec any more..
|
* This sample has extra elements in <searchParam> that are not actually a part of the spec any more..
|
||||||
*/
|
*/
|
||||||
|
@ -864,13 +838,13 @@ public class JsonParserTest {
|
||||||
|
|
||||||
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(bundle));
|
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(bundle));
|
||||||
String encoded = ourCtx.newJsonParser().encodeBundleToString(bundle);
|
String encoded = ourCtx.newJsonParser().encodeBundleToString(bundle);
|
||||||
assertEquals(bundleString,encoded);
|
assertEquals(bundleString, encoded);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeBundle() throws InterruptedException {
|
public void testEncodeBundle() throws InterruptedException {
|
||||||
Bundle b= new Bundle();
|
Bundle b = new Bundle();
|
||||||
|
|
||||||
InstantDt pub = InstantDt.withCurrentTime();
|
InstantDt pub = InstantDt.withCurrentTime();
|
||||||
b.setPublished(pub);
|
b.setPublished(pub);
|
||||||
|
@ -899,18 +873,17 @@ public class JsonParserTest {
|
||||||
ourLog.info(bundleString);
|
ourLog.info(bundleString);
|
||||||
|
|
||||||
List<String> strings = new ArrayList<String>();
|
List<String> strings = new ArrayList<String>();
|
||||||
strings.addAll(Arrays.asList("\"published\":\""+pub.getValueAsString()+"\""));
|
strings.addAll(Arrays.asList("\"published\":\"" + pub.getValueAsString() + "\""));
|
||||||
strings.addAll(Arrays.asList("\"id\":\"1\""));
|
strings.addAll(Arrays.asList("\"id\":\"1\""));
|
||||||
strings.addAll(Arrays.asList("this is the summary"));
|
strings.addAll(Arrays.asList("this is the summary"));
|
||||||
strings.addAll(Arrays.asList("\"id\":\"2\"", "\"rel\":\"alternate\"", "\"href\":\"http://foo/bar\""));
|
strings.addAll(Arrays.asList("\"id\":\"2\"", "\"rel\":\"alternate\"", "\"href\":\"http://foo/bar\""));
|
||||||
strings.addAll(Arrays.asList("\"deleted\":\""+nowDt.getValueAsString()+"\"", "\"id\":\"Patient/3\""));
|
strings.addAll(Arrays.asList("\"deleted\":\"" + nowDt.getValueAsString() + "\"", "\"id\":\"Patient/3\""));
|
||||||
assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));
|
assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));
|
||||||
|
|
||||||
b.getEntries().remove(2);
|
b.getEntries().remove(2);
|
||||||
bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||||
assertThat(bundleString, not(containsString("deleted")));
|
assertThat(bundleString, not(containsString("deleted")));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -978,11 +951,10 @@ public class JsonParserTest {
|
||||||
public void testParseWithIncorrectReference() throws IOException {
|
public void testParseWithIncorrectReference() throws IOException {
|
||||||
String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"));
|
String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"));
|
||||||
jsonString = jsonString.replace("\"reference\"", "\"resource\"");
|
jsonString = jsonString.replace("\"reference\"", "\"resource\"");
|
||||||
Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class,jsonString);
|
Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, jsonString);
|
||||||
assertEquals("Organization/1", parsed.getManagingOrganization().getReference().getValue());
|
assertEquals("Organization/1", parsed.getManagingOrganization().getReference().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleResourceEncodeWithCustomType() throws IOException {
|
public void testSimpleResourceEncodeWithCustomType() throws IOException {
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ public class XmlParserTest {
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
BundleEntry e = b.addEntry();
|
BundleEntry e = b.addEntry();
|
||||||
e.setResource(new Patient());
|
e.setResource(new Patient());
|
||||||
e.addCategory().setLabel("label").setTerm("term").setScheme("scheme");
|
e.addCategory("scheme", "term", "label");
|
||||||
|
|
||||||
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||||
ourLog.info(val);
|
ourLog.info(val);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package ca.uhn.fhir.rest.server;
|
package ca.uhn.fhir.rest.server;
|
||||||
|
|
||||||
import static org.apache.commons.lang.StringUtils.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package ca.uhn.fhir.rest.server;
|
package ca.uhn.fhir.rest.server;
|
||||||
|
|
||||||
import static org.apache.commons.lang.StringUtils.*;
|
import static org.apache.commons.lang.StringUtils.defaultString;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
@ -33,7 +34,6 @@ import ca.uhn.fhir.rest.annotation.DeleteTags;
|
||||||
import ca.uhn.fhir.rest.annotation.GetTags;
|
import ca.uhn.fhir.rest.annotation.GetTags;
|
||||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||||
import ca.uhn.fhir.rest.annotation.TagListParam;
|
import ca.uhn.fhir.rest.annotation.TagListParam;
|
||||||
import ca.uhn.fhir.rest.annotation.VersionIdParam;
|
|
||||||
import ca.uhn.fhir.util.PortUtil;
|
import ca.uhn.fhir.util.PortUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,17 +94,6 @@ public class TagsServerTest {
|
||||||
assertEquals(tagList, ourLastTagList);
|
assertEquals(tagList, ourLastTagList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEquals() {
|
|
||||||
TagList list1 = ourProvider.getAllTagsPatient();
|
|
||||||
TagList list2 = ourProvider.getAllTagsPatient();
|
|
||||||
assertEquals(list1, list2);
|
|
||||||
|
|
||||||
list1 = ourProvider.getAllTagsPatient();
|
|
||||||
list2 = ourProvider.getAllTagsPatient();
|
|
||||||
list2.get(0).setTerm("!!!!!");
|
|
||||||
assertNotEquals(list1, list2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllTags() throws Exception {
|
public void testGetAllTags() throws Exception {
|
||||||
|
@ -134,8 +123,10 @@ public class TagsServerTest {
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||||
TagList expected = ourProvider.getAllTags();
|
|
||||||
expected.get(0).setTerm("Patient");
|
TagList expected = new TagList();
|
||||||
|
expected.addTag(null, "Patient", "DogLabel");
|
||||||
|
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,8 +143,10 @@ public class TagsServerTest {
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||||
TagList expected = ourProvider.getAllTags();
|
|
||||||
expected.get(0).setTerm("Patient111");
|
TagList expected = new TagList();
|
||||||
|
expected.addTag(null, "Patient111", "DogLabel");
|
||||||
|
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,8 +163,9 @@ public class TagsServerTest {
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||||
TagList expected = ourProvider.getAllTags();
|
TagList expected = new TagList();
|
||||||
expected.get(0).setTerm("Patient111222");
|
expected.addTag(null, "Patient111222", "DogLabel");
|
||||||
|
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,8 +182,9 @@ public class TagsServerTest {
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||||
TagList expected = ourProvider.getAllTags();
|
TagList expected = new TagList();
|
||||||
expected.get(0).setTerm("Patient111222");
|
expected.addTag(null, "Patient111222", "DogLabel");
|
||||||
|
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,15 +256,9 @@ public class TagsServerTest {
|
||||||
|
|
||||||
public static class DummyProvider {
|
public static class DummyProvider {
|
||||||
|
|
||||||
@AddTags(type = Patient.class)
|
|
||||||
public void addTagsPatient(@IdParam IdDt theId, @VersionIdParam IdDt theVersion, @TagListParam TagList theTagList) {
|
|
||||||
ourLastOutcome = "add" + theId.getIdPart() + theVersion.getVersionIdPart();
|
|
||||||
ourLastTagList=theTagList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@AddTags(type = Patient.class)
|
@AddTags(type = Patient.class)
|
||||||
public void addTagsPatient(@IdParam IdDt theId, @TagListParam TagList theTagList) {
|
public void addTagsPatient(@IdParam IdDt theId, @TagListParam TagList theTagList) {
|
||||||
ourLastOutcome = "add" + theId.getIdPart();
|
ourLastOutcome = "add" + theId.getIdPart() + StringUtils.defaultString(theId.getVersionIdPart());
|
||||||
ourLastTagList=theTagList;
|
ourLastTagList=theTagList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,13 +286,13 @@ public class TagsServerTest {
|
||||||
return tagList;
|
return tagList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetTags(type = Patient.class)
|
// @GetTags(type = Patient.class)
|
||||||
public TagList getAllTagsPatientIdVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersion) {
|
// public TagList getAllTagsPatientIdVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersion) {
|
||||||
TagList tagList = new TagList();
|
// TagList tagList = new TagList();
|
||||||
tagList.add(new Tag((String) null, "Patient" + theId.getIdPart() + theVersion.getVersionIdPart(), "DogLabel"));
|
// tagList.add(new Tag((String) null, "Patient" + theId.getIdPart() + theVersion.getVersionIdPart(), "DogLabel"));
|
||||||
tagList.add(new Tag("http://cats", "AllCat", "CatLabel"));
|
// tagList.add(new Tag("http://cats", "AllCat", "CatLabel"));
|
||||||
return tagList;
|
// return tagList;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@GetTags(type = Observation.class)
|
@GetTags(type = Observation.class)
|
||||||
public TagList getAllTagsObservationIdVersion(@IdParam IdDt theId) {
|
public TagList getAllTagsObservationIdVersion(@IdParam IdDt theId) {
|
||||||
|
@ -313,15 +302,15 @@ public class TagsServerTest {
|
||||||
return tagList;
|
return tagList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteTags(type = Patient.class)
|
// @DeleteTags(type = Patient.class)
|
||||||
public void RemoveTagsPatient(@IdParam IdDt theId, @VersionIdParam IdDt theVersion, @TagListParam TagList theTagList) {
|
// public void RemoveTagsPatient(@IdParam IdDt theId, @VersionIdParam IdDt theVersion, @TagListParam TagList theTagList) {
|
||||||
ourLastOutcome = "Remove" + theId.getIdPart() + theVersion.getVersionIdPart();
|
// ourLastOutcome = "Remove" + theId.getIdPart() + theVersion.getVersionIdPart();
|
||||||
ourLastTagList=theTagList;
|
// ourLastTagList=theTagList;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@DeleteTags(type = Patient.class)
|
@DeleteTags(type = Patient.class)
|
||||||
public void RemoveTagsPatient(@IdParam IdDt theId, @TagListParam TagList theTagList) {
|
public void RemoveTagsPatient(@IdParam IdDt theId, @TagListParam TagList theTagList) {
|
||||||
ourLastOutcome = "Remove" + theId.getIdPart();
|
ourLastOutcome = "Remove" + theId.getIdPart()+StringUtils.defaultString(theId.getVersionIdPart());
|
||||||
ourLastTagList=theTagList;
|
ourLastTagList=theTagList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,23 +142,25 @@ public class UpdateTest {
|
||||||
dr.addCodedDiagnosis().addCoding().setCode("AAA");
|
dr.addCodedDiagnosis().addCoding().setCode("AAA");
|
||||||
|
|
||||||
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
||||||
httpPost.addHeader("Category", "Dog, Cat");
|
httpPost.addHeader("Category", "Dog; scheme=\"urn:animals\", Cat; scheme=\"urn:animals\"");
|
||||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||||
assertEquals(2, ourReportProvider.getLastTags().size());
|
|
||||||
assertEquals(new Tag("Dog"), ourReportProvider.getLastTags().get(0));
|
|
||||||
assertEquals(new Tag("Cat"), ourReportProvider.getLastTags().get(1));
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
|
assertEquals(2, ourReportProvider.getLastTags().size());
|
||||||
|
assertEquals(new Tag("urn:animals", "Dog"), ourReportProvider.getLastTags().get(0));
|
||||||
|
assertEquals(new Tag("urn:animals", "Cat"), ourReportProvider.getLastTags().get(1));
|
||||||
|
|
||||||
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
||||||
httpPost.addHeader("Category", "Dog; label=\"aa\", Cat; label=\"bb\"");
|
httpPost.addHeader("Category", "Dog; label=\"aa\"; scheme=\"urn:animals\", Cat; label=\"bb\"; scheme=\"urn:animals\"");
|
||||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
status = ourClient.execute(httpPost);
|
status = ourClient.execute(httpPost);
|
||||||
assertEquals(2, ourReportProvider.getLastTags().size());
|
|
||||||
assertEquals(new Tag((String) null, "Dog", "aa"), ourReportProvider.getLastTags().get(0));
|
|
||||||
assertEquals(new Tag((String) null, "Cat", "bb"), ourReportProvider.getLastTags().get(1));
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
|
assertEquals(2, ourReportProvider.getLastTags().size());
|
||||||
|
assertEquals(new Tag("urn:animals", "Dog", "aa"), ourReportProvider.getLastTags().get(0));
|
||||||
|
assertEquals(new Tag("urn:animals", "Cat", "bb"), ourReportProvider.getLastTags().get(1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -168,13 +170,14 @@ public class UpdateTest {
|
||||||
dr.addCodedDiagnosis().addCoding().setCode("AAA");
|
dr.addCodedDiagnosis().addCoding().setCode("AAA");
|
||||||
|
|
||||||
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
||||||
httpPost.addHeader("Category", "Dog");
|
httpPost.addHeader("Category", "Dog; scheme=\"animals\"");
|
||||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
|
||||||
assertEquals(new Tag("Dog"), ourReportProvider.getLastTags().get(0));
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
|
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||||
|
assertEquals(new Tag("animals", "Dog"), ourReportProvider.getLastTags().get(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -187,17 +190,19 @@ public class UpdateTest {
|
||||||
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"");
|
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"");
|
||||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||||
assertEquals(new Tag("http://foo", "Dog", null), ourReportProvider.getLastTags().get(0));
|
assertEquals(new Tag("http://foo", "Dog", null), ourReportProvider.getLastTags().get(0));
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
|
|
||||||
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
||||||
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\";");
|
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\";");
|
||||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
ourClient.execute(httpPost);
|
ourClient.execute(httpPost);
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||||
assertEquals(new Tag("http://foo", "Dog", null), ourReportProvider.getLastTags().get(0));
|
assertEquals(new Tag("http://foo", "Dog", null), ourReportProvider.getLastTags().get(0));
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,9 +224,10 @@ public class UpdateTest {
|
||||||
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"; label=\"aaaa\"; ");
|
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"; label=\"aaaa\"; ");
|
||||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
status=ourClient.execute(httpPost);
|
status=ourClient.execute(httpPost);
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||||
assertEquals(new Tag("http://foo", "Dog", "aaaa"), ourReportProvider.getLastTags().get(0));
|
assertEquals(new Tag("http://foo", "Dog", "aaaa"), ourReportProvider.getLastTags().get(0));
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,6 +242,7 @@ public class UpdateTest {
|
||||||
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
|
|
||||||
HttpResponse status = ourClient.execute(httpPut);
|
HttpResponse status = ourClient.execute(httpPut);
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
// String responseContent =
|
// String responseContent =
|
||||||
// IOUtils.toString(status.getEntity().getContent());
|
// IOUtils.toString(status.getEntity().getContent());
|
||||||
|
@ -243,7 +250,6 @@ public class UpdateTest {
|
||||||
|
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
assertEquals("http://localhost:" + ourPort + "/DiagnosticReport/001/_history/002", status.getFirstHeader("Location").getValue());
|
assertEquals("http://localhost:" + ourPort + "/DiagnosticReport/001/_history/002", status.getFirstHeader("Location").getValue());
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,11 +264,12 @@ public class UpdateTest {
|
||||||
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
|
|
||||||
CloseableHttpResponse status = ourClient.execute(httpPut);
|
CloseableHttpResponse status = ourClient.execute(httpPut);
|
||||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
|
||||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||||
ourLog.info("Response was:\n{}", responseContent);
|
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
ourLog.info("Response was:\n{}", responseContent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUpdateWrongResourceType() throws Exception {
|
public void testUpdateWrongResourceType() throws Exception {
|
||||||
|
@ -290,9 +297,11 @@ public class UpdateTest {
|
||||||
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Organization/001");
|
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Organization/001");
|
||||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
|
|
||||||
CloseableHttpResponse response = ourClient.execute(httpPost);
|
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
response.close();
|
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
status.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -377,6 +386,7 @@ public class UpdateTest {
|
||||||
return Observation.class;
|
return Observation.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
@Update()
|
@Update()
|
||||||
public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @ResourceParam DiagnosticOrder thePatient) {
|
public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @ResourceParam DiagnosticOrder thePatient) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1189,14 +1189,17 @@ public class FhirResourceDaoTest {
|
||||||
patient.addName().addFamily("Tester").addGiven("Joe");
|
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||||
TagList tagList = new TagList();
|
TagList tagList = new TagList();
|
||||||
tagList.addTag(null, "Dog", "Puppies");
|
tagList.addTag(null, "Dog", "Puppies");
|
||||||
|
// Add this twice
|
||||||
|
tagList.addTag("http://foo", "Cat", "Kittens");
|
||||||
tagList.addTag("http://foo", "Cat", "Kittens");
|
tagList.addTag("http://foo", "Cat", "Kittens");
|
||||||
patient.getResourceMetadata().put(ResourceMetadataKeyEnum.TAG_LIST, tagList);
|
patient.getResourceMetadata().put(ResourceMetadataKeyEnum.TAG_LIST, tagList);
|
||||||
|
|
||||||
MethodOutcome outcome = ourPatientDao.create(patient);
|
MethodOutcome outcome = ourPatientDao.create(patient);
|
||||||
assertNotNull(outcome.getId());
|
IdDt patientId = outcome.getId();
|
||||||
assertFalse(outcome.getId().isEmpty());
|
assertNotNull(patientId);
|
||||||
|
assertFalse(patientId.isEmpty());
|
||||||
|
|
||||||
Patient retrieved = ourPatientDao.read(outcome.getId());
|
Patient retrieved = ourPatientDao.read(patientId);
|
||||||
TagList published = (TagList) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
|
TagList published = (TagList) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
|
||||||
assertEquals(2, published.size());
|
assertEquals(2, published.size());
|
||||||
assertEquals("Dog", published.get(0).getTerm());
|
assertEquals("Dog", published.get(0).getTerm());
|
||||||
|
@ -1217,6 +1220,23 @@ public class FhirResourceDaoTest {
|
||||||
assertEquals("Kittens", published.get(1).getLabel());
|
assertEquals("Kittens", published.get(1).getLabel());
|
||||||
assertEquals("http://foo", published.get(1).getScheme());
|
assertEquals("http://foo", published.get(1).getScheme());
|
||||||
|
|
||||||
|
ourPatientDao.addTag(patientId, "http://foo", "Cat", "Kittens");
|
||||||
|
ourPatientDao.addTag(patientId, "http://foo", "Cow", "Calves");
|
||||||
|
|
||||||
|
retrieved = ourPatientDao.read(patientId);
|
||||||
|
published = (TagList) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
|
||||||
|
assertEquals(3, published.size());
|
||||||
|
assertEquals("Dog", published.get(0).getTerm());
|
||||||
|
assertEquals("Puppies", published.get(0).getLabel());
|
||||||
|
assertEquals(null, published.get(0).getScheme());
|
||||||
|
assertEquals("Cat", published.get(1).getTerm());
|
||||||
|
assertEquals("Kittens", published.get(1).getLabel());
|
||||||
|
assertEquals("http://foo", published.get(1).getScheme());
|
||||||
|
assertEquals("Cow", published.get(2).getTerm());
|
||||||
|
assertEquals("Calves", published.get(2).getLabel());
|
||||||
|
assertEquals("http://foo", published.get(2).getScheme());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue