SliceAccessorTypes SliceAccessorType(ElementDefinitionNode sliceNode) { const String fcn = nameof(SliceAccessorType); String baseType = sliceNode.FhirType.FriendlyName(); if (sliceNode.IsListType) { switch (sliceNode.Element.Max.ToMax()) { case 0: this.gen.ConversionError(this.GetType().Name, fcn, $"Slice node '{sliceNode.FullPath()}' has max of 0. Not sure what I am supposed to do!"); return(SliceAccessorTypes.Error); case 1: return(SliceAccessorTypes.Single); default: return(SliceAccessorTypes.Multiple); } } else { this.gen.ConversionError(this.GetType().Name, fcn, $"Slice node '{sliceNode.FullPath()}' unknown base type {baseType}"); return(SliceAccessorTypes.Error); } }
bool DefineDiscriminator(Int32 index, CodeBlockNested sliceDiscriminators, ElementDefinitionNode sliceNode, String varName, ElementDefinition.DiscriminatorComponent discriminator) { const String fcn = nameof(DefineDiscriminator); switch (discriminator.Type) { case ElementDefinition.DiscriminatorType.Value: if (DefineSliceOnValueDiscriminator(index, sliceDiscriminators, sliceNode, varName, discriminator, "valueFilterMethod", "leafType") == false) { return(false); } return(true); default: this.gen.ConversionError(this.GetType().Name, fcn, $"TODO: discriminator.Type {discriminator.Type} currently implemented. '{elementNode.FullPath()}'"); return(false); } }
Element GetItem(ElementDefinitionNode sliceNode, String path) { const String fcn = nameof(GetItem); String[] pathParts = path.Split('.'); ElementDefinitionNode node = sliceNode; for (Int32 i = 0; i < pathParts.Length; i++) { String pathPart = pathParts[i]; ElementDefinitionNode next = null; foreach (ElementDefinitionNode n in node.ChildNodes) { if (n.Name == pathPart) { next = n; break; } } if (next == null) { this.Gen.ConversionError(this.GetType().Name, fcn, $"Cant find child node '{pathPart}' in '{sliceNode.FullPath()}'"); return(null); } node = next; } return(node.Element.Fixed); }