public override string GetFlatFile() { var path = "\"" + string.Join("/", PathToRoot.Split('/').Take(PathToRoot.Split('/').Length - 1)) + "\""; var value = "\"" + PathToRoot.Split('/').Last() + "\""; return(" " + path + ": " + value + ",\n"); }
/// <summary> /// Displays a leaf node to console as it was before parsing. /// </summary> public override void DisplayFlatFile() { var path = "\"" + string.Join("/", PathToRoot.Split('/').Take(PathToRoot.Split('/').Length - 1)) + "\""; var value = "\"" + PathToRoot.Split('/').Last() + "\""; Console.Write(path + ": "); Console.Write(value, Console.ForegroundColor = ConsoleColor.Green); Console.ResetColor(); Console.Write(",\n"); }
public override int ParentResourceIndex(List <BaseMapping> mappings) { var parts = PathToRoot.Split('/'); foreach (var part in parts) { var subParts = part.Split(':'); if (subParts.Length > 1) { var field = subParts[0]; var index = subParts[1]; var mapping = mappings.FirstOrDefault(x => field + ":" == x.OpenEhrFieldPath); if (mapping != null) { if (mapping.MappingType == MappingType.Resource) { return(int.Parse(index)); } } } } return(int.MinValue); }
public override string InnerNetPath(List <BaseMapping> mappings) { var path = ""; var parts = PathToRoot.Split('/'); foreach (var part in parts) { var listParts = part.Split(':'); var codeableConceptParts = part.Split('|'); if (listParts.Length > 1) { var field = listParts[0]; var index = listParts[1]; var mapping = mappings.FirstOrDefault(x => field + ":" == x.OpenEhrFieldPath); if (mapping != null) { var mappingType = mapping.MappingType; switch (mappingType) { case MappingType.Resource: continue; default: field = mapping.FhirFieldPath; break; } path += $"{field}[{index}]"; if (part != parts.Last()) { path += "."; } } } else if (codeableConceptParts.Length > 1) { var field = codeableConceptParts[0]; var subField = codeableConceptParts[1]; var mapping = mappings.FirstOrDefault(x => field + "|" == x.OpenEhrFieldPath); if (mapping != null) { var mappingType = mapping.MappingType; switch (mappingType) { case MappingType.Resource: field = "ResourceList"; break; default: { field = mapping.FhirFieldPath; if (field.Contains("[]")) { var emptyIndexCount = field.GetSubStringCount(); for (var i = 0; i < emptyIndexCount; i++) { var parent = Parent; // TODO may need to rework this for (var j = 0; j < i; j++) { parent = (Composite)parent.Parent; } var insideIndexLocation = field.GetIndexOfNthOccurence("[]", i + 1) + 1; var indexNumber = parent.Parent.NetPath(mappings) != $"ResourceList[{parent.ParentResourceIndex(mappings)}]" ? parent.Parent.ListIndex : 0; field = field.Insert(insideIndexLocation, indexNumber.ToString()); } } break; } } path += $"{field}"; if (part != parts.Last()) { path += "."; } } } else { var mapping = mappings.FirstOrDefault(x => parts.Last() == x.OpenEhrFieldPath); if (mapping != null) { var mappingType = mapping.MappingType; string field; switch (mappingType) { case MappingType.Resource: field = "ResourceList"; break; default: { field = mapping.FhirFieldPath; if (field.Contains("[]")) { var emptyIndexCount = field.GetSubStringCount(); for (var i = 0; i < emptyIndexCount; i++) { var parent = Parent; // TODO may need to rework this for (var j = 0; j < i; j++) { parent = (Composite)parent.Parent; } var insideIndexLocation = field.GetIndexOfNthOccurence("[]", i + 1) + 1; var indexNumber = parent.Parent.NetPath(mappings) != $"ResourceList[{parent.ParentResourceIndex(mappings)}]" ? parent.Parent.ListIndex : 0; field = field.Insert(insideIndexLocation, indexNumber.ToString()); } } break; } } path += $"{field}"; break; } } } if (ListIndex != int.MinValue) { path = path.Remove(path.Length - 3); } return(path); }
public override string InnerNetPath(List <BaseMapping> mappings) { var path = ""; var parts = PathToRoot.Split('/'); foreach (var part in parts) { var listParts = part.Split(':'); if (listParts.Length > 1) { var field = listParts[0]; var index = listParts[1]; var mapping = mappings.FirstOrDefault(x => field == x.OpenEhrFieldPath); if (mapping != null) { var mappingType = mapping.MappingType; switch (mappingType) { case MappingType.Resource: continue; default: if (!mapping.FhirFieldPath.Contains("[]")) { field = mapping.FhirFieldPath; } break; } if (index.Contains("|")) { var indexParts = index.Split('|'); path += $"{field}[{indexParts[0]}]"; } else { path += $"{field}[{index}]"; } if (part != parts.Last()) { path += "."; } } } else if (part == parts.Last()) { var mapping = mappings.FirstOrDefault(x => part == x.OpenEhrFieldPath || !string.IsNullOrEmpty(x.RegexPattern) && Regex.Match(part, x.RegexPattern).Success); if (mapping != null) { var mappingType = mapping.MappingType; string field; switch (mappingType) { case MappingType.Resource: field = "ResourceList"; break; case MappingType.Extension: field = "Extension"; break; default: { field = mapping.FhirFieldPath; if (field.Contains("[]")) { var emptyIndexCount = field.GetSubStringCount(); for (var i = 0; i < emptyIndexCount; i++) { var parent = this; for (var j = 0; j < i; j++) { parent = (Composite)parent.Parent; } var insideIndexLocation = field.GetIndexOfNthOccurence("[]", i + 1) + 1; var indexNumber = parent.Parent.NetPath(mappings) != $"ResourceList[{parent.ParentResourceIndex(mappings)}]" ? parent.Parent.ListIndex : 0; field = field.Insert(insideIndexLocation, indexNumber.ToString()); } } break; } } path += $"{field}"; break; } } } if (Children == null && ListIndex != int.MinValue) { path = path.Remove(path.Length - 3); } return(path); }