FHIR Chat · Questionnaire · questionnaire

Stream: questionnaire

Topic: Questionnaire


view this post on Zulip Rajesh B (Jan 09 2021 at 19:17):

How to add custom fields to item in Questionnaire resource ?

I am using HAPI FHIR models as dependency in my project.
How can override getItem() method in MyQuestionnaire class to return item[] which contains customField?

// HAPI FHIR model class to represent Questionnaire Resource.
public class Questionnaire {
protected List<QuestionnaireItemComponent> item;
}

// HAPI FHIR model class to represent single item in Questionnaire Resource.
public class QuestionnaireItemComponent {
protected StringType linkId;
protected UriType definition;
}

// this class is to add additional fields to Questionnaire resource
public class MyQuestionnaire extends Questionnaire {

// this throws compilation error.
@Override
public List<MyQuestionnaireItem> getItem() {
  if (this.item == null) this.item = new ArrayList<MyQuestionnaireItem>();
  return this.item;
}

}

// this class is to add additional fields to item.
public class MyQuestionnaireItem extends QuestionnaireItemComponent {
protected StringType customField;
}

view this post on Zulip Lloyd McKenzie (Jan 09 2021 at 23:22):

You shouldn't have any custom fields - any custom elements should be captured via extensions...

view this post on Zulip Rajesh B (Jan 10 2021 at 16:24):

I understood that custom elements can be added via extensions to a Resource. As per the documentation given here https://hapifhir.io/hapi-fhir/docs/model/profiles_and_extensions.html, I am able to add custom elements via extension to MyQuestionnaire resource. Where as my question is, how we can add custom elements via extension to a complex object in Questionnaire Resource.?

view this post on Zulip Lloyd McKenzie (Jan 10 2021 at 17:41):

If you're making use of extensions, then you're not adding custom elements. The 'extension' element already exists. You're just defining specific patterns on the extension element that your code will be looking for.

view this post on Zulip Lloyd McKenzie (Jan 10 2021 at 17:42):

You might reach out on the #hapi stream for further guidance on HAPI-specific questions.

view this post on Zulip Lloyd McKenzie (Jan 10 2021 at 17:43):

Out of curiousity, what sort of extensions are you defining on Questionnaire? (That's a good thing to discuss on this stream.) Have you looked at the SDC implementation guide - it defines quite a few 'standard' ones.

view this post on Zulip Brian Postlethwaite (Jan 11 2021 at 00:18):

I'm also very curious on this "custom field"


Last updated: Apr 12 2022 at 19:14 UTC