integration_config_api_controller.go 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_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. }
  20. func (c *IntegrationConfigApiController) GetPatientsList() {
  21. page, _ := c.GetInt64("page", 1)
  22. limit, _ := c.GetInt64("limit", 10)
  23. if page <= 0 {
  24. page = 1
  25. }
  26. if limit <= 0 {
  27. limit = 10
  28. }
  29. adminUserInfo := c.GetAdminUserInfo()
  30. patients, total, _ := service.GetIntegrationPatientList(adminUserInfo.CurrentOrgId, page, limit)
  31. c.ServeSuccessJSON(map[string]interface{}{
  32. "list": patients,
  33. "total": total,
  34. })
  35. return
  36. }
  37. func (c *IntegrationConfigApiController) EditPatientHis() {
  38. his_user_id := c.GetString("his_user_id")
  39. id, _ := c.GetInt64("id", 0)
  40. adminUserInfo := c.GetAdminUserInfo()
  41. total, _ := service.FindHisPatientByHisId(adminUserInfo.CurrentOrgId, his_user_id)
  42. if total > 0 {
  43. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisIdExist)
  44. return
  45. }
  46. err := service.UpdatePatientsHis(adminUserInfo.CurrentOrgId, his_user_id, id)
  47. if err == nil {
  48. c.ServeSuccessJSON(map[string]interface{}{
  49. "his_user_id": his_user_id,
  50. })
  51. } else {
  52. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  53. }
  54. return
  55. }
  56. func (c *IntegrationConfigApiController) CreatePatientHis() {
  57. his_user_id := c.GetString("his_user_id")
  58. id, _ := c.GetInt64("id", 0)
  59. adminUserInfo := c.GetAdminUserInfo()
  60. patient, _ := service.FindVMPatientById(adminUserInfo.CurrentOrgId, id)
  61. total, _ := service.FindHisPatientByHisId(adminUserInfo.CurrentOrgId, his_user_id)
  62. if total > 0 {
  63. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisIdExist)
  64. return
  65. }
  66. hisPatient := &models.HisPatients{
  67. UserOrgId: adminUserInfo.CurrentOrgId,
  68. UserId: patient.UserId,
  69. Avatar: patient.Avatar,
  70. PatientType: patient.PatientType,
  71. DialysisNo: patient.DialysisNo,
  72. AdmissionNumber: patient.AdmissionNumber,
  73. Source: patient.Source,
  74. Lapseto: patient.Lapseto,
  75. PartitionId: patient.PartitionId,
  76. BedId: patient.BedId,
  77. Name: patient.Name,
  78. Alias: patient.Alias,
  79. Gender: patient.Gender,
  80. Nation: patient.Nation,
  81. NativePlace: patient.NativePlace,
  82. MaritalStatus: patient.MaritalStatus,
  83. IdCardNo: patient.IdCardNo,
  84. Birthday: patient.Birthday,
  85. ReimbursementWayId: patient.ReimbursementWayId,
  86. HealthCareType: patient.HealthCareType,
  87. HealthCareNo: patient.HealthCareNo,
  88. HealthCareDueDate: patient.HealthCareDueDate,
  89. Height: patient.Height,
  90. BloodType: patient.BloodType,
  91. Rh: patient.Rh,
  92. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  93. EducationLevel: patient.EducationLevel,
  94. Profession: patient.Profession,
  95. Phone: patient.Phone,
  96. HomeTelephone: patient.HomeTelephone,
  97. RelativePhone: patient.RelativePhone,
  98. HomeAddress: patient.HomeAddress,
  99. WorkUnit: patient.WorkUnit,
  100. UnitAddress: patient.UnitAddress,
  101. ReceivingDate: patient.ReceivingDate,
  102. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  103. FirstDialysisDate: patient.FirstDialysisDate,
  104. FirstDialysisHospital: patient.FirstDialysisHospital,
  105. PredialysisCondition: patient.PredialysisCondition,
  106. PreHospitalDialysisFrequency: patient.PreHospitalDialysisFrequency,
  107. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  108. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  109. InductionPeriod: patient.InductionPeriod,
  110. InitialDialysis: patient.InitialDialysis,
  111. TotalDialysis: patient.TotalDialysis,
  112. AttendingDoctorId: patient.AttendingDoctorId,
  113. HeadNurseId: patient.HeadNurseId,
  114. Evaluate: patient.Evaluate,
  115. Diagnose: patient.Diagnose,
  116. Remark: patient.Remark,
  117. RegistrarsId: patient.RegistrarsId,
  118. Registrars: patient.Registrars,
  119. QrCode: patient.QrCode,
  120. BindingState: patient.BindingState,
  121. PatientComplains: patient.PatientComplains,
  122. PresentHistory: patient.PresentHistory,
  123. PastHistory: patient.PastHistory,
  124. Temperature: patient.Temperature,
  125. Pulse: patient.Pulse,
  126. Respiratory: patient.Respiratory,
  127. Sbp: patient.SBP,
  128. Dbp: patient.DBP,
  129. Status: 1,
  130. CreatedTime: time.Now().Unix(),
  131. UpdatedTime: time.Now().Unix(),
  132. Age: patient.Age,
  133. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  134. IsInfectious: patient.IsInfectious,
  135. RemindCycle: patient.RemindCycle,
  136. ResponseResult: patient.ResponseResult,
  137. IsOpenRemind: patient.IsOpenRemind,
  138. DialysisAge: patient.DialysisAge,
  139. ExpenseKind: patient.ExpenseKind,
  140. TellPhone: patient.TellPhone,
  141. FirstTreatmentDate: patient.FirstTreatmentDate,
  142. ContactName: patient.ContactName,
  143. HisUserId: his_user_id,
  144. XtPatientId: patient.ID,
  145. }
  146. err := service.CreatePatientsHis(hisPatient)
  147. if err == nil {
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "patient": hisPatient,
  150. })
  151. } else {
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  153. }
  154. return
  155. }
  156. func (c *IntegrationConfigApiController) GetAdminsList() {
  157. page, _ := c.GetInt("page", 1)
  158. limit, _ := c.GetInt("limit", 10)
  159. if page <= 0 {
  160. page = 1
  161. }
  162. if limit <= 0 {
  163. limit = 10
  164. }
  165. adminUserInfo := c.GetAdminUserInfo()
  166. viewModels, total, getAdminsErr := service.GetAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, limit)
  167. if getAdminsErr != nil {
  168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  169. return
  170. }
  171. c.ServeSuccessJSON(map[string]interface{}{
  172. "admins": viewModels,
  173. "total_count": total,
  174. })
  175. return
  176. }
  177. func (c *IntegrationConfigApiController) EditAdminHis() {
  178. his_user_id := c.GetString("his_user_id")
  179. id, _ := c.GetInt64("id", 0)
  180. adminUserInfo := c.GetAdminUserInfo()
  181. total, _ := service.FindHisAdminByHisId(adminUserInfo.CurrentOrgId, his_user_id, adminUserInfo.CurrentAppId)
  182. if total > 0 {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisIdExist)
  184. return
  185. }
  186. err := service.UpdateAdminsHis(adminUserInfo.CurrentOrgId, his_user_id, id)
  187. if err == nil {
  188. c.ServeSuccessJSON(map[string]interface{}{
  189. "his_user_id": his_user_id,
  190. })
  191. } else {
  192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  193. }
  194. return
  195. }
  196. func (c *IntegrationConfigApiController) CreateAdminHis() {
  197. his_user_id := c.GetString("his_user_id")
  198. id, _ := c.GetInt64("id", 0)
  199. adminUserInfo := c.GetAdminUserInfo()
  200. adminRole, _ := service.FindVMAdminRoleById(adminUserInfo.CurrentOrgId, id, adminUserInfo.CurrentAppId)
  201. total, _ := service.FindHisAdminByHisId(adminUserInfo.CurrentOrgId, his_user_id, adminUserInfo.CurrentAppId)
  202. if total > 0 {
  203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisIdExist)
  204. return
  205. }
  206. hisAdminRole := &models.HisUserAdminRole{
  207. OrgId: adminUserInfo.CurrentOrgId,
  208. AdminUserId: adminRole.AdminUserId,
  209. AppId: adminRole.AppId,
  210. RoleId: adminRole.RoleId,
  211. UserName: adminRole.UserName,
  212. Avatar: adminRole.Avatar,
  213. UserType: adminRole.UserType,
  214. UserTitle: adminRole.UserTitle,
  215. Intro: adminRole.Intro,
  216. Status: 1,
  217. Ctime: time.Now().Unix(),
  218. Mtime: time.Now().Unix(),
  219. XtRoleId: adminRole.ID,
  220. HisUserId: his_user_id,
  221. }
  222. err := service.CreateAdminsHis(hisAdminRole)
  223. if err == nil {
  224. c.ServeSuccessJSON(map[string]interface{}{
  225. "his_role": hisAdminRole,
  226. })
  227. } else {
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  229. }
  230. return
  231. }