Get tags working as a set instead of a list
This commit is contained in:
parent
0d6eca70a9
commit
24caec9f44
|
@ -59,12 +59,20 @@ public class Bundle extends BaseBundle /* implements IElement */{
|
|||
private IntegerDt myTotalResults;
|
||||
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() {
|
||||
Tag retVal = new Tag();
|
||||
getCategories().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public void addCategory(String theScheme, String theTerm, String theLabel) {
|
||||
getCategories().add(new Tag(theScheme, theTerm, theLabel));
|
||||
}
|
||||
|
||||
|
||||
public void addCategory(Tag theTag) {
|
||||
getCategories().add(theTag);
|
||||
}
|
||||
|
|
|
@ -50,12 +50,19 @@ public class BundleEntry extends BaseBundle {
|
|||
private StringDt myTitle;
|
||||
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() {
|
||||
Tag retVal = new Tag();
|
||||
getCategories().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public void addCategory(String theScheme, String theTerm, String theLabel) {
|
||||
getCategories().add(new Tag(theScheme, theTerm, theLabel));
|
||||
}
|
||||
|
||||
public void addCategory(Tag theTag) {
|
||||
getCategories().add(theTag);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,13 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
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 static final String ATTR_LABEL = "label";
|
||||
|
@ -47,18 +54,28 @@ public class Tag extends BaseElement implements IElement {
|
|||
*/
|
||||
public static final String HL7_ORG_SECURITY_TAG = "http://hl7.org/fhir/tag/security";
|
||||
|
||||
private transient Integer myHashCode;
|
||||
private String myLabel;
|
||||
private String myScheme;
|
||||
private String myTerm;
|
||||
|
||||
/**
|
||||
* @deprecated Tags will become immutable in a future release, so this constructor should not be used.
|
||||
*/
|
||||
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) {
|
||||
this((String) null, theTerm, null);
|
||||
}
|
||||
|
||||
public Tag(String theScheme, String theTerm) {
|
||||
myScheme = theScheme;
|
||||
myTerm = theTerm;
|
||||
}
|
||||
|
||||
public Tag(String theScheme, String theTerm, String theLabel) {
|
||||
myTerm = theTerm;
|
||||
myLabel = theLabel;
|
||||
|
@ -75,32 +92,6 @@ public class Tag extends BaseElement implements IElement {
|
|||
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() {
|
||||
return myLabel;
|
||||
|
@ -114,19 +105,34 @@ public class Tag extends BaseElement implements IElement {
|
|||
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
|
||||
public int hashCode() {
|
||||
if (myHashCode != null) {
|
||||
System.out.println("Tag alread has hashcode " + myHashCode + " - " + myScheme + " - " + myTerm + " - " + myLabel);
|
||||
return myHashCode;
|
||||
}
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((myLabel == null) ? 0 : myLabel.hashCode());
|
||||
result = prime * result + ((myScheme == null) ? 0 : myScheme.hashCode());
|
||||
result = prime * result + ((myTerm == null) ? 0 : myTerm.hashCode());
|
||||
myHashCode = result;
|
||||
System.out.println("Tag has hashcode " + myHashCode + " - " + myScheme + " - " + myTerm + " - " + myLabel);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -135,21 +141,33 @@ public class Tag extends BaseElement implements IElement {
|
|||
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) {
|
||||
myLabel = theLabel;
|
||||
myHashCode = null;
|
||||
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) {
|
||||
myScheme = theScheme;
|
||||
myHashCode = null;
|
||||
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) {
|
||||
myTerm = theTerm;
|
||||
myHashCode = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,11 +74,41 @@ public class TagList implements Set<Tag>, Serializable {
|
|||
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);
|
||||
myOrderedTags = null;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
@ -131,81 +161,6 @@ public class TagList implements Set<Tag>, Serializable {
|
|||
}
|
||||
return myOrderedTags.get(theIndex);
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public Tag set(int theIndex, Tag theElement) {
|
||||
// throw new UnsupportedOperationException();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public void add(int theIndex, Tag theElement) {
|
||||
// myTagSet.add(theElement);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public Tag remove(int theIndex) {
|
||||
// Tag retVal = myTagSet.remove(theIndex);
|
||||
// myTagSet.remove(retVal);
|
||||
// return retVal;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public int indexOf(Object theO) {
|
||||
// myTagSet.remove(theO);
|
||||
// return myTagSet.indexOf(theO);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public int lastIndexOf(Object theO) {
|
||||
// return myTagSet.lastIndexOf(theO);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public ListIterator<Tag> listIterator() {
|
||||
// return myTagSet.listIterator();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public ListIterator<Tag> listIterator(int theIndex) {
|
||||
// return myTagSet.listIterator(theIndex);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public List<Tag> subList(int theFromIndex, int theToIndex) {
|
||||
// return myTagSet.subList(theFromIndex, theToIndex);
|
||||
// }
|
||||
|
||||
public Tag getTag(String theScheme, String theTerm) {
|
||||
for (Tag next : this) {
|
||||
|
@ -269,22 +224,6 @@ public class TagList implements Set<Tag>, Serializable {
|
|||
return myTagSet.toArray();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
// public boolean addAll(int theIndex, Collection<? extends Tag> theC) {
|
||||
// myTagSet.addAll(theC);
|
||||
// return myTagSet.addAll(theC);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @deprecated TagList will not implement the {@link List} interface in a future release, as tag order is not supposed to be meaningful
|
||||
// */
|
||||
// @Deprecated
|
||||
// @Override
|
||||
|
||||
@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
|
||||
* intended for embedded XHTML content
|
||||
* Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically intended for embedded XHTML content
|
||||
*/
|
||||
public void xmlEvent(XMLEvent theNextEvent) {
|
||||
myState.xmlEvent(theNextEvent);
|
||||
|
@ -222,35 +221,37 @@ class ParserState<T> {
|
|||
private static final int STATE_TERM = 1;
|
||||
|
||||
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);
|
||||
myInstance = theEntry;
|
||||
myTagList = theTagList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
if ("term".equals(theName)) {
|
||||
myInstance.setTerm(theValue);
|
||||
myTerm = theValue;
|
||||
} else if ("label".equals(theName)) {
|
||||
myInstance.setLabel(theValue);
|
||||
myLabel = theValue;
|
||||
} else if ("scheme".equals(theName)) {
|
||||
myInstance.setScheme(theValue);
|
||||
myScheme = theValue;
|
||||
} else if ("value".equals(theName)) {
|
||||
/*
|
||||
* This handles XML parsing, which is odd for this quasi-resource type, since the tag has three values
|
||||
* instead of one like everything else.
|
||||
* This handles XML parsing, which is odd for this quasi-resource type, since the tag has three values instead of one like everything else.
|
||||
*/
|
||||
switch (myCatState) {
|
||||
case STATE_LABEL:
|
||||
myInstance.setLabel(theValue);
|
||||
myLabel = theValue;
|
||||
break;
|
||||
case STATE_TERM:
|
||||
myInstance.setTerm(theValue);
|
||||
myTerm = theValue;
|
||||
break;
|
||||
case STATE_SCHEME:
|
||||
myInstance.setScheme(theValue);
|
||||
myScheme = theValue;
|
||||
break;
|
||||
default:
|
||||
super.string(theValue);
|
||||
|
@ -265,6 +266,9 @@ class ParserState<T> {
|
|||
if (myCatState != STATE_NONE) {
|
||||
myCatState = STATE_NONE;
|
||||
} else {
|
||||
if (isNotEmpty(myScheme) || isNotBlank(myTerm) || isNotBlank(myLabel)) {
|
||||
myTagList.addTag(myScheme, myTerm, myLabel);
|
||||
}
|
||||
pop();
|
||||
}
|
||||
}
|
||||
|
@ -422,7 +426,7 @@ class ParserState<T> {
|
|||
} else if ("summary".equals(theLocalPart)) {
|
||||
push(new XhtmlState(getPreResourceState(), myEntry.getSummary(), false));
|
||||
} else if ("category".equals(theLocalPart)) {
|
||||
push(new AtomCategoryState(myEntry.addCategory()));
|
||||
push(new AtomCategoryState(myEntry.getCategories()));
|
||||
} else if ("deleted".equals(theLocalPart) && myJsonMode) {
|
||||
// JSON and XML deleted entries are completely different for some reason
|
||||
myDeleted = true;
|
||||
|
@ -629,7 +633,7 @@ class ParserState<T> {
|
|||
} else if ("author".equals(theLocalPart)) {
|
||||
push(new AtomAuthorState(myInstance));
|
||||
} 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)) {
|
||||
push(new AtomDeletedEntryState(myInstance, myResourceType));
|
||||
} else {
|
||||
|
@ -707,7 +711,8 @@ class ParserState<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param theData The string value
|
||||
* @param theData
|
||||
* The string value
|
||||
*/
|
||||
public void string(String theData) {
|
||||
// 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) {
|
||||
// ignore
|
||||
|
@ -1275,7 +1281,8 @@ class ParserState<T> {
|
|||
myContext.newTerser().visit(myInstance, new IModelVisitor() {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
@ -1508,7 +1515,7 @@ class ParserState<T> {
|
|||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
if (TagList.ATTR_CATEGORY.equals(theLocalPart)) {
|
||||
push(new TagState(myTagList.addTag()));
|
||||
push(new TagState(myTagList));
|
||||
} else {
|
||||
throw new DataFormatException("Unexpected element: " + theLocalPart);
|
||||
}
|
||||
|
@ -1524,11 +1531,14 @@ class ParserState<T> {
|
|||
private static final int SCHEME = 3;
|
||||
private static final int TERM = 1;
|
||||
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);
|
||||
myTag = theTag;
|
||||
myTagList = theTagList;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1537,13 +1547,13 @@ class ParserState<T> {
|
|||
|
||||
switch (mySubState) {
|
||||
case TERM:
|
||||
myTag.setTerm(value);
|
||||
myTerm = (value);
|
||||
break;
|
||||
case LABEL:
|
||||
myTag.setLabel(value);
|
||||
myLabel = (value);
|
||||
break;
|
||||
case SCHEME:
|
||||
myTag.setScheme(value);
|
||||
myScheme = (value);
|
||||
break;
|
||||
case NONE:
|
||||
// This handles JSON encoding, which is a bit weird
|
||||
|
@ -1559,6 +1569,9 @@ class ParserState<T> {
|
|||
if (mySubState != NONE) {
|
||||
mySubState = NONE;
|
||||
} else {
|
||||
if (isNotEmpty(myScheme) || isNotBlank(myTerm) || isNotBlank(myLabel)) {
|
||||
myTagList.addTag(myScheme, myTerm, myLabel);
|
||||
}
|
||||
pop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,10 +214,6 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding<Void>
|
|||
return false;
|
||||
}
|
||||
|
||||
if ((myVersionIdParamIndex != null) != (theRequest.getId() != null && theRequest.getId().hasVersionIdPart())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isDelete()) {
|
||||
if (Constants.PARAM_DELETE.equals(theRequest.getSecondaryOperation()) == false) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ package ca.uhn.fhir.rest.method;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
import java.io.IOException;
|
||||
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.IResourceProvider;
|
||||
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.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
|
|
@ -28,6 +28,20 @@ public class TagListTest {
|
|||
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();
|
||||
|
|
|
@ -63,18 +63,17 @@ public class JsonParserTest {
|
|||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserTest.class);
|
||||
private static FhirContext ourCtx;
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeNarrativeBlockInBundle() {
|
||||
Patient p = new Patient();
|
||||
p.addIdentifier("foo", "bar");
|
||||
p.getText().setStatus(NarrativeStatusEnum.GENERATED);
|
||||
p.getText().setDiv("<div>hello</div>");
|
||||
|
||||
|
||||
Bundle b = new Bundle();
|
||||
b.getTotalResults().setValue(123);
|
||||
b.addEntry().setResource(p);
|
||||
|
||||
|
||||
String out = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
ourLog.info(out);
|
||||
assertThat(out, containsString("<div>hello</div>"));
|
||||
|
@ -84,29 +83,28 @@ public class JsonParserTest {
|
|||
ourLog.info(out);
|
||||
// Backslashes need to be escaped because they are in a JSON value
|
||||
assertThat(out, containsString("<xhtml:div xmlns:xhtml=\\\"http://www.w3.org/1999/xhtml\\\">hello</xhtml:div>"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodingNullExtension() {
|
||||
Patient p = new Patient();
|
||||
ExtensionDt extension = new ExtensionDt(false, "http://foo#bar");
|
||||
p.addUndeclaredExtension(extension);
|
||||
String str = ourCtx.newJsonParser().encodeResourceToString(p);
|
||||
|
||||
|
||||
assertEquals("{\"resourceType\":\"Patient\"}", str);
|
||||
|
||||
|
||||
extension.setValue(new StringDt());
|
||||
|
||||
str = ourCtx.newJsonParser().encodeResourceToString(p);
|
||||
str = ourCtx.newJsonParser().encodeResourceToString(p);
|
||||
assertEquals("{\"resourceType\":\"Patient\"}", str);
|
||||
|
||||
extension.setValue(new StringDt(""));
|
||||
|
||||
str = ourCtx.newJsonParser().encodeResourceToString(p);
|
||||
str = ourCtx.newJsonParser().encodeResourceToString(p);
|
||||
assertEquals("{\"resourceType\":\"Patient\"}", str);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -119,79 +117,77 @@ public class JsonParserTest {
|
|||
assertThat(e.getMessage(), containsString("double quote"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionInCompositeElement() {
|
||||
|
||||
|
||||
Conformance c = new Conformance();
|
||||
c.addRest().getSecurity().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
assertEquals(encoded, "{\"resourceType\":\"Conformance\",\"rest\":[{\"security\":{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}}]}");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionInPrimitiveElement() {
|
||||
|
||||
|
||||
Conformance c = new Conformance();
|
||||
c.getAcceptUnknown().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
assertEquals(encoded, "{\"resourceType\":\"Conformance\",\"_acceptUnknown\":[{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}]}");
|
||||
|
||||
// Now with a value
|
||||
ourLog.info("---------------");
|
||||
|
||||
|
||||
c = new Conformance();
|
||||
c.getAcceptUnknown().setValue(true);
|
||||
c.getAcceptUnknown().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
assertEquals(encoded, "{\"resourceType\":\"Conformance\",\"acceptUnknown\":true,\"_acceptUnknown\":[{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}]}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionInResourceElement() {
|
||||
|
||||
|
||||
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"));
|
||||
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
assertEquals(encoded, "{\"resourceType\":\"Conformance\",\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBinaryResource() {
|
||||
|
||||
Binary patient = new Binary();
|
||||
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);
|
||||
assertEquals("{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}",val);
|
||||
|
||||
assertEquals("{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}", val);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -210,84 +206,69 @@ public class JsonParserTest {
|
|||
" }" +
|
||||
"}";
|
||||
//@formatter:on
|
||||
|
||||
|
||||
Patient res = (Patient) ourCtx.newJsonParser().parseResource(text);
|
||||
String value = res.getText().getDiv().getValueAsString();
|
||||
|
||||
|
||||
assertNull(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testNestedContainedResources() {
|
||||
|
||||
Observation A = new Observation();
|
||||
A.getName().setText("A");
|
||||
|
||||
|
||||
Observation B = new Observation();
|
||||
B.getName().setText("B");
|
||||
A.addRelated().setTarget(new ResourceReferenceDt(B));
|
||||
|
||||
|
||||
Observation C = new Observation();
|
||||
C.getName().setText("C");
|
||||
B.addRelated().setTarget(new ResourceReferenceDt(C));
|
||||
|
||||
String str = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(A);
|
||||
ourLog.info(str);
|
||||
|
||||
|
||||
assertThat(str, stringContainsInOrder(Arrays.asList("\"text\":\"B\"", "\"text\":\"C\"", "\"text\":\"A\"")));
|
||||
|
||||
|
||||
// Only one (outer) contained block
|
||||
int idx0 = str.indexOf("\"contained\"");
|
||||
int idx1 = str.indexOf("\"contained\"",idx0+1);
|
||||
|
||||
int idx1 = str.indexOf("\"contained\"", idx0 + 1);
|
||||
|
||||
assertNotEquals(-1, idx0);
|
||||
assertEquals(-1, idx1);
|
||||
|
||||
|
||||
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();
|
||||
assertEquals("B",obsB.getName().getText().getValue());
|
||||
assertEquals("B", obsB.getName().getText().getValue());
|
||||
|
||||
Observation obsC = (Observation) obsB.getRelatedFirstRep().getTarget().getResource();
|
||||
assertEquals("C",obsC.getName().getText().getValue());
|
||||
assertEquals("C", obsC.getName().getText().getValue());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParseQuery() {
|
||||
String msg = "{\n" +
|
||||
" \"resourceType\": \"Query\",\n" +
|
||||
" \"text\": {\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" +
|
||||
"}";
|
||||
String msg = "{\n" + " \"resourceType\": \"Query\",\n" + " \"text\": {\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);
|
||||
|
||||
|
||||
assertEquals("urn:uuid:42b253f5-fa17-40d0-8da5-44aeb4230376", query.getIdentifier().getValueAsString());
|
||||
assertEquals("http://hl7.org/fhir/query#_query", query.getParameterFirstRep().getUrlAsString());
|
||||
assertEquals("example", query.getParameterFirstRep().getValueAsPrimitive().getValueAsString());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeQuery() {
|
||||
Query q = new Query();
|
||||
ExtensionDt parameter = q.addParameter();
|
||||
parameter.setUrl("http://hl7.org/fhir/query#_query").setValue(new StringDt("example"));
|
||||
|
||||
|
||||
|
||||
String val = new FhirContext().newJsonParser().encodeResourceToString(q);
|
||||
ourLog.info(val);
|
||||
|
||||
|
@ -307,21 +288,21 @@ public class JsonParserTest {
|
|||
ourLog.info("Expect: {}", expected);
|
||||
ourLog.info("Got : {}", val);
|
||||
assertEquals(expected, val);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParseBinaryResource() {
|
||||
|
||||
Binary val = ourCtx.newJsonParser().parseResource(Binary.class, "{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}");
|
||||
assertEquals("foo", val.getContentType());
|
||||
assertArrayEquals(new byte[] {1,2,3,4}, val.getContent());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, val.getContent());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTagList() {
|
||||
|
||||
|
||||
//@formatter:off
|
||||
String tagListStr = "{\n" +
|
||||
" \"resourceType\" : \"TagList\", " +
|
||||
|
@ -343,7 +324,7 @@ public class JsonParserTest {
|
|||
" ] " +
|
||||
"}";
|
||||
//@formatter:on
|
||||
|
||||
|
||||
TagList tagList = new FhirContext().newJsonParser().parseTagList(tagListStr);
|
||||
assertEquals(3, tagList.size());
|
||||
assertEquals("term0", tagList.get(0).getTerm());
|
||||
|
@ -355,7 +336,7 @@ public class JsonParserTest {
|
|||
assertEquals("term2", tagList.get(2).getTerm());
|
||||
assertEquals("label2", tagList.get(2).getLabel());
|
||||
assertEquals(null, tagList.get(2).getScheme());
|
||||
|
||||
|
||||
/*
|
||||
* Encode
|
||||
*/
|
||||
|
@ -380,28 +361,28 @@ public class JsonParserTest {
|
|||
"]" +
|
||||
"}";
|
||||
//@formatter:on
|
||||
|
||||
|
||||
String encoded = new FhirContext().newJsonParser().encodeTagListToString(tagList);
|
||||
assertEquals(expected,encoded);
|
||||
assertEquals(expected, encoded);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleCategory() {
|
||||
|
||||
Bundle b = new Bundle();
|
||||
BundleEntry e = b.addEntry();
|
||||
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);
|
||||
ourLog.info(val);
|
||||
|
||||
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
||||
|
||||
|
||||
b = new FhirContext().newJsonParser().parseBundle(val);
|
||||
assertEquals(1,b.getEntries().size());
|
||||
assertEquals(1,b.getCategories().size());
|
||||
assertEquals(1, b.getEntries().size());
|
||||
assertEquals(1, b.getCategories().size());
|
||||
assertEquals("term", b.getCategories().get(0).getTerm());
|
||||
assertEquals("label", b.getCategories().get(0).getLabel());
|
||||
assertEquals("scheme", b.getCategories().get(0).getScheme());
|
||||
|
@ -415,23 +396,23 @@ public class JsonParserTest {
|
|||
Bundle b = new Bundle();
|
||||
BundleEntry e = b.addEntry();
|
||||
e.setResource(new Patient());
|
||||
e.addCategory().setLabel("label").setTerm("term").setScheme("scheme");
|
||||
|
||||
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
||||
e.addCategory("scheme", "term", "label");
|
||||
|
||||
String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
||||
ourLog.info(val);
|
||||
|
||||
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
||||
|
||||
b = new FhirContext().newJsonParser().parseBundle(val);
|
||||
assertEquals(1,b.getEntries().size());
|
||||
assertEquals(1,b.getEntries().get(0).getCategories().size());
|
||||
|
||||
b = ourCtx.newJsonParser().parseBundle(val);
|
||||
assertEquals(1, b.getEntries().size());
|
||||
assertEquals(1, b.getEntries().get(0).getCategories().size());
|
||||
assertEquals("term", b.getEntries().get(0).getCategories().get(0).getTerm());
|
||||
assertEquals("label", b.getEntries().get(0).getCategories().get(0).getLabel());
|
||||
assertEquals("scheme", b.getEntries().get(0).getCategories().get(0).getScheme());
|
||||
assertNull(b.getEntries().get(0).getResource());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeContainedResources() throws IOException {
|
||||
|
||||
|
@ -450,7 +431,6 @@ public class JsonParserTest {
|
|||
parseAndEncode("/alert.profile.json");
|
||||
}
|
||||
|
||||
|
||||
private void parseAndEncode(String name) throws IOException {
|
||||
String msg = IOUtils.toString(XmlParser.class.getResourceAsStream(name));
|
||||
ourLog.info(msg);
|
||||
|
@ -465,16 +445,14 @@ public class JsonParserTest {
|
|||
JSON actual = JSONSerializer.toJSON(encoded.trim());
|
||||
|
||||
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("Actual : {}", act);
|
||||
|
||||
|
||||
assertEquals(exp, act);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeContainedResourcesMore() {
|
||||
|
||||
|
@ -517,8 +495,7 @@ public class JsonParserTest {
|
|||
assertEquals("line1", ref.getLineFirstRep().getValue());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeDeclaredExtensionWithResourceContent() {
|
||||
IParser parser = new FhirContext().newJsonParser();
|
||||
|
@ -543,20 +520,18 @@ public class JsonParserTest {
|
|||
|
||||
ValueSet valueSet = new ValueSet();
|
||||
valueSet.addTelecom().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
|
||||
|
||||
String encoded = ourCtx.newJsonParser().encodeResourceToString(valueSet);
|
||||
assertThat(encoded, containsString("\"telecom\":[{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeExt() throws Exception {
|
||||
|
||||
ValueSet valueSet = new ValueSet();
|
||||
valueSet.setId("123456");
|
||||
|
||||
|
||||
Define define = valueSet.getDefine();
|
||||
DefineConcept code = define.addConcept();
|
||||
code.setCode("someCode");
|
||||
|
@ -567,11 +542,12 @@ public class JsonParserTest {
|
|||
ourLog.info(encoded);
|
||||
|
||||
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
|
||||
public void testEncodeExtensionWithResourceContent() {
|
||||
IParser parser = new FhirContext().newJsonParser();
|
||||
|
@ -593,7 +569,6 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeInvalidChildGoodException() {
|
||||
Observation obs = new Observation();
|
||||
|
@ -607,7 +582,7 @@ public class JsonParserTest {
|
|||
assertThat(e.getMessage(), StringContains.containsString("DecimalDt"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeResourceRef() throws DataFormatException {
|
||||
|
||||
|
@ -662,7 +637,7 @@ public class JsonParserTest {
|
|||
String enc = new FhirContext().newJsonParser().encodeResourceToString(patient);
|
||||
ourLog.info(enc);
|
||||
assertEquals("{\"resourceType\":\"Patient\",\"name\":[{\"extension\":[{\"url\":\"http://examples.com#givenext\",\"valueString\":\"Hello\"}],\"family\":[\"Shmoe\"],\"given\":[\"Joe\"]}]}", enc);
|
||||
|
||||
|
||||
IParser newJsonParser = new FhirContext().newJsonParser();
|
||||
StringReader reader = new StringReader(enc);
|
||||
Patient parsed = newJsonParser.parseResource(Patient.class, reader);
|
||||
|
@ -753,7 +728,7 @@ public class JsonParserTest {
|
|||
assertEquals("http://scheme", bundle.getCategories().get(0).getScheme());
|
||||
assertEquals("http://term", bundle.getCategories().get(0).getTerm());
|
||||
assertEquals("label", bundle.getCategories().get(0).getLabel());
|
||||
|
||||
|
||||
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(bundle);
|
||||
ourLog.info(encoded);
|
||||
|
||||
|
@ -768,9 +743,9 @@ public class JsonParserTest {
|
|||
|
||||
DiagnosticReport res = (DiagnosticReport) entry.getResource();
|
||||
assertEquals("Complete Blood Count", res.getName().getText().getValue());
|
||||
|
||||
|
||||
assertThat(entry.getSummary().getValueAsString(), containsString("CBC Report for Wile"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -790,10 +765,9 @@ public class JsonParserTest {
|
|||
|
||||
BundleEntry deletedEntry = bundle.getEntries().get(3);
|
||||
assertEquals("2014-06-20T20:15:49Z", deletedEntry.getDeletedAt().getValueAsString());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This sample has extra elements in <searchParam> that are not actually a part of the spec any more..
|
||||
*/
|
||||
|
@ -828,10 +802,10 @@ public class JsonParserTest {
|
|||
public static void beforeClass() {
|
||||
ourCtx = new FhirContext();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParseBundleDeletedEntry() {
|
||||
|
||||
|
||||
//@formatter:off
|
||||
String bundleString =
|
||||
"{" +
|
||||
|
@ -851,7 +825,7 @@ public class JsonParserTest {
|
|||
"]" +
|
||||
"}";
|
||||
//@formatter:on
|
||||
|
||||
|
||||
Bundle bundle = ourCtx.newJsonParser().parseBundle(bundleString);
|
||||
BundleEntry entry = bundle.getEntries().get(0);
|
||||
assertEquals("2012-05-29T23:45:32+00:00", entry.getDeletedAt().getValueAsString());
|
||||
|
@ -859,19 +833,19 @@ public class JsonParserTest {
|
|||
assertEquals("1", entry.getResource().getId().getIdPart());
|
||||
assertEquals("2", entry.getResource().getId().getVersionIdPart());
|
||||
assertEquals(new InstantDt("2012-05-29T23:45:32+00:00"), entry.getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.DELETED_AT));
|
||||
|
||||
|
||||
// Now encode
|
||||
|
||||
|
||||
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(bundle));
|
||||
String encoded = ourCtx.newJsonParser().encodeBundleToString(bundle);
|
||||
assertEquals(bundleString,encoded);
|
||||
|
||||
assertEquals(bundleString, encoded);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundle() throws InterruptedException {
|
||||
Bundle b= new Bundle();
|
||||
|
||||
Bundle b = new Bundle();
|
||||
|
||||
InstantDt pub = InstantDt.withCurrentTime();
|
||||
b.setPublished(pub);
|
||||
Thread.sleep(2);
|
||||
|
@ -882,35 +856,34 @@ public class JsonParserTest {
|
|||
entry.getId().setValue("1");
|
||||
entry.setResource(p1);
|
||||
entry.getSummary().setValueAsString("this is the summary");
|
||||
|
||||
|
||||
Patient p2 = new Patient();
|
||||
p2.addName().addFamily("Family2");
|
||||
entry = b.addEntry();
|
||||
entry.getId().setValue("2");
|
||||
entry.setLinkAlternate(new StringDt("http://foo/bar"));
|
||||
entry.setResource(p2);
|
||||
|
||||
|
||||
BundleEntry deletedEntry = b.addEntry();
|
||||
deletedEntry.setId(new IdDt("Patient/3"));
|
||||
InstantDt nowDt = InstantDt.withCurrentTime();
|
||||
deletedEntry.setDeleted(nowDt);
|
||||
|
||||
|
||||
String bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
ourLog.info(bundleString);
|
||||
|
||||
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("this is the summary"));
|
||||
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));
|
||||
|
||||
|
||||
b.getEntries().remove(2);
|
||||
bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
assertThat(bundleString, not(containsString("deleted")));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -964,7 +937,7 @@ public class JsonParserTest {
|
|||
// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
|
||||
String exp = expected.toString().replace("\\\"Jim\\\"", ""Jim"");
|
||||
String act = actual.toString();
|
||||
|
||||
|
||||
ourLog.info("Expected: {}", exp);
|
||||
ourLog.info("Actual : {}", act);
|
||||
assertEquals(exp, act);
|
||||
|
@ -978,11 +951,10 @@ public class JsonParserTest {
|
|||
public void testParseWithIncorrectReference() throws IOException {
|
||||
String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"));
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleResourceEncodeWithCustomType() throws IOException {
|
||||
|
||||
|
@ -1011,7 +983,7 @@ public class JsonParserTest {
|
|||
// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
|
||||
String exp = expected.toString().replace("\\\"Jim\\\"", ""Jim"");
|
||||
String act = actual.toString();
|
||||
|
||||
|
||||
ourLog.info("Expected: {}", exp);
|
||||
ourLog.info("Actual : {}", act);
|
||||
assertEquals(exp, act);
|
||||
|
|
|
@ -199,7 +199,7 @@ public class XmlParserTest {
|
|||
Bundle b = new Bundle();
|
||||
BundleEntry e = b.addEntry();
|
||||
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);
|
||||
ourLog.info(val);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package ca.uhn.fhir.rest.server;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package ca.uhn.fhir.rest.server;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.apache.commons.lang.StringUtils.defaultString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
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.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.TagListParam;
|
||||
import ca.uhn.fhir.rest.annotation.VersionIdParam;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
|
||||
/**
|
||||
|
@ -94,17 +94,6 @@ public class TagsServerTest {
|
|||
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
|
||||
public void testGetAllTags() throws Exception {
|
||||
|
@ -134,8 +123,10 @@ public class TagsServerTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -152,8 +143,10 @@ public class TagsServerTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -170,8 +163,9 @@ public class TagsServerTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||
TagList expected = ourProvider.getAllTags();
|
||||
expected.get(0).setTerm("Patient111222");
|
||||
TagList expected = new TagList();
|
||||
expected.addTag(null, "Patient111222", "DogLabel");
|
||||
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
@ -188,8 +182,9 @@ public class TagsServerTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||
TagList expected = ourProvider.getAllTags();
|
||||
expected.get(0).setTerm("Patient111222");
|
||||
TagList expected = new TagList();
|
||||
expected.addTag(null, "Patient111222", "DogLabel");
|
||||
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
@ -261,15 +256,9 @@ public class TagsServerTest {
|
|||
|
||||
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)
|
||||
public void addTagsPatient(@IdParam IdDt theId, @TagListParam TagList theTagList) {
|
||||
ourLastOutcome = "add" + theId.getIdPart();
|
||||
ourLastOutcome = "add" + theId.getIdPart() + StringUtils.defaultString(theId.getVersionIdPart());
|
||||
ourLastTagList=theTagList;
|
||||
}
|
||||
|
||||
|
@ -297,13 +286,13 @@ public class TagsServerTest {
|
|||
return tagList;
|
||||
}
|
||||
|
||||
@GetTags(type = Patient.class)
|
||||
public TagList getAllTagsPatientIdVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersion) {
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag((String) null, "Patient" + theId.getIdPart() + theVersion.getVersionIdPart(), "DogLabel"));
|
||||
tagList.add(new Tag("http://cats", "AllCat", "CatLabel"));
|
||||
return tagList;
|
||||
}
|
||||
// @GetTags(type = Patient.class)
|
||||
// public TagList getAllTagsPatientIdVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersion) {
|
||||
// TagList tagList = new TagList();
|
||||
// tagList.add(new Tag((String) null, "Patient" + theId.getIdPart() + theVersion.getVersionIdPart(), "DogLabel"));
|
||||
// tagList.add(new Tag("http://cats", "AllCat", "CatLabel"));
|
||||
// return tagList;
|
||||
// }
|
||||
|
||||
@GetTags(type = Observation.class)
|
||||
public TagList getAllTagsObservationIdVersion(@IdParam IdDt theId) {
|
||||
|
@ -313,15 +302,15 @@ public class TagsServerTest {
|
|||
return tagList;
|
||||
}
|
||||
|
||||
@DeleteTags(type = Patient.class)
|
||||
public void RemoveTagsPatient(@IdParam IdDt theId, @VersionIdParam IdDt theVersion, @TagListParam TagList theTagList) {
|
||||
ourLastOutcome = "Remove" + theId.getIdPart() + theVersion.getVersionIdPart();
|
||||
ourLastTagList=theTagList;
|
||||
}
|
||||
// @DeleteTags(type = Patient.class)
|
||||
// public void RemoveTagsPatient(@IdParam IdDt theId, @VersionIdParam IdDt theVersion, @TagListParam TagList theTagList) {
|
||||
// ourLastOutcome = "Remove" + theId.getIdPart() + theVersion.getVersionIdPart();
|
||||
// ourLastTagList=theTagList;
|
||||
// }
|
||||
|
||||
@DeleteTags(type = Patient.class)
|
||||
public void RemoveTagsPatient(@IdParam IdDt theId, @TagListParam TagList theTagList) {
|
||||
ourLastOutcome = "Remove" + theId.getIdPart();
|
||||
ourLastOutcome = "Remove" + theId.getIdPart()+StringUtils.defaultString(theId.getVersionIdPart());
|
||||
ourLastTagList=theTagList;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,23 +141,25 @@ public class UpdateTest {
|
|||
dr.addCodedDiagnosis().addCoding().setCode("AAA");
|
||||
|
||||
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")));
|
||||
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());
|
||||
|
||||
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.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")));
|
||||
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());
|
||||
|
||||
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
|
||||
|
@ -167,13 +169,14 @@ public class UpdateTest {
|
|||
dr.addCodedDiagnosis().addCoding().setCode("AAA");
|
||||
|
||||
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")));
|
||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("Dog"), ourReportProvider.getLastTags().get(0));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("animals", "Dog"), ourReportProvider.getLastTags().get(0));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -186,17 +189,19 @@ public class UpdateTest {
|
|||
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
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.addHeader("Category", "Dog; scheme=\"http://foo\";");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
ourClient.execute(httpPost);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("http://foo", "Dog", null), ourReportProvider.getLastTags().get(0));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -218,9 +223,10 @@ public class UpdateTest {
|
|||
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")));
|
||||
status=ourClient.execute(httpPost);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("http://foo", "Dog", "aaaa"), ourReportProvider.getLastTags().get(0));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -235,6 +241,7 @@ public class UpdateTest {
|
|||
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPut);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
// String responseContent =
|
||||
// IOUtils.toString(status.getEntity().getContent());
|
||||
|
@ -242,7 +249,6 @@ public class UpdateTest {
|
|||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertEquals("http://localhost:" + ourPort + "/DiagnosticReport/001/_history/002", status.getFirstHeader("Location").getValue());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -257,10 +263,11 @@ public class UpdateTest {
|
|||
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
|
||||
CloseableHttpResponse status = ourClient.execute(httpPut);
|
||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
}
|
||||
|
||||
|
@ -289,9 +296,11 @@ public class UpdateTest {
|
|||
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")));
|
||||
|
||||
CloseableHttpResponse response = ourClient.execute(httpPost);
|
||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||
response.close();
|
||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
status.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -376,6 +385,7 @@ public class UpdateTest {
|
|||
return Observation.class;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Update()
|
||||
public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @ResourceParam DiagnosticOrder thePatient) {
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue