InsertDictData.cls 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #Import SQLUSER
  2. /// 字典数据初始化工具类
  3. /// 提供字典数据批量插入功能
  4. Class src.DRG.BasicData.DictDataInit Extends (%RegisteredObject, %XML.Adaptor) [ Not ProcedureBlock ]
  5. {
  6. /// 初始化HIS数据同步相关字典数据
  7. /// 包括:同步类型、同步状态、HIS配置类型
  8. ClassMethod InitHisSyncDict() As %Status
  9. {
  10. new (tSC, tDictTypeID, tID)
  11. set $zt="Error"
  12. set tSC=$$$OK
  13. try {
  14. // 1. 插入字典类型(Parent_Dr = NULL)
  15. // 同步类型 (SYNC_TYPE)
  16. set tDictTypeID=..InsertDictType("SYNC_TYPE", "同步类型", "HIS数据同步类型")
  17. if tDictTypeID="" {
  18. set tSC=$$$ERROR($$$GeneralError, "插入SYNC_TYPE类型失败")
  19. quit
  20. }
  21. // 同步状态 (SYNC_STATUS)
  22. set tID=..InsertDictType("SYNC_STATUS", "同步状态", "HIS数据同步状态")
  23. if tID="" {
  24. set tSC=$$$ERROR($$$GeneralError, "插入SYNC_STATUS类型失败")
  25. quit
  26. }
  27. // HIS配置类型 (HIS_CONFIG)
  28. set tID=..InsertDictType("HIS_CONFIG", "HIS配置类型", "HIS服务配置类型")
  29. if tID="" {
  30. set tSC=$$$ERROR($$$GeneralError, "插入HIS_CONFIG类型失败")
  31. quit
  32. }
  33. // 2. 插入字典项(Parent_Dr = 类型ID)
  34. // 同步类型字典项
  35. do ..InsertDictItem(tDictTypeID, "incremental", "增量同步", 1, "按上次同步时间增量同步")
  36. do ..InsertDictItem(tDictTypeID, "full", "全量同步", 2, "按日期范围全量同步")
  37. // 同步状态字典项
  38. do ..InsertDictItem(tID, "running", "同步中", 1, "同步任务正在执行")
  39. do ..InsertDictItem(tID, "success", "成功", 2, "同步任务执行成功")
  40. do ..InsertDictItem(tID, "failed", "失败", 3, "同步任务执行失败")
  41. do ..InsertDictItem(tID, "pending", "等待中", 4, "同步任务等待执行")
  42. do ..InsertDictItem(tID, "stopped", "已停止", 5, "同步任务已停止")
  43. // HIS配置类型字典项
  44. do ..InsertDictItem(tID, "HisIP", "HIS服务器IP", 1, "HIS服务器IP地址")
  45. do ..InsertDictItem(tID, "HisPort", "HIS服务器端口", 2, "HIS服务器端口号")
  46. do ..InsertDictItem(tID, "HisURL", "HIS服务URL", 3, "HIS服务URL路径")
  47. do ..InsertDictItem(tID, "Authorization", "认证信息", 4, "HIS接口认证信息")
  48. } catch tException {
  49. set tSC=tException.AsStatus()
  50. }
  51. quit tSC
  52. Error:
  53. set $zt=""
  54. quit $$$ERROR($$$GeneralError, $ZE)
  55. }
  56. /// 插入字典类型(Parent_Dr = NULL)
  57. /// pCode: 字典类型编码
  58. /// pName: 字典类型名称
  59. /// pRemark: 备注
  60. /// 返回:插入的记录ID(失败返回空字符串)
  61. ClassMethod InsertDictType(pCode As %String, pName As %String, pRemark As %String) As %String
  62. {
  63. new (tObj, tID)
  64. set $zt="Error"
  65. set tID=""
  66. try {
  67. // 检查是否已存在
  68. set tID=$o(^CBDRGDictTableI("Code", pCode, 0))
  69. if tID'="" {
  70. quit
  71. }
  72. set tObj=##class(User.CBDRGDictTable).%New()
  73. set tObj.Code=pCode
  74. set tObj.Name=pName
  75. set tObj.Status="Y"
  76. set tObj.SortNo=0
  77. set tObj.Remark=pRemark
  78. set tObj.CreateDate=$zd($h,5)
  79. set tObj.CreateTime=$zt($p($h,",",2))
  80. // CreateUserDr 暂时留空,实际应从session获取
  81. set tSC=tObj.%Save()
  82. if $$$ISERR(tSC) {
  83. set tID=""
  84. quit
  85. }
  86. set tID=tObj.%Id()
  87. } catch {
  88. set tID=""
  89. }
  90. quit tID
  91. Error:
  92. set $zt=""
  93. quit ""
  94. }
  95. /// 插入字典项(Parent_Dr = 类型ID)
  96. /// pParentID: 父级类型ID
  97. /// pCode: 字典项编码
  98. /// pName: 字典项名称
  99. /// pSortNo: 排序号
  100. /// pRemark: 备注
  101. ClassMethod InsertDictItem(pParentID As %String, pCode As %String, pName As %String, pSortNo As %Integer, pRemark As %String) As %Status
  102. {
  103. new (tObj, tSC)
  104. set $zt="Error"
  105. set tSC=$$$OK
  106. try {
  107. // 检查是否已存在
  108. set tID=$o(^CBDRGDictTableI("Code", pParentID, pCode, 0))
  109. if tID'="" {
  110. quit
  111. }
  112. set tObj=##class(User.CBDRGDictTable).%New()
  113. set tObj.ParentDr=##class(User.CBDRGDictTable).%OpenId(pParentID)
  114. set tObj.Code=pCode
  115. set tObj.Name=pName
  116. set tObj.Status="Y"
  117. set tObj.SortNo=pSortNo
  118. set tObj.Remark=pRemark
  119. set tObj.CreateDate=$zd($h,5)
  120. set tObj.CreateTime=$zt($p($h,",",2))
  121. // CreateUserDr 暂时留空,实际应从session获取
  122. set tSaveSC=tObj.%Save()
  123. if $$$ISERR(tSaveSC) {
  124. set tSC=tSaveSC
  125. quit
  126. }
  127. } catch tException {
  128. set tSC=tException.AsStatus()
  129. }
  130. quit tSC
  131. Error:
  132. set $zt=""
  133. quit $$$ERROR($$$GeneralError, $ZE)
  134. }
  135. }