internal static ValueSet.ContainsComponent ToContainsComponent(this CodeSystem.ConceptDefinitionComponent source, CodeSystem system) { var newContains = new ValueSet.ContainsComponent(); newContains.System = system.Url; newContains.Version = system.Version; newContains.Code = source.Code; newContains.Display = source.Display; var abstractProperty = source.ListConceptProperties(system, CodeSystem.CONCEPTPROPERTY_NOT_SELECTABLE).SingleOrDefault(); var isAbstract = (FhirBoolean)abstractProperty?.Value; if (isAbstract?.Value != null) { newContains.Abstract = isAbstract.Value; } var inactiveProperty = source.ListConceptProperties(system, CodeSystem.CONCEPTPROPERTY_STATUS).SingleOrDefault(); var isInactive = (FhirBoolean)inactiveProperty?.Value; if (isInactive?.Value != null) { newContains.Inactive = isInactive.Value; } if (source.Concept.Any()) { newContains.Contains.AddRange( source.Concept.Select(c => c.ToContainsComponent(system))); } return(newContains); }
/// <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); } } } }
void Process(String codeSystemName, CodeSystem.ConceptDefinitionComponent concept, FSHFile f) { if (String.IsNullOrEmpty(concept.Definition) == true) { return; } String code = concept.Code; switch (code) { case "mgBreastDensityObservation": break; case "mgFindingObservationObservation": code = "mgFindingObservation"; break; case "mgDensity": code = "mgBreastDensity"; break; case "EqualDensity": code = "HeterogeneouslyDense"; break; case "FatContaining": code = "AlmostEntirelyFat"; break; case "HighDensity": code = "ExtremelyDense"; break; case "LowDensity": code = "ScatteredAreasOfFibroglandularDensity"; break; case "mgCalcificationDistribution": case "CentralLucent": return; default: code = code.Replace("Quadrent", "Quadrant"); if (code.StartsWith("sectionCode")) { code = code.Substring(11); } if (code.StartsWith("section")) { code = code.Substring(7); } if (code.StartsWith("mg")) { code = code.Substring(2); } break; } Int32 i = f.FindConcept(codeSystemName, code); if (i < 0) { Console.WriteLine($"Error finding concept '{codeSystemName}#{code}' in FSH file {Path.GetFileName(f.Path)}"); return; } void InsertLine(String s) { i += 1; f.Lines.Insert(i, s); } void RemoveBlanks() { Int32 j = i + 1; while (j < f.Lines.Count) { if (String.IsNullOrEmpty(f.Lines[j].Trim()) == false) { return; } f.Lines.RemoveAt(j); } } bool HasMLComment() { if (i >= f.Lines.Count) { return(false); } return(f.Lines[i + 1].Trim().StartsWith("\"\"\"")); } if (HasMLComment()) { return; } InsertLine(" \"\"\""); bool blankLineFlag = false; foreach (String s in concept.Definition.Split('\n')) { String line = s.Trim() .Replace("\r", "") .Replace("\"", "'") ; bool thisBlanksLine = String.IsNullOrEmpty(line); if ((blankLineFlag == false) || (thisBlanksLine == false)) { InsertLine($" {line}"); } blankLineFlag = thisBlanksLine; } InsertLine(" \"\"\""); InsertLine(""); RemoveBlanks(); }