parent
ba28ff977f
commit
1441a90a9f
|
@ -24,6 +24,7 @@ import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
|
|||
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
import org.hl7.fhir.instance.model.api.ICompositeType;
|
||||
|
@ -41,8 +42,8 @@ public class AttachmentUtil {
|
|||
return getOrCreateChild(theContext, theAttachment, "data", "base64Binary");
|
||||
}
|
||||
|
||||
public static IPrimitiveType<String> getOrCreateContentType(FhirContext theContext, ICompositeType theAttachment) {
|
||||
return getOrCreateChild(theContext, theAttachment, "contentType", "string");
|
||||
public static IPrimitiveType<CodeDt> getOrCreateContentType(FhirContext theContext, ICompositeType theAttachment) {
|
||||
return getOrCreateChild(theContext, theAttachment, "contentType", "code");
|
||||
}
|
||||
|
||||
public static IPrimitiveType<String> getOrCreateUrl(FhirContext theContext, ICompositeType theAttachment) {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 5537
|
||||
title: "Calling the method getOrCreateContentType in AttachmentUtil on an attachment with no content type would throw exception because contentType is a code not a string.
|
||||
This fixes the function to create an empty code as expected"
|
|
@ -1,11 +1,16 @@
|
|||
package ca.uhn.fhir.validator;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||
import ca.uhn.fhir.util.AttachmentUtil;
|
||||
import org.hl7.fhir.instance.model.api.ICompositeType;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
import org.hl7.fhir.r4.model.Attachment;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class AttachmentUtilTest {
|
||||
|
||||
|
@ -53,4 +58,18 @@ public class AttachmentUtilTest {
|
|||
String encoded = ctx.newJsonParser().encodeResourceToString(communication);
|
||||
assertEquals("{\"resourceType\":\"Communication\",\"payload\":[{\"contentAttachment\":{\"contentType\":\"text/plain\",\"data\":\"AAECAw==\",\"url\":\"http://foo\",\"size\":123}}]}", encoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrCreateContentTypeOnEmptyAttachmentR4(){
|
||||
FhirContext ctx = FhirContext.forR4Cached();
|
||||
Attachment attachment = (Attachment) AttachmentUtil.newInstance(ctx);
|
||||
|
||||
assertNull(attachment.getContentType());
|
||||
|
||||
IPrimitiveType<CodeDt> contentType = AttachmentUtil.getOrCreateContentType(ctx, attachment);
|
||||
|
||||
contentType.setValueAsString("text/plain");
|
||||
|
||||
assertNotNull(attachment.getContentType());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue