edit.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. interface Document {
  2. categoryId: string;
  3. _id: string;
  4. valid: number;
  5. properties: any;
  6. styles: any;
  7. scripts: any;
  8. layout: any;
  9. document: any;
  10. }
  11. interface Validator {
  12. name: string;
  13. level: string;
  14. message: string;
  15. }
  16. export type EditorMode = "form" | "free" | "readonly" | "design";
  17. export interface DataElements {
  18. [key: string]: DataElementItem | DataElementItem[];
  19. }
  20. export type DataElementItem = {
  21. id: string;
  22. value: any | null;
  23. element: {
  24. id: string;
  25. type: string;
  26. name: string;
  27. code: { internal: string; dataElement: string; business: string };
  28. labels: null;
  29. attributes: [];
  30. };
  31. };
  32. type CursorPlace =
  33. | "PARAGRAPH_START"
  34. | "PARAGRAPH_END"
  35. | "DOCUMENT_START"
  36. | "DOCUMENT_END";
  37. interface MenuItem {
  38. global: {
  39. text: string;
  40. menu?: {
  41. items: MenuItem[];
  42. };
  43. handler?: (menu?: any) => void;
  44. }[];
  45. }
  46. interface NodesByCode {
  47. target: {
  48. setReadonly: (val: boolean) => void;
  49. setDeletable: (val: boolean) => void;
  50. };
  51. }
  52. interface ElementByValue extends HTMLElement {
  53. /**
  54. * 元素聚焦
  55. */
  56. focusEnter: () => void;
  57. }
  58. type customEdit = {
  59. _getPatientInfo: () => any;
  60. };
  61. export declare type EditType = {
  62. EMR: {
  63. getDocument(): {
  64. getTablesByCode: (id: string) => any[];
  65. };
  66. };
  67. setViewStyle: (view, value) => void;
  68. isRevisionMode: boolean;
  69. documentData: {
  70. _id: string;
  71. categoryId: string;
  72. properties: {
  73. categoryCode: string;
  74. };
  75. };
  76. _cacheDB: IDBTransaction;
  77. loadCacheData: (val: string) => any;
  78. delCacheData: (val: string) => any;
  79. setCacheData: (val: string) => any;
  80. openCache: () => void;
  81. _cacheDBIsOpen: boolean;
  82. on: (name: string, callback: (...args: any[]) => void) => void;
  83. /**
  84. * 用于获取当前病历完整数据 该方法通常用于保存病历数据时调用
  85. *
  86. * 参数:无
  87. * 返回值:返回json结构,参见:文档结构。
  88. * 业务系统可在保存前对其内容进行修改。
  89. */
  90. getDocument: () => Document;
  91. getEditorMode: () => EditorMode;
  92. highlight: (comp: HTMLElement, time: number) => void;
  93. getElementsData: () => {
  94. [key: string]: any;
  95. };
  96. getElementByValue: (id: string, value?: any) => ElementByValue;
  97. view: HTMLElement & {
  98. container: {
  99. find: (id: string) => any[] & {
  100. each: (fn: (index: number, item: any) => void) => void;
  101. };
  102. };
  103. };
  104. ModelService: {
  105. setWalkerRoot: (walker: any, node: any) => any;
  106. createTreeWalker: (node: any) => any;
  107. getDataElementsFromWalker: (
  108. walker: any,
  109. name: string,
  110. value: string
  111. ) => any;
  112. getElementsDataFromWalker: (walker: any, name?: string) => any;
  113. };
  114. setEditorMode: (val: EditorMode) => void;
  115. getValidator: () => {
  116. /**
  117. *
  118. * @param val 是否显示节点信息 , 默认值 false
  119. */
  120. valid: (val: boolean) => Validator[];
  121. };
  122. /**
  123. * {Boolean} includeEmptyValue 是否获取非必填并且不是数据元 值为空的元素 默认 false
  124. * @param val type 要获取的编码类型 默认 code。 code|business|internal|dataElement, 一般不用dataElement,当指定的编码类型不存在时返回 code
  125. */
  126. getDataElements: (
  127. val: "code" | "business" | "internal" | "dataElement",
  128. a?: boolean,
  129. b?: boolean
  130. ) => DataElements;
  131. /**
  132. * 批量设置组件值
  133. *
  134. * 适用组件:智能文本框(smarttext)、复选框(checkfield)
  135. * 参数:
  136. * {Object} data 要设置的key/value对象 同getAppContext中的data节点
  137. * {Boolean} overwrite 是否覆盖原来的值 默认true
  138. * {Boolean}. commandStack 是否进入撤销命令栈 默认true。当setValues在一个操作命令中调用的时候commandStack设置为false和合并父操作的命令栈 例如插入片段事件/或设置值后出发的change事件
  139. * {DocumentFragment} documdentFragment插入的文档片段模型,为空时将值填充到整个文档,不为空时将值填充到文档片段
  140. * 返回值 无
  141. * @param val
  142. */
  143. setValues: (
  144. val: object,
  145. overwrite?: boolean,
  146. commandStack?: boolean,
  147. documentFragment?: object
  148. ) => void;
  149. getComponents: () => any[];
  150. /**
  151. * editor.execute(commandName,[...args])
  152. *
  153. * 执行编辑器命令
  154. *
  155. * 参数
  156. * @param name commandName 命令名称
  157. * @param value args 执行命令携带的参数
  158. */
  159. execute: (name: string | "insertContents", ...value: any[]) => void;
  160. /**
  161. * 移动光标到place 指定位置
  162. *
  163. * 参数:
  164. * {string} place PARAGRAPH_START | PARAGRAPH_END | DOCUMENT_START | DOCUMENT_END
  165. * PARAGRAPH_START:移动光标到当前段落开头
  166. * PARAGRAPH_END:移动光标到当前段落结尾
  167. * DOCUMENT_START:移动光标到文档开头
  168. * DOCUMENT_END:移动光标到文档结尾
  169. * 返回值:undefined
  170. * @param place
  171. */
  172. setCursor: (place: CursorPlace) => void;
  173. /**
  174. * 滚动到当前光标所在位置
  175. *
  176. * editor.scrollToCursor([middle])
  177. *
  178. * @param middle middle 当光标在可视区域后方时,是否滚动到屏幕中间 默认false
  179. */
  180. scrollToCursor: (...middle: boolean[]) => void;
  181. model: {
  182. document: {
  183. getRoot: () => {
  184. getChild: (val: number) => {
  185. view: any;
  186. };
  187. childCount: number;
  188. getChildren: any;
  189. };
  190. };
  191. };
  192. /**
  193. * 设置审阅模式
  194. *
  195. * 参数
  196. * {String} mode 接收 on:开启审阅模式,off:关闭审阅模式
  197. * 开启审阅模式后,病历上的修改会被记录下来,默认开启后,页面上没有任何表现,需要通过调用editor.setRevisionShowMode(flag) 展示修改
  198. */
  199. setRevisionMode: (val: "on" | "off") => void;
  200. /**
  201. * 设置审阅模式的展现方式
  202. * @param val flag可接受的值如下
  203. * 0: 页面上不显示修改记录
  204. * 1: 病历右侧会以列表的形式显示 添加,删除,更新的记录
  205. * 2: 嵌入病历显示修改记录,新增的记录会用背景颜色标记,删除的记录 通过画删除线标记
  206. */
  207. setRevisionShowMode: (val: 0 | 1 | 2 | number) => void;
  208. getScriptRuntime: () => {
  209. EMR: {
  210. getDocument: () => {
  211. getNodesByCode: (val: any, name: string) => NodesByCode[];
  212. getComponentsByCode: (name: string) => any[];
  213. };
  214. };
  215. };
  216. getViewByElType: (value: any, name: string) => any;
  217. /**
  218. * 自定义编辑器快捷键
  219. *
  220. * 参数
  221. * {Function} callback
  222. * @param keyName 绑定快捷键
  223. * @param callback 快捷键触发函数 该函数接受3个参数 evt:事件
  224. * view: 当前光标或者选区开始所在位置的组件view
  225. * position: {x ,y} 光标或者选区开始位置坐标(相对于文档,内部通过getBoundingClientRect()方法获取)
  226. */
  227. setShortcutKey: (
  228. keyName: string,
  229. callback: (
  230. e: Event,
  231. view: any,
  232. position: {
  233. x: number;
  234. y: number;
  235. }
  236. ) => void
  237. ) => void;
  238. /**
  239. * 注册右键菜单
  240. * @param menuItem 数据
  241. */
  242. regCtxMenu: (menuItem: MenuItem) => void;
  243. /**
  244. * 获取鼠标位置
  245. */
  246. getCursorPosition: () => { x: number; y: number };
  247. /**
  248. * 用于设置当前病历文档完整数据
  249. *
  250. * 参数
  251. * @param data 完整的病历文档结构。
  252. * @param isRender 是否根据文档结构进行立即渲染页面,如果为false 则只设置文档数据不进行渲染操作
  253. * @param clearUndoStack 是否清空撤销栈
  254. */
  255. setDocument: (
  256. data: any,
  257. isRender?: boolean,
  258. clearUndoStack?: boolean
  259. ) => void;
  260. /**
  261. * 设置实时分页
  262. * @param isPaginate true:开启实时分页 false:关闭实时分页
  263. */
  264. setPaginate: (isPaginate: boolean) => void;
  265. renderer: {
  266. pageView: {
  267. marginTopWithPaging: number;
  268. /**
  269. * 重新绘制页面布局
  270. */
  271. attachLayout: () => void;
  272. fixEmpty: () => void;
  273. };
  274. };
  275. /**
  276. * 获取大纲的树状图
  277. */
  278. getOutline: () => Outline[];
  279. /**
  280. * 设置 setApplicatioinContext
  281. * @param data 数据
  282. * @param filling 是否填充
  283. * @param forcedReplacement 是否强制替换
  284. */
  285. setApplicationContext: (
  286. data: any,
  287. filling: boolean,
  288. forcedReplacement: boolean
  289. ) => void;
  290. } & customEdit;
  291. export declare type Runtime = {
  292. saveDocument: (
  293. document: any,
  294. success: (res?: any) => void,
  295. error: (err?: any) => void
  296. ) => void;
  297. loadDocument: (
  298. success: (res?: any) => void,
  299. error: (err?: any) => void,
  300. param: any
  301. ) => void;
  302. };
  303. export interface Outline {
  304. id: string;
  305. type: string;
  306. typeName: string;
  307. text: string;
  308. parent: string;
  309. business: string;
  310. children: {
  311. business: string;
  312. code: string;
  313. dataElement: string;
  314. id: string;
  315. internal: string;
  316. leaf: boolean;
  317. parent: string;
  318. text: string;
  319. type: string;
  320. typeName: string;
  321. }[];
  322. }