data.go 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. _ "github.com/astaxie/beego"
  5. _ "strconv"
  6. _ "strings"
  7. "time"
  8. )
  9. //GetPatientList 返回患者的列表
  10. func GetConfigList(orgID int64) (dataconfig interface{}, err error) {
  11. var configList []*models.Dataconfig
  12. err = readDb.Model(&models.Dataconfig{}).Where("(org_id in (0,?) and status = 1) or (status = 0 and delete_id_system > 0 and org_id = ?)", orgID, orgID).Order("orders asc, id asc").Find(&configList).Error
  13. if err != nil {
  14. return nil, err
  15. }
  16. // configResult := make([]*ConfigViewModel,0)
  17. childConfig := make(map[int64][]*models.Dataconfig)
  18. resultConfig := make(map[string][]*models.ConfigViewModel)
  19. deleteSystemChilds := make([]*models.Dataconfig, 0)
  20. editSystemChilds := make([]*models.Dataconfig, 0)
  21. for _, config := range configList {
  22. if config.Status == 1 && config.DeleteIdSystem > 0 {
  23. editSystemChilds = append(editSystemChilds, config)
  24. }
  25. if config.Status == 0 && config.DeleteIdSystem > 0 {
  26. deleteSystemChilds = append(deleteSystemChilds, config)
  27. }
  28. }
  29. continueFlag := false
  30. for _, config := range configList {
  31. continueFlag = false
  32. if config.ParentId == 0 {
  33. newConfig := &models.ConfigViewModel{
  34. ID: config.ID,
  35. ParentId: config.ParentId,
  36. Module: config.Module,
  37. OrgId: config.OrgId,
  38. Name: config.Name,
  39. FieldName: config.FieldName,
  40. Value: config.Value,
  41. CreateUserId: config.CreateUserId,
  42. Status: config.Status,
  43. Remark: config.Remark,
  44. Title: config.Title,
  45. Content: config.Content,
  46. }
  47. // configResult = append(configResult,newConfig)
  48. result := resultConfig[config.Module]
  49. if result == nil {
  50. result = make([]*models.ConfigViewModel, 0)
  51. }
  52. for _, vm := range editSystemChilds {
  53. if vm.DeleteIdSystem == config.ID {
  54. continueFlag = true
  55. break
  56. }
  57. }
  58. for _, _vm := range deleteSystemChilds {
  59. if _vm.DeleteIdSystem == config.ID {
  60. continueFlag = true
  61. break
  62. }
  63. }
  64. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  65. continue
  66. }
  67. if continueFlag {
  68. continue
  69. }
  70. result = append(result, newConfig)
  71. resultConfig[config.Module] = result
  72. } else {
  73. childs := childConfig[config.ParentId]
  74. if childs == nil {
  75. childs = make([]*models.Dataconfig, 0)
  76. }
  77. continueFlag := false
  78. for _, vm := range editSystemChilds {
  79. if vm.DeleteIdSystem == config.ID {
  80. continueFlag = true
  81. break
  82. }
  83. }
  84. for _, _vm := range deleteSystemChilds {
  85. if _vm.DeleteIdSystem == config.ID {
  86. continueFlag = true
  87. break
  88. }
  89. }
  90. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  91. continue
  92. }
  93. if continueFlag {
  94. continue
  95. }
  96. childs = append(childs, config)
  97. childConfig[config.ParentId] = childs
  98. }
  99. }
  100. for _, vm := range resultConfig {
  101. for _, _vm := range vm {
  102. _vm.Childs = childConfig[_vm.ID]
  103. }
  104. // vm.Childs = childConfig[vm.ID]
  105. }
  106. return resultConfig, err
  107. }
  108. func FindConfigByFieldname(module string, field_name string, org_id int64) (dataconfig models.Dataconfig, err error) {
  109. err = readDb.Model(&models.Dataconfig{}).Where("module=? and field_name=? and org_id in (0,?) and status = 1", module, field_name, org_id).First(&dataconfig).Error
  110. return
  111. }
  112. func FindConfigByTitle(module string, title string, org_id int64) (dataconfig models.Dataconfig, err error) {
  113. err = readDb.Model(&models.Dataconfig{}).Where("module=? and title=? and org_id in (0,?) and status = 1", module, title, org_id).First(&dataconfig).Error
  114. return
  115. }
  116. func FindConfigByName(module string, name string, parent_id int64, org_id int64) (dataconfig models.Dataconfig, err error) {
  117. err = readDb.Model(&models.Dataconfig{}).Where("module=? and name=? and parent_id=? and org_id in (0,?) and status = 1", module, name, parent_id, org_id).First(&dataconfig).Error
  118. return
  119. }
  120. func FindConfigByNameForUpdate(module string, name string, parent_id int64, org_id int64, id int64) (dataconfig models.Dataconfig, err error) {
  121. err = readDb.Model(&models.Dataconfig{}).Where("module=? and name=? and parent_id=? and org_id in (0,?) and id != ? and status = 1", module, name, parent_id, org_id, id).First(&dataconfig).Error
  122. return
  123. }
  124. func FindConfigByTitleForUpdate(module string, title string, org_id int64, id int64) (dataconfig models.Dataconfig, err error) {
  125. err = readDb.Model(&models.Dataconfig{}).Where("module=? and title=? and org_id in (0,?) and id != ? and status = 1", module, title, org_id, id).First(&dataconfig).Error
  126. return
  127. }
  128. func UpdateChildConfig(dataconfig *models.Dataconfig) (err error) {
  129. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"name": dataconfig.Name, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark, "orders": dataconfig.Order}).Error
  130. return
  131. }
  132. func UpdateTemplate(dataconfig *models.Dataconfig) (err error) {
  133. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"title": dataconfig.Title, "content": dataconfig.Content, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark}).Error
  134. return
  135. }
  136. func CreateConfig(dataconfig *models.Dataconfig) (err error) {
  137. // readDb.Model(&models.Dataconfig{}).Where("module = ? and parent_id = 0 and org_id in (0,?)",dataconfig.Module,dataconfig.OrgId).Count(&total)
  138. err = readDb.Create(&dataconfig).Error
  139. return
  140. }
  141. func GetChildValue(module string, parent_id int64, org_id int64) (value int) {
  142. readDb.Model(&models.Dataconfig{}).Where("module=? and parent_id=? and org_id in (0,?)", module, parent_id, org_id).Count(&value)
  143. return
  144. }
  145. func DeleteChildConfig(dataconfig *models.Dataconfig) (err error) {
  146. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"status": dataconfig.Status, "update_time": dataconfig.UpdatedTime}).Error
  147. return
  148. }
  149. func FindFiledByOrgId(org_id int64) (filedConfig []*models.FiledConfig, err error) {
  150. err = readDb.Model(&models.FiledConfig{}).Where("org_id =? AND sys_module = 0", org_id).Find(&filedConfig).Error
  151. return
  152. }
  153. func FindQualityByOrgId(orgid int64) (xtquality []*models.XtQualityControlStandard, err error) {
  154. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id =? and status =1 and is_status = 1", orgid).Find(&xtquality).Error
  155. return
  156. }
  157. func GetDefaultSystolicPressure(orgid int64) (xtquality []*models.XtQualityControlStandard, err error) {
  158. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id = ? and status = 1 and is_status =0", orgid).Find(&xtquality).Error
  159. return
  160. }
  161. func FindeInspectionByOrgId(orgid int64) (xtquality []*models.XtCheckConfiguration, err error) {
  162. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id = ? and status =1", orgid).Find(&xtquality).Error
  163. return
  164. }
  165. func BatchInsertFiledConfig(org_id int64) (err error) {
  166. err = readDb.Exec("INSERT INTO sgj_xt.xt_filed_config ( org_id, module, filed_name, filed_name_cn, is_show ) SELECT ?, module, filed_name, filed_name_cn, is_show FROM sgj_xt.xt_filed_config WHERE org_id = 0 AND is_show = 1", org_id).Error
  167. return
  168. }
  169. func BatchInsertQualityControl(org_id int64) (err error) {
  170. err = readDb.Exec("INSERT INTO xt_quality_control_standard(user_org_id,inspection_major,inspection_minor,min_range,large_range,sort,created_time,status,range_type,range_value,is_status) SELECT ?,inspection_major,inspection_minor,min_range,large_range,sort,created_time,status,range_type,range_value,is_status FROM xt_quality_control_standard where user_org_id = 0 and is_status = 1", org_id).Error
  171. return
  172. }
  173. func BathInsertQualityControlTwo(org_id int64) (err error) {
  174. err = readDb.Exec("INSERT INTO xt_quality_control_standard(user_org_id,inspection_major,inspection_minor,min_range,large_range,sort,created_time,status,range_type,range_value,is_status) SELECT ?,inspection_major,inspection_minor,min_range,large_range,sort,created_time,status,range_type,range_value,is_status FROM xt_quality_control_standard where user_org_id = 0 and is_status = 0", org_id).Error
  175. return
  176. }
  177. func BatchInspectionConfiguration(orgid int64) (err error) {
  178. err = readDb.Exec("INSERT INTO xt_check_configuration(user_org_id,inspection_major,inspection_frequency,sort,created_time,status) SELECT ?,inspection_major,inspection_frequency,sort,created_time,status FROM xt_check_configuration where user_org_id = 0", orgid).Error
  179. return
  180. }
  181. func ShowFiledConfig(org_id int64, isShow int, id int64) (err error) {
  182. err = readDb.Model(&models.FiledConfig{}).Where("org_id = ? AND id = ?", org_id, id).Updates(map[string]interface{}{"ctime": time.Now().Unix(), "mtime": time.Now().Unix(), "is_show": isShow}).Error
  183. return
  184. }
  185. func FindSysDialysisFiledByOrgId() (filedConfig []*models.FiledConfig, err error) {
  186. err = readDb.Model(&models.FiledConfig{}).Where("org_id =? AND id in (11250,11251,11252,11253,11254,11255,11256,11257,11258,11259,11260,11261,11262)", 0).Find(&filedConfig).Error
  187. return
  188. }
  189. func BatchInsertFiledSystemConfig(org_id int64) (err error) {
  190. err = readDb.Exec("INSERT INTO sgj_xt.xt_filed_config ( org_id, module, filed_name, filed_name_cn, is_show ) SELECT ?, module, filed_name, filed_name_cn, is_show FROM sgj_xt.xt_filed_config WHERE org_id = 9442", org_id).Error
  191. return
  192. }
  193. func BatchInsertDoctorSchedule(orgid int64) (err error) {
  194. err = readDb.Exec("INSERT INTO sgj_xt.xt_doctor_schedules(user_org_id,class_name,class_attributes,timeone_start,timeone_type,timeone_end,timetwo_start,timetwo_type,timetwo_end,work_time,remarks,status,ctime,minute) SELECT ?, class_name,class_attributes,timeone_start,timeone_type,timeone_end,timetwo_start,timetwo_type,timetwo_end,work_time,remarks,status,ctime,minute FROM xt_doctor_schedules WHERE user_org_id = 0", orgid).Error
  195. return
  196. }
  197. func CreateContinueSchedule(schedule *models.ContinueSchedule) error {
  198. err := writeDb.Model(&schedule).Create(&schedule).Error
  199. return err
  200. }