Stream: implementers
Topic: Printing Nested Extensions
Tia Cummings (Jun 19 2019 at 18:06):
We're trying to implement nested extensions:
Extension pop = new Extension().setUrl(StringValues.MEMBER_POPULATIONS.getValue()).setValue(new IntegerType(index)); if (StringUtils.isNotBlank(memberPopulation.getPopulationId())) { pop.addExtension(StringValues.POPULATION_ID.getValue(), new StringType(memberPopulation.getPopulationId())); } if (StringUtils.isNotBlank(memberPopulation.getPopulationRuleName())) { pop.addExtension(StringValues.POPULATION_RULE_NAME.getValue(), new StringType(memberPopulation.getPopulationRuleName())); } if (null != memberPopulation.getStartDate() || null != memberPopulation.getEndDate()) { pop.addExtension(StringValues.DATES.getValue(), new Period().setStart(null != memberPopulation.getStartDate() ? memberPopulation.getStartDate().getTime() : null) .setEnd(null != memberPopulation.getEndDate() ? memberPopulation.getEndDate().getTime() : null)); } if (null != memberPopulation.getMemberPopAssociationDateTime()) { pop.addExtension(StringValues.MEMBER_POP_ASSOCIATION_DATE_TIME.getValue(), new DateTimeType(memberPopulation.getMemberPopAssociationDateTime())); } patient.addExtension(pop);
But our FhirServer and our JsonParser doesn't print out the nested extensions. It only prints out the parent extension.
Any insights on this? Maybe there is a setting that needs to be turned on.
Lloyd McKenzie (Jun 19 2019 at 20:45):
What library are you using?
Tia Cummings (Jun 20 2019 at 12:23):
@Lloyd McKenzie we're using hapi fhir dependencies for R4 in java
Lloyd McKenzie (Jun 20 2019 at 12:30):
@James Agnew ?
James Agnew (Jun 20 2019 at 14:28):
That code looks correct. Are you sure that all of the if statements are actually hitting, and the nested extensions are being correct?
If so, can you try posting a code snipped using constants (e.g. "foo"
) instead of externally defined variables that isn't behaving the way you expect?
Tia Cummings (Jun 20 2019 at 14:39):
Yes, all of those if statements are being hit. When I run the code in debug mode, I can see that the parent extension has 4 extensions
Tia Cummings (Jun 24 2019 at 17:35):
@James Agnew ???
James Agnew (Jun 24 2019 at 20:29):
@Tia Cummings OK- Can you try posting a code snippet using constants (e.g. "foo") instead of externally defined variables that isn't behaving the way you expect?
The code snippet you provided isn't something that could be run easily but you because it relies on variables from your application (e.g. "memberpopulation"). If you replace all of these with constants (e.g. "foo"
) I might be able to help.
Tia Cummings (Jun 24 2019 at 20:40):
Extension pop = new Extension().setUrl("memberPopulations").setValue(new IntegerType(1));
if (StringUtils.isNotBlank("population id")) {
pop.addExtension("populationId", new StringType("population id"));
}
if (StringUtils.isNotBlank("population rule name)) {
pop.addExtension("populationRuleName", new StringType("population rule name));
}
patient.addExtension(pop);
James Agnew (Jun 24 2019 at 20:46):
@Tia Cummings Ahh I see it: The issue is that you're setting both a value and child extensions your your root extension (pop
). You can't have both according to FHIR's rules, so the value takes presedence in HAPI's encoding rules. We should probably emit a warning in that case...
Tia Cummings (Jun 25 2019 at 12:27):
Oooohh. That's actually better. Thanks, I'll try that
Last updated: Apr 12 2022 at 19:14 UTC