@fnndsc/brasa 0.57.4 → 0.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (512) hide show
  1. package/dist/api/models.d.ts +2 -3
  2. package/dist/api/models.js.map +1 -1
  3. package/dist/buildinfo.json +1 -1
  4. package/dist/builtins/argumentTokens.js +25 -6
  5. package/dist/builtins/argumentTokens.js.map +1 -1
  6. package/dist/builtins/berth/berth.d.ts +0 -14
  7. package/dist/builtins/berth/berth.js +255 -88
  8. package/dist/builtins/berth/berth.js.map +1 -1
  9. package/dist/builtins/berth/berthClose.d.ts +66 -1
  10. package/dist/builtins/berth/berthClose.js +312 -26
  11. package/dist/builtins/berth/berthClose.js.map +1 -1
  12. package/dist/builtins/berth/berthClosed.d.ts +212 -0
  13. package/dist/builtins/berth/berthClosed.js +231 -0
  14. package/dist/builtins/berth/berthClosed.js.map +1 -0
  15. package/dist/builtins/berth/berthCube.js +27 -6
  16. package/dist/builtins/berth/berthCube.js.map +1 -1
  17. package/dist/builtins/berth/berthDisk.js +1 -1
  18. package/dist/builtins/berth/berthDisk.js.map +1 -1
  19. package/dist/builtins/berth/berthProcesses.js +15 -3
  20. package/dist/builtins/berth/berthProcesses.js.map +1 -1
  21. package/dist/builtins/berth/berthRecord.d.ts +14 -2
  22. package/dist/builtins/berth/berthRecord.js +20 -5
  23. package/dist/builtins/berth/berthRecord.js.map +1 -1
  24. package/dist/builtins/berth/berthState.d.ts +26 -6
  25. package/dist/builtins/berth/berthState.js +47 -13
  26. package/dist/builtins/berth/berthState.js.map +1 -1
  27. package/dist/builtins/debug.d.ts +0 -8
  28. package/dist/builtins/debug.js +1 -12
  29. package/dist/builtins/debug.js.map +1 -1
  30. package/dist/builtins/executable.js +102 -75
  31. package/dist/builtins/executable.js.map +1 -1
  32. package/dist/builtins/feedTotals.js +30 -25
  33. package/dist/builtins/feedTotals.js.map +1 -1
  34. package/dist/builtins/fs/acl.args.d.ts +3 -10
  35. package/dist/builtins/fs/acl.args.js +16 -24
  36. package/dist/builtins/fs/acl.args.js.map +1 -1
  37. package/dist/builtins/fs/acl.d.ts +0 -37
  38. package/dist/builtins/fs/acl.js +36 -58
  39. package/dist/builtins/fs/acl.js.map +1 -1
  40. package/dist/builtins/fs/archive.js +4 -7
  41. package/dist/builtins/fs/archive.js.map +1 -1
  42. package/dist/builtins/fs/cat.d.ts +0 -16
  43. package/dist/builtins/fs/cat.js +163 -96
  44. package/dist/builtins/fs/cat.js.map +1 -1
  45. package/dist/builtins/fs/cd.js +23 -5
  46. package/dist/builtins/fs/cd.js.map +1 -1
  47. package/dist/builtins/fs/configWrite.d.ts +0 -8
  48. package/dist/builtins/fs/configWrite.js +33 -46
  49. package/dist/builtins/fs/configWrite.js.map +1 -1
  50. package/dist/builtins/fs/cp.d.ts +6 -10
  51. package/dist/builtins/fs/cp.js +83 -86
  52. package/dist/builtins/fs/cp.js.map +1 -1
  53. package/dist/builtins/fs/deliveryIntent.d.ts +24 -0
  54. package/dist/builtins/fs/deliveryIntent.js +182 -0
  55. package/dist/builtins/fs/deliveryIntent.js.map +1 -0
  56. package/dist/builtins/fs/deliveryMatch.d.ts +138 -0
  57. package/dist/builtins/fs/deliveryMatch.js +135 -0
  58. package/dist/builtins/fs/deliveryMatch.js.map +1 -0
  59. package/dist/builtins/fs/destination.d.ts +37 -1
  60. package/dist/builtins/fs/destination.js +80 -0
  61. package/dist/builtins/fs/destination.js.map +1 -1
  62. package/dist/builtins/fs/download.d.ts +19 -8
  63. package/dist/builtins/fs/download.js +142 -72
  64. package/dist/builtins/fs/download.js.map +1 -1
  65. package/dist/builtins/fs/du.d.ts +0 -8
  66. package/dist/builtins/fs/du.js +23 -20
  67. package/dist/builtins/fs/du.js.map +1 -1
  68. package/dist/builtins/fs/edit.js +117 -50
  69. package/dist/builtins/fs/edit.js.map +1 -1
  70. package/dist/builtins/fs/entries.d.ts +38 -0
  71. package/dist/builtins/fs/entries.js +48 -1
  72. package/dist/builtins/fs/entries.js.map +1 -1
  73. package/dist/builtins/fs/find.d.ts +1 -1
  74. package/dist/builtins/fs/find.js +462 -271
  75. package/dist/builtins/fs/find.js.map +1 -1
  76. package/dist/builtins/fs/ls.d.ts +2 -8
  77. package/dist/builtins/fs/ls.js +144 -93
  78. package/dist/builtins/fs/ls.js.map +1 -1
  79. package/dist/builtins/fs/mkdir.d.ts +2 -7
  80. package/dist/builtins/fs/mkdir.js +110 -58
  81. package/dist/builtins/fs/mkdir.js.map +1 -1
  82. package/dist/builtins/fs/mv.d.ts +7 -10
  83. package/dist/builtins/fs/mv.js +155 -100
  84. package/dist/builtins/fs/mv.js.map +1 -1
  85. package/dist/builtins/fs/pull.js +155 -92
  86. package/dist/builtins/fs/pull.js.map +1 -1
  87. package/dist/builtins/fs/pwd.d.ts +0 -7
  88. package/dist/builtins/fs/pwd.js +0 -12
  89. package/dist/builtins/fs/pwd.js.map +1 -1
  90. package/dist/builtins/fs/rm.d.ts +6 -7
  91. package/dist/builtins/fs/rm.js +364 -174
  92. package/dist/builtins/fs/rm.js.map +1 -1
  93. package/dist/builtins/fs/rmdir.d.ts +0 -7
  94. package/dist/builtins/fs/rmdir.js +40 -21
  95. package/dist/builtins/fs/rmdir.js.map +1 -1
  96. package/dist/builtins/fs/touch.d.ts +0 -7
  97. package/dist/builtins/fs/touch.js +14 -27
  98. package/dist/builtins/fs/touch.js.map +1 -1
  99. package/dist/builtins/fs/transferJobs.d.ts +12 -0
  100. package/dist/builtins/fs/transferJobs.js +19 -0
  101. package/dist/builtins/fs/transferJobs.js.map +1 -1
  102. package/dist/builtins/fs/tree.d.ts +0 -8
  103. package/dist/builtins/fs/tree.js +1 -12
  104. package/dist/builtins/fs/tree.js.map +1 -1
  105. package/dist/builtins/fs/upload.d.ts +0 -8
  106. package/dist/builtins/fs/upload.js +23 -20
  107. package/dist/builtins/fs/upload.js.map +1 -1
  108. package/dist/builtins/fs/url.d.ts +14 -2
  109. package/dist/builtins/fs/url.js +6 -8
  110. package/dist/builtins/fs/url.js.map +1 -1
  111. package/dist/builtins/fs/writeReport.d.ts +40 -0
  112. package/dist/builtins/fs/writeReport.js +71 -0
  113. package/dist/builtins/fs/writeReport.js.map +1 -0
  114. package/dist/builtins/fs/xattr.args.d.ts +14 -13
  115. package/dist/builtins/fs/xattr.args.js +3 -24
  116. package/dist/builtins/fs/xattr.args.js.map +1 -1
  117. package/dist/builtins/fs/xattr.d.ts +0 -25
  118. package/dist/builtins/fs/xattr.js +82 -65
  119. package/dist/builtins/fs/xattr.js.map +1 -1
  120. package/dist/builtins/games/bytes.d.ts +0 -55
  121. package/dist/builtins/games/bytes.js +95 -120
  122. package/dist/builtins/games/bytes.js.map +1 -1
  123. package/dist/builtins/games/chimes.d.ts +0 -36
  124. package/dist/builtins/games/chimes.js +58 -64
  125. package/dist/builtins/games/chimes.js.map +1 -1
  126. package/dist/builtins/games/chrislab.d.ts +0 -12
  127. package/dist/builtins/games/chrislab.js +0 -14
  128. package/dist/builtins/games/chrislab.js.map +1 -1
  129. package/dist/builtins/games/cowsay.d.ts +0 -24
  130. package/dist/builtins/games/cowsay.js +0 -29
  131. package/dist/builtins/games/cowsay.js.map +1 -1
  132. package/dist/builtins/games/figlet.d.ts +0 -24
  133. package/dist/builtins/games/figlet.js +0 -29
  134. package/dist/builtins/games/figlet.js.map +1 -1
  135. package/dist/builtins/games/lab.d.ts +0 -36
  136. package/dist/builtins/games/lab.js +0 -43
  137. package/dist/builtins/games/lab.js.map +1 -1
  138. package/dist/builtins/games/lolcat.d.ts +0 -12
  139. package/dist/builtins/games/lolcat.js +2 -17
  140. package/dist/builtins/games/lolcat.js.map +1 -1
  141. package/dist/builtins/games/numbers.d.ts +0 -60
  142. package/dist/builtins/games/numbers.js +0 -71
  143. package/dist/builtins/games/numbers.js.map +1 -1
  144. package/dist/builtins/games/play.d.ts +0 -36
  145. package/dist/builtins/games/play.js +47 -58
  146. package/dist/builtins/games/play.js.map +1 -1
  147. package/dist/builtins/games/qr.d.ts +0 -12
  148. package/dist/builtins/games/qr.js +189 -68
  149. package/dist/builtins/games/qr.js.map +1 -1
  150. package/dist/builtins/games/show.d.ts +0 -73
  151. package/dist/builtins/games/show.js +0 -85
  152. package/dist/builtins/games/show.js.map +1 -1
  153. package/dist/builtins/games/sky.d.ts +0 -36
  154. package/dist/builtins/games/sky.js +25 -45
  155. package/dist/builtins/games/sky.js.map +1 -1
  156. package/dist/builtins/games/text.d.ts +0 -72
  157. package/dist/builtins/games/text.js +0 -85
  158. package/dist/builtins/games/text.js.map +1 -1
  159. package/dist/builtins/games/trek.d.ts +0 -12
  160. package/dist/builtins/games/trek.js +0 -15
  161. package/dist/builtins/games/trek.js.map +1 -1
  162. package/dist/builtins/games/wtf.d.ts +0 -12
  163. package/dist/builtins/games/wtf.js +0 -15
  164. package/dist/builtins/games/wtf.js.map +1 -1
  165. package/dist/builtins/help.d.ts +0 -19
  166. package/dist/builtins/help.js +56 -39
  167. package/dist/builtins/help.js.map +1 -1
  168. package/dist/builtins/helpSections.js +13 -1
  169. package/dist/builtins/helpSections.js.map +1 -1
  170. package/dist/builtins/index.d.ts +1 -1
  171. package/dist/builtins/index.js +1 -1
  172. package/dist/builtins/index.js.map +1 -1
  173. package/dist/builtins/net/connect.d.ts +1 -8
  174. package/dist/builtins/net/connect.js +2 -13
  175. package/dist/builtins/net/connect.js.map +1 -1
  176. package/dist/builtins/net/cubepath.js +30 -20
  177. package/dist/builtins/net/cubepath.js.map +1 -1
  178. package/dist/builtins/net/logout.d.ts +0 -8
  179. package/dist/builtins/net/logout.js +1 -12
  180. package/dist/builtins/net/logout.js.map +1 -1
  181. package/dist/builtins/net/netstat.d.ts +0 -8
  182. package/dist/builtins/net/netstat.js +1 -12
  183. package/dist/builtins/net/netstat.js.map +1 -1
  184. package/dist/builtins/net/pacs.d.ts +3 -17
  185. package/dist/builtins/net/pacs.js +50 -42
  186. package/dist/builtins/net/pacs.js.map +1 -1
  187. package/dist/builtins/net/pacsUtils.d.ts +0 -2
  188. package/dist/builtins/net/pacsUtils.js +67 -30
  189. package/dist/builtins/net/pacsUtils.js.map +1 -1
  190. package/dist/builtins/net/query.anon.d.ts +61 -0
  191. package/dist/builtins/net/query.anon.js +362 -0
  192. package/dist/builtins/net/query.anon.js.map +1 -0
  193. package/dist/builtins/net/query.args.d.ts +2 -1
  194. package/dist/builtins/net/query.args.js +1 -1
  195. package/dist/builtins/net/query.args.js.map +1 -1
  196. package/dist/builtins/net/query.cohort.d.ts +125 -0
  197. package/dist/builtins/net/query.cohort.js +267 -0
  198. package/dist/builtins/net/query.cohort.js.map +1 -0
  199. package/dist/builtins/net/query.csv.d.ts +26 -5
  200. package/dist/builtins/net/query.csv.js +61 -115
  201. package/dist/builtins/net/query.csv.js.map +1 -1
  202. package/dist/builtins/net/query.d.ts +27 -34
  203. package/dist/builtins/net/query.deliver.d.ts +96 -0
  204. package/dist/builtins/net/query.deliver.js +188 -0
  205. package/dist/builtins/net/query.deliver.js.map +1 -0
  206. package/dist/builtins/net/query.fanout.d.ts +32 -0
  207. package/dist/builtins/net/query.fanout.js +91 -0
  208. package/dist/builtins/net/query.fanout.js.map +1 -1
  209. package/dist/builtins/net/query.held.d.ts +60 -0
  210. package/dist/builtins/net/query.held.js +125 -0
  211. package/dist/builtins/net/query.held.js.map +1 -0
  212. package/dist/builtins/net/query.ignored.d.ts +3 -1
  213. package/dist/builtins/net/query.ignored.js +9 -3
  214. package/dist/builtins/net/query.ignored.js.map +1 -1
  215. package/dist/builtins/net/query.js +360 -634
  216. package/dist/builtins/net/query.js.map +1 -1
  217. package/dist/builtins/net/query.model.d.ts +15 -0
  218. package/dist/builtins/net/query.model.js +109 -46
  219. package/dist/builtins/net/query.model.js.map +1 -1
  220. package/dist/builtins/net/query.view.js +29 -8
  221. package/dist/builtins/net/query.view.js.map +1 -1
  222. package/dist/builtins/operandRuns.js +4 -3
  223. package/dist/builtins/operandRuns.js.map +1 -1
  224. package/dist/builtins/operands.js +97 -39
  225. package/dist/builtins/operands.js.map +1 -1
  226. package/dist/builtins/pluginExecute.js +311 -205
  227. package/dist/builtins/pluginExecute.js.map +1 -1
  228. package/dist/builtins/proc.d.ts +1 -13
  229. package/dist/builtins/proc.helpers.d.ts +0 -7
  230. package/dist/builtins/proc.helpers.js +0 -10
  231. package/dist/builtins/proc.helpers.js.map +1 -1
  232. package/dist/builtins/proc.js +159 -116
  233. package/dist/builtins/proc.js.map +1 -1
  234. package/dist/builtins/procWatch.d.ts +2 -2
  235. package/dist/builtins/procWatch.js +54 -13
  236. package/dist/builtins/procWatch.js.map +1 -1
  237. package/dist/builtins/res/compute.d.ts +0 -13
  238. package/dist/builtins/res/compute.js +0 -16
  239. package/dist/builtins/res/compute.js.map +1 -1
  240. package/dist/builtins/res/diagram.tree.js +36 -12
  241. package/dist/builtins/res/diagram.tree.js.map +1 -1
  242. package/dist/builtins/res/dicom.d.ts +24 -17
  243. package/dist/builtins/res/dicom.js +78 -79
  244. package/dist/builtins/res/dicom.js.map +1 -1
  245. package/dist/builtins/res/expect.d.ts +8 -17
  246. package/dist/builtins/res/expect.js +173 -101
  247. package/dist/builtins/res/expect.js.map +1 -1
  248. package/dist/builtins/res/feed.d.ts +0 -13
  249. package/dist/builtins/res/feed.diagram.js +89 -57
  250. package/dist/builtins/res/feed.diagram.js.map +1 -1
  251. package/dist/builtins/res/feed.js +61 -42
  252. package/dist/builtins/res/feed.js.map +1 -1
  253. package/dist/builtins/res/feed.tree.collapse.d.ts +0 -10
  254. package/dist/builtins/res/feed.tree.collapse.js +12 -5
  255. package/dist/builtins/res/feed.tree.collapse.js.map +1 -1
  256. package/dist/builtins/res/files.d.ts +0 -37
  257. package/dist/builtins/res/files.js +0 -44
  258. package/dist/builtins/res/files.js.map +1 -1
  259. package/dist/builtins/res/gather.d.ts +0 -13
  260. package/dist/builtins/res/gather.facts.js +24 -16
  261. package/dist/builtins/res/gather.facts.js.map +1 -1
  262. package/dist/builtins/res/gather.js +47 -36
  263. package/dist/builtins/res/gather.js.map +1 -1
  264. package/dist/builtins/res/gather.process.js +49 -15
  265. package/dist/builtins/res/gather.process.js.map +1 -1
  266. package/dist/builtins/res/gather.store.d.ts +4 -2
  267. package/dist/builtins/res/gather.store.js +43 -31
  268. package/dist/builtins/res/gather.store.js.map +1 -1
  269. package/dist/builtins/res/group.d.ts +0 -13
  270. package/dist/builtins/res/group.js +78 -40
  271. package/dist/builtins/res/group.js.map +1 -1
  272. package/dist/builtins/res/image.d.ts +0 -13
  273. package/dist/builtins/res/image.js +0 -15
  274. package/dist/builtins/res/image.js.map +1 -1
  275. package/dist/builtins/res/manifestRead.d.ts +65 -0
  276. package/dist/builtins/res/manifestRead.js +161 -0
  277. package/dist/builtins/res/manifestRead.js.map +1 -0
  278. package/dist/builtins/res/pipeline.d.ts +1 -1
  279. package/dist/builtins/res/pipeline.js +152 -103
  280. package/dist/builtins/res/pipeline.js.map +1 -1
  281. package/dist/builtins/res/pipeline.manifest.js +17 -7
  282. package/dist/builtins/res/pipeline.manifest.js.map +1 -1
  283. package/dist/builtins/res/play.d.ts +0 -13
  284. package/dist/builtins/res/play.js +367 -226
  285. package/dist/builtins/res/play.js.map +1 -1
  286. package/dist/builtins/res/plugin.d.ts +1 -13
  287. package/dist/builtins/res/plugin.info.js +36 -14
  288. package/dist/builtins/res/plugin.info.js.map +1 -1
  289. package/dist/builtins/res/plugin.js +1 -17
  290. package/dist/builtins/res/plugin.js.map +1 -1
  291. package/dist/builtins/res/plugin.sync.d.ts +3 -5
  292. package/dist/builtins/res/plugin.sync.js +175 -40
  293. package/dist/builtins/res/plugin.sync.js.map +1 -1
  294. package/dist/builtins/res/plugininstance.d.ts +0 -13
  295. package/dist/builtins/res/plugininstance.js +0 -16
  296. package/dist/builtins/res/plugininstance.js.map +1 -1
  297. package/dist/builtins/res/pluginmeta.d.ts +0 -13
  298. package/dist/builtins/res/pluginmeta.js +0 -16
  299. package/dist/builtins/res/pluginmeta.js.map +1 -1
  300. package/dist/builtins/res/record.d.ts +0 -13
  301. package/dist/builtins/res/record.js +2 -18
  302. package/dist/builtins/res/record.js.map +1 -1
  303. package/dist/builtins/res/runWait.js +32 -8
  304. package/dist/builtins/res/runWait.js.map +1 -1
  305. package/dist/builtins/res/tag.d.ts +0 -13
  306. package/dist/builtins/res/tag.js +0 -16
  307. package/dist/builtins/res/tag.js.map +1 -1
  308. package/dist/builtins/res/thumbnail.js +23 -8
  309. package/dist/builtins/res/thumbnail.js.map +1 -1
  310. package/dist/builtins/res/user.d.ts +0 -12
  311. package/dist/builtins/res/user.js +0 -17
  312. package/dist/builtins/res/user.js.map +1 -1
  313. package/dist/builtins/res/workflow.d.ts +0 -13
  314. package/dist/builtins/res/workflow.js +0 -16
  315. package/dist/builtins/res/workflow.js.map +1 -1
  316. package/dist/builtins/runEcho.js +2 -1
  317. package/dist/builtins/runEcho.js.map +1 -1
  318. package/dist/builtins/store.d.ts +0 -13
  319. package/dist/builtins/store.js +32 -32
  320. package/dist/builtins/store.js.map +1 -1
  321. package/dist/builtins/sys/apropos.d.ts +2 -27
  322. package/dist/builtins/sys/apropos.js +2 -32
  323. package/dist/builtins/sys/apropos.js.map +1 -1
  324. package/dist/builtins/sys/cal.d.ts +0 -12
  325. package/dist/builtins/sys/cal.js +0 -15
  326. package/dist/builtins/sys/cal.js.map +1 -1
  327. package/dist/builtins/sys/command.js +3 -7
  328. package/dist/builtins/sys/command.js.map +1 -1
  329. package/dist/builtins/sys/context.d.ts +0 -8
  330. package/dist/builtins/sys/context.js +1 -12
  331. package/dist/builtins/sys/context.js.map +1 -1
  332. package/dist/builtins/sys/date.d.ts +0 -12
  333. package/dist/builtins/sys/date.js +0 -15
  334. package/dist/builtins/sys/date.js.map +1 -1
  335. package/dist/builtins/sys/echo.d.ts +0 -12
  336. package/dist/builtins/sys/echo.js +54 -49
  337. package/dist/builtins/sys/echo.js.map +1 -1
  338. package/dist/builtins/sys/fortune.d.ts +0 -12
  339. package/dist/builtins/sys/fortune.js +0 -15
  340. package/dist/builtins/sys/fortune.js.map +1 -1
  341. package/dist/builtins/sys/grep.d.ts +14 -18
  342. package/dist/builtins/sys/grep.js +239 -114
  343. package/dist/builtins/sys/grep.js.map +1 -1
  344. package/dist/builtins/sys/hostGrants.d.ts +85 -0
  345. package/dist/builtins/sys/hostGrants.js +207 -0
  346. package/dist/builtins/sys/hostGrants.js.map +1 -0
  347. package/dist/builtins/sys/joblets.d.ts +0 -24
  348. package/dist/builtins/sys/joblets.js +0 -29
  349. package/dist/builtins/sys/joblets.js.map +1 -1
  350. package/dist/builtins/sys/motd.d.ts +0 -12
  351. package/dist/builtins/sys/motd.js +14 -21
  352. package/dist/builtins/sys/motd.js.map +1 -1
  353. package/dist/builtins/sys/notes.js +26 -16
  354. package/dist/builtins/sys/notes.js.map +1 -1
  355. package/dist/builtins/sys/physicalmode.d.ts +0 -8
  356. package/dist/builtins/sys/physicalmode.js +1 -12
  357. package/dist/builtins/sys/physicalmode.js.map +1 -1
  358. package/dist/builtins/sys/tasks.d.ts +0 -24
  359. package/dist/builtins/sys/tasks.js +30 -36
  360. package/dist/builtins/sys/tasks.js.map +1 -1
  361. package/dist/builtins/sys/textFilters.d.ts +0 -84
  362. package/dist/builtins/sys/textFilters.js +33 -110
  363. package/dist/builtins/sys/textFilters.js.map +1 -1
  364. package/dist/builtins/sys/timing.d.ts +0 -8
  365. package/dist/builtins/sys/timing.js +1 -12
  366. package/dist/builtins/sys/timing.js.map +1 -1
  367. package/dist/builtins/sys/variables.d.ts +0 -24
  368. package/dist/builtins/sys/variables.js +0 -29
  369. package/dist/builtins/sys/variables.js.map +1 -1
  370. package/dist/builtins/sys/version.d.ts +0 -12
  371. package/dist/builtins/sys/version.js +0 -15
  372. package/dist/builtins/sys/version.js.map +1 -1
  373. package/dist/builtins/sys/weather.js +46 -27
  374. package/dist/builtins/sys/weather.js.map +1 -1
  375. package/dist/builtins/sys/whoami.d.ts +0 -22
  376. package/dist/builtins/sys/whoami.js +16 -43
  377. package/dist/builtins/sys/whoami.js.map +1 -1
  378. package/dist/builtins/utils.d.ts +4 -39
  379. package/dist/builtins/utils.js +24 -55
  380. package/dist/builtins/utils.js.map +1 -1
  381. package/dist/chris/backend.js +7 -12
  382. package/dist/chris/backend.js.map +1 -1
  383. package/dist/chris/binDeclarations.d.ts +0 -44
  384. package/dist/chris/binDeclarations.js +111 -29
  385. package/dist/chris/binDeclarations.js.map +1 -1
  386. package/dist/chris/binExecutables.js +26 -18
  387. package/dist/chris/binExecutables.js.map +1 -1
  388. package/dist/chris/chiliDelegate.d.ts +104 -0
  389. package/dist/chris/chiliDelegate.js +240 -0
  390. package/dist/chris/chiliDelegate.js.map +1 -1
  391. package/dist/chris/commandFallback.d.ts +2 -2
  392. package/dist/chris/commandFallback.js +107 -50
  393. package/dist/chris/commandFallback.js.map +1 -1
  394. package/dist/chris/completion.d.ts +3 -1
  395. package/dist/chris/completion.js +5 -17
  396. package/dist/chris/completion.js.map +1 -1
  397. package/dist/chris/connect.d.ts +37 -0
  398. package/dist/chris/connect.js +46 -0
  399. package/dist/chris/connect.js.map +1 -1
  400. package/dist/chris/files.js +32 -2
  401. package/dist/chris/files.js.map +1 -1
  402. package/dist/chris/navigation.js +87 -53
  403. package/dist/chris/navigation.js.map +1 -1
  404. package/dist/chris/pacsResources.js +28 -11
  405. package/dist/chris/pacsResources.js.map +1 -1
  406. package/dist/chris/promptContext.js +68 -35
  407. package/dist/chris/promptContext.js.map +1 -1
  408. package/dist/chris/universeLayout.d.ts +8 -2
  409. package/dist/chris/universeLayout.js +40 -11
  410. package/dist/chris/universeLayout.js.map +1 -1
  411. package/dist/chris/warmup.d.ts +140 -0
  412. package/dist/chris/warmup.js +622 -0
  413. package/dist/chris/warmup.js.map +1 -0
  414. package/dist/core/argumentKinds.js +4 -4
  415. package/dist/core/argumentKinds.js.map +1 -1
  416. package/dist/core/assignment.js +8 -6
  417. package/dist/core/assignment.js.map +1 -1
  418. package/dist/core/backend.d.ts +44 -8
  419. package/dist/core/backend.js.map +1 -1
  420. package/dist/core/commandDeclaration.d.ts +8 -0
  421. package/dist/core/commandDeclaration.js.map +1 -1
  422. package/dist/core/commandParse.d.ts +34 -1
  423. package/dist/core/commandParse.js +156 -28
  424. package/dist/core/commandParse.js.map +1 -1
  425. package/dist/core/commandRegistry.d.ts +24 -5
  426. package/dist/core/commandRegistry.js +28 -5
  427. package/dist/core/commandRegistry.js.map +1 -1
  428. package/dist/core/dispatch.d.ts +1 -12
  429. package/dist/core/dispatch.js +12 -16
  430. package/dist/core/dispatch.js.map +1 -1
  431. package/dist/core/elevation.js +30 -5
  432. package/dist/core/elevation.js.map +1 -1
  433. package/dist/core/engine.d.ts +5 -11
  434. package/dist/core/engine.js +126 -50
  435. package/dist/core/engine.js.map +1 -1
  436. package/dist/core/expansion.d.ts +0 -6
  437. package/dist/core/expansion.js +0 -8
  438. package/dist/core/expansion.js.map +1 -1
  439. package/dist/core/filesystem.js +1 -1
  440. package/dist/core/filesystem.js.map +1 -1
  441. package/dist/core/handlerRun.d.ts +13 -0
  442. package/dist/core/handlerRun.js +21 -0
  443. package/dist/core/handlerRun.js.map +1 -1
  444. package/dist/core/holds.js +3 -3
  445. package/dist/core/holds.js.map +1 -1
  446. package/dist/core/hostGate.d.ts +62 -0
  447. package/dist/core/hostGate.js +72 -0
  448. package/dist/core/hostGate.js.map +1 -0
  449. package/dist/core/joblets.js +53 -27
  450. package/dist/core/joblets.js.map +1 -1
  451. package/dist/core/paths.d.ts +3 -5
  452. package/dist/core/paths.js +107 -36
  453. package/dist/core/paths.js.map +1 -1
  454. package/dist/core/preprocess.d.ts +12 -0
  455. package/dist/core/preprocess.js +42 -15
  456. package/dist/core/preprocess.js.map +1 -1
  457. package/dist/core/question.d.ts +27 -3
  458. package/dist/core/question.js +14 -6
  459. package/dist/core/question.js.map +1 -1
  460. package/dist/core/runner.d.ts +31 -7
  461. package/dist/core/runner.js +189 -37
  462. package/dist/core/runner.js.map +1 -1
  463. package/dist/core/sink.d.ts +7 -19
  464. package/dist/core/sink.js +56 -28
  465. package/dist/core/sink.js.map +1 -1
  466. package/dist/core/surface.js +1 -0
  467. package/dist/core/surface.js.map +1 -1
  468. package/dist/core/variables.js +37 -11
  469. package/dist/core/variables.js.map +1 -1
  470. package/dist/core/version.d.ts +0 -20
  471. package/dist/core/version.js +2 -26
  472. package/dist/core/version.js.map +1 -1
  473. package/dist/core/warmupFailures.d.ts +3 -6
  474. package/dist/core/warmupFailures.js.map +1 -1
  475. package/dist/core.d.ts +2 -0
  476. package/dist/core.js +2 -0
  477. package/dist/core.js.map +1 -1
  478. package/dist/index.d.ts +8 -1
  479. package/dist/index.js +8 -1
  480. package/dist/index.js.map +1 -1
  481. package/dist/lib/completer/cfsPaths.js +66 -26
  482. package/dist/lib/completer/cfsPaths.js.map +1 -1
  483. package/dist/lib/completer/declared.js +81 -20
  484. package/dist/lib/completer/declared.js.map +1 -1
  485. package/dist/lib/completer/index.d.ts +3 -0
  486. package/dist/lib/completer/index.js +44 -7
  487. package/dist/lib/completer/index.js.map +1 -1
  488. package/dist/lib/parser.d.ts +0 -16
  489. package/dist/lib/parser.js +223 -135
  490. package/dist/lib/parser.js.map +1 -1
  491. package/dist/lib/vfs/folderListing.d.ts +85 -0
  492. package/dist/lib/vfs/folderListing.js +86 -0
  493. package/dist/lib/vfs/folderListing.js.map +1 -0
  494. package/dist/lib/vfs/vfs.d.ts +37 -9
  495. package/dist/lib/vfs/vfs.js +195 -110
  496. package/dist/lib/vfs/vfs.js.map +1 -1
  497. package/dist/lib/wildcard.d.ts +7 -34
  498. package/dist/lib/wildcard.js +123 -95
  499. package/dist/lib/wildcard.js.map +1 -1
  500. package/dist/notes.json +1 -1
  501. package/dist/session/answerAdapters.js +249 -131
  502. package/dist/session/answerAdapters.js.map +1 -1
  503. package/package.json +12 -10
  504. package/dist/builtins/wildcard.d.ts +0 -8
  505. package/dist/builtins/wildcard.js +0 -9
  506. package/dist/builtins/wildcard.js.map +0 -1
  507. package/dist/lib/quoting.d.ts +0 -40
  508. package/dist/lib/quoting.js +0 -70
  509. package/dist/lib/quoting.js.map +0 -1
  510. package/dist/lib/semicolonParser.d.ts +0 -41
  511. package/dist/lib/semicolonParser.js +0 -93
  512. package/dist/lib/semicolonParser.js.map +0 -1
@@ -6,26 +6,41 @@
6
6
  *
7
7
  * Also exports `pacsQuery_createAndWait` for reuse by `builtin_pull`.
8
8
  *
9
+ * Key components:
10
+ * - queryCommand, queryLine_run: the verb, and the handler `pacs query` shares.
11
+ * - pacsQuery_createAndWait: one question asked of a PACS, waited on.
12
+ *
13
+ * Typical usage:
14
+ * ```ts
15
+ * await declaredCommand_run(queryCommand, ['PatientID:1234', '--table']);
16
+ * ```
17
+ *
18
+ * Dependencies: query.cohort.ts and query.fanout.ts (the questions),
19
+ * query.model.ts and query.held.ts (the answer), query.anon.ts (`--anon`),
20
+ * query.view.ts, query.csv.ts and query.deliver.ts (how it reads).
21
+ *
9
22
  * @module
10
23
  */
11
- import chalk from 'chalk';
12
- import { chrisContext, Context, pacsQuery_get, pacsQuery_resultDecode, pacsQueries_create, pacsServers_list, listCache_get, queryIndex_get, seriesStorage_resolveMany } from '@fnndsc/cumin';
13
- import { queryFolderName_build, answer_standIn, criteria_standIn } from '@fnndsc/salsa';
24
+ import { chrisContext, Context, pacsQuery_get, pacsQuery_resultDecode, pacsQueries_create, pacsServers_list, listCache_get, queryIndex_get } from '@fnndsc/cumin';
25
+ import { errorStack } from '@fnndsc/fond';
14
26
  import { PACS_QUERY_MODEL_KIND, envelope_ok, envelope_error } from '@fnndsc/menu';
15
- import { PATIENT_KEY, QUERY_COHORT_MAX, QUERY_INLINE_FANOUT_MAX, fanout_permit, patients_read, queryTerms_expand, queryTerms_parse, } from './query.fanout.js';
16
- import { sink_get } from '../../core/sink.js';
17
- import { pacsQueryModel_build } from './query.model.js';
18
- import { pacsAnswer_render } from './query.view.js';
19
- import { ignoredKeys_hint } from './query.ignored.js';
20
- import { csvFile_write, pacsAnswer_renderCsv, pacsAnswer_renderTable } from './query.csv.js';
21
- import { series_cubePathGet } from './pacsUtils.js';
22
- import { spinner } from '../../lib/spinner.js';
27
+ import { queryFolderName_build } from '@fnndsc/salsa';
28
+ import chalk from 'chalk';
23
29
  import { pacsRefusal_hint, pacsRefusal_is } from './pacsAccess.js';
30
+ import { QUERY_ANON_FAILED, QUERY_ANON_PROGRESS, QUERY_ANON_REFUSED, anonAnswer_run, expressionShown_build, pacsModel_standIn, } from './query.anon.js';
24
31
  import { QUERY_GRAMMAR } from './query.args.js';
32
+ import { cohortAsks_build, cohortTally_render, criteria_format, fanoutModel_build, inlineAsks_build, } from './query.cohort.js';
33
+ import { pacsAnswer_renderTable } from './query.csv.js';
34
+ import { csvAnswer_envelope, csv_deliver } from './query.deliver.js';
35
+ import { jsonTerms_parse, queryTerms_parse } from './query.fanout.js';
36
+ import { modelPulledState_fill } from './query.held.js';
37
+ import { ignoredKeys_hint } from './query.ignored.js';
38
+ import { pacsQueryModel_build } from './query.model.js';
39
+ import { pacsAnswer_render } from './query.view.js';
25
40
  import { command_declare } from '../../core/commandDeclaration.js';
26
- import { declaredCommand_run } from '../../core/commandParse.js';
27
- import { errorStack } from '@fnndsc/fond';
28
41
  import { exitCode_set } from '../../core/handlerRun.js';
42
+ import { sink_get } from '../../core/sink.js';
43
+ import { spinner } from '../../lib/spinner.js';
29
44
  const QUERY_POLL_INTERVAL_MS = 2_000;
30
45
  const QUERY_TIMEOUT_MS = 60_000;
31
46
  /**
@@ -166,90 +181,7 @@ function queryIndex_file(queryId, criteria, server, owner, hasResult) {
166
181
  // The answer's model is built in its own module, so a verb that reads one
167
182
  // answer (`gather add`) loads the projection without the whole query verb.
168
183
  export { pacsQueryModel_build };
169
- /**
170
- * What to ask CUBE, for an answer's held state.
171
- *
172
- * One filter per STUDY, which is the shape that matters: asking per series
173
- * costs two round trips each and a patient's history runs to hundreds,
174
- * while studies are counted in tens. A study the answer does not name is
175
- * left out, and its series are asked about one at a time instead.
176
- *
177
- * @param model - The answer.
178
- * @returns One filter per named study, in the answer's order.
179
- */
180
- export function pulledFilters_build(model) {
181
- return model.studies
182
- .filter((study) => typeof study.studyUID === 'string' && study.studyUID !== '')
183
- .map((study) => ({ StudyInstanceUID: study.studyUID }));
184
- }
185
- /** How many already-in-CUBE checks run at once, on the per-series path. */
186
- const PULLED_CHECK_CONCURRENCY = 4;
187
- /**
188
- * Fills each series' `pulled` state by asking CUBE what it already holds.
189
- *
190
- * Asked by STUDY, not by series. The obvious shape — ask about each series
191
- * in turn — costs two round trips per series, and a patient's history runs
192
- * to hundreds: reconciling one stored answer of 299 series took twenty
193
- * seconds against a live CUBE, which is why a replayed query felt exactly
194
- * like a fresh one. CUBE indexes a stored series by its study, so the same
195
- * reconciliation is one page per study, and a study count is small.
196
- *
197
- * A study whose UID the answer does not carry falls back to asking about
198
- * its series one at a time, since a study that cannot be named in bulk is
199
- * still owed an answer.
200
- *
201
- * @param model - The query model to annotate in place.
202
- */
203
- async function modelPulledState_fill(model) {
204
- const named = model.studies.filter((study) => typeof study.studyUID === 'string' && study.studyUID !== '');
205
- const unnamed = model.studies.filter((study) => !(typeof study.studyUID === 'string' && study.studyUID !== ''));
206
- if (named.length > 0) {
207
- const held = await seriesStorage_resolveMany(pulledFilters_build(model));
208
- if (held.ok) {
209
- for (const study of named) {
210
- for (const series of study.series) {
211
- const state = series.seriesUID === undefined ? undefined : held.value.get(series.seriesUID);
212
- if (state === undefined || state.folderPath === null)
213
- continue;
214
- series.pulled = true;
215
- series.pulledFiles = state.fileCount;
216
- // Where the series landed, so a surface can open it as an image.
217
- series.folderPath = state.folderPath;
218
- }
219
- }
220
- }
221
- else {
222
- // CUBE would not answer in bulk. Ask the old way rather than report a
223
- // whole answer as unheld, which would offer PULL for series already in.
224
- await seriesPulledState_fillOneByOne(named.flatMap((study) => study.series));
225
- }
226
- }
227
- if (unnamed.length > 0)
228
- await seriesPulledState_fillOneByOne(unnamed.flatMap((study) => study.series));
229
- }
230
- /**
231
- * The per-series fallback: one lookup each, a few at a time.
232
- *
233
- * An unreachable check leaves the flag unset rather than guessing.
234
- *
235
- * @param allSeries - The series to ask about.
236
- */
237
- async function seriesPulledState_fillOneByOne(allSeries) {
238
- for (let start = 0; start < allSeries.length; start += PULLED_CHECK_CONCURRENCY) {
239
- const batch = allSeries.slice(start, start + PULLED_CHECK_CONCURRENCY);
240
- await Promise.all(batch.map(async (series) => {
241
- if (!series.seriesUID)
242
- return;
243
- const home = await series_cubePathGet(series.seriesUID, 1, 0);
244
- if (home !== null) {
245
- series.pulled = true;
246
- series.pulledFiles = home.fileCount;
247
- if (home.folderPath !== null && home.folderPath !== undefined)
248
- series.folderPath = home.folderPath;
249
- }
250
- }));
251
- }
252
- }
184
+ export { pulledFilters_build } from './query.held.js';
253
185
  /**
254
186
  * Who is asking, as the index keys it.
255
187
  *
@@ -265,25 +197,19 @@ async function seriesPulledState_fillOneByOne(allSeries) {
265
197
  async function askingIdentity_get() {
266
198
  return (await chrisContext.ChRISuser_get()) ?? '';
267
199
  }
268
- /**
269
- * What each way of naming a server resolves to. Server identifiers do not
270
- * change under a session, and this is on the path of every query.
271
- */
272
- const pacsIdentifiers = new Map();
273
200
  /**
274
201
  * Resolves whatever names a PACS server into its canonical identifier.
275
202
  *
276
203
  * The context may hold a numeric id, a `--pacsserver` may be either, and
277
204
  * CUBE files a query under the identifier. The index is keyed on what CUBE
278
- * stores, so both the write and the lookup have to speak that.
205
+ * stores, so both the write and the lookup have to speak that. Asked
206
+ * afresh each time, of the server list cumin keeps for the client asking:
207
+ * what a name resolves to is that CUBE's answer to that identity.
279
208
  *
280
209
  * @param pacsserver - An id or an identifier.
281
210
  * @returns The identifier, or the input unchanged when it cannot be resolved.
282
211
  */
283
212
  export async function pacsIdentifier_resolve(pacsserver) {
284
- const remembered = pacsIdentifiers.get(pacsserver);
285
- if (remembered !== undefined)
286
- return remembered;
287
213
  const servers = await pacsServers_list();
288
214
  // Best effort by design: this only decides what a lookup is filed under,
289
215
  // so an unreachable or unhelpful CUBE must never fail the query itself.
@@ -300,9 +226,30 @@ export async function pacsIdentifier_resolve(pacsserver) {
300
226
  break;
301
227
  }
302
228
  }
303
- pacsIdentifiers.set(pacsserver, resolved);
304
229
  return resolved;
305
230
  }
231
+ /**
232
+ * The servers CUBE lists, by identifier: the only server names a
233
+ * screen-safe answer shows. None when CUBE will not say.
234
+ *
235
+ * @returns The identifiers.
236
+ */
237
+ async function serverIdentifiers_list() {
238
+ const servers = await pacsServers_list();
239
+ if (!servers.ok)
240
+ return new Set();
241
+ return new Set(servers.value.flatMap((server) => (server.identifier ? [server.identifier] : [])));
242
+ }
243
+ /**
244
+ * What a screen-safe answer shows of its question, and the servers it may name.
245
+ *
246
+ * @param terms - The question's parsed terms.
247
+ * @param patientsArg - The `--patients` value, or null.
248
+ * @returns The question as shown, and the servers CUBE lists.
249
+ */
250
+ async function answerShown_build(terms, patientsArg) {
251
+ return { expression: expressionShown_build(terms, patientsArg), servers: await serverIdentifiers_list() };
252
+ }
306
253
  /**
307
254
  * Says how long ago something was answered, in the coarsest true unit.
308
255
  *
@@ -373,89 +320,8 @@ async function replay_attempt(criteria, identifier, owner) {
373
320
  answeredAt: entry.answeredAt,
374
321
  };
375
322
  }
376
- /**
377
- * Reads a JSON expression as single-valued terms.
378
- *
379
- * The JSON form predates multi-value and stays what it was: one question,
380
- * spelled as an object.
381
- *
382
- * @param expr - The expression, starting with `{`.
383
- * @returns Terms with one value each, or null when the JSON is not an object.
384
- */
385
- function termsFromJson_read(expr) {
386
- const parsed = queryExpr_parse(expr);
387
- if (parsed === null)
388
- return null;
389
- return Object.fromEntries(Object.entries(parsed).map(([key, value]) => [key, [value]]));
390
- }
391
323
  /** How many patient queries are in flight at once. */
392
324
  const QUERY_FANOUT_CONCURRENCY = 4;
393
- /**
394
- * Renders criteria back into the expression syntax they were parsed from,
395
- * so a single question inside a fan-out is asked exactly as one typed by
396
- * hand — the create path takes an expression, not a record.
397
- *
398
- * @param criteria - One question's criteria.
399
- * @returns The `Key:Value,Key:Value` form.
400
- */
401
- function criteria_format(criteria) {
402
- return Object.entries(criteria)
403
- .map(([key, value]) => `${key}:${value}`)
404
- .join(',');
405
- }
406
- /**
407
- * One answer with a stand-in for everything it says about a person.
408
- *
409
- * Substituted in the DECODED payload, which is what the model, the table,
410
- * the CSV and the console line are all built from — so one substitution
411
- * reaches every one of them and none of them has to know.
412
- *
413
- * @param answer - What came back.
414
- * @returns The same answer, saying nothing identifying.
415
- */
416
- function answer_stoodIn(answer) {
417
- if (answer.result === null)
418
- return answer;
419
- return {
420
- ...answer,
421
- result: {
422
- ...answer.result,
423
- decoded: { ...answer.result.decoded, json: answer_standIn(answer.result.decoded.json) },
424
- },
425
- };
426
- }
427
- /**
428
- * The typed line, with stand-ins for the values in it.
429
- *
430
- * The line an operator typed is the first identifying thing on a screen,
431
- * and it is echoed above the answer. Rewriting the VALUES rather than
432
- * starring them out keeps the line honest — a PACS reads `*` as a wildcard,
433
- * so a starred line is one an onlooker could run to mean something else
434
- * entirely — and ties the line to the rows below it, which carry the same
435
- * tokens.
436
- *
437
- * @param expression - The line as typed.
438
- * @param asks - The questions it lowered to, holding the real values.
439
- * @returns The line with each value stood in for.
440
- */
441
- function expression_standIn(expression, asks) {
442
- let out = expression;
443
- const seen = [];
444
- for (const ask of asks) {
445
- for (const [field, value] of Object.entries(ask.criteria))
446
- seen.push([field, value]);
447
- }
448
- // Longest first: a short value that is a substring of a longer one must
449
- // not be replaced inside it.
450
- seen.sort((a, b) => b[1].length - a[1].length);
451
- for (const [field, value] of seen) {
452
- if (value === '')
453
- continue;
454
- const stoodIn = criteria_standIn({ [field]: value })[field] ?? value;
455
- out = out.split(value).join(stoodIn);
456
- }
457
- return out;
458
- }
459
325
  /**
460
326
  * Asks one question, replaying it when the same question has been asked
461
327
  * before.
@@ -550,74 +416,28 @@ async function fanout_run(asks, title, owner, fresh) {
550
416
  return answers;
551
417
  }
552
418
  /**
553
- * Unions a fan-out's answers into one model.
554
- *
555
- * The studies keep their own identities and paths, each already built
556
- * against the query that found it. The patient level records what was
557
- * ASKED — including the questions that found nothing and the ones that
558
- * could not be asked at all, which is the half of a cohort answer that
559
- * cannot be derived from studies nobody has.
419
+ * Renders one patient row in the cohort audit table.
560
420
  *
561
- * @param answers - What every question came back with.
562
- * @param facts - The command's identity facts.
563
- * @returns The union model.
421
+ * @param patient - The patient record.
422
+ * @param manyServers - Whether the SERVER column is shown.
423
+ * @param serverWidth - Width of the SERVER column.
424
+ * @returns The formatted row line.
564
425
  */
565
- function fanoutModel_build(answers, facts) {
566
- // A row says which PACS answered only when more than one could have. On
567
- // a single-server query the column would repeat one value down the page
568
- // and tell an operator nothing.
569
- const manyServers = new Set(answers.map((answer) => answer.ask.identifier)).size > 1;
570
- const studies = [];
571
- const patients = [];
572
- let anchor = null;
573
- let oldest = null;
574
- let allReplayed = true;
575
- for (const answer of answers) {
576
- const found = answer.result === null ? [] : pacsQueryModel_build(answer.result.decoded, {
577
- queryId: answer.result.queryId,
578
- vfsPath: answer.result.vfsPath,
579
- pacsName: answer.ask.server,
580
- expression: criteria_format(answer.ask.criteria),
581
- }).studies.map((study) => (manyServers ? { ...study, server: answer.ask.identifier } : study));
582
- studies.push(...found);
583
- if (answer.result !== null && (anchor === null || found.length > 0)) {
584
- if (anchor === null || anchor.decoded.json === undefined)
585
- anchor = answer.result;
586
- }
587
- const answeredAt = answer.answeredAt ?? new Date().toISOString();
588
- if (answer.answeredAt === null)
589
- allReplayed = false;
590
- if (answer.result !== null && (oldest === null || answeredAt < oldest))
591
- oldest = answeredAt;
592
- if (answer.ask.patientId === undefined)
593
- continue;
594
- const seriesCount = found.reduce((total, study) => total + study.series.length, 0);
595
- patients.push({
596
- patientId: answer.ask.patientId,
597
- ...(manyServers ? { server: answer.ask.identifier } : {}),
598
- ...(found[0]?.patientName ? { patientName: found[0].patientName } : {}),
599
- status: answer.result === null ? 'unasked' : (found.length > 0 ? 'found' : 'none'),
600
- studyCount: found.length,
601
- seriesCount,
602
- ...(answer.result === null ? {} : { queryId: answer.result.queryId }),
603
- ...(answer.result === null ? {} : {
604
- provenance: { replayed: answer.answeredAt !== null, answeredAt },
605
- }),
606
- ...(answer.error === undefined ? {} : { error: answer.error }),
607
- });
608
- }
609
- return {
610
- queryId: anchor?.queryId ?? 0,
611
- vfsPath: anchor?.vfsPath ?? '',
612
- pacsName: facts.pacsName,
613
- expression: facts.expression,
614
- studies,
615
- // The set's provenance is its OLDEST row: the worst row is what decides
616
- // whether an audit table can be trusted, and a set is only "replayed"
617
- // when nothing in it troubled the PACS.
618
- ...(oldest === null ? {} : { provenance: { replayed: allReplayed, answeredAt: oldest } }),
619
- ...(patients.length > 0 ? { patients } : {}),
620
- };
426
+ function cohortRow_render(patient, manyServers, serverWidth) {
427
+ const answered = patient.provenance === undefined
428
+ ? null
429
+ : age_describe(patient.provenance.answeredAt);
430
+ const counts = patient.status === 'unasked'
431
+ ? ['—', '—']
432
+ : [String(patient.studyCount), String(patient.seriesCount)];
433
+ const hue = patient.status === 'unasked'
434
+ ? chalk.red
435
+ : (patient.status === 'none' ? chalk.gray : chalk.white);
436
+ const note = patient.status === 'unasked'
437
+ ? chalk.red(patient.error ?? 'unasked')
438
+ : chalk.gray(answered ?? 'just now');
439
+ const server = manyServers ? (patient.server ?? '').padEnd(serverWidth) : '';
440
+ return ` ${hue(patient.patientId.padEnd(18))}${server}${counts[0].padEnd(10)}${counts[1].padEnd(9)}${note}`;
621
441
  }
622
442
  /**
623
443
  * Renders a cohort as the audit table it is: one row per patient asked.
@@ -639,127 +459,10 @@ function cohort_render(patients) {
639
459
  lines.push(` ${chalk.bold.white('MRN'.padEnd(18))}${serverCap}${chalk.bold.white('STUDIES'.padEnd(10))}${chalk.bold.white('SERIES'.padEnd(9))}${chalk.bold.white('ANSWERED')}`);
640
460
  lines.push(` ${chalk.gray('─'.repeat(manyServers ? 74 : 60))}`);
641
461
  for (const patient of patients) {
642
- const answered = patient.provenance === undefined
643
- ? null
644
- : age_describe(patient.provenance.answeredAt);
645
- const counts = patient.status === 'unasked'
646
- ? ['—', '—']
647
- : [String(patient.studyCount), String(patient.seriesCount)];
648
- const hue = patient.status === 'unasked'
649
- ? chalk.red
650
- : (patient.status === 'none' ? chalk.gray : chalk.white);
651
- const note = patient.status === 'unasked'
652
- ? chalk.red(patient.error ?? 'unasked')
653
- : chalk.gray(answered ?? 'just now');
654
- const server = manyServers ? server_extract(patient).padEnd(serverWidth) : '';
655
- lines.push(` ${hue(patient.patientId.padEnd(18))}${server}${counts[0].padEnd(10)}${counts[1].padEnd(9)}${note}`);
462
+ lines.push(cohortRow_render(patient, manyServers, serverWidth));
656
463
  }
657
464
  return `${lines.join('\n')}\n${cohortTally_render(patients)}`;
658
465
  }
659
- /**
660
- * The cohort's closing tally: found, none, unasked.
661
- *
662
- * @param patients - Every patient asked.
663
- * @returns The tally line with a blank line either side, or '' when no patient was asked.
664
- */
665
- function cohortTally_render(patients) {
666
- if (patients.length === 0)
667
- return '';
668
- const tally = (state) => patients.filter((patient) => patient.status === state).length;
669
- return ` ${chalk.green(`FOUND ${tally('found')}`)} ${chalk.gray('·')} ${chalk.gray(`NONE ${tally('none')}`)} ${chalk.gray('·')} ${chalk.red(`UNASKED ${tally('unasked')}`)}\n\n`;
670
- }
671
- /**
672
- * Renders an answer as CSV, and writes it into ChRIS storage when asked.
673
- *
674
- * Two flags rather than one with an optional value: `--csv PatientID:1234`
675
- * could not tell a destination from a query expression, and guessing wrong
676
- * writes a file named after a patient.
677
- *
678
- * A local terminal needs no destination — `--csv > audit.csv` writes the
679
- * operator's own disk, because engine and operator share a filesystem. A
680
- * detached surface does not: the engine runs on the daemon's host, so a
681
- * redirect lands on somebody else's machine. `--csv-to` puts the table in
682
- * CFS instead, where a cohort's MRNs and study descriptions stay inside
683
- * ChRIS rather than on whatever laptop the operator is sitting at.
684
- *
685
- * @param model - The answer.
686
- * @param destination - A CFS path to write to, or null to render only.
687
- * @returns The CSV text and where it went, or a failure already explained.
688
- */
689
- async function csv_deliver(model, destination, ask = false, force = false, level = 'study', table = false) {
690
- const csv = pacsAnswer_renderCsv(model, level);
691
- let target = destination;
692
- if (target === null && ask) {
693
- // Asked only once there is something to write: a question raised before
694
- // the PACS answered would be a question about a file that may never
695
- // exist.
696
- const chosen = await csvDestination_ask();
697
- if (chosen === '')
698
- return { ok: false, message: 'query: no destination given; nothing written.' };
699
- target = chosen;
700
- }
701
- if (target === null)
702
- return { ok: true, rendered: csv };
703
- const written = await csvFile_write(csv, target, force);
704
- if (!written.ok)
705
- return { ok: false, message: `query: ${written.message}` };
706
- // A folder that had to be made is said, not discovered later.
707
- const made = written.created === undefined
708
- ? ''
709
- : `${chalk.gray(` made ${written.created}`)}\n`;
710
- // A file that was there and is not any more is said, for the same reason
711
- // the folder is: an act nobody reported is an act nobody can check.
712
- const gone = written.replaced === true
713
- ? `${chalk.gray(` replaced the table that was there`)}\n`
714
- : '';
715
- // The file went where it was sent; the screen, asked for the table,
716
- // shows the same rows beside the word that they were written.
717
- const shown = table ? `\n${pacsAnswer_renderTable(model, level)}` : '';
718
- return { ok: true, rendered: `${made}${gone}${chalk.green(`✓ wrote ${written.path}`)}\n${shown}` };
719
- }
720
- /**
721
- * Asks where the table should go.
722
- *
723
- * The anchor is the session's own cwd — a fact, not a guess. Inventing a
724
- * directory here would mean creating one behind the operator's back, which
725
- * is what the surface used to do.
726
- *
727
- * @returns The location given, absolute, or '' when the operator abandoned the ask.
728
- */
729
- async function csvDestination_ask() {
730
- const { session } = await import('../../session/index.js');
731
- const { repl_questionPath } = await import('../../core/question.js');
732
- const stamp = new Date().toISOString().slice(0, 19).replace(/[:T]/g, '-');
733
- // Where the operator is, unless they are somewhere nothing can be
734
- // written: a session sitting in `/bin` or `/proc` is browsing a provider,
735
- // not a place a file lands, and an errand that opens there offers a
736
- // destination that is refused the moment it is committed.
737
- const cwd = await session.getCWD();
738
- const virtual = ['/bin', '/usr', '/etc', '/proc', '/net']
739
- .some((prefix) => cwd === prefix || cwd.startsWith(`${prefix}/`));
740
- try {
741
- const answer = await repl_questionPath('Where should the table go? ', {
742
- anchor: virtual ? '~' : cwd,
743
- wantsDirectory: false,
744
- suggest: `pacs-${stamp}.csv`,
745
- }, 'EXPORT HERE');
746
- // Absolute, against the place the question showed: other commands run
747
- // while it is open, and a `cd` among them must not move the file.
748
- const given = answer.trim();
749
- if (given === '')
750
- return '';
751
- const { path_resolve } = await import('../utils.js');
752
- if (given.startsWith('/') || given.startsWith('~'))
753
- return await path_resolve(given);
754
- const base = virtual ? '~' : cwd;
755
- return await path_resolve(`${base === '/' ? '' : base}/${given}`);
756
- }
757
- catch {
758
- // A refused or abandoned ask is not a failure of the query: the answer
759
- // stands, and only the writing of it does not happen.
760
- return '';
761
- }
762
- }
763
466
  /**
764
467
  * Answers a cohort: many questions, one model, one table.
765
468
  *
@@ -768,30 +471,18 @@ async function csvDestination_ask() {
768
471
  * @returns One envelope carrying every answer.
769
472
  */
770
473
  async function cohort_answer(asks, facts) {
771
- spinner.start(`Querying PACS for ${asks.length} questions...`, true);
474
+ const anon = facts.shown !== null;
475
+ spinner.start(anon ? QUERY_ANON_PROGRESS : `Querying PACS for ${asks.length} questions...`, true);
772
476
  const answers = await fanout_run(asks, facts.title, facts.owner, facts.fresh);
773
477
  spinner.stop();
774
- const model = fanoutModel_build(facts.anon ? answers.map(answer_stoodIn) : answers, {
775
- pacsName: facts.pacsserver,
776
- expression: facts.expression,
777
- });
778
- await modelPulledState_fill(model);
478
+ const built = fanoutModel_build(answers, { pacsName: facts.pacsserver, expression: facts.expression });
479
+ await modelPulledState_fill(built);
480
+ // Built and reconciled on the real answers; shown, under --anon, saying no patient.
481
+ const model = facts.shown === null ? built : pacsModel_standIn(built, facts.shown.expression, facts.shown.servers);
779
482
  const patients = model.patients ?? [];
780
483
  const unasked = patients.filter((patient) => patient.status === 'unasked').length;
781
484
  if (facts.csv || facts.csvTo !== null || facts.csvToAsk) {
782
- const delivered = await csv_deliver(model, facts.csvTo, facts.csvToAsk, facts.force, facts.level, facts.table);
783
- if (!delivered.ok) {
784
- exitCode_set(1);
785
- // The ANSWER stands: only the writing of it did not happen. An
786
- // abandoned question, or a refused destination, is no reason to
787
- // throw away a PACS answer the operator waited for — the model
788
- // crosses either way, and a surface still shows what was found.
789
- return {
790
- ...envelope_error('', undefined, `${chalk.red(delivered.message)}\n`),
791
- model: { kind: PACS_QUERY_MODEL_KIND, data: model },
792
- };
793
- }
794
- return envelope_ok(delivered.rendered, { kind: PACS_QUERY_MODEL_KIND, data: model });
485
+ return csvAnswer_envelope(await csv_deliver(model, facts.csvTo, facts.csvToAsk, facts.force, facts.level, facts.table, anon), model);
795
486
  }
796
487
  // A fan-out over something other than patients has no audit table to
797
488
  // show; its studies are the answer, and they are already in the model.
@@ -837,7 +528,12 @@ export const queryCommand = command_declare({
837
528
  + 'A PACS matches one patient at a time, so several MRNs (PatientID:1,2,3 or --patients) is several queries, one table. '
838
529
  + 'Some PACS ignore keys: PACSDCM answers SeriesDescription and StudyDescription as if they were not asked (query says so); '
839
530
  + 'narrow the answer with grep. The keys each server ignores are in ~/.config/mise/pacs.json, as '
840
- + '{"ignoredKeys": {"PACSDCM": ["SeriesDescription", "StudyDescription"]}}.',
531
+ + '{"ignoredKeys": {"PACSDCM": ["SeriesDescription", "StudyDescription"]}}. '
532
+ + '--anon makes what the query itself prints or hands a surface screen-safe: names, record and accession numbers are stand-ins, '
533
+ + 'dates fall to the month, descriptions, reasons and the progress line say no patient, and anything it does not recognise is withheld. '
534
+ + 'It does not mask the line you typed, '
535
+ + 'nor what you carry onward from it (history, variables, the next command). Paths stay real, because a surface acts on them: '
536
+ + 'vfsPath, the @STD/@SER handle targets, studies[].series[].folderPath and the --csv-to destination.',
841
537
  category: 'PACS',
842
538
  examples: [
843
539
  'query PatientID:1234',
@@ -864,260 +560,254 @@ export const queryCommand = command_declare({
864
560
  handler: queryLine_run,
865
561
  });
866
562
  /**
867
- * `query` over words already split: the declaration's parse and handler.
868
- *
869
- * @param args - The words after `query`.
870
- * @returns The answer, or the refusal of a bad line.
563
+ * Refuses a query line: non-zero, the reason in red.
871
564
  *
872
- * @example
873
- * ```ts
874
- * await builtin_query(['PatientID:1234', '--table']);
875
- * ```
565
+ * @param message - Why.
566
+ * @returns The error envelope.
876
567
  */
877
- export async function builtin_query(args) {
878
- return declaredCommand_run(queryCommand, args);
568
+ function queryLine_refuse(message) {
569
+ exitCode_set(1);
570
+ return envelope_error('', undefined, `${chalk.red(message)}\n`);
879
571
  }
880
572
  /**
881
- * Creates a PACS query, waits for results, displays findings, and prints the
882
- * VFS path: the handler of `query` and of `pacs query`.
573
+ * Reads what a query line asks for, refusing a line that asks for two
574
+ * formats for one screen or for nothing at all.
883
575
  *
884
576
  * @param args - The line, parsed.
885
- * @returns The answer, its model beside it.
886
- *
887
- * @example
888
- * ```ts
889
- * await queryLine_run({ operands: { expression: ['PatientID:1234'] }, options: { …, table: true } });
890
- * ```
577
+ * @returns The request, or the refusal.
891
578
  */
892
- export async function queryLine_run(args) {
579
+ function queryRequest_read(args) {
893
580
  const { options } = args;
894
581
  const title = options.title ?? `Query ${Date.now()}`;
895
- const pacsserverOverride = options.pacsserver ?? null;
896
- let tableMode = options.table;
897
- const fresh = options.fresh;
898
- const patientsArg = options.patients ?? null;
899
582
  const csv = options.csv;
900
- // A value-taking flag given no value is an ASK: `--csv-to` with nothing
901
- // after it means "ask me where", which is how a graphical surface opens
902
- // its errand and how a terminal gets a prompt.
903
- const csvTo = options.csvTo ?? null;
904
- const csvToAsk = options.csvTo === null;
905
- const force = options.force;
906
- // Standing in for what the answer says about a person is for
907
- // demonstrating against a live hospital PACS, where every answer carries
908
- // somebody's name and record number onto the screen.
909
- const anon = options.anon;
910
583
  const level = options.series ? 'series' : 'study';
584
+ const patientsArg = options.patients ?? null;
911
585
  const positional = args.operands.expression;
912
586
  // Two renderings for one screen: CSV is the answer's text, the table is
913
587
  // its rows aligned. Asked for both, neither is guessed; writing the CSV
914
588
  // to a file (`--csv-to`) leaves the screen free for the table.
915
- if (csv && tableMode) {
916
- exitCode_set(1);
917
- return envelope_error('', undefined, `${chalk.red('query: --csv and --table are two formats for one screen; pick one (or --csv-to <cfs-path> --table: the file gets the CSV, the screen the table)')}\n`);
589
+ if (csv && options.table) {
590
+ return queryLine_refuse('query: --csv and --table are two formats for one screen; pick one (or --csv-to <cfs-path> --table: the file gets the CSV, the screen the table)');
918
591
  }
919
- // A level is a property of rows: asked for series with no format named,
920
- // the answer is the series table.
921
- if (level === 'series' && !csv)
922
- tableMode = true;
923
592
  if (positional.length === 0 && patientsArg === null) {
924
- exitCode_set(1);
925
- return envelope_error('', undefined, `${chalk.red('query: Missing query expression. Usage: query <Key:Value[,...]> [--patients <list|@file>] [--title <title>]')}\n`);
593
+ return queryLine_refuse('query: Missing query expression. Usage: query <Key:Value[,...]> [--patients <list|@file>] [--title <title>]');
926
594
  }
927
- const queryExpr = positional.join(' ');
928
- // Validate expression early. A cohort may narrow with terms or with none
929
- // at all — `--patients @mrns.txt` is a complete question.
930
- const terms = queryExpr === '' ? {} : (queryExpr.trimStart().startsWith('{')
931
- ? termsFromJson_read(queryExpr)
932
- : queryTerms_parse(queryExpr));
933
- if (terms === null) {
934
- exitCode_set(1);
935
- return envelope_error('', undefined, `${chalk.red(`query: Invalid expression: "${queryExpr}". Use Key:Value pairs (e.g. PatientID:1234) or JSON.`)}\n`);
936
- }
937
- // Resolve the PACS servers. Several is a QUERY across them; one is the
938
- // ordinary case. There is no sweep-everything: a fan-out is always
939
- // something the operator named, because thirteen registrations of
940
- // unknown liveness is thousands of C-FINDs mostly into the void.
941
- const named = (pacsserverOverride ?? '')
595
+ return {
596
+ title,
597
+ pacsserverOverride: options.pacsserver ?? null,
598
+ // A level is a property of rows: asked for series with no format named,
599
+ // the answer is the series table.
600
+ tableMode: options.table || (level === 'series' && !csv),
601
+ fresh: options.fresh,
602
+ patientsArg,
603
+ csv,
604
+ // A value-taking flag given no value is an ASK: `--csv-to` with nothing
605
+ // after it means "ask me where", which is how a graphical surface opens
606
+ // its errand and how a terminal gets a prompt.
607
+ csvTo: options.csvTo ?? null,
608
+ csvToAsk: options.csvTo === null,
609
+ force: options.force,
610
+ // Standing in for what the answer says about a person is for
611
+ // demonstrating against a live hospital PACS, where every answer carries
612
+ // somebody's name and record number onto the screen.
613
+ anon: options.anon,
614
+ level,
615
+ queryExpr: positional.join(' '),
616
+ };
617
+ }
618
+ /**
619
+ * Reads the expression's terms, or refuses a line whose expression does not
620
+ * read: under --anon without echoing it. A cohort may narrow with terms or
621
+ * with none at all: `--patients @mrns.txt` is a complete question.
622
+ *
623
+ * @param queryExpr - The expression as typed.
624
+ * @param anon - True when the line must not be echoed.
625
+ * @returns The terms, or the refusal.
626
+ */
627
+ function queryTerms_read(queryExpr, anon) {
628
+ if (queryExpr === '')
629
+ return { terms: {} };
630
+ const terms = queryExpr.trimStart().startsWith('{') ? jsonTerms_parse(queryExpr) : queryTerms_parse(queryExpr);
631
+ if (terms === 'unquoted')
632
+ return queryLine_refuse('query: a JSON question\'s identifiers must be strings, its other values strings or numbers (quote it: {"PatientID": "…"})');
633
+ if (terms === null)
634
+ return queryLine_refuse(`query: Invalid expression${anon ? '' : `: "${queryExpr}"`}. Use Key:Value pairs (e.g. PatientID:1234) or JSON.`);
635
+ return { terms };
636
+ }
637
+ /**
638
+ * The servers `--pacsserver` names. Several is a QUERY across them; one is
639
+ * the ordinary case. There is no sweep-everything: a fan-out is always
640
+ * something the operator named, because thirteen registrations of unknown
641
+ * liveness is thousands of C-FINDs mostly into the void.
642
+ *
643
+ * @param override - The flag's value, or null.
644
+ * @returns The servers named, possibly none.
645
+ */
646
+ function serverList_parse(override) {
647
+ return (override ?? '')
942
648
  .split(',')
943
649
  .map((entry) => entry.trim())
944
650
  .filter((entry) => entry !== '');
945
- let servers = named;
946
- if (servers.length === 0) {
947
- const inContext = await chrisContext.current_get(Context.PACSserver);
948
- if (inContext) {
949
- servers = [inContext];
950
- }
951
- else {
952
- const serversResult = await pacsServers_list();
953
- if (serversResult.ok && serversResult.value.length > 0) {
954
- servers = [String(serversResult.value[0].id)];
955
- }
956
- else {
957
- exitCode_set(1);
958
- return envelope_error('', undefined, `${chalk.red('query: No PACS server available. Set one with: pacs connect <id>')}\n`);
959
- }
960
- }
961
- }
962
- const pacsserver = servers[0];
963
- // The index is keyed on what CUBE stores, which is the identifier.
964
- const identifiers = await Promise.all(servers.map((server) => pacsIdentifier_resolve(server)));
965
- const identifier = identifiers[0];
966
- const owner = await askingIdentity_get();
967
- // A key the PACS ignores narrows nothing: said once, on the err channel,
968
- // before the question goes out; the query runs as asked (#1105).
651
+ }
652
+ /**
653
+ * The server asked when none is named: the session's, else the first
654
+ * registered.
655
+ *
656
+ * @returns The one server, or the refusal when there is none.
657
+ */
658
+ async function queryServerDefault_resolve() {
659
+ const inContext = await chrisContext.current_get(Context.PACSserver);
660
+ if (inContext)
661
+ return [inContext];
662
+ const serversResult = await pacsServers_list();
663
+ if (serversResult.ok && serversResult.value.length > 0)
664
+ return [String(serversResult.value[0].id)];
665
+ return queryLine_refuse('query: No PACS server available. Set one with: pacs connect <id>');
666
+ }
667
+ /**
668
+ * Says, once, on the err channel and before the question goes out, each key
669
+ * a server ignores: it narrows nothing, and the query runs as asked (#1105).
670
+ *
671
+ * @param terms - The terms asked.
672
+ * @param identifiers - The servers asked.
673
+ * @param anon - True for the screen-safe hint: no server, nothing asked.
674
+ */
675
+ function ignoredKeys_say(terms, identifiers, anon) {
676
+ // Under --anon the hint names no server and nothing asked, so one hint
677
+ // said for two servers is the same words: it is said once.
678
+ const said = new Set();
969
679
  for (const server of [...new Set(identifiers)]) {
970
- const hint = ignoredKeys_hint(terms, server);
971
- if (hint !== null)
680
+ const hint = ignoredKeys_hint(terms, server, undefined, anon);
681
+ if (hint !== null && !said.has(hint))
972
682
  sink_get().err_write(`${chalk.yellow(hint)}\n`);
683
+ if (hint !== null)
684
+ said.add(hint);
973
685
  }
974
- // What the operator asked for, as the questions it stands for. A PACS
975
- // will not match a list, so several patients is several C-FINDs.
976
- const asks = [];
977
- if (patientsArg !== null) {
978
- const cohort = await patients_read(patientsArg);
979
- if (!cohort.ok) {
980
- const problem = errorStack.stack_pop();
981
- exitCode_set(1);
982
- return envelope_error('', undefined, `${chalk.red(problem?.message ?? 'query: --patients could not be read.')}\n`);
983
- }
984
- if (!fanout_permit(cohort.value.length, QUERY_COHORT_MAX)) {
985
- const problem = errorStack.stack_pop();
986
- exitCode_set(1);
987
- return envelope_error('', undefined, `${chalk.red(problem?.message ?? 'query: too many patients.')}\n`);
988
- }
989
- const base = Object.fromEntries(Object.entries(terms).map(([key, values]) => [key, values[0]]));
990
- if (!fanout_permit(cohort.value.length * servers.length, QUERY_COHORT_MAX)) {
991
- const problem = errorStack.stack_pop();
992
- exitCode_set(1);
993
- return envelope_error('', undefined, `${chalk.red(problem?.message ?? 'query: too many questions.')}\n`);
994
- }
995
- for (const mrn of cohort.value) {
996
- for (let index = 0; index < servers.length; index++) {
997
- asks.push({
998
- criteria: { ...base, [PATIENT_KEY]: mrn },
999
- patientId: mrn,
1000
- server: servers[index],
1001
- identifier: identifiers[index],
1002
- });
1003
- }
1004
- }
1005
- }
1006
- else {
1007
- const expanded = queryTerms_expand(terms);
1008
- if (!fanout_permit(expanded.length * servers.length, QUERY_INLINE_FANOUT_MAX)) {
1009
- const problem = errorStack.stack_pop();
1010
- exitCode_set(1);
1011
- return envelope_error('', undefined, `${chalk.red(problem?.message ?? 'query: too many queries.')}\n`);
1012
- }
1013
- const asksPerServer = expanded.length * servers.length;
1014
- for (const one of expanded) {
1015
- for (let index = 0; index < servers.length; index++) {
1016
- asks.push({
1017
- criteria: one,
1018
- // A single question put to a single server is not a cohort: it
1019
- // needs no patient level, and inventing one would put an audit
1020
- // table where a study list belongs.
1021
- ...(one[PATIENT_KEY] === undefined || asksPerServer === 1
1022
- ? {}
1023
- : { patientId: one[PATIENT_KEY] }),
1024
- server: servers[index],
1025
- identifier: identifiers[index],
1026
- });
1027
- }
1028
- }
1029
- }
1030
- if (asks.length > 1) {
1031
- return await cohort_answer(asks, {
1032
- // The model names the server the way CUBE does. `--pacsserver 1` and
1033
- // `--pacsserver PACSDCM` are the same server, and a table that says
1034
- // "1" tells an operator nothing about which PACS answered.
1035
- title, pacsserver: identifier, owner, fresh, csv, csvTo, csvToAsk, force, anon, level, table: tableMode,
1036
- expression: anon ? expression_standIn(patientsArg === null ? queryExpr : `${queryExpr} --patients ${patientsArg}`.trim(), asks)
1037
- : (patientsArg === null ? queryExpr : `${queryExpr} --patients ${patientsArg}`.trim()),
1038
- });
686
+ }
687
+ /**
688
+ * The failure of a single question, as the error stack says it, carried
689
+ * directly: in -c/-f mode nothing else will. A refusal says what to do about
690
+ * it: PACS is a group CUBE grants. Under --anon the reason is withheld: a
691
+ * PACS's own words may name anyone.
692
+ *
693
+ * @param anon - True when the answer must be screen-safe.
694
+ * @returns The error envelope.
695
+ */
696
+ function queryFailure_answer(anon) {
697
+ const errs = errorStack.stack_getAll?.() ?? [];
698
+ const said = errs.map((err) => (typeof err === 'string' ? err : err.message ?? String(err)));
699
+ const reasons = anon ? [QUERY_ANON_FAILED] : said;
700
+ let errOut = reasons.length > 0
701
+ ? reasons.map((reason) => `${chalk.red(reason)}\n`).join('')
702
+ : `${chalk.red('query: Failed — check connection and PACS server context.')}\n`;
703
+ if (pacsRefusal_is(said))
704
+ errOut += pacsRefusal_hint();
705
+ exitCode_set(1);
706
+ return envelope_error('', undefined, errOut);
707
+ }
708
+ /**
709
+ * The text of a single answer: complete, or answered how long ago; the
710
+ * rows; and the path to `cd` into or `pull`, held back when standing in.
711
+ * Rendered FROM the model's provenance, not from a second copy of the same
712
+ * fact: one timestamp, one claim, however many surfaces say it.
713
+ *
714
+ * @param model - The answer's model.
715
+ * @param queryId - The query that answered.
716
+ * @param vfsPath - Where it lives.
717
+ * @param renderedResult - The rows, rendered.
718
+ * @param shownExpr - The question as shown.
719
+ * @param anon - True when standing in.
720
+ * @returns The text.
721
+ */
722
+ function singleAnswer_text(model, queryId, vfsPath, renderedResult, shownExpr, anon) {
723
+ const replayed = model.provenance?.replayed === true ? model.provenance : undefined;
724
+ const age = replayed === undefined ? null : age_describe(replayed.answeredAt);
725
+ let rendered = replayed === undefined
726
+ ? `${chalk.green(`✓ Query ${queryId} complete`)}\n`
727
+ : `${chalk.green(`✓ Query ${queryId} — answered ${age ?? 'earlier'}`)}\n`;
728
+ rendered += `${renderedResult}\n`;
729
+ if (anon) {
730
+ // The path spells the question, record number and all, and these three
731
+ // lines exist to be read off a screen — which is the one thing that
732
+ // must not happen here. The row's own controls still act on the real
733
+ // path, which the surface holds and never shows. The line that would
734
+ // ask again is held back with it: run, it would say the question.
735
+ return `${rendered}${chalk.gray(' the path is held back while standing in for this answer')}\n`;
736
+ }
737
+ rendered += `${chalk.bold(` VFS path: ${chalk.cyan(vfsPath)}`)}\n`;
738
+ rendered += `${chalk.gray(` cd ${vfsPath}`)}\n`;
739
+ rendered += `${chalk.gray(` pull ${vfsPath}`)}\n`;
740
+ // Said, never decided: mise states the age and leaves the judgement with
741
+ // the operator, who knows whether this question can gain an answer since.
742
+ if (replayed !== undefined)
743
+ rendered += `${chalk.gray(` query ${shownExpr} --fresh # ask the PACS again`)}\n`;
744
+ return rendered;
745
+ }
746
+ /**
747
+ * Fetches one question's answer: replayed when it was asked before, else
748
+ * asked of the PACS while the progress line says so. Under --anon that line
749
+ * names no question, and the backend's own status words are not passed on.
750
+ *
751
+ * @param request - What the line asked for.
752
+ * @param criteria - The one question.
753
+ * @param target - Where it goes, and who asks.
754
+ * @returns The answer (null when the question failed), and when it was answered for a replay.
755
+ */
756
+ async function question_fetch(request, criteria, target) {
757
+ if (!request.fresh) {
758
+ const replayed = await replay_attempt(criteria, target.identifier, target.owner);
759
+ if (replayed !== null)
760
+ return replayed;
1039
761
  }
1040
- const criteria = asks[0]?.criteria ?? {};
762
+ const askExpr = criteria_format(criteria);
763
+ const status_say = request.anon ? undefined : (msg) => spinner.updateMessage(msg);
764
+ spinner.start(request.anon ? QUERY_ANON_PROGRESS : `Querying PACS for ${askExpr}...`, true);
765
+ const result = await pacsQuery_createAndWait(askExpr, request.title, target.pacsserver, status_say);
766
+ spinner.stop();
767
+ return { result, answeredAt: null };
768
+ }
769
+ /**
770
+ * Answers one question: replayed when it was asked before, else asked of
771
+ * the PACS; the answer modelled, marked with what CUBE already holds, and
772
+ * shown, written as CSV, or said to be empty.
773
+ *
774
+ * @param request - What the line asked for.
775
+ * @param criteria - The one question.
776
+ * @param target - Where it goes, and who asks.
777
+ * @param shown - Under --anon, the question as shown and the servers CUBE lists; null otherwise.
778
+ * @returns The answer, its model beside it.
779
+ */
780
+ async function singleQuestion_answer(request, criteria, target, shown) {
781
+ const { tableMode, anon, level } = request;
1041
782
  // One question, spelled as the create path wants it — which is not
1042
783
  // necessarily what was typed: `--patients 1234` names a patient without
1043
784
  // an expression to carry it.
1044
785
  const askExpr = criteria_format(criteria);
1045
- let result = null;
1046
- let answeredAt = null;
1047
- if (!fresh) {
1048
- const replayed = await replay_attempt(criteria, identifier, owner);
1049
- if (replayed !== null) {
1050
- result = replayed.result;
1051
- answeredAt = replayed.answeredAt;
1052
- }
1053
- }
1054
- if (result === null) {
1055
- spinner.start(`Querying PACS for ${askExpr}...`, true);
1056
- result = await pacsQuery_createAndWait(askExpr, title, pacsserver, (msg) => spinner.updateMessage(msg));
1057
- spinner.stop();
1058
- }
1059
- if (!result) {
1060
- let errOut = '';
1061
- const errs = errorStack.stack_getAll?.() ?? [];
1062
- if (errs.length) {
1063
- // Carry the stack directly: in -c/-f mode nothing else will.
1064
- errs.forEach((err) => {
1065
- const msg = typeof err === 'string' ? err : (err.message ?? String(err));
1066
- errOut += `${chalk.red(msg)}\n`;
1067
- });
1068
- }
1069
- else {
1070
- errOut += `${chalk.red('query: Failed — check connection and PACS server context.')}\n`;
1071
- }
1072
- // A refusal says what to do about it: PACS is a group CUBE grants.
1073
- const said = errs.map((err) => typeof err === 'string' ? err : (err.message ?? String(err)));
1074
- if (pacsRefusal_is(said))
1075
- errOut += pacsRefusal_hint();
1076
- exitCode_set(1);
1077
- return envelope_error('', undefined, errOut);
1078
- }
1079
- // Everything below reads from `decoded`, so standing in here reaches the
1080
- // table, the model a surface renders, and any CSV, all at once. The
1081
- // DICOM identifiers are left alone: they are never shown, and they are
1082
- // what the held-state reconciliation matches on.
1083
- if (anon) {
1084
- result = { ...result, decoded: { ...result.decoded, json: answer_standIn(result.decoded.json) } };
1085
- }
1086
- // What the operator typed, said in the same tokens the rows carry.
1087
- const shownExpr = anon ? criteria_format(criteria_standIn(criteria)) : askExpr;
1088
- let renderedResult = null;
1089
- const model = pacsQueryModel_build(result.decoded, {
786
+ const { result, answeredAt } = await question_fetch(request, criteria, target);
787
+ if (!result)
788
+ return queryFailure_answer(anon);
789
+ const built = pacsQueryModel_build(result.decoded, {
1090
790
  queryId: result.queryId,
1091
791
  vfsPath: result.vfsPath,
1092
- pacsName: identifier,
1093
- expression: shownExpr,
1094
- provenance: {
1095
- replayed: answeredAt !== null,
1096
- answeredAt: answeredAt ?? new Date().toISOString(),
1097
- },
792
+ pacsName: target.identifier,
793
+ expression: askExpr,
794
+ provenance: { replayed: answeredAt !== null, answeredAt: answeredAt ?? new Date().toISOString() },
1098
795
  });
1099
796
  // Mark what CUBE already holds: a surface then offers gather instead of
1100
797
  // pull for series that are already home. One bounded sweep, no retries.
1101
- await modelPulledState_fill(model);
1102
- // The table reads the model, pulled state and all, so it is rendered
1103
- // once the model knows what CUBE already holds.
798
+ await modelPulledState_fill(built);
799
+ // Built and reconciled on the real answer; everything below (the table,
800
+ // the view, the CSV, the model a surface renders) reads its display form.
801
+ const model = shown === null ? built : pacsModel_standIn(built, shown.expression, shown.servers);
802
+ // The table and the default view read the model, pulled state and all, so
803
+ // the handles the view prints are the ones an index expands to (#1099).
804
+ let renderedResult = null;
1104
805
  if (tableMode && model.studies.length > 0)
1105
806
  renderedResult = `\n${pacsAnswer_renderTable(model, level)}`;
1106
- // The default view reads the model too, so the handles it prints are the
1107
- // ones an index expands to (#1099).
1108
807
  if (!tableMode)
1109
808
  renderedResult = pacsAnswer_render(model);
1110
- if (csv || csvTo !== null || csvToAsk) {
1111
- const delivered = await csv_deliver(model, csvTo, csvToAsk, force, level, tableMode);
1112
- if (!delivered.ok) {
1113
- exitCode_set(1);
1114
- // The answer stands; only the writing of it did not happen.
1115
- return {
1116
- ...envelope_error('', undefined, `${chalk.red(delivered.message)}\n`),
1117
- model: { kind: PACS_QUERY_MODEL_KIND, data: model },
1118
- };
1119
- }
1120
- return envelope_ok(delivered.rendered, { kind: PACS_QUERY_MODEL_KIND, data: model });
809
+ if (request.csv || request.csvTo !== null || request.csvToAsk) {
810
+ return csvAnswer_envelope(await csv_deliver(model, request.csvTo, request.csvToAsk, request.force, level, tableMode, anon), model);
1121
811
  }
1122
812
  if (!renderedResult) {
1123
813
  // Nothing matched: browsing or pulling the empty query would be
@@ -1125,32 +815,68 @@ export async function queryLine_run(args) {
1125
815
  // graphical surface can say "no studies" in its own voice.
1126
816
  return envelope_ok(`${chalk.yellow(`⚠ Query ${result.queryId} complete — no studies found.`)}\n`, { kind: PACS_QUERY_MODEL_KIND, data: model });
1127
817
  }
1128
- // Rendered FROM the model's provenance, not from a second copy of the
1129
- // same fact: one timestamp, one claim, however many surfaces say it.
1130
- const replayed = model.provenance?.replayed === true ? model.provenance : undefined;
1131
- const age = replayed === undefined ? null : age_describe(replayed.answeredAt);
1132
- let rendered = replayed === undefined
1133
- ? `${chalk.green(`✓ Query ${result.queryId} complete`)}\n`
1134
- : `${chalk.green(`✓ Query ${result.queryId} — answered ${age ?? 'earlier'}`)}\n`;
1135
- rendered += `${renderedResult}\n`;
1136
- if (anon) {
1137
- // The path spells the question, record number and all, and these three
1138
- // lines exist to be read off a screen — which is the one thing that
1139
- // must not happen here. The row's own controls still act on the real
1140
- // path, which the surface holds and never shows.
1141
- rendered += `${chalk.gray(' the path is held back while standing in for this answer')}\n`;
1142
- }
1143
- else {
1144
- rendered += `${chalk.bold(` VFS path: ${chalk.cyan(result.vfsPath)}`)}\n`;
1145
- rendered += `${chalk.gray(` cd ${result.vfsPath}`)}\n`;
1146
- rendered += `${chalk.gray(` pull ${result.vfsPath}`)}\n`;
1147
- }
1148
- if (replayed !== undefined) {
1149
- // Said, never decided: mise states the age and leaves the judgement
1150
- // with the operator, who knows whether this question can gain an
1151
- // answer between then and now.
1152
- rendered += `${chalk.gray(` query ${shownExpr}${anon ? ' --anon' : ''} --fresh # ask the PACS again`)}\n`;
818
+ return envelope_ok(singleAnswer_text(model, result.queryId, result.vfsPath, renderedResult, askExpr, anon), { kind: PACS_QUERY_MODEL_KIND, data: model });
819
+ }
820
+ /**
821
+ * Creates a PACS query, waits for results, displays findings, and prints the
822
+ * VFS path: the handler of `query` and of `pacs query`. Under --anon the
823
+ * answer is screen-safe, and so is every reason it leaves behind.
824
+ *
825
+ * @param args - The line, parsed.
826
+ * @returns The answer, its model beside it.
827
+ *
828
+ * @example
829
+ * ```ts
830
+ * await queryLine_run({ operands: { expression: ['PatientID:1234'] }, options: { …, table: true } });
831
+ * ```
832
+ */
833
+ export async function queryLine_run(args) {
834
+ if (!args.options.anon)
835
+ return queryLine_answer(args);
836
+ return anonAnswer_run(() => queryLine_answer(args));
837
+ }
838
+ /**
839
+ * Answers a query line: its questions read, asked, and answered.
840
+ *
841
+ * @param args - The line, parsed.
842
+ * @returns The answer, its model beside it.
843
+ */
844
+ async function queryLine_answer(args) {
845
+ const request = queryRequest_read(args);
846
+ if ('status' in request)
847
+ return request;
848
+ const { queryExpr, patientsArg, anon } = request;
849
+ // Validate expression early.
850
+ const read = queryTerms_read(queryExpr, anon);
851
+ if (!('terms' in read))
852
+ return read;
853
+ const terms = read.terms;
854
+ const named = serverList_parse(request.pacsserverOverride);
855
+ const servers = named.length > 0 ? named : await queryServerDefault_resolve();
856
+ if (!Array.isArray(servers))
857
+ return servers;
858
+ // The index is keyed on what CUBE stores, which is the identifier.
859
+ const identifiers = await Promise.all(servers.map((server) => pacsIdentifier_resolve(server)));
860
+ const target = { identifier: identifiers[0], pacsserver: servers[0], owner: await askingIdentity_get() };
861
+ ignoredKeys_say(terms, identifiers, anon);
862
+ // What the operator asked for, as the questions it stands for.
863
+ const asks = patientsArg !== null
864
+ ? await cohortAsks_build(patientsArg, terms, servers, identifiers)
865
+ : inlineAsks_build(terms, servers, identifiers);
866
+ if (!Array.isArray(asks))
867
+ return anon ? queryLine_refuse(QUERY_ANON_REFUSED) : asks;
868
+ // The question as shown under --anon: built from what was parsed, never searched for in what was typed.
869
+ const shown = anon ? await answerShown_build(terms, patientsArg) : null;
870
+ if (asks.length > 1) {
871
+ const asked = patientsArg === null ? queryExpr : `${queryExpr} --patients ${patientsArg}`.trim();
872
+ return await cohort_answer(asks, {
873
+ // The model names the server the way CUBE does. `--pacsserver 1` and
874
+ // `--pacsserver PACSDCM` are the same server, and a table that says
875
+ // "1" tells an operator nothing about which PACS answered.
876
+ title: request.title, pacsserver: target.identifier, owner: target.owner, fresh: request.fresh, csv: request.csv, csvTo: request.csvTo, csvToAsk: request.csvToAsk, force: request.force, shown, level: request.level, table: request.tableMode,
877
+ expression: asked,
878
+ });
1153
879
  }
1154
- return envelope_ok(rendered, { kind: PACS_QUERY_MODEL_KIND, data: model });
880
+ return singleQuestion_answer(request, asks[0]?.criteria ?? {}, target, shown);
1155
881
  }
1156
882
  //# sourceMappingURL=query.js.map