Slice on structured fields
- Dominant language
- C++
- Stars
- 955
- Forks
- 207
- Avg merge
- 10h 4m
- Merged PRs (30d)
- 4
Description
I need to generate C++ code from profiles (json) containing slices on structured fields (e.g. Address).
Maybe I can implement the missing feature myself, but I need some advice.
- Is there a function or functions in the java part, that could be used to generate the slice message?
- I have the following use case: The address field of Organization is sliced into two slices of an Adress based profile (address-de-basis) to support two different flavours of Address.line - physical address vs. post box. (This is done in an intermediate profile base "KBV_PR_Base_Organization".)
- Which function could be used in the C++ part to read the different slices? (I think writing just means selection of the active slice.)
- Any Idea how to implement a default slice?
Details:
From my investigations I found two problems:
1) In ProtoGenerator.java, slices like this are not supported:
```java
private DescriptorProto generateMessage(
ElementDefinition currentElement,
List elementList,
DescriptorProto.Builder builder)
throws InvalidFhirException {
...
for (ElementDefinition deferredElement : deferredElements) {
// Currently we only support slicing for Extensions and Codings
if (isElementSupportedForSlicing(deferredElement)
...
} else {
cgmDebugOut(2, "Build field slicing (not supported yet):" + cgmStringify(deferredElement.getId().getValue()));
builder
.addFieldBuilder()
.setNumber(nextTag)
.getOptionsBuilder()
.setExtension(
ProtoGeneratorAnnotations.reservedReason,
"field "
+ nextTag
+ " reserved for "
+ deferredElement.getId().getValue()
+ " which uses an unsupported slicing on "
+ deferredElement.getType(0).getCode().getValue());
nextTag++;
}
}
...
}
```
2) Once the java generator would have been enhanced to generate a sliced proto message, serialization to and from json has to be handled correctly in the c++ part.
- To Json: Just write the slices´ content (if any)? Maybe respecting place where the original field resides.
- From Json: Detect sliced field by annotation. Extract slice discriminator (Maybe by reading into (new) instance of non sliced field when slice discrimination is on value?). Select correct slice by attribute. Read into that slice. Here, it is not clear to me, what infrastructure in C++ could be used.
If I'm right, some annotations have been foreseen for discrimination of the right slice.
Regarding annotation fhir_slice_by, I am not sure, if this is the intended use. As far as I understand, slicing type and path must be specified.
Something like this:
"[(.google.fhir.proto.fhir_slice_by) = "value:type"]" means the slice discriminator is by "value" from field "type".
Contributor guide
Assessment
This issue has not been assessed yet.