void LoadFhirElement(StructureDefinition sDef) { const String fcn = "LoadFhirElement"; // This is to eliminate the derived types. For now, // we only want to do that base resource types. if (sDef.Type != sDef.Name) { this.ConversionWarn(this.GetType().Name, fcn, $"Skipping derived class {sDef.Name}"); return; } SDefInfo sDefInfo = new SDefInfo(sDef); switch (sDef.Url) { case "http://hl7.org/fhir/StructureDefinition/Element": sDefInfo.TFlag = SDefInfo.TypeFlag.Group; break; case "http://hl7.org/fhir/StructureDefinition/Resource": sDefInfo.TFlag = SDefInfo.TypeFlag.Entry; break; default: sDefInfo.TFlag = SDefInfo.TypeFlag.Unknown; break; } this.items.Add(sDef.Url, sDefInfo); }
void ProcessRequestedFhirElements() { Int32 index = 0; while (index < this.resourcesToProcess.Count) { String key = this.resourcesToProcess.ElementAt(index++); if (processedResources.Contains(key) == false) { processedResources.Add(key); SDefInfo sDef = this.GetTypedSDef(key); this.ProcessFhirElement(sDef); } } // Output those resources that we just create an entry for (no properties). // These will define entries that we can reference, w/o the overhead of defining // the properties and such. index = 0; while (index < this.abbreviatedResourcesToProcess.Count) { String key = this.abbreviatedResourcesToProcess.ElementAt(index++); ProcessAbbreviatedResource(key); } }
void ProcessAbbreviatedResource(String key) { if (processedResources.Contains(key) == true) { return; } if (this.IgnoreResource(key) == true) { return; } processedResources.Add(key); SDefInfo sDef = this.GetTypedSDef(key); this.ProcessFhirElementAbbreviated(sDef); }
/// <summary> /// Process one fhir element /// </summary> void ProcessFhirElement(SDefInfo sDefInfo) { const string fcn = "ProcessFhirElement"; StructureDefinition sDef = sDefInfo.SDef; if (this.IgnoreResource(sDef.Url) == true) { return; } sDef.SaveJson(Path.Combine(this.GeneratedPath, $"{sDef.Id}.json")); String baseDefinition = sDef.BaseDefinition; switch (baseDefinition) { case null: this.DoProcessFhirElementSpecialization(sDefInfo); break; case "http://hl7.org/fhir/StructureDefinition/Extension": break; default: switch (sDef.Derivation) { case null: return; case StructureDefinition.TypeDerivationRule.Specialization: this.DoProcessFhirElementSpecialization(sDefInfo); break; case StructureDefinition.TypeDerivationRule.Constraint: //this.DoProcessFhirElementConstraint(sDefInfo); break; default: throw new ConvertErrorException(this.GetType().Name, fcn, $"Internal error. Unknown derivation {sDef.Derivation}"); } break; } }
SDefInfo GetTypedSDef(String path) { const String fcn = "GetTypedSDef"; this.AddResource(path); if (this.items.TryGetValue(path, out SDefInfo sDef) == false) { throw new ConvertErrorException(this.GetType().Name, fcn, $"Internal error. Item {path} not in dictionary"); } // If TFlag s unknown, use parents TFlag value. if (sDef.TFlag == SDefInfo.TypeFlag.Unknown) { SDefInfo parentInfo = this.GetTypedSDef(sDef.SDef.BaseDefinition); sDef.TFlag = parentInfo.TFlag; } return(sDef); }
void DoProcessFhirElementSpecialization(SDefInfo sDefInfo) { const string fcn = "ProcessSpecialiation"; StructureDefinition sDef = sDefInfo.SDef; this.ConversionInfo(this.GetType().Name, fcn, $"Processing Specialization {sDef.Url}"); String parent = sDef.BaseDefinition?.LastUriPart(); String description = this.ToDescription(sDef.Description); // remove items that derive directly from primitives. switch (parent) { case "boolean": case "integer": case "decimal": case "uri": case "string": case "base64Binary": case "instant": case "dateTime": case "time": case "oid": case "id": case "markdown": case "unsignedInt": case "positiveInt": case "xhtml": this.ConversionInfo(this.GetType().Name, fcn, $"Ignoring '{sDef.Url}' because it derives from primitive '{parent}'"); return; } ConvertFhirClass cfc = new ConvertFhirClass(this, sDefInfo); cfc.Specialize(); }
/// <summary> /// Process one fhir element /// </summary> void ProcessFhirElementAbbreviated(SDefInfo sDefInfo) { const string fcn = "ProcessFhirElementAbbreviated"; StructureDefinition sDef = sDefInfo.SDef; { CodeEditor entryEditor = this.CreateEntryEditor(sDef.Id); CodeBlockNested entryBlock = entryEditor.Blocks.AppendBlock(); String typeName; switch (sDefInfo.TFlag) { case DirectFhirGenerator.SDefInfo.TypeFlag.Entry: typeName = "Entry"; break; case DirectFhirGenerator.SDefInfo.TypeFlag.Group: typeName = "Group"; break; default: throw new ConvertErrorException(this.GetType().Name, fcn, $"Invalid TFlag value"); } entryBlock .BlankLine() .AppendCode($"{typeName}: {sDef.Id}") ; } { CodeEditor mapEditor = this.CreateMapEditor(sDef.Id); CodeBlockNested mapBlock = mapEditor.Blocks.AppendBlock(); mapBlock .BlankLine() .AppendCode($"{sDef.Id} maps to {sDef.Id}:") ; } }