Guest User

Untitled

a guest
Apr 17th, 2026
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. let
  2. Quelle = Json.Document(File.Contents("put path here")),
  3. Tree = Quelle[tree],
  4.  
  5. FlattenTree = (current_node as record, current_path as text) as table =>
  6. let
  7. // 1. Core Metadata
  8. MinOcc = Record.FieldOrDefault(current_node, "min", 0),
  9. MaxOcc = Record.FieldOrDefault(current_node, "max", 1),
  10. IsMultiple = if MaxOcc = -1 or MaxOcc > 1 then true else false,
  11. AtCode = Record.FieldOrDefault(current_node, "nodeId", ""),
  12. RMType = current_node[rmType],
  13.  
  14. // 2. Path Logic (with :0 index for multiples)
  15. NodeId = current_node[id],
  16. IndexedId = if IsMultiple then NodeId & ":0" else NodeId,
  17. NewPath = if current_path = "" then IndexedId else current_path & "/" & IndexedId,
  18.  
  19. // 3. Clinical Name
  20. NodeName = if Record.HasFields(current_node, "localizedName") then current_node[localizedName]
  21. else if Record.HasFields(current_node, "name") then current_node[name]
  22. else NodeId,
  23.  
  24. // 4. Spec-Specific Attribute Expansion based on RM Type
  25. AttributeList =
  26. if RMType = "DV_CODED_TEXT" then
  27. {
  28. [Path = NewPath & "|code", Type = RMType],
  29. [Path = NewPath & "|value", Type = RMType],
  30. [Path = NewPath & "|terminology", Type = RMType]
  31. }
  32. else if RMType = "DV_QUANTITY" then
  33. {
  34. [Path = NewPath & "|magnitude", Type = RMType],
  35. [Path = NewPath & "|unit", Type = RMType]
  36. }
  37. else if RMType = "DV_PROPORTION" then
  38. {
  39. [Path = NewPath & "|numerator", Type = RMType],
  40. [Path = NewPath & "|denominator", Type = RMType],
  41. [Path = NewPath & "|type", Type = RMType]
  42. }
  43. else if RMType = "DV_COUNT" or RMType = "DV_INTEGER" or RMType = "DV_DATE_TIME" or RMType = "DV_TEXT" then
  44. {
  45. [Path = NewPath, Type = RMType]
  46. }
  47. else
  48. {},
  49.  
  50. AttributeTable = if List.IsEmpty(AttributeList) then #table({},{}) else Table.FromRecords(AttributeList),
  51.  
  52. // 5. Structural Row
  53. CurrentRow = #table(
  54. {"Path", "Node_Name", "at_Code", "Type", "Max_Occ"},
  55. {{NewPath, NodeName, AtCode, RMType, if MaxOcc = -1 then "Unbounded" else Text.From(MaxOcc)}}
  56. ),
  57.  
  58. // 6. Enrich Attribute Table
  59. FinalAttributeTable = if Table.IsEmpty(AttributeTable) then #table({},{}) else
  60. let
  61. AddedName = Table.AddColumn(AttributeTable, "Node_Name", each NodeName),
  62. AddedAt = Table.AddColumn(AddedName, "at_Code", each AtCode),
  63. AddedMax = Table.AddColumn(AddedAt, "Max_Occ", each if MaxOcc = -1 then "Unbounded" else Text.From(MaxOcc)),
  64. Selected = Table.SelectColumns(AddedMax, {"Path", "Node_Name", "at_Code", "Type", "Max_Occ"})
  65. in
  66. Selected,
  67.  
  68. // 7. Combine & Recurse
  69. NodeContent = if Table.IsEmpty(FinalAttributeTable) then CurrentRow else Table.Combine({CurrentRow, FinalAttributeTable}),
  70. Children = if Record.HasFields(current_node, "children") then current_node[children] else {},
  71. ChildTables = List.Transform(Children, each @FlattenTree(_, NewPath)),
  72. Combined = Table.Combine({NodeContent} & ChildTables)
  73. in
  74. Combined,
  75.  
  76. FinalTable = FlattenTree(Tree, "")
  77. in
  78. FinalTable
Add Comment
Please, Sign In to add comment