integration_config_api_controller.go 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_New/service"
  6. "github.com/astaxie/beego"
  7. "time"
  8. )
  9. type IntegrationConfigApiController struct {
  10. BaseAuthAPIController
  11. }
  12. func IntegrationConfigRegistRouters() {
  13. beego.Router("/api/integration/patients", &IntegrationConfigApiController{}, "get:GetPatientsList")
  14. beego.Router("/api/patienthis/edit", &IntegrationConfigApiController{}, "post:EditPatientHis")
  15. beego.Router("/api/patienthis/create", &IntegrationConfigApiController{}, "post:CreatePatientHis")
  16. beego.Router("/api/integration/admin", &IntegrationConfigApiController{}, "get:GetAdminsList")
  17. beego.Router("/api/adminhis/edit", &IntegrationConfigApiController{}, "post:EditAdminHis")
  18. beego.Router("/api/adminhis/create", &IntegrationConfigApiController{}, "post:CreateAdminHis")
  19. beego.Router("/api/patienthis/getinterface", &IntegrationConfigApiController{}, "post:GetInterface")
  20. beego.Router("/api/patienthis/saveinterface", &IntegrationConfigApiController{}, "post:SaveInterface")
  21. beego.Router("/api/integration/synclist", &IntegrationConfigApiController{}, "get:GetSyncList")
  22. beego.Router("/api/integration/sysinspectionlist", &IntegrationConfigApiController{}, "get:GetSysInspectionList")
  23. beego.Router("/api/patienthis/saveinspectionsysitemid", &IntegrationConfigApiController{}, "post:SaveInspectionSysItemId")
  24. }
  25. func (c *IntegrationConfigApiController) SaveInspectionSysItemId() {
  26. adminUserInfo := c.GetAdminUserInfo()
  27. org_id, _ := c.GetInt64("org_id", 0)
  28. sys_item_id, _ := c.GetInt64("sys_item_id", 0)
  29. id, _ := c.GetInt64("id", 0)
  30. if org_id != adminUserInfo.CurrentOrgId || sys_item_id <= 0 || id <= 0 {
  31. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  32. }
  33. inspection_reference := &models.InspectionReference{
  34. ID: id,
  35. SysItemId: sys_item_id,
  36. UpdatedTime: time.Now().Unix(),
  37. }
  38. err := service.UpdateSysItemIdByID(inspection_reference)
  39. if err != nil {
  40. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. }
  42. c.ServeSuccessJSON(map[string]interface{}{
  43. "inspection_reference": inspection_reference,
  44. })
  45. return
  46. }
  47. func (c *IntegrationConfigApiController) GetSysInspectionList() {
  48. adminUserInfo := c.GetAdminUserInfo()
  49. sysInspection, ownerInspection, err := service.GetSysInspectionList(adminUserInfo.CurrentOrgId)
  50. if err != nil {
  51. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  52. }
  53. type InspectionStruce struct {
  54. ProjectName string `gorm:"-" json:"project_name" form:"project_name"`
  55. ProjectId int64 `gorm:"-" json:"project_id" form:"project_id"`
  56. InspectionReference []*models.InspectionReference `gorm:"-" json:"inspection_reference" form:"inspection_reference"`
  57. }
  58. sysInspec := make(map[int64]*InspectionStruce, 0)
  59. ownerInspec := make(map[int64]*InspectionStruce, 0)
  60. for _, item := range sysInspection {
  61. result := sysInspec[item.ProjectId]
  62. if result == nil {
  63. result = new(InspectionStruce)
  64. result.ProjectName = item.ProjectName
  65. result.ProjectId = item.ProjectId
  66. }
  67. result.InspectionReference = append(result.InspectionReference, item)
  68. sysInspec[item.ProjectId] = result
  69. }
  70. for _, oitem := range ownerInspection {
  71. oresult := ownerInspec[oitem.ProjectId]
  72. if oresult == nil {
  73. oresult = new(InspectionStruce)
  74. oresult.ProjectName = oitem.ProjectName
  75. oresult.ProjectId = oitem.ProjectId
  76. }
  77. oresult.InspectionReference = append(oresult.InspectionReference, oitem)
  78. ownerInspec[oitem.ProjectId] = oresult
  79. }
  80. c.ServeSuccessJSON(map[string]interface{}{
  81. "sysInspec": sysInspec,
  82. "ownerInspec": ownerInspec,
  83. })
  84. return
  85. }
  86. func (c *IntegrationConfigApiController) GetSyncList() {
  87. page, _ := c.GetInt64("page", 1)
  88. limit, _ := c.GetInt64("limit", 10)
  89. if page <= 0 {
  90. page = 1
  91. }
  92. if limit <= 0 {
  93. limit = 10
  94. }
  95. adminUserInfo := c.GetAdminUserInfo()
  96. patients, total, _ := service.GetSyncList(adminUserInfo.CurrentOrgId, page, limit)
  97. c.ServeSuccessJSON(map[string]interface{}{
  98. "list": patients,
  99. "total": total,
  100. })
  101. return
  102. }
  103. func (c *IntegrationConfigApiController) SaveInterface() {
  104. adminUserInfo := c.GetAdminUserInfo()
  105. ID, _ := c.GetInt64("id", 0)
  106. OrgId := adminUserInfo.CurrentOrgId
  107. Creater := adminUserInfo.AdminUser.Id
  108. Pattern, _ := c.GetInt("pattern", 0)
  109. Dbhost := c.GetString("dbhost")
  110. Dbuser := c.GetString("dbuser")
  111. Dbpassword := c.GetString("dbpassword")
  112. Dbname := c.GetString("dbname")
  113. InterfaceUrl := c.GetString("interface_url")
  114. InterFaceToken := c.GetString("interface_token")
  115. AllowIp := c.GetString("allow_ip")
  116. AllowToken := c.GetString("allow_token")
  117. SyncFrequency, _ := c.GetInt("sync_frequency")
  118. Status := 1
  119. UpdatedTime := time.Now().Unix()
  120. interfaceinfo := &models.MiddleInterface{
  121. ID: ID,
  122. OrgId: OrgId,
  123. Creater: Creater,
  124. Pattern: Pattern,
  125. Dbhost: Dbhost,
  126. Dbuser: Dbuser,
  127. Dbpassword: Dbpassword,
  128. Dbname: Dbname,
  129. InterfaceUrl: InterfaceUrl,
  130. InterFaceToken: InterFaceToken,
  131. AllowIp: AllowIp,
  132. AllowToken: AllowToken,
  133. SyncFrequency: SyncFrequency,
  134. Status: Status,
  135. UpdatedTime: UpdatedTime,
  136. }
  137. if ID <= 0 {
  138. interfaceinfo.CreatedTime = time.Now().Unix()
  139. }
  140. err := service.SaveInterface(interfaceinfo)
  141. if err == nil {
  142. c.ServeSuccessJSON(map[string]interface{}{
  143. "interfaceinfo": interfaceinfo,
  144. })
  145. } else {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  147. }
  148. return
  149. }
  150. func (c *IntegrationConfigApiController) GetInterface() {
  151. adminUserInfo := c.GetAdminUserInfo()
  152. interfaceinfo, _ := service.GetInterface(adminUserInfo.CurrentOrgId)
  153. c.ServeSuccessJSON(map[string]interface{}{
  154. "interfaceinfo": interfaceinfo,
  155. })
  156. return
  157. }
  158. func (c *IntegrationConfigApiController) GetPatientsList() {
  159. page, _ := c.GetInt64("page", 1)
  160. limit, _ := c.GetInt64("limit", 10)
  161. if page <= 0 {
  162. page = 1
  163. }
  164. if limit <= 0 {
  165. limit = 10
  166. }
  167. adminUserInfo := c.GetAdminUserInfo()
  168. patients, total, _ := service.GetIntegrationPatientList(adminUserInfo.CurrentOrgId, page, limit)
  169. c.ServeSuccessJSON(map[string]interface{}{
  170. "list": patients,
  171. "total": total,
  172. })
  173. return
  174. }
  175. func (c *IntegrationConfigApiController) EditPatientHis() {
  176. his_user_id := c.GetString("his_user_id")
  177. id, _ := c.GetInt64("id", 0)
  178. adminUserInfo := c.GetAdminUserInfo()
  179. total, _ := service.FindHisPatientByHisId(adminUserInfo.CurrentOrgId, his_user_id)
  180. if total > 0 {
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisIdExist)
  182. return
  183. }
  184. err := service.UpdatePatientsHis(adminUserInfo.CurrentOrgId, his_user_id, id)
  185. if err == nil {
  186. c.ServeSuccessJSON(map[string]interface{}{
  187. "his_user_id": his_user_id,
  188. })
  189. } else {
  190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  191. }
  192. return
  193. }
  194. func (c *IntegrationConfigApiController) CreatePatientHis() {
  195. his_user_id := c.GetString("his_user_id")
  196. id, _ := c.GetInt64("id", 0)
  197. adminUserInfo := c.GetAdminUserInfo()
  198. patient, _ := service.FindVMPatientById(adminUserInfo.CurrentOrgId, id)
  199. total, _ := service.FindHisPatientByHisId(adminUserInfo.CurrentOrgId, his_user_id)
  200. if total > 0 {
  201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisIdExist)
  202. return
  203. }
  204. hisPatient := &models.HisPatients{
  205. UserOrgId: adminUserInfo.CurrentOrgId,
  206. UserId: patient.UserId,
  207. Avatar: patient.Avatar,
  208. PatientType: patient.PatientType,
  209. DialysisNo: patient.DialysisNo,
  210. AdmissionNumber: patient.AdmissionNumber,
  211. Source: patient.Source,
  212. Lapseto: patient.Lapseto,
  213. PartitionId: patient.PartitionId,
  214. BedId: patient.BedId,
  215. Name: patient.Name,
  216. Alias: patient.Alias,
  217. Gender: patient.Gender,
  218. Nation: patient.Nation,
  219. NativePlace: patient.NativePlace,
  220. MaritalStatus: patient.MaritalStatus,
  221. IdCardNo: patient.IdCardNo,
  222. Birthday: patient.Birthday,
  223. ReimbursementWayId: patient.ReimbursementWayId,
  224. HealthCareType: patient.HealthCareType,
  225. HealthCareNo: patient.HealthCareNo,
  226. HealthCareDueDate: patient.HealthCareDueDate,
  227. Height: patient.Height,
  228. BloodType: patient.BloodType,
  229. Rh: patient.Rh,
  230. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  231. EducationLevel: patient.EducationLevel,
  232. Profession: patient.Profession,
  233. Phone: patient.Phone,
  234. HomeTelephone: patient.HomeTelephone,
  235. RelativePhone: patient.RelativePhone,
  236. HomeAddress: patient.HomeAddress,
  237. WorkUnit: patient.WorkUnit,
  238. UnitAddress: patient.UnitAddress,
  239. ReceivingDate: patient.ReceivingDate,
  240. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  241. FirstDialysisDate: patient.FirstDialysisDate,
  242. FirstDialysisHospital: patient.FirstDialysisHospital,
  243. PredialysisCondition: patient.PredialysisCondition,
  244. PreHospitalDialysisFrequency: patient.PreHospitalDialysisFrequency,
  245. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  246. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  247. InductionPeriod: patient.InductionPeriod,
  248. InitialDialysis: patient.InitialDialysis,
  249. TotalDialysis: patient.TotalDialysis,
  250. AttendingDoctorId: patient.AttendingDoctorId,
  251. HeadNurseId: patient.HeadNurseId,
  252. Evaluate: patient.Evaluate,
  253. Diagnose: patient.Diagnose,
  254. Remark: patient.Remark,
  255. RegistrarsId: patient.RegistrarsId,
  256. Registrars: patient.Registrars,
  257. QrCode: patient.QrCode,
  258. BindingState: patient.BindingState,
  259. PatientComplains: patient.PatientComplains,
  260. PresentHistory: patient.PresentHistory,
  261. PastHistory: patient.PastHistory,
  262. Temperature: patient.Temperature,
  263. Pulse: patient.Pulse,
  264. Respiratory: patient.Respiratory,
  265. Sbp: patient.SBP,
  266. Dbp: patient.DBP,
  267. Status: 1,
  268. CreatedTime: time.Now().Unix(),
  269. UpdatedTime: time.Now().Unix(),
  270. Age: patient.Age,
  271. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  272. IsInfectious: patient.IsInfectious,
  273. RemindCycle: patient.RemindCycle,
  274. ResponseResult: patient.ResponseResult,
  275. IsOpenRemind: patient.IsOpenRemind,
  276. DialysisAge: patient.DialysisAge,
  277. ExpenseKind: patient.ExpenseKind,
  278. TellPhone: patient.TellPhone,
  279. FirstTreatmentDate: patient.FirstTreatmentDate,
  280. ContactName: patient.ContactName,
  281. HisUserId: his_user_id,
  282. XtPatientId: patient.ID,
  283. }
  284. err := service.CreatePatientsHis(hisPatient)
  285. if err == nil {
  286. c.ServeSuccessJSON(map[string]interface{}{
  287. "patient": hisPatient,
  288. })
  289. } else {
  290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  291. }
  292. return
  293. }
  294. func (c *IntegrationConfigApiController) GetAdminsList() {
  295. page, _ := c.GetInt("page", 1)
  296. limit, _ := c.GetInt("limit", 10)
  297. if page <= 0 {
  298. page = 1
  299. }
  300. if limit <= 0 {
  301. limit = 10
  302. }
  303. adminUserInfo := c.GetAdminUserInfo()
  304. viewModels, total, getAdminsErr := service.GetAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, limit)
  305. if getAdminsErr != nil {
  306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  307. return
  308. }
  309. c.ServeSuccessJSON(map[string]interface{}{
  310. "admins": viewModels,
  311. "total_count": total,
  312. })
  313. return
  314. }
  315. func (c *IntegrationConfigApiController) EditAdminHis() {
  316. his_user_id := c.GetString("his_user_id")
  317. id, _ := c.GetInt64("id", 0)
  318. adminUserInfo := c.GetAdminUserInfo()
  319. total, _ := service.FindHisAdminByHisId(adminUserInfo.CurrentOrgId, his_user_id, adminUserInfo.CurrentAppId)
  320. if total > 0 {
  321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisIdExist)
  322. return
  323. }
  324. err := service.UpdateAdminsHis(adminUserInfo.CurrentOrgId, his_user_id, id)
  325. if err == nil {
  326. c.ServeSuccessJSON(map[string]interface{}{
  327. "his_user_id": his_user_id,
  328. })
  329. } else {
  330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  331. }
  332. return
  333. }
  334. func (c *IntegrationConfigApiController) CreateAdminHis() {
  335. his_user_id := c.GetString("his_user_id")
  336. id, _ := c.GetInt64("id", 0)
  337. adminUserInfo := c.GetAdminUserInfo()
  338. adminRole, _ := service.FindVMAdminRoleById(adminUserInfo.CurrentOrgId, id, adminUserInfo.CurrentAppId)
  339. total, _ := service.FindHisAdminByHisId(adminUserInfo.CurrentOrgId, his_user_id, adminUserInfo.CurrentAppId)
  340. if total > 0 {
  341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisIdExist)
  342. return
  343. }
  344. hisAdminRole := &models.HisUserAdminRole{
  345. OrgId: adminUserInfo.CurrentOrgId,
  346. AdminUserId: adminRole.AdminUserId,
  347. AppId: adminRole.AppId,
  348. RoleId: adminRole.RoleId,
  349. UserName: adminRole.UserName,
  350. Avatar: adminRole.Avatar,
  351. UserType: adminRole.UserType,
  352. UserTitle: adminRole.UserTitle,
  353. Intro: adminRole.Intro,
  354. Status: 1,
  355. Ctime: time.Now().Unix(),
  356. Mtime: time.Now().Unix(),
  357. XtRoleId: adminRole.ID,
  358. HisUserId: his_user_id,
  359. }
  360. err := service.CreateAdminsHis(hisAdminRole)
  361. if err == nil {
  362. c.ServeSuccessJSON(map[string]interface{}{
  363. "his_role": hisAdminRole,
  364. })
  365. } else {
  366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. }
  368. return
  369. }