Using FHIR extension in normal spring rest call

240 views
Skip to first unread message

maz...@gmail.com

unread,
Oct 31, 2017, 2:08:51 AM10/31/17
to HAPI FHIR
Hi,

I am building a REST API where I have both FHIR and non FHIR resources. All FHIR resources follow the HAPI FHIR RestFulServer implementation, where as other resources are normal Spring Rest APIs using Jackson. I have developed an Extension for FHIR. Now I have few API operations whose input/output type is the FHIR extension. I tried using the extension as is, but the output is not a normal java object to json conversion. Below is the output

{

    "fieldOne": {

        "myCoercedValue": "1",

        "myStringValue": "1"

    },

    "FieldTwo": {

        "myCoercedValue": "2",

        "myStringValue": "2"

    }

}


Ideally, it should have been



{

    "fieldOne": "2",

     "FieldTwo": "2"

}


How can I make use of FHIR extension in my normal API operations that uses Spring Rest with Jackson?

Message has been deleted

Mazkozi M

unread,
Oct 31, 2017, 2:15:58 AM10/31/17
to HAPI FHIR
Adding to it,

My extension is of type BaseIdentifiableElement. I tried using the parsers, but it requires object of type IBaseResource. Tried marking my extension as IBaseResource as well, but it is a clash on method setID(String) between IBaseResource and BaseIdentifiableElement. Not sure if this was the right thing to do, just wanted to get it working somehow.

Kevin Mayfield

unread,
Oct 31, 2017, 2:33:51 AM10/31/17
to Mazkozi M, HAPI FHIR
Are you extending an existing resource.

Wondering if you should be using custom structures instead.

On 31 Oct 2017, at 06:14, Mazkozi M <maz...@gmail.com> wrote:

Adding to it,

My extension is of type BaseIdentifiableElement. I tried using the parsers, but it requires object of type IBaseResource. Tried marking my extension as IBaseResource as well, but it is a clash on method setID(String) between IBaseResource and BaseIdentifiableElement. Not sure if this was the right thing to do, just wanted to get it working somehow.

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/b7b9ff59-4059-481f-86c9-190a0f62cdde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mazkozi M

unread,
Oct 31, 2017, 2:38:49 AM10/31/17
to HAPI FHIR
I can use custom resource. But I am not sure if I can declare my extension as resource as well. I thought extensions should be extending BaseIdentifiableElement always.

James Agnew

unread,
Oct 31, 2017, 10:04:36 AM10/31/17
to Mazkozi M, HAPI FHIR
The problem here is probably that HAPI's structures aren't designed to be encoded directly using a JSON parser like Jackson or GSON, they are intended to use a FHIR-aware parser like HAPI.

For what it's worth, I've solved similar issues in the past by using a Jackson custom serializer. Here's an example from another project I did- This one is using the FHIR 8601 datatype encoding on a field so it's not exactly the same thing, but it's a similar concept.

The field on the data model:

   @JsonProperty("timestamp")
   @JsonSerialize(using = JsonDateSerializer.class)
   @JsonDeserialize(using = JsonDateDeserializer.class)
   private Date myTimestamp;

And the serializer:

public class JsonDateSerializer extends JsonSerializer<Date> {
   @Override
   public void serialize(Date theValue, JsonGenerator theGen, SerializerProvider theSerializers) throws IOException, JsonProcessingException {
      if (theValue != null) {
         theGen.writeString(new InstantType(theValue).getValueAsString());
      }
   }
}

Cheers,
James


On Tue, Oct 31, 2017 at 2:38 AM, Mazkozi M <maz...@gmail.com> wrote:
I can use custom resource. But I am not sure if I can declare my extension as resource as well. I thought extensions should be extending BaseIdentifiableElement always.

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages