mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-03-08 13:09:50 +00:00
Don't include an mpty text element in Bundles being returned by the server
This commit is contained in:
parent
e18433d709
commit
5bcd6a4751
hapi-fhir-base/src/main/java/ca/uhn/fhir
hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider
hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir
src/changes
@ -28,6 +28,7 @@ import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.YEAR;
|
|||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
@ -64,7 +65,9 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
|
|||||||
private static final FastDateFormat ourYearMonthDayTimeZoneFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssZZ");
|
private static final FastDateFormat ourYearMonthDayTimeZoneFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssZZ");
|
||||||
private static final FastDateFormat ourYearMonthFormat = FastDateFormat.getInstance("yyyy-MM");
|
private static final FastDateFormat ourYearMonthFormat = FastDateFormat.getInstance("yyyy-MM");
|
||||||
private static final FastDateFormat ourYearMonthNoDashesFormat = FastDateFormat.getInstance("yyyyMM");
|
private static final FastDateFormat ourYearMonthNoDashesFormat = FastDateFormat.getInstance("yyyyMM");
|
||||||
private static final Pattern ourYearMonthPattern = Pattern.compile("[0-9]{4}[0-9]{2}");
|
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
||||||
|
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
||||||
|
private static final Pattern ourYearMonthPattern = Pattern.compile("[0-9]{4}[0-9]{2}");
|
||||||
private static final Pattern ourYearPattern = Pattern.compile("[0-9]{4}");
|
private static final Pattern ourYearPattern = Pattern.compile("[0-9]{4}");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -89,7 +92,55 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
|
|||||||
private boolean myTimeZoneZulu = false;
|
private boolean myTimeZoneZulu = false;
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDt.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDt.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns a human readable version of this date/time using the system local format.
|
||||||
|
* <p>
|
||||||
|
* <b>Note on time zones:</b> This method renders the value using the time zone
|
||||||
|
* that is contained within the value. For example, if this date object contains the
|
||||||
|
* value "2012-01-05T12:00:00-08:00", the human display will be rendered as "12:00:00"
|
||||||
|
* even if the application is being executed on a system in a different time zone. If
|
||||||
|
* this behaviour is not what you want, use {@link #toHumanDisplayLocalTimezone()}
|
||||||
|
* instead.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public String toHumanDisplay() {
|
||||||
|
TimeZone tz = getTimeZone();
|
||||||
|
Calendar value = tz != null ? Calendar.getInstance(tz) : Calendar.getInstance();
|
||||||
|
value.setTime(getValue());
|
||||||
|
|
||||||
|
switch (getPrecision()) {
|
||||||
|
case YEAR:
|
||||||
|
case MONTH:
|
||||||
|
case DAY:
|
||||||
|
return ourHumanDateFormat.format(value);
|
||||||
|
case MILLI:
|
||||||
|
case SECOND:
|
||||||
|
default:
|
||||||
|
return ourHumanDateTimeFormat.format(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a human readable version of this date/time using the system local format,
|
||||||
|
* converted to the local timezone if neccesary.
|
||||||
|
*
|
||||||
|
* @see #toHumanDisplay() for a method which does not convert the time to the local
|
||||||
|
* timezone before rendering it.
|
||||||
|
*/
|
||||||
|
public String toHumanDisplayLocalTimezone() {
|
||||||
|
switch (getPrecision()) {
|
||||||
|
case YEAR:
|
||||||
|
case MONTH:
|
||||||
|
case DAY:
|
||||||
|
return ourHumanDateFormat.format(getValue());
|
||||||
|
case MILLI:
|
||||||
|
case SECOND:
|
||||||
|
default:
|
||||||
|
return ourHumanDateTimeFormat.format(getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public BaseDateTimeDt() {
|
public BaseDateTimeDt() {
|
||||||
|
@ -24,7 +24,6 @@ import static org.apache.commons.lang3.StringUtils.*;
|
|||||||
import ca.uhn.fhir.model.api.BasePrimitive;
|
import ca.uhn.fhir.model.api.BasePrimitive;
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
import ca.uhn.fhir.model.api.annotation.SimpleSetter;
|
import ca.uhn.fhir.model.api.annotation.SimpleSetter;
|
||||||
import ca.uhn.fhir.parser.DataFormatException;
|
|
||||||
|
|
||||||
@DatatypeDef(name = "code")
|
@DatatypeDef(name = "code")
|
||||||
public class CodeDt extends BasePrimitive<String> implements ICodedDatatype, Comparable<CodeDt> {
|
public class CodeDt extends BasePrimitive<String> implements ICodedDatatype, Comparable<CodeDt> {
|
||||||
@ -46,7 +45,7 @@ public class CodeDt extends BasePrimitive<String> implements ICodedDatatype, Com
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return isBlank(getValueAsString());
|
return super.isBaseEmpty() && isBlank(getValueAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,7 +50,7 @@ public class XhtmlDt extends BasePrimitive<List<XMLEvent>> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return super.isEmpty() && (getValue() == null || getValue().isEmpty());
|
return super.isBaseEmpty() && (getValue() == null || getValue().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -479,7 +479,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||||||
if (gen != null) {
|
if (gen != null) {
|
||||||
BaseNarrativeDt<?> narr = ((IResource) theResource).getText();
|
BaseNarrativeDt<?> narr = ((IResource) theResource).getText();
|
||||||
gen.generateNarrative(theResDef.getResourceProfile(), theResource, narr);
|
gen.generateNarrative(theResDef.getResourceProfile(), theResource, narr);
|
||||||
if (narr != null) {
|
if (narr != null && !narr.isEmpty()) {
|
||||||
RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild;
|
RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild;
|
||||||
String childName = nextChild.getChildNameByDatatype(child.getDatatype());
|
String childName = nextChild.getChildNameByDatatype(child.getDatatype());
|
||||||
BaseRuntimeElementDefinition<?> type = child.getChildByName(childName);
|
BaseRuntimeElementDefinition<?> type = child.getChildByName(childName);
|
||||||
|
@ -273,6 +273,20 @@ public class ResourceProviderDstu2Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchBundleDoesntIncludeTextElement() throws Exception {
|
||||||
|
HttpGet read = new HttpGet(ourServerBase + "/Patient?_format=json");
|
||||||
|
CloseableHttpResponse response = ourHttpClient.execute(read);
|
||||||
|
try {
|
||||||
|
String text = IOUtils.toString(response.getEntity().getContent());
|
||||||
|
ourLog.info(text);
|
||||||
|
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatusLine().getStatusCode());
|
||||||
|
assertThat(text, not(containsString("\"text\",\"type\"")));
|
||||||
|
} finally {
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchWithInclude() throws Exception {
|
public void testSearchWithInclude() throws Exception {
|
||||||
Organization org = new Organization();
|
Organization org = new Organization();
|
||||||
|
@ -15,12 +15,21 @@ import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
|||||||
|
|
||||||
public class BaseDateTimeDtTest {
|
public class BaseDateTimeDtTest {
|
||||||
private SimpleDateFormat myDateInstantParser;
|
private SimpleDateFormat myDateInstantParser;
|
||||||
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDtTest.class);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
myDateInstantParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
myDateInstantParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToHumanDisplay() {
|
||||||
|
DateTimeDt dt = new DateTimeDt("2012-01-05T12:00:00-08:00");
|
||||||
|
String human = dt.toHumanDisplay();
|
||||||
|
ourLog.info(human);
|
||||||
|
assertEquals("Jan 5, 2012 12:00:00 PM", human);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See HAPI #101 - https://github.com/jamesagnew/hapi-fhir/issues/101
|
* See HAPI #101 - https://github.com/jamesagnew/hapi-fhir/issues/101
|
||||||
*/
|
*/
|
||||||
|
@ -108,7 +108,7 @@ public class JsonParserDstu2Test {
|
|||||||
public void testEncodeBundleNewBundleNoText() {
|
public void testEncodeBundleNewBundleNoText() {
|
||||||
|
|
||||||
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
||||||
// b.getText().setDiv("<div>aaa</div>");
|
b.getText().setDiv("");
|
||||||
b.getText().getStatus().setValueAsString("");;
|
b.getText().getStatus().setValueAsString("");;
|
||||||
|
|
||||||
Entry e = b.addEntry();
|
Entry e = b.addEntry();
|
||||||
|
@ -140,6 +140,10 @@
|
|||||||
Prevent server from returning a Content-Location header for search
|
Prevent server from returning a Content-Location header for search
|
||||||
response when using the DSTU2 bundle format
|
response when using the DSTU2 bundle format
|
||||||
</action>
|
</action>
|
||||||
|
<action type="fix">
|
||||||
|
JPA server (uhnfhirtest.uhn.ca) sometimes included an empty
|
||||||
|
"text" element in Bundles being returned.
|
||||||
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="0.9" date="2015-Mar-14">
|
<release version="0.9" date="2015-Mar-14">
|
||||||
<action type="add">
|
<action type="add">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user