Custom structure for extensions on elements.

118 views
Skip to first unread message

Linden Quan

unread,
Jul 26, 2022, 10:33:43 AM7/26/22
to HAPI FHIR
I have a custom profile that has extensions on an Resource element. For example:
{
  "resourceType": "Patient",
  "active": true,
  "gender": "male",
  "birthDate": "1970-01-01",
  "_birthDate": {
    "extension": [
      {
        "url": "http://example.com/fhir/StructureDefinition/date-type",
        "valueString": "A"
      }
    ]
  }
}
The element "birthDate" has an extension.
I'm not sure how I can define this with HAPI fhir client. I found the related documentation.
However the documentation only mentioned how to add extensions to the Resource, but not to an element.

Thanks very much for your help !



Patrick Werner

unread,
Jul 26, 2022, 11:03:40 AM7/26/22
to Linden Quan, HAPI FHIR
Hi Linden,

You can see how to do this in the doc as well:

In the doc an extension is added to Patient.given.



--
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 view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/92586b43-1a02-4695-a313-4ec1584d9824n%40googlegroups.com.

Linden Quan

unread,
Jul 26, 2022, 12:43:51 PM7/26/22
to HAPI FHIR
Thanks for your comments. The example in the doc is helpful. Do you happen to know how I can have a custom Patient class that defines extension ?
for example something like this
@ResourceDef(name="Patient", profile="http://example.com/StructureDefinition/mypatient")
public class MyPatient extends Patient {
 @Extension(url="http://example.com/fhir/StructureDefinition/date-type", onField="birthDate")
 private StringType birthDateType;

alejandro...@gmail.com

unread,
Jul 26, 2022, 12:50:30 PM7/26/22
to Patrick Werner, Linden Quan, HAPI FHIR
Hello Linden,

You need to declare the extension  and set to the "getBirthDateElement()
Patient newPatient = new Patient();
// Define the extension
Extension birthplace = new Extension();
// Define the Address
Address address = new Address();
address.setCountry("Chile");
// Set the Address to the extension
birthplace.setUrl("http://hl7.org/fhir/StructureDefinition/patient-birthPlace");
birthplace.setValue(address);
// Add the birthdate
newPatient.setBirthDateElement(new DateType("2015-11-18"));
// Set the extension to the birthdate Element
newPatient.getBirthDateElement().addExtension(birthplace);




--
______________________________
Alejandro Sebastián Medina Negrete
Ingeniero Civil en Computación

Ian Bacher

unread,
Jul 26, 2022, 12:54:21 PM7/26/22
to Linden Quan, HAPI FHIR
I’d think creating a custom structure is probably overkill for this. There are some docs here on using extensions: https://hapifhir.io/hapi-fhir/docs/model/profiles_and_extensions.html, but really all you need is:
patient.getBirthDateElement().addExtension("http://example.com/fhir/StructureDefinition/date-type", new StringType("A"));
- Ian

Linden Quan

unread,
Jul 26, 2022, 12:59:27 PM7/26/22
to HAPI FHIR
Thanks very much !

Linden Quan

unread,
Jul 26, 2022, 12:59:36 PM7/26/22
to HAPI FHIR

Thanks very much !
Reply all
Reply to author
Forward
0 new messages