/// <summary> /// Create local code systems for those that are not defined in this project. /// Add all value set codes taht reference this code system into it. /// </summary> /// <param name="vi"></param> void BuildLocalCodeSystem(VSInfo vi) { foreach (ValueSet.ConceptSetComponent component in vi.ValueSet.Compose.Include) { foreach (ValueSet.ConceptReferenceComponent concept in component.Concept) { // if code system not found if (this.CodeSystems.TryGetValue(component.System, out CSInfo ci) == false) { if (this.LocalCodeSystems.TryGetValue(component.System, out ci) == false) { ci = new CSInfo(new CodeSystem { Name = component.System.LastUriPart(), Url = component.System }); this.LocalCodeSystems.Add(component.System, ci); } CodeSystem.ConceptDefinitionComponent c = new CodeSystem.ConceptDefinitionComponent { Code = concept.Code, Display = concept.Display }; ci.CodeSystem.Concept.Add(c); } } } }
public void AddFragment(String filePath) { const String fcn = "AddFragment"; DomainResource domainResource; switch (Path.GetExtension(filePath).ToUpper(CultureInfo.InvariantCulture)) { case ".XML": { FhirXmlParser parser = new FhirXmlParser(); domainResource = parser.Parse <DomainResource>(File.ReadAllText(filePath)); break; } case ".JSON": { FhirJsonParser parser = new FhirJsonParser(); domainResource = parser.Parse <DomainResource>(File.ReadAllText(filePath)); break; } default: throw new Exception($"Unknown extension for serialized fhir resource '{filePath}'"); } switch (domainResource) { case CodeSystem cs: { CSInfo ci = new CSInfo(cs); this.CodeSystems.Add(cs.Url, ci); } break; case ValueSet vs: { VSInfo vi = new VSInfo(vs); this.ValueSets.Add(vs.Url, vi); } break; case StructureDefinition sd: { SDInfo fi = new SDInfo(this, sd); this.SDFragments.Add(sd.Url.Trim(), fi); } break; default: this.ConversionError(this.GetType().Name, fcn, $"Unimplemented fragment resource type {domainResource.GetType().Name} file {filePath}"); return; } }
void BuildValueSet(VSInfo vi) { vi.ClassCode.Blocks.Find("Fields") .DefineBlock(out CodeBlockNested fieldsBlock) ; vi.ClassCode.Blocks.Find("Methods") .DefineBlock(out CodeBlockNested methodBlock) ; if (vi.ValueSet.Compose.Exclude.Count > 0) { throw new NotImplementedException("Have not implemented ValueSet.Compose.Exclude"); } methodBlock .AppendCode($"public static IEnumerable<TCoding> Codes()") .OpenBrace() ; foreach (ValueSet.ConceptSetComponent component in vi.ValueSet.Compose.Include) { if (component.Filter.Count > 0) { throw new NotImplementedException("Have not implemented ValueSet.Compose.Include.Filter"); } foreach (ValueSet.ConceptReferenceComponent concept in component.Concept) { if (this.CodeSystems.TryGetValue(component.System, out CSInfo ci) == false) { throw new Exception($"CodeSystem {component.System} not found"); } String codeName = CSMisc.CodeName(concept.Code); String codingReference = $"{CSMisc.CodeSystemName(ci)}.{codeName}"; fieldsBlock .AppendCode($"public static TCoding {codeName} = new TCoding({codingReference});") ; methodBlock .AppendCode($"yield return {codeName};") ; } } methodBlock .CloseBrace() ; }
public static String ValueSetName(VSInfo vi) => $"{MachineName(vi.ValueSet.Name)}";