dialysis_record_api_controller.go 105KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "github.com/jinzhu/gorm"
  6. "math"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "XT_New/enums"
  11. "XT_New/service"
  12. "XT_New/utils"
  13. "fmt"
  14. "github.com/astaxie/beego"
  15. )
  16. func DialysisRecordAPIControllerRegistRouter() {
  17. beego.Router("/api/dialysis/initdata", &DialysisRecordAPIController{}, "get:RecordInitData")
  18. beego.Router("/api/dialysis/schedules", &DialysisRecordAPIController{}, "get:GetSchedules")
  19. beego.Router("/api/dislysis/schedule", &DialysisRecordAPIController{}, "get:DialysisSchedule")
  20. beego.Router("/api/dislysis/monitor/edit", &DialysisRecordAPIController{}, "post:EditMonitor")
  21. beego.Router("/api/dialysis/start_record", &DialysisRecordAPIController{}, "post:StartDialysis")
  22. beego.Router("/api/dialysis/finish", &DialysisRecordAPIController{}, "post:FinishDialysis")
  23. beego.Router("/api/start_dialysis/modify", &DialysisRecordAPIController{}, "post:ModifyStartDialysis")
  24. beego.Router("/api/finish_dialysis/modify", &DialysisRecordAPIController{}, "post:ModifyFinishDialysis")
  25. }
  26. type DialysisRecordAPIController struct {
  27. BaseAuthAPIController
  28. }
  29. // /api/dialysis/initdata [get]
  30. func (this *DialysisRecordAPIController) RecordInitData() {
  31. adminInfo := this.GetAdminUserInfo()
  32. orgID := adminInfo.CurrentOrgId
  33. now := time.Now()
  34. ymdDate, _ := utils.ParseTimeStringToTime("2006-01-02", now.Format("2006-01-02"))
  35. schedules, getSchedulesErr := service.GetDialysisScheduals(orgID, ymdDate.Unix())
  36. if getSchedulesErr != nil {
  37. this.ErrorLog("获取排班信息失败:%v", getSchedulesErr)
  38. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  39. return
  40. }
  41. zones, getZonesErr := service.GetAllValidDeviceZones(orgID)
  42. if getZonesErr != nil {
  43. this.ErrorLog("获取全部分区失败:%v", getZonesErr)
  44. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  45. return
  46. }
  47. this.ServeSuccessJSON(map[string]interface{}{
  48. "schedules": schedules,
  49. "zones": zones,
  50. })
  51. }
  52. // /api/dialysis/schedules [get]
  53. // @param date:string (yyyy-mm-dd)
  54. func (this *DialysisRecordAPIController) GetSchedules() {
  55. schedualDate := this.GetString("date")
  56. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  57. if parseDateErr != nil {
  58. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  59. return
  60. }
  61. adminInfo := this.GetAdminUserInfo()
  62. orgID := adminInfo.CurrentOrgId
  63. schedules, err := service.GetDialysisScheduals(orgID, date.Unix())
  64. if err != nil {
  65. this.ErrorLog("获取排班信息失败:%v", err)
  66. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  67. } else {
  68. this.ServeSuccessJSON(map[string]interface{}{
  69. "schedules": schedules,
  70. })
  71. }
  72. }
  73. // /api/dislysis/schedule [get]
  74. // @param patient_id:int
  75. // @param date:string (yyyy-MM-dd)
  76. func (this *DialysisRecordAPIController) DialysisSchedule() {
  77. patientID, _ := this.GetInt64("patient_id")
  78. recordDateStr := this.GetString("date")
  79. if patientID <= 0 {
  80. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  81. return
  82. }
  83. if len(recordDateStr) == 0 {
  84. recordDateStr = time.Now().Format("2006-01-02")
  85. }
  86. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  87. if parseDateErr != nil {
  88. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  90. return
  91. }
  92. adminInfo := this.GetAdminUserInfo()
  93. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.CurrentOrgId, patientID)
  94. if getPatientErr != nil {
  95. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  96. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  97. return
  98. } else if patient == nil {
  99. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  100. return
  101. }
  102. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.CurrentOrgId, patientID, date.Unix())
  103. if getSchedualErr != nil {
  104. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  106. return
  107. }
  108. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  109. if getRTARErr != nil {
  110. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  112. return
  113. }
  114. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  115. fmt.Println("predialysisEvaluatiotion", predialysisEvaluation)
  116. if getPEErr != nil {
  117. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  119. return
  120. }
  121. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvices(adminInfo.CurrentOrgId, patientID, date.Unix())
  122. if getDoctorAdvicesErr != nil {
  123. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. return
  126. }
  127. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  128. if getDialysisOrderErr != nil {
  129. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  131. return
  132. }
  133. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.CurrentOrgId, patientID, date.Unix())
  134. if getDoubleCheckErr != nil {
  135. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  137. return
  138. }
  139. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.CurrentOrgId, patientID, date.Unix())
  140. if getMonitorRecordsErr != nil {
  141. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  143. return
  144. }
  145. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  146. if getAADErr != nil {
  147. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  149. return
  150. }
  151. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.CurrentOrgId, patientID, date.Unix())
  152. if getTreatmentSummaryErr != nil {
  153. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  155. return
  156. }
  157. admins, getAdminsErr := service.GetAllAdminUsers(adminInfo.CurrentOrgId, adminInfo.CurrentAppId)
  158. if getAdminsErr != nil {
  159. this.ErrorLog("获取医护列表失败:%v", getAdminsErr)
  160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  161. return
  162. }
  163. devices, getDevicesErr := service.GetValidDevicesBy(adminInfo.CurrentOrgId, 0, 0)
  164. if getDevicesErr != nil {
  165. this.ErrorLog("获取设备列表失败:%v", getDevicesErr)
  166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  167. return
  168. }
  169. deviceNumbers, getDeviceNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  170. if getDeviceNumbersErr != nil {
  171. this.ErrorLog("获取床位号列表失败:%v", getDeviceNumbersErr)
  172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  173. return
  174. }
  175. lastPredialysisEvaluation, getLPEErr := service.GetLastTimePredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  176. if getLPEErr != nil {
  177. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  179. return
  180. }
  181. var lastMonitorRecord *models.MonitoringRecord
  182. lastMonitorRecord, getLastErr := service.GetLastMonitorRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  183. if getLastErr != nil {
  184. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  186. return
  187. }
  188. lastAssessmentAfterDislysis, getLAADErr := service.GetLastTimeAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  189. if getLAADErr != nil {
  190. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  192. return
  193. }
  194. dialysisPrescribe, getDialysisPrescribeErr := service.GetDialysisPrescribe(adminInfo.CurrentOrgId, patientID, date.Unix())
  195. if getDialysisPrescribeErr != nil {
  196. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  198. return
  199. }
  200. dialysisSolution, getDialysisSolutionErr := service.GetDialysisSolution(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  201. if getDialysisSolutionErr != nil {
  202. this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  204. return
  205. }
  206. lastDialysisPrescribe, getDialysisPrescribeErr := service.GetLastDialysisPrescribeByModeId(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  207. if getDialysisPrescribeErr != nil {
  208. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  210. return
  211. }
  212. systemDialysisPrescribe, getSystemDialysisPrescribeErr := service.GetSystemDialysisPrescribeByModeId(adminInfo.CurrentOrgId, schedual.ModeId)
  213. if getSystemDialysisPrescribeErr != nil {
  214. this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  216. return
  217. }
  218. if getLPEErr != nil {
  219. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  221. return
  222. }
  223. lastDryWeightDislysis, getDryErr := service.GetLastDryWeight(adminInfo.CurrentOrgId, patientID)
  224. if getDryErr != nil {
  225. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  227. return
  228. }
  229. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  230. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.CurrentOrgId)
  231. if record.IsOpen == 1 {
  232. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  233. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  234. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  235. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  236. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  237. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  238. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  239. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  240. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  241. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  242. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  243. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  244. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  245. niprocart_info, _ := service.FindWarehouseInfoByGoodType(niprocart_good_type_id, adminInfo.CurrentOrgId)
  246. jms_info, _ := service.FindWarehouseInfoByGoodType(jms_good_type_id, adminInfo.CurrentOrgId)
  247. fistula_needle_set_info, _ := service.FindWarehouseInfoByGoodType(fistula_needle_set_good_type_id, adminInfo.CurrentOrgId)
  248. fistula_needle_set_16_info, _ := service.FindWarehouseInfoByGoodType(fistula_needle_set_16_good_type_id, adminInfo.CurrentOrgId)
  249. hemoperfusion_info, _ := service.FindWarehouseInfoByGoodType(hemoperfusion_good_type_id, adminInfo.CurrentOrgId)
  250. dialyser_sterilised_info, _ := service.FindWarehouseInfoByGoodType(dialyser_sterilised_good_type_id, adminInfo.CurrentOrgId)
  251. filtryzer_info, _ := service.FindWarehouseInfoByGoodType(filtryzer_good_type_id, adminInfo.CurrentOrgId)
  252. dialyzers_info, _ := service.FindWarehouseInfoByGoodType(dialyzers_good_type_id, adminInfo.CurrentOrgId)
  253. injector_info, _ := service.FindWarehouseInfoByGoodType(injector_good_type_id, adminInfo.CurrentOrgId)
  254. bloodlines_info, _ := service.FindWarehouseInfoByGoodType(bloodlines_good_type_id, adminInfo.CurrentOrgId)
  255. tubingHemodialysis_info, _ := service.FindWarehouseInfoByGoodType(tubingHemodialysis_good_type_id, adminInfo.CurrentOrgId)
  256. safe_package_info, _ := service.FindWarehouseInfoByGoodType(safe_package_good_type_id, adminInfo.CurrentOrgId)
  257. aliquid_info, _ := service.FindWarehouseInfoByGoodType(aliquid_good_type_id, adminInfo.CurrentOrgId)
  258. returnData := map[string]interface{}{
  259. "patient": patient,
  260. "schedual": schedual,
  261. "prescription": dialysisPrescribe,
  262. "solution": dialysisSolution,
  263. "receiver_treatment_access": receiverTreatmentAccess,
  264. "predialysis_evaluation": predialysisEvaluation,
  265. "doctor_advices": doctorAdvices,
  266. "double_check": doubleCheck,
  267. "assessment_after_dislysis": assessmentAfterDislysis,
  268. "treatment_summary": treatmentSummary,
  269. "monitor_records": monitorRecords,
  270. "dialysis_order": dialysisOrder,
  271. "doctors": admins,
  272. "devices": devices,
  273. "device_numbers": deviceNumbers,
  274. "niprocart_info": niprocart_info,
  275. "jms_info": jms_info,
  276. "fistula_needle_set_info": fistula_needle_set_info,
  277. "fistula_needle_set_16_info": fistula_needle_set_16_info,
  278. "hemoperfusion_info": hemoperfusion_info,
  279. "dialyser_sterilised_info": dialyser_sterilised_info,
  280. "filtryzer_info": filtryzer_info,
  281. "dialyzers_info": dialyzers_info,
  282. "injector_info": injector_info,
  283. "bloodlines_info": bloodlines_info,
  284. "tubingHemodialysis_info": tubingHemodialysis_info,
  285. "safe_package_info": safe_package_info,
  286. "aliquid_info": aliquid_info,
  287. "config": record,
  288. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  289. "lastMonitorRecord": lastMonitorRecord,
  290. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  291. "lastDialysisPrescribe": lastDialysisPrescribe,
  292. "lastDryWeightDislysis": lastDryWeightDislysis,
  293. "headNurses": headNurses,
  294. "system_prescribe": systemDialysisPrescribe,
  295. }
  296. this.ServeSuccessJSON(returnData)
  297. } else {
  298. returnData := map[string]interface{}{
  299. "patient": patient,
  300. "schedual": schedual,
  301. "prescription": dialysisPrescribe,
  302. "solution": dialysisSolution,
  303. "receiver_treatment_access": receiverTreatmentAccess,
  304. "predialysis_evaluation": predialysisEvaluation,
  305. "doctor_advices": doctorAdvices,
  306. "double_check": doubleCheck,
  307. "assessment_after_dislysis": assessmentAfterDislysis,
  308. "treatment_summary": treatmentSummary,
  309. "monitor_records": monitorRecords,
  310. "dialysis_order": dialysisOrder,
  311. "doctors": admins,
  312. "devices": devices,
  313. "device_numbers": deviceNumbers,
  314. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  315. "lastMonitorRecord": lastMonitorRecord,
  316. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  317. "lastDialysisPrescribe": lastDialysisPrescribe,
  318. "lastDryWeightDislysis": lastDryWeightDislysis,
  319. "headNurses": headNurses,
  320. "system_prescribe": systemDialysisPrescribe,
  321. }
  322. this.ServeSuccessJSON(returnData)
  323. }
  324. }
  325. type EditMonitorParamObject struct {
  326. ID int64 `json:"id"`
  327. MonitoringDate int64 `json:"monitoring_date"`
  328. OperateTime int64 `json:"operate_time"`
  329. // MonitoringTime string `json:"monitoring_time"`
  330. SystolicBP float64 `json:"systolic_bp"`
  331. DiastolicBP float64 `json:"diastolic_bp"`
  332. PulseFrequency float64 `json:"pulse_frequency"`
  333. BreathingRated float64 `json:"breathing_rated"`
  334. BloodFlowVolume float64 `json:"blood_flow_volume"`
  335. VenousPressure float64 `json:"venous_pressure"`
  336. TransmembranePressure float64 `json:"transmembrane_pressure"`
  337. UltrafiltrationVolume float64 `json:"ultrafiltration_volume"`
  338. UltrafiltrationRate float64 `json:"ultrafiltration_rate"`
  339. ArterialPressure float64 `json:"arterial_pressure"`
  340. SodiumConcentration float64 `json:"sodium_concentration"`
  341. DialysateTemperature float64 `json:"dialysate_temperature"`
  342. Temperature float64 `json:"temperature"`
  343. ReplacementRate float64 `json:"replacement_rate"`
  344. DisplacementQuantity float64 `json:"displacement_quantity"`
  345. KTV float64 `json:"ktv"`
  346. Symptom string `json:"symptom"`
  347. Dispose string `json:"dispose"`
  348. Result string `json:"result"`
  349. Conductivity float64 `json:"conductivity"`
  350. DisplacementFlowQuantity float64 `json:"displacement_flow_quantity"`
  351. BloodOxygenSaturation string `gorm:"column:blood_oxygen_saturation" json:"blood_oxygen_saturation" form:"blood_oxygen_saturation"`
  352. }
  353. // /api/dislysis/monitor/edit [post]
  354. // @param patient_id:int 患者id
  355. // @param schedule_date:int 排班日期
  356. // 下面的参数放到 body
  357. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  358. // @param monitoring_date:int 排班日期
  359. // @param operate_time:int 实际测量日期
  360. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  361. // @param systolic_bp?:float 收缩压
  362. // @param diastolic_bp?:float 舒张压
  363. // @param pulse_frequency?:float 心率
  364. // @param breathing_rated?:float 呼吸频率
  365. // @param blood_flow_volume?:float 血流量
  366. // @param venous_pressure?:float 静脉压
  367. // @param transmembrane_pressure?:float 跨膜压
  368. // @param ultrafiltration_volume?:float 超滤量
  369. // @param ultrafiltration_rate?:float 超滤率
  370. // @param arterial_pressure?:float 动脉压
  371. // @param sodium_concentration?:float 钠浓度
  372. // @param dialysate_temperature?:float 透析液温度
  373. // @param replacement_rate?:float 置换率
  374. // @param displacement_quantity?:float 置换量
  375. // @param ktv?:float KT/V
  376. // @param symptom?:string 病情变化
  377. // @param dispose?:string 处理
  378. // @param result?:string 结果
  379. func (this *DialysisRecordAPIController) EditMonitor() {
  380. patientID, _ := this.GetInt64("patient_id")
  381. scheduleDate, _ := this.GetInt64("schedule_date")
  382. if patientID <= 0 || scheduleDate <= 0 {
  383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  384. return
  385. }
  386. var monitorParam EditMonitorParamObject
  387. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  388. this.ErrorLog("参数解析失败:%v", parseErr)
  389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  390. return
  391. }
  392. if monitorParam.MonitoringDate != scheduleDate {
  393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  394. return
  395. }
  396. adminUserInfo := this.GetAdminUserInfo()
  397. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  398. if getScheduleErr != nil {
  399. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  401. return
  402. } else if schedule == nil {
  403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  404. return
  405. }
  406. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  407. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  408. if getDialysisOrderErr != nil {
  409. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  411. return
  412. }
  413. orderID := int64(0)
  414. if dialysisOrder != nil {
  415. orderID = dialysisOrder.ID
  416. }
  417. if monitorParam.ID <= 0 { // 新建记录
  418. monitor := models.MonitoringRecord{
  419. UserOrgId: adminUserInfo.CurrentOrgId,
  420. PatientId: patientID,
  421. DialysisOrderId: orderID,
  422. MonitoringDate: monitorParam.MonitoringDate,
  423. OperateTime: monitorParam.OperateTime,
  424. // MonitoringTime: monitorParam.MonitoringTime,
  425. PulseFrequency: monitorParam.PulseFrequency,
  426. BreathingRate: monitorParam.BreathingRated,
  427. SystolicBloodPressure: monitorParam.SystolicBP,
  428. DiastolicBloodPressure: monitorParam.DiastolicBP,
  429. BloodFlowVolume: monitorParam.BloodFlowVolume,
  430. VenousPressure: monitorParam.VenousPressure,
  431. ArterialPressure: monitorParam.ArterialPressure,
  432. TransmembranePressure: monitorParam.TransmembranePressure,
  433. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  434. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  435. SodiumConcentration: monitorParam.SodiumConcentration,
  436. DialysateTemperature: monitorParam.DialysateTemperature,
  437. Temperature: monitorParam.Temperature,
  438. ReplacementRate: monitorParam.ReplacementRate,
  439. DisplacementQuantity: monitorParam.DisplacementQuantity,
  440. Ktv: monitorParam.KTV,
  441. Symptom: monitorParam.Symptom,
  442. Dispose: monitorParam.Dispose,
  443. Result: monitorParam.Result,
  444. MonitoringNurse: adminUserInfo.AdminUser.Id,
  445. Conductivity: monitorParam.Conductivity,
  446. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  447. Status: 1,
  448. CreatedTime: time.Now().Unix(),
  449. UpdatedTime: time.Now().Unix(),
  450. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  451. }
  452. createErr := service.CreateMonitor(&monitor)
  453. if createErr != nil {
  454. this.ErrorLog("创建监测记录失败:%v", createErr)
  455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  456. return
  457. }
  458. this.ServeSuccessJSON(map[string]interface{}{
  459. "monitor": monitor,
  460. })
  461. } else { // 修改记录
  462. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  463. if getMonitorErr != nil {
  464. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  466. return
  467. } else if monitor == nil {
  468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  469. return
  470. }
  471. if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  472. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  473. if getPermissionErr != nil {
  474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  475. return
  476. } else if headNursePermission == nil {
  477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  478. return
  479. }
  480. }
  481. monitor.OperateTime = monitorParam.OperateTime
  482. monitor.PulseFrequency = monitorParam.PulseFrequency
  483. monitor.BreathingRate = monitorParam.BreathingRated
  484. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  485. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  486. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  487. monitor.VenousPressure = monitorParam.VenousPressure
  488. monitor.ArterialPressure = monitorParam.ArterialPressure
  489. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  490. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  491. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  492. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  493. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  494. monitor.Temperature = monitorParam.Temperature
  495. monitor.ReplacementRate = monitorParam.ReplacementRate
  496. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  497. monitor.Conductivity = monitorParam.Conductivity
  498. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  499. monitor.Ktv = monitorParam.KTV
  500. monitor.Symptom = monitorParam.Symptom
  501. monitor.Dispose = monitorParam.Dispose
  502. monitor.Result = monitorParam.Result
  503. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  504. monitor.UpdatedTime = time.Now().Unix()
  505. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  506. updateErr := service.UpdateMonitor(monitor)
  507. if updateErr != nil {
  508. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  510. return
  511. }
  512. this.ServeSuccessJSON(map[string]interface{}{
  513. "monitor": monitor,
  514. })
  515. }
  516. }
  517. // /api/dialysis/start_record [post]
  518. // @param patient_id:int
  519. // @param date:string 排班时间 (yyyy-mm-dd)
  520. // @param nurse:int 上机护士
  521. // @param bed:int 上机床位号
  522. func (this *DialysisRecordAPIController) StartDialysis() {
  523. patientID, _ := this.GetInt64("patient_id")
  524. recordDateStr := this.GetString("date")
  525. nurseID, _ := this.GetInt64("nurse")
  526. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  527. startDateStr := this.GetString("start_time")
  528. blood_drawing, _ := this.GetInt64("blood_drawing")
  529. schedual_type, _ := this.GetInt64("schedual_type")
  530. bedID, _ := this.GetInt64("bed")
  531. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  533. return
  534. }
  535. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  536. if parseErr != nil {
  537. this.ErrorLog("时间解析失败:%v", parseErr)
  538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  539. return
  540. }
  541. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  542. if parseErr != nil {
  543. this.ErrorLog("时间解析失败:%v", parseErr)
  544. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. adminUserInfo := this.GetAdminUserInfo()
  548. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  549. if getPatientErr != nil {
  550. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  552. return
  553. } else if patient == nil {
  554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  555. return
  556. }
  557. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  558. if getNurseErr != nil {
  559. this.ErrorLog("获取护士失败:%v", getNurseErr)
  560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  561. return
  562. } else if nurse == nil {
  563. this.ErrorLog("护士不存在")
  564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  565. return
  566. }
  567. nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  568. if getNurseErr != nil {
  569. this.ErrorLog("获取护士失败:%v", getNurseErr)
  570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  571. return
  572. } else if nurse == nil {
  573. this.ErrorLog("护士不存在")
  574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  578. if getDeviceNumberErr != nil {
  579. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  581. return
  582. } else if deviceNumber == nil {
  583. this.ErrorLog("床位号不存在")
  584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  585. return
  586. }
  587. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  588. if getRecordErr != nil {
  589. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  591. return
  592. } else if dialysisRecord != nil {
  593. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  594. return
  595. }
  596. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  597. //是否启动自动扣减功能
  598. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  599. //启动的话
  600. if config.IsOpen == 1 {
  601. niprocart, _ := beego.AppConfig.Int64("niprocart")
  602. jms, _ := beego.AppConfig.Int64("jms")
  603. fistula_needle_set, _ := beego.AppConfig.Int64("fistula_needle_set")
  604. fistula_needle_set_16, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  605. hemoperfusion, _ := beego.AppConfig.Int64("hemoperfusion")
  606. dialyser_sterilised, _ := beego.AppConfig.Int64("dialyser_sterilised")
  607. filtryzer, _ := beego.AppConfig.Int64("filtryzer")
  608. dialyzers, _ := beego.AppConfig.Int64("dialyzers")
  609. injector, _ := beego.AppConfig.Int64("injector")
  610. bloodlines, _ := beego.AppConfig.Int64("bloodlines")
  611. tubingHemodialysis, _ := beego.AppConfig.Int64("tubingHemodialysis")
  612. safe_package, _ := beego.AppConfig.Int64("package")
  613. aliquid, _ := beego.AppConfig.Int64("aliquid")
  614. //库存自动扣减功能
  615. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  616. if prescription.ID > 0 {
  617. out, err := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, recordDate.Unix())
  618. if err == gorm.ErrRecordNotFound {
  619. //没有记录,则创建出库单
  620. timeStr := time.Now().Format("2006-01-02")
  621. timeArr := strings.Split(timeStr, "-")
  622. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  623. total = total + 1
  624. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  625. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  626. number = number + total
  627. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  628. creater := adminUserInfo.AdminUser.Id
  629. warehouseOut := models.WarehouseOut{
  630. WarehouseOutOrderNumber: warehousing_out_order,
  631. OperationTime: time.Now().Unix(),
  632. OrgId: adminUserInfo.CurrentOrgId,
  633. Creater: creater,
  634. Ctime: time.Now().Unix(),
  635. Status: 1,
  636. WarehouseOutTime: recordDate.Unix(),
  637. Dealer: 0,
  638. Manufacturer: 0,
  639. Type: 1,
  640. IsSys: 1,
  641. }
  642. err := service.AddSigleWarehouseOut(&warehouseOut)
  643. if err != nil {
  644. utils.TraceLog("创建出库单失败 err = %v", err)
  645. } else {
  646. if prescription.Niprocart > 0 {
  647. warehouseOutInfo := &models.WarehouseOutInfo{
  648. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  649. WarehouseOutId: warehouseOut.ID,
  650. Count: 1,
  651. Status: 1,
  652. Ctime: time.Now().Unix(),
  653. Remark: "",
  654. OrgId: adminUserInfo.CurrentOrgId,
  655. Type: 1,
  656. Manufacturer: 0,
  657. Dealer: 0,
  658. IsSys: 1,
  659. SysRecordTime: startDate.Unix(),
  660. }
  661. //查出入库记录中最后一条记录
  662. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.CurrentOrgId)
  663. warehouseOutInfo.Price = stockInInfo.Price
  664. warehouseOutInfo.GoodId = prescription.Niprocart
  665. warehouseOutInfo.GoodTypeId = niprocart
  666. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  667. if err == nil {
  668. details := &models.AutomaticReduceDetail{
  669. WarehouseOutId: warehouseOutInfo.ID,
  670. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  671. PatientId: patientID,
  672. Ctime: time.Now().Unix(),
  673. Mtime: time.Now().Unix(),
  674. Status: 1,
  675. RecordTime: startDate.Unix(),
  676. OrgId: adminUserInfo.CurrentOrgId,
  677. GoodId: prescription.Niprocart,
  678. GoodTypeId: niprocart,
  679. }
  680. service.AddSigleAutoReduceRecordInfo(details)
  681. }
  682. }
  683. if prescription.Jms > 0 {
  684. warehouseOutInfo := &models.WarehouseOutInfo{
  685. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  686. WarehouseOutId: warehouseOut.ID,
  687. Count: 1,
  688. Status: 1,
  689. Ctime: time.Now().Unix(),
  690. Remark: "",
  691. OrgId: adminUserInfo.CurrentOrgId,
  692. Type: 1,
  693. Manufacturer: 0,
  694. Dealer: 0,
  695. IsSys: 1,
  696. SysRecordTime: startDate.Unix(),
  697. }
  698. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.CurrentOrgId)
  699. warehouseOutInfo.Price = stockInInfo.Price
  700. warehouseOutInfo.GoodId = prescription.Jms
  701. warehouseOutInfo.GoodTypeId = jms
  702. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  703. if err == nil {
  704. details := &models.AutomaticReduceDetail{
  705. WarehouseOutId: warehouseOutInfo.ID,
  706. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  707. PatientId: patientID,
  708. Ctime: time.Now().Unix(),
  709. Mtime: time.Now().Unix(),
  710. Status: 1,
  711. RecordTime: startDate.Unix(),
  712. OrgId: adminUserInfo.CurrentOrgId,
  713. GoodId: prescription.Jms,
  714. GoodTypeId: jms,
  715. }
  716. service.AddSigleAutoReduceRecordInfo(details)
  717. }
  718. }
  719. if prescription.FistulaNeedleSet > 0 {
  720. warehouseOutInfo := &models.WarehouseOutInfo{
  721. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  722. WarehouseOutId: warehouseOut.ID,
  723. Count: 1,
  724. Status: 1,
  725. Ctime: time.Now().Unix(),
  726. Remark: "",
  727. OrgId: adminUserInfo.CurrentOrgId,
  728. Type: 1,
  729. Manufacturer: 0,
  730. Dealer: 0,
  731. IsSys: 1,
  732. SysRecordTime: startDate.Unix(),
  733. }
  734. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.CurrentOrgId)
  735. warehouseOutInfo.Price = stockInInfo.Price
  736. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  737. warehouseOutInfo.GoodTypeId = fistula_needle_set
  738. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  739. if err == nil {
  740. details := &models.AutomaticReduceDetail{
  741. WarehouseOutId: warehouseOutInfo.ID,
  742. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  743. PatientId: patientID,
  744. Ctime: time.Now().Unix(),
  745. Mtime: time.Now().Unix(),
  746. Status: 1,
  747. RecordTime: startDate.Unix(),
  748. OrgId: adminUserInfo.CurrentOrgId,
  749. GoodId: prescription.FistulaNeedleSet,
  750. GoodTypeId: fistula_needle_set,
  751. }
  752. service.AddSigleAutoReduceRecordInfo(details)
  753. }
  754. }
  755. if prescription.FistulaNeedleSet16 > 0 {
  756. warehouseOutInfo := &models.WarehouseOutInfo{
  757. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  758. WarehouseOutId: warehouseOut.ID,
  759. Count: 1,
  760. Status: 1,
  761. Ctime: time.Now().Unix(),
  762. Remark: "",
  763. OrgId: adminUserInfo.CurrentOrgId,
  764. Type: 1,
  765. Manufacturer: 0,
  766. Dealer: 0,
  767. IsSys: 1,
  768. SysRecordTime: startDate.Unix(),
  769. }
  770. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.CurrentOrgId)
  771. warehouseOutInfo.Price = stockInInfo.Price
  772. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  773. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  774. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  775. if err == nil {
  776. details := &models.AutomaticReduceDetail{
  777. WarehouseOutId: warehouseOutInfo.ID,
  778. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  779. PatientId: patientID,
  780. Ctime: time.Now().Unix(),
  781. Mtime: time.Now().Unix(),
  782. Status: 1,
  783. RecordTime: startDate.Unix(),
  784. OrgId: adminUserInfo.CurrentOrgId,
  785. GoodId: prescription.FistulaNeedleSet16,
  786. GoodTypeId: fistula_needle_set_16,
  787. }
  788. service.AddSigleAutoReduceRecordInfo(details)
  789. }
  790. }
  791. if prescription.Hemoperfusion > 0 {
  792. warehouseOutInfo := &models.WarehouseOutInfo{
  793. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  794. WarehouseOutId: warehouseOut.ID,
  795. Count: 1,
  796. Status: 1,
  797. Ctime: time.Now().Unix(),
  798. Remark: "",
  799. OrgId: adminUserInfo.CurrentOrgId,
  800. Type: 1,
  801. Manufacturer: 0,
  802. Dealer: 0,
  803. IsSys: 1,
  804. SysRecordTime: startDate.Unix(),
  805. }
  806. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.CurrentOrgId)
  807. warehouseOutInfo.Price = stockInInfo.Price
  808. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  809. warehouseOutInfo.GoodTypeId = hemoperfusion
  810. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  811. if err == nil {
  812. details := &models.AutomaticReduceDetail{
  813. WarehouseOutId: warehouseOutInfo.ID,
  814. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  815. PatientId: patientID,
  816. Ctime: time.Now().Unix(),
  817. Mtime: time.Now().Unix(),
  818. Status: 1,
  819. RecordTime: startDate.Unix(),
  820. OrgId: adminUserInfo.CurrentOrgId,
  821. GoodId: prescription.Hemoperfusion,
  822. GoodTypeId: hemoperfusion,
  823. }
  824. service.AddSigleAutoReduceRecordInfo(details)
  825. }
  826. }
  827. if prescription.DialyserSterilised > 0 {
  828. warehouseOutInfo := &models.WarehouseOutInfo{
  829. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  830. WarehouseOutId: warehouseOut.ID,
  831. Count: 1,
  832. Status: 1,
  833. Ctime: time.Now().Unix(),
  834. Remark: "",
  835. OrgId: adminUserInfo.CurrentOrgId,
  836. Type: 1,
  837. Manufacturer: 0,
  838. Dealer: 0,
  839. IsSys: 1,
  840. SysRecordTime: startDate.Unix(),
  841. }
  842. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.CurrentOrgId)
  843. warehouseOutInfo.Price = stockInInfo.Price
  844. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  845. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  846. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  847. if err == nil {
  848. details := &models.AutomaticReduceDetail{
  849. WarehouseOutId: warehouseOutInfo.ID,
  850. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  851. PatientId: patientID,
  852. Ctime: time.Now().Unix(),
  853. Mtime: time.Now().Unix(),
  854. Status: 1,
  855. RecordTime: startDate.Unix(),
  856. OrgId: adminUserInfo.CurrentOrgId,
  857. GoodId: prescription.DialyserSterilised,
  858. GoodTypeId: dialyser_sterilised,
  859. }
  860. service.AddSigleAutoReduceRecordInfo(details)
  861. }
  862. }
  863. if prescription.Filtryzer > 0 {
  864. warehouseOutInfo := &models.WarehouseOutInfo{
  865. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  866. WarehouseOutId: warehouseOut.ID,
  867. Count: 1,
  868. Status: 1,
  869. Ctime: time.Now().Unix(),
  870. Remark: "",
  871. OrgId: adminUserInfo.CurrentOrgId,
  872. Type: 1,
  873. Manufacturer: 0,
  874. Dealer: 0,
  875. IsSys: 1,
  876. SysRecordTime: startDate.Unix(),
  877. }
  878. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.CurrentOrgId)
  879. warehouseOutInfo.Price = stockInInfo.Price
  880. warehouseOutInfo.GoodId = prescription.Filtryzer
  881. warehouseOutInfo.GoodTypeId = filtryzer
  882. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  883. if err == nil {
  884. details := &models.AutomaticReduceDetail{
  885. WarehouseOutId: warehouseOutInfo.ID,
  886. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  887. PatientId: patientID,
  888. Ctime: time.Now().Unix(),
  889. Mtime: time.Now().Unix(),
  890. Status: 1,
  891. RecordTime: startDate.Unix(),
  892. OrgId: adminUserInfo.CurrentOrgId,
  893. GoodId: prescription.Filtryzer,
  894. GoodTypeId: filtryzer,
  895. }
  896. service.AddSigleAutoReduceRecordInfo(details)
  897. }
  898. }
  899. if prescription.Dialyzers > 0 {
  900. warehouseOutInfo := &models.WarehouseOutInfo{
  901. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  902. WarehouseOutId: warehouseOut.ID,
  903. Count: 1,
  904. Status: 1,
  905. Ctime: time.Now().Unix(),
  906. Remark: "",
  907. OrgId: adminUserInfo.CurrentOrgId,
  908. Type: 1,
  909. Manufacturer: 0,
  910. Dealer: 0,
  911. IsSys: 1,
  912. SysRecordTime: startDate.Unix(),
  913. }
  914. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.CurrentOrgId)
  915. warehouseOutInfo.Price = stockInInfo.Price
  916. warehouseOutInfo.GoodId = prescription.Dialyzers
  917. warehouseOutInfo.GoodTypeId = dialyzers
  918. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  919. if err == nil {
  920. details := &models.AutomaticReduceDetail{
  921. WarehouseOutId: warehouseOutInfo.ID,
  922. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  923. PatientId: patientID,
  924. Ctime: time.Now().Unix(),
  925. Mtime: time.Now().Unix(),
  926. Status: 1,
  927. RecordTime: startDate.Unix(),
  928. OrgId: adminUserInfo.CurrentOrgId,
  929. GoodId: prescription.Dialyzers,
  930. GoodTypeId: dialyzers,
  931. }
  932. service.AddSigleAutoReduceRecordInfo(details)
  933. }
  934. }
  935. if prescription.Injector > 0 {
  936. warehouseOutInfo := &models.WarehouseOutInfo{
  937. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  938. WarehouseOutId: warehouseOut.ID,
  939. Count: 1,
  940. Status: 1,
  941. Ctime: time.Now().Unix(),
  942. Remark: "",
  943. OrgId: adminUserInfo.CurrentOrgId,
  944. Type: 1,
  945. Manufacturer: 0,
  946. Dealer: 0,
  947. IsSys: 1,
  948. SysRecordTime: startDate.Unix(),
  949. }
  950. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.CurrentOrgId)
  951. warehouseOutInfo.Price = stockInInfo.Price
  952. warehouseOutInfo.GoodId = prescription.Injector
  953. warehouseOutInfo.GoodTypeId = injector
  954. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  955. if err == nil {
  956. details := &models.AutomaticReduceDetail{
  957. WarehouseOutId: warehouseOutInfo.ID,
  958. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  959. PatientId: patientID,
  960. Ctime: time.Now().Unix(),
  961. Mtime: time.Now().Unix(),
  962. Status: 1,
  963. RecordTime: startDate.Unix(),
  964. OrgId: adminUserInfo.CurrentOrgId,
  965. GoodId: prescription.Injector,
  966. GoodTypeId: injector,
  967. }
  968. service.AddSigleAutoReduceRecordInfo(details)
  969. }
  970. }
  971. if prescription.Bloodlines > 0 {
  972. warehouseOutInfo := &models.WarehouseOutInfo{
  973. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  974. WarehouseOutId: warehouseOut.ID,
  975. Count: 1,
  976. Status: 1,
  977. Ctime: time.Now().Unix(),
  978. Remark: "",
  979. OrgId: adminUserInfo.CurrentOrgId,
  980. Type: 1,
  981. Manufacturer: 0,
  982. Dealer: 0,
  983. IsSys: 1,
  984. SysRecordTime: startDate.Unix(),
  985. }
  986. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.CurrentOrgId)
  987. warehouseOutInfo.Price = stockInInfo.Price
  988. warehouseOutInfo.GoodId = prescription.Bloodlines
  989. warehouseOutInfo.GoodTypeId = bloodlines
  990. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  991. if err == nil {
  992. details := &models.AutomaticReduceDetail{
  993. WarehouseOutId: warehouseOutInfo.ID,
  994. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  995. PatientId: patientID,
  996. Ctime: time.Now().Unix(),
  997. Mtime: time.Now().Unix(),
  998. Status: 1,
  999. RecordTime: startDate.Unix(),
  1000. OrgId: adminUserInfo.CurrentOrgId,
  1001. GoodId: prescription.Bloodlines,
  1002. GoodTypeId: bloodlines,
  1003. }
  1004. service.AddSigleAutoReduceRecordInfo(details)
  1005. }
  1006. }
  1007. if prescription.TubingHemodialysis > 0 {
  1008. warehouseOutInfo := &models.WarehouseOutInfo{
  1009. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1010. WarehouseOutId: warehouseOut.ID,
  1011. Count: 1,
  1012. Status: 1,
  1013. Ctime: time.Now().Unix(),
  1014. Remark: "",
  1015. OrgId: adminUserInfo.CurrentOrgId,
  1016. Type: 1,
  1017. Manufacturer: 0,
  1018. Dealer: 0,
  1019. IsSys: 1,
  1020. SysRecordTime: startDate.Unix(),
  1021. }
  1022. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.CurrentOrgId)
  1023. warehouseOutInfo.Price = stockInInfo.Price
  1024. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  1025. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  1026. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1027. if err == nil {
  1028. details := &models.AutomaticReduceDetail{
  1029. WarehouseOutId: warehouseOutInfo.ID,
  1030. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1031. PatientId: patientID,
  1032. Ctime: time.Now().Unix(),
  1033. Mtime: time.Now().Unix(),
  1034. Status: 1,
  1035. RecordTime: startDate.Unix(),
  1036. OrgId: adminUserInfo.CurrentOrgId,
  1037. GoodId: prescription.TubingHemodialysis,
  1038. GoodTypeId: tubingHemodialysis,
  1039. }
  1040. service.AddSigleAutoReduceRecordInfo(details)
  1041. }
  1042. }
  1043. if prescription.Package > 0 {
  1044. warehouseOutInfo := &models.WarehouseOutInfo{
  1045. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1046. WarehouseOutId: warehouseOut.ID,
  1047. Count: 1,
  1048. Status: 1,
  1049. Ctime: time.Now().Unix(),
  1050. Remark: "",
  1051. OrgId: adminUserInfo.CurrentOrgId,
  1052. Type: 1,
  1053. Manufacturer: 0,
  1054. Dealer: 0,
  1055. IsSys: 1,
  1056. SysRecordTime: startDate.Unix(),
  1057. }
  1058. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.CurrentOrgId)
  1059. warehouseOutInfo.Price = stockInInfo.Price
  1060. warehouseOutInfo.GoodId = prescription.Package
  1061. warehouseOutInfo.GoodTypeId = safe_package
  1062. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1063. if err == nil {
  1064. details := &models.AutomaticReduceDetail{
  1065. WarehouseOutId: warehouseOutInfo.ID,
  1066. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1067. PatientId: patientID,
  1068. Ctime: time.Now().Unix(),
  1069. Mtime: time.Now().Unix(),
  1070. Status: 1,
  1071. RecordTime: startDate.Unix(),
  1072. OrgId: adminUserInfo.CurrentOrgId,
  1073. GoodId: prescription.Package,
  1074. GoodTypeId: safe_package,
  1075. }
  1076. service.AddSigleAutoReduceRecordInfo(details)
  1077. }
  1078. }
  1079. if prescription.ALiquid > 0 {
  1080. warehouseOutInfo := &models.WarehouseOutInfo{
  1081. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1082. WarehouseOutId: warehouseOut.ID,
  1083. Count: 1,
  1084. Status: 1,
  1085. Ctime: time.Now().Unix(),
  1086. Remark: "",
  1087. OrgId: adminUserInfo.CurrentOrgId,
  1088. Type: 1,
  1089. Manufacturer: 0,
  1090. Dealer: 0,
  1091. IsSys: 1,
  1092. SysRecordTime: startDate.Unix(),
  1093. }
  1094. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.CurrentOrgId)
  1095. warehouseOutInfo.Price = stockInInfo.Price
  1096. warehouseOutInfo.GoodId = prescription.ALiquid
  1097. warehouseOutInfo.GoodTypeId = aliquid
  1098. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1099. if err == nil {
  1100. details := &models.AutomaticReduceDetail{
  1101. WarehouseOutId: warehouseOutInfo.ID,
  1102. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1103. PatientId: patientID,
  1104. Ctime: time.Now().Unix(),
  1105. Mtime: time.Now().Unix(),
  1106. Status: 1,
  1107. RecordTime: startDate.Unix(),
  1108. OrgId: adminUserInfo.CurrentOrgId,
  1109. GoodId: prescription.ALiquid,
  1110. GoodTypeId: aliquid,
  1111. }
  1112. service.AddSigleAutoReduceRecordInfo(details)
  1113. }
  1114. }
  1115. }
  1116. } else if err == nil {
  1117. if out.ID > 0 {
  1118. if prescription.Niprocart > 0 {
  1119. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, niprocart, prescription.Niprocart, out.WarehouseOutOrderNumber)
  1120. if err == gorm.ErrRecordNotFound {
  1121. warehouseOutInfo := &models.WarehouseOutInfo{
  1122. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1123. WarehouseOutId: out.ID,
  1124. Status: 1,
  1125. Ctime: time.Now().Unix(),
  1126. Remark: "",
  1127. OrgId: adminUserInfo.CurrentOrgId,
  1128. Type: 1,
  1129. Manufacturer: 0,
  1130. Dealer: 0,
  1131. IsSys: 1,
  1132. SysRecordTime: startDate.Unix(),
  1133. }
  1134. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.CurrentOrgId)
  1135. warehouseOutInfo.Price = stockInInfo.Price
  1136. warehouseOutInfo.GoodId = prescription.Niprocart
  1137. warehouseOutInfo.GoodTypeId = niprocart
  1138. warehouseOutInfo.Count = 1
  1139. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1140. if err == nil {
  1141. details := &models.AutomaticReduceDetail{
  1142. WarehouseOutId: warehouseOutInfo.ID,
  1143. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1144. PatientId: patientID,
  1145. Ctime: time.Now().Unix(),
  1146. Mtime: time.Now().Unix(),
  1147. Status: 1,
  1148. RecordTime: startDate.Unix(),
  1149. OrgId: adminUserInfo.CurrentOrgId,
  1150. GoodId: prescription.Niprocart,
  1151. GoodTypeId: niprocart,
  1152. }
  1153. service.AddSigleAutoReduceRecordInfo(details)
  1154. }
  1155. } else if err == nil { //记录存在,则将数量加1
  1156. if outInfo.ID > 0 {
  1157. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1158. }
  1159. details := &models.AutomaticReduceDetail{
  1160. WarehouseOutId: outInfo.ID,
  1161. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1162. PatientId: patientID,
  1163. Ctime: time.Now().Unix(),
  1164. Mtime: time.Now().Unix(),
  1165. Status: 1,
  1166. RecordTime: startDate.Unix(),
  1167. OrgId: adminUserInfo.CurrentOrgId,
  1168. GoodId: prescription.Niprocart,
  1169. GoodTypeId: niprocart,
  1170. }
  1171. service.AddSigleAutoReduceRecordInfo(details)
  1172. }
  1173. }
  1174. if prescription.Jms > 0 {
  1175. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, jms, prescription.Jms, out.WarehouseOutOrderNumber)
  1176. if err == gorm.ErrRecordNotFound {
  1177. warehouseOutInfo := &models.WarehouseOutInfo{
  1178. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1179. WarehouseOutId: out.ID,
  1180. Status: 1,
  1181. Ctime: time.Now().Unix(),
  1182. Remark: "",
  1183. OrgId: adminUserInfo.CurrentOrgId,
  1184. Type: 1,
  1185. Manufacturer: 0,
  1186. Dealer: 0,
  1187. IsSys: 1,
  1188. SysRecordTime: startDate.Unix(),
  1189. }
  1190. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.CurrentOrgId)
  1191. warehouseOutInfo.Price = stockInInfo.Price
  1192. warehouseOutInfo.GoodId = prescription.Jms
  1193. warehouseOutInfo.GoodTypeId = jms
  1194. warehouseOutInfo.Count = 1
  1195. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1196. if err == nil {
  1197. details := &models.AutomaticReduceDetail{
  1198. WarehouseOutId: warehouseOutInfo.ID,
  1199. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1200. PatientId: patientID,
  1201. Ctime: time.Now().Unix(),
  1202. Mtime: time.Now().Unix(),
  1203. Status: 1,
  1204. RecordTime: startDate.Unix(),
  1205. OrgId: adminUserInfo.CurrentOrgId,
  1206. GoodId: prescription.Jms,
  1207. GoodTypeId: jms,
  1208. }
  1209. service.AddSigleAutoReduceRecordInfo(details)
  1210. }
  1211. } else if err == nil { //记录存在,则将数量加1
  1212. if outInfo.ID > 0 {
  1213. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1214. }
  1215. details := &models.AutomaticReduceDetail{
  1216. WarehouseOutId: outInfo.ID,
  1217. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1218. PatientId: patientID,
  1219. Ctime: time.Now().Unix(),
  1220. Mtime: time.Now().Unix(),
  1221. Status: 1,
  1222. RecordTime: startDate.Unix(),
  1223. OrgId: adminUserInfo.CurrentOrgId,
  1224. GoodId: prescription.Jms,
  1225. GoodTypeId: jms,
  1226. }
  1227. service.AddSigleAutoReduceRecordInfo(details)
  1228. }
  1229. }
  1230. if prescription.FistulaNeedleSet > 0 {
  1231. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, fistula_needle_set, prescription.FistulaNeedleSet, out.WarehouseOutOrderNumber)
  1232. if err == gorm.ErrRecordNotFound {
  1233. warehouseOutInfo := &models.WarehouseOutInfo{
  1234. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1235. WarehouseOutId: out.ID,
  1236. Status: 1,
  1237. Ctime: time.Now().Unix(),
  1238. Remark: "",
  1239. OrgId: adminUserInfo.CurrentOrgId,
  1240. Type: 1,
  1241. Manufacturer: 0,
  1242. Dealer: 0,
  1243. IsSys: 1,
  1244. SysRecordTime: startDate.Unix(),
  1245. }
  1246. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.CurrentOrgId)
  1247. warehouseOutInfo.Price = stockInInfo.Price
  1248. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  1249. warehouseOutInfo.GoodTypeId = fistula_needle_set
  1250. warehouseOutInfo.Count = 1
  1251. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1252. if err == nil {
  1253. details := &models.AutomaticReduceDetail{
  1254. WarehouseOutId: warehouseOutInfo.ID,
  1255. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1256. PatientId: patientID,
  1257. Ctime: time.Now().Unix(),
  1258. Mtime: time.Now().Unix(),
  1259. Status: 1,
  1260. RecordTime: startDate.Unix(),
  1261. OrgId: adminUserInfo.CurrentOrgId,
  1262. GoodId: prescription.FistulaNeedleSet,
  1263. GoodTypeId: fistula_needle_set,
  1264. }
  1265. service.AddSigleAutoReduceRecordInfo(details)
  1266. }
  1267. } else if err == nil { //记录存在,则将数量加1
  1268. if outInfo.ID > 0 {
  1269. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1270. }
  1271. details := &models.AutomaticReduceDetail{
  1272. WarehouseOutId: outInfo.ID,
  1273. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1274. PatientId: patientID,
  1275. Ctime: time.Now().Unix(),
  1276. Mtime: time.Now().Unix(),
  1277. Status: 1,
  1278. RecordTime: startDate.Unix(),
  1279. OrgId: adminUserInfo.CurrentOrgId,
  1280. GoodId: prescription.FistulaNeedleSet,
  1281. GoodTypeId: fistula_needle_set,
  1282. }
  1283. service.AddSigleAutoReduceRecordInfo(details)
  1284. }
  1285. }
  1286. if prescription.FistulaNeedleSet16 > 0 {
  1287. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, fistula_needle_set_16, prescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber)
  1288. if err == gorm.ErrRecordNotFound {
  1289. warehouseOutInfo := &models.WarehouseOutInfo{
  1290. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1291. WarehouseOutId: out.ID,
  1292. Status: 1,
  1293. Ctime: time.Now().Unix(),
  1294. Remark: "",
  1295. OrgId: adminUserInfo.CurrentOrgId,
  1296. Type: 1,
  1297. Manufacturer: 0,
  1298. Dealer: 0,
  1299. IsSys: 1,
  1300. SysRecordTime: startDate.Unix(),
  1301. }
  1302. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.CurrentOrgId)
  1303. warehouseOutInfo.Price = stockInInfo.Price
  1304. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  1305. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  1306. warehouseOutInfo.Count = 1
  1307. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1308. if err == nil {
  1309. details := &models.AutomaticReduceDetail{
  1310. WarehouseOutId: warehouseOutInfo.ID,
  1311. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1312. PatientId: patientID,
  1313. Ctime: time.Now().Unix(),
  1314. Mtime: time.Now().Unix(),
  1315. Status: 1,
  1316. RecordTime: startDate.Unix(),
  1317. OrgId: adminUserInfo.CurrentOrgId,
  1318. GoodId: prescription.FistulaNeedleSet16,
  1319. GoodTypeId: fistula_needle_set_16,
  1320. }
  1321. service.AddSigleAutoReduceRecordInfo(details)
  1322. }
  1323. } else if err == nil { //记录存在,则将数量加1
  1324. if outInfo.ID > 0 {
  1325. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1326. }
  1327. details := &models.AutomaticReduceDetail{
  1328. WarehouseOutId: outInfo.ID,
  1329. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1330. PatientId: patientID,
  1331. Ctime: time.Now().Unix(),
  1332. Mtime: time.Now().Unix(),
  1333. Status: 1,
  1334. RecordTime: startDate.Unix(),
  1335. OrgId: adminUserInfo.CurrentOrgId,
  1336. GoodId: prescription.FistulaNeedleSet16,
  1337. GoodTypeId: fistula_needle_set_16,
  1338. }
  1339. service.AddSigleAutoReduceRecordInfo(details)
  1340. }
  1341. }
  1342. if prescription.Hemoperfusion > 0 {
  1343. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, hemoperfusion, prescription.Hemoperfusion, out.WarehouseOutOrderNumber)
  1344. if err == gorm.ErrRecordNotFound {
  1345. warehouseOutInfo := &models.WarehouseOutInfo{
  1346. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1347. WarehouseOutId: out.ID,
  1348. Status: 1,
  1349. Ctime: time.Now().Unix(),
  1350. Remark: "",
  1351. OrgId: adminUserInfo.CurrentOrgId,
  1352. Type: 1,
  1353. Manufacturer: 0,
  1354. Dealer: 0,
  1355. IsSys: 1,
  1356. SysRecordTime: startDate.Unix(),
  1357. }
  1358. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.CurrentOrgId)
  1359. warehouseOutInfo.Price = stockInInfo.Price
  1360. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  1361. warehouseOutInfo.GoodTypeId = hemoperfusion
  1362. warehouseOutInfo.Count = 1
  1363. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1364. if err == nil {
  1365. details := &models.AutomaticReduceDetail{
  1366. WarehouseOutId: warehouseOutInfo.ID,
  1367. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1368. PatientId: patientID,
  1369. Ctime: time.Now().Unix(),
  1370. Mtime: time.Now().Unix(),
  1371. Status: 1,
  1372. RecordTime: startDate.Unix(),
  1373. OrgId: adminUserInfo.CurrentOrgId,
  1374. GoodId: prescription.Hemoperfusion,
  1375. GoodTypeId: hemoperfusion,
  1376. }
  1377. service.AddSigleAutoReduceRecordInfo(details)
  1378. }
  1379. } else if err == nil { //记录存在,则将数量加1
  1380. if outInfo.ID > 0 {
  1381. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1382. }
  1383. details := &models.AutomaticReduceDetail{
  1384. WarehouseOutId: outInfo.ID,
  1385. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1386. PatientId: patientID,
  1387. Ctime: time.Now().Unix(),
  1388. Mtime: time.Now().Unix(),
  1389. Status: 1,
  1390. RecordTime: startDate.Unix(),
  1391. OrgId: adminUserInfo.CurrentOrgId,
  1392. GoodId: prescription.Hemoperfusion,
  1393. GoodTypeId: hemoperfusion,
  1394. }
  1395. service.AddSigleAutoReduceRecordInfo(details)
  1396. }
  1397. }
  1398. if prescription.DialyserSterilised > 0 {
  1399. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, dialyser_sterilised, prescription.DialyserSterilised, out.WarehouseOutOrderNumber)
  1400. if err == gorm.ErrRecordNotFound {
  1401. warehouseOutInfo := &models.WarehouseOutInfo{
  1402. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1403. WarehouseOutId: out.ID,
  1404. Status: 1,
  1405. Ctime: time.Now().Unix(),
  1406. Remark: "",
  1407. OrgId: adminUserInfo.CurrentOrgId,
  1408. Type: 1,
  1409. Manufacturer: 0,
  1410. Dealer: 0,
  1411. IsSys: 1,
  1412. SysRecordTime: startDate.Unix(),
  1413. }
  1414. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.CurrentOrgId)
  1415. warehouseOutInfo.Price = stockInInfo.Price
  1416. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  1417. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  1418. warehouseOutInfo.Count = 1
  1419. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1420. if err == nil {
  1421. details := &models.AutomaticReduceDetail{
  1422. WarehouseOutId: warehouseOutInfo.ID,
  1423. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1424. PatientId: patientID,
  1425. Ctime: time.Now().Unix(),
  1426. Mtime: time.Now().Unix(),
  1427. Status: 1,
  1428. RecordTime: startDate.Unix(),
  1429. OrgId: adminUserInfo.CurrentOrgId,
  1430. GoodId: prescription.DialyserSterilised,
  1431. GoodTypeId: dialyser_sterilised,
  1432. }
  1433. service.AddSigleAutoReduceRecordInfo(details)
  1434. }
  1435. } else if err == nil { //记录存在,则将数量加1
  1436. if outInfo.ID > 0 {
  1437. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1438. }
  1439. details := &models.AutomaticReduceDetail{
  1440. WarehouseOutId: outInfo.ID,
  1441. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1442. PatientId: patientID,
  1443. Ctime: time.Now().Unix(),
  1444. Mtime: time.Now().Unix(),
  1445. Status: 1,
  1446. RecordTime: startDate.Unix(),
  1447. OrgId: adminUserInfo.CurrentOrgId,
  1448. GoodId: prescription.DialyserSterilised,
  1449. GoodTypeId: dialyser_sterilised,
  1450. }
  1451. service.AddSigleAutoReduceRecordInfo(details)
  1452. }
  1453. }
  1454. if prescription.Filtryzer > 0 {
  1455. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, filtryzer, prescription.Filtryzer, out.WarehouseOutOrderNumber)
  1456. if err == gorm.ErrRecordNotFound {
  1457. warehouseOutInfo := &models.WarehouseOutInfo{
  1458. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1459. WarehouseOutId: out.ID,
  1460. Status: 1,
  1461. Ctime: time.Now().Unix(),
  1462. Remark: "",
  1463. OrgId: adminUserInfo.CurrentOrgId,
  1464. Type: 1,
  1465. Manufacturer: 0,
  1466. Dealer: 0,
  1467. IsSys: 1,
  1468. SysRecordTime: startDate.Unix(),
  1469. }
  1470. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.CurrentOrgId)
  1471. warehouseOutInfo.Price = stockInInfo.Price
  1472. warehouseOutInfo.GoodId = prescription.Filtryzer
  1473. warehouseOutInfo.GoodTypeId = filtryzer
  1474. warehouseOutInfo.Count = 1
  1475. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1476. if err == nil {
  1477. details := &models.AutomaticReduceDetail{
  1478. WarehouseOutId: warehouseOutInfo.ID,
  1479. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1480. PatientId: patientID,
  1481. Ctime: time.Now().Unix(),
  1482. Mtime: time.Now().Unix(),
  1483. Status: 1,
  1484. RecordTime: startDate.Unix(),
  1485. OrgId: adminUserInfo.CurrentOrgId,
  1486. GoodId: prescription.Filtryzer,
  1487. GoodTypeId: filtryzer,
  1488. }
  1489. service.AddSigleAutoReduceRecordInfo(details)
  1490. }
  1491. } else if err == nil { //记录存在,则将耗材使用数量加1
  1492. if outInfo.ID > 0 {
  1493. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1494. }
  1495. //插入病人耗材使用记录
  1496. details := &models.AutomaticReduceDetail{
  1497. WarehouseOutId: outInfo.ID,
  1498. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1499. PatientId: patientID,
  1500. Ctime: time.Now().Unix(),
  1501. Mtime: time.Now().Unix(),
  1502. Status: 1,
  1503. RecordTime: startDate.Unix(),
  1504. OrgId: adminUserInfo.CurrentOrgId,
  1505. GoodId: prescription.Filtryzer,
  1506. GoodTypeId: filtryzer,
  1507. }
  1508. service.AddSigleAutoReduceRecordInfo(details)
  1509. }
  1510. }
  1511. if prescription.Dialyzers > 0 {
  1512. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, dialyzers, prescription.Dialyzers, out.WarehouseOutOrderNumber)
  1513. if err == gorm.ErrRecordNotFound {
  1514. warehouseOutInfo := &models.WarehouseOutInfo{
  1515. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1516. WarehouseOutId: out.ID,
  1517. Status: 1,
  1518. Ctime: time.Now().Unix(),
  1519. Remark: "",
  1520. OrgId: adminUserInfo.CurrentOrgId,
  1521. Type: 1,
  1522. Manufacturer: 0,
  1523. Dealer: 0,
  1524. IsSys: 1,
  1525. SysRecordTime: startDate.Unix(),
  1526. }
  1527. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.CurrentOrgId)
  1528. warehouseOutInfo.Price = stockInInfo.Price
  1529. warehouseOutInfo.GoodId = prescription.Dialyzers
  1530. warehouseOutInfo.GoodTypeId = dialyzers
  1531. warehouseOutInfo.Count = 1
  1532. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1533. if err == nil {
  1534. details := &models.AutomaticReduceDetail{
  1535. WarehouseOutId: warehouseOutInfo.ID,
  1536. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1537. PatientId: patientID,
  1538. Ctime: time.Now().Unix(),
  1539. Mtime: time.Now().Unix(),
  1540. Status: 1,
  1541. RecordTime: startDate.Unix(),
  1542. OrgId: adminUserInfo.CurrentOrgId,
  1543. GoodId: prescription.Dialyzers,
  1544. GoodTypeId: dialyzers,
  1545. }
  1546. service.AddSigleAutoReduceRecordInfo(details)
  1547. }
  1548. } else if err == nil { //记录存在,则将耗材使用数量加1
  1549. if outInfo.ID > 0 {
  1550. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1551. }
  1552. //插入病人耗材使用记录
  1553. details := &models.AutomaticReduceDetail{
  1554. WarehouseOutId: outInfo.ID,
  1555. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1556. PatientId: patientID,
  1557. Ctime: time.Now().Unix(),
  1558. Mtime: time.Now().Unix(),
  1559. Status: 1,
  1560. RecordTime: startDate.Unix(),
  1561. OrgId: adminUserInfo.CurrentOrgId,
  1562. GoodId: prescription.Dialyzer,
  1563. GoodTypeId: dialyzers,
  1564. }
  1565. service.AddSigleAutoReduceRecordInfo(details)
  1566. }
  1567. }
  1568. if prescription.Injector > 0 {
  1569. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, injector, prescription.Injector, out.WarehouseOutOrderNumber)
  1570. if err == gorm.ErrRecordNotFound {
  1571. warehouseOutInfo := &models.WarehouseOutInfo{
  1572. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1573. WarehouseOutId: out.ID,
  1574. Status: 1,
  1575. Ctime: time.Now().Unix(),
  1576. Remark: "",
  1577. OrgId: adminUserInfo.CurrentOrgId,
  1578. Type: 1,
  1579. Manufacturer: 0,
  1580. Dealer: 0,
  1581. IsSys: 1,
  1582. SysRecordTime: startDate.Unix(),
  1583. }
  1584. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.CurrentOrgId)
  1585. warehouseOutInfo.Price = stockInInfo.Price
  1586. warehouseOutInfo.GoodId = prescription.Injector
  1587. warehouseOutInfo.GoodTypeId = injector
  1588. warehouseOutInfo.Count = 1
  1589. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1590. if err == nil {
  1591. details := &models.AutomaticReduceDetail{
  1592. WarehouseOutId: warehouseOutInfo.ID,
  1593. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1594. PatientId: patientID,
  1595. Ctime: time.Now().Unix(),
  1596. Mtime: time.Now().Unix(),
  1597. Status: 1,
  1598. RecordTime: startDate.Unix(),
  1599. OrgId: adminUserInfo.CurrentOrgId,
  1600. GoodId: prescription.Injector,
  1601. GoodTypeId: injector,
  1602. }
  1603. service.AddSigleAutoReduceRecordInfo(details)
  1604. }
  1605. } else if err == nil { //记录存在,则将耗材使用数量加1
  1606. if outInfo.ID > 0 {
  1607. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1608. }
  1609. //插入病人耗材使用记录
  1610. details := &models.AutomaticReduceDetail{
  1611. WarehouseOutId: outInfo.ID,
  1612. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1613. PatientId: patientID,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: time.Now().Unix(),
  1616. Status: 1,
  1617. RecordTime: startDate.Unix(),
  1618. OrgId: adminUserInfo.CurrentOrgId,
  1619. GoodId: prescription.Injector,
  1620. GoodTypeId: injector,
  1621. }
  1622. service.AddSigleAutoReduceRecordInfo(details)
  1623. }
  1624. }
  1625. if prescription.Bloodlines > 0 {
  1626. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, bloodlines, prescription.Bloodlines, out.WarehouseOutOrderNumber)
  1627. if err == gorm.ErrRecordNotFound {
  1628. warehouseOutInfo := &models.WarehouseOutInfo{
  1629. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1630. WarehouseOutId: out.ID,
  1631. Status: 1,
  1632. Ctime: time.Now().Unix(),
  1633. Remark: "",
  1634. OrgId: adminUserInfo.CurrentOrgId,
  1635. Type: 1,
  1636. Manufacturer: 0,
  1637. Dealer: 0,
  1638. IsSys: 1,
  1639. SysRecordTime: startDate.Unix(),
  1640. }
  1641. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.CurrentOrgId)
  1642. warehouseOutInfo.Price = stockInInfo.Price
  1643. warehouseOutInfo.GoodId = prescription.Bloodlines
  1644. warehouseOutInfo.GoodTypeId = bloodlines
  1645. warehouseOutInfo.Count = 1
  1646. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1647. if err == nil {
  1648. details := &models.AutomaticReduceDetail{
  1649. WarehouseOutId: warehouseOutInfo.ID,
  1650. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1651. PatientId: patientID,
  1652. Ctime: time.Now().Unix(),
  1653. Mtime: time.Now().Unix(),
  1654. Status: 1,
  1655. RecordTime: startDate.Unix(),
  1656. OrgId: adminUserInfo.CurrentOrgId,
  1657. GoodId: prescription.Bloodlines,
  1658. GoodTypeId: bloodlines,
  1659. }
  1660. service.AddSigleAutoReduceRecordInfo(details)
  1661. }
  1662. } else if err == nil { //记录存在,则将耗材使用数量加1
  1663. if outInfo.ID > 0 {
  1664. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1665. }
  1666. //插入病人耗材使用记录
  1667. details := &models.AutomaticReduceDetail{
  1668. WarehouseOutId: outInfo.ID,
  1669. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1670. PatientId: patientID,
  1671. Ctime: time.Now().Unix(),
  1672. Mtime: time.Now().Unix(),
  1673. Status: 1,
  1674. RecordTime: startDate.Unix(),
  1675. OrgId: adminUserInfo.CurrentOrgId,
  1676. GoodId: prescription.Bloodlines,
  1677. GoodTypeId: bloodlines,
  1678. }
  1679. service.AddSigleAutoReduceRecordInfo(details)
  1680. }
  1681. }
  1682. if prescription.TubingHemodialysis > 0 {
  1683. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, tubingHemodialysis, prescription.TubingHemodialysis, out.WarehouseOutOrderNumber)
  1684. if err == gorm.ErrRecordNotFound {
  1685. warehouseOutInfo := &models.WarehouseOutInfo{
  1686. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1687. WarehouseOutId: out.ID,
  1688. Status: 1,
  1689. Ctime: time.Now().Unix(),
  1690. Remark: "",
  1691. OrgId: adminUserInfo.CurrentOrgId,
  1692. Type: 1,
  1693. Manufacturer: 0,
  1694. Dealer: 0,
  1695. IsSys: 1,
  1696. SysRecordTime: startDate.Unix(),
  1697. }
  1698. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.CurrentOrgId)
  1699. warehouseOutInfo.Price = stockInInfo.Price
  1700. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  1701. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  1702. warehouseOutInfo.Count = 1
  1703. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1704. if err == nil {
  1705. details := &models.AutomaticReduceDetail{
  1706. WarehouseOutId: warehouseOutInfo.ID,
  1707. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1708. PatientId: patientID,
  1709. Ctime: time.Now().Unix(),
  1710. Mtime: time.Now().Unix(),
  1711. Status: 1,
  1712. RecordTime: startDate.Unix(),
  1713. OrgId: adminUserInfo.CurrentOrgId,
  1714. GoodId: prescription.TubingHemodialysis,
  1715. GoodTypeId: tubingHemodialysis,
  1716. }
  1717. service.AddSigleAutoReduceRecordInfo(details)
  1718. }
  1719. } else if err == nil { //记录存在,则将耗材使用数量加1
  1720. if outInfo.ID > 0 {
  1721. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1722. }
  1723. //插入病人耗材使用记录
  1724. details := &models.AutomaticReduceDetail{
  1725. WarehouseOutId: outInfo.ID,
  1726. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1727. PatientId: patientID,
  1728. Ctime: time.Now().Unix(),
  1729. Mtime: time.Now().Unix(),
  1730. Status: 1,
  1731. RecordTime: startDate.Unix(),
  1732. OrgId: adminUserInfo.CurrentOrgId,
  1733. GoodId: prescription.TubingHemodialysis,
  1734. GoodTypeId: tubingHemodialysis,
  1735. }
  1736. service.AddSigleAutoReduceRecordInfo(details)
  1737. }
  1738. }
  1739. if prescription.Package > 0 {
  1740. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, safe_package, prescription.Package, out.WarehouseOutOrderNumber)
  1741. if err == gorm.ErrRecordNotFound {
  1742. warehouseOutInfo := &models.WarehouseOutInfo{
  1743. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1744. WarehouseOutId: out.ID,
  1745. Status: 1,
  1746. Ctime: time.Now().Unix(),
  1747. Remark: "",
  1748. OrgId: adminUserInfo.CurrentOrgId,
  1749. Type: 1,
  1750. Manufacturer: 0,
  1751. Dealer: 0,
  1752. IsSys: 1,
  1753. SysRecordTime: startDate.Unix(),
  1754. }
  1755. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.CurrentOrgId)
  1756. warehouseOutInfo.Price = stockInInfo.Price
  1757. warehouseOutInfo.GoodId = prescription.Package
  1758. warehouseOutInfo.GoodTypeId = safe_package
  1759. warehouseOutInfo.Count = 1
  1760. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1761. if err == nil {
  1762. details := &models.AutomaticReduceDetail{
  1763. WarehouseOutId: warehouseOutInfo.ID,
  1764. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1765. PatientId: patientID,
  1766. Ctime: time.Now().Unix(),
  1767. Mtime: time.Now().Unix(),
  1768. Status: 1,
  1769. RecordTime: startDate.Unix(),
  1770. OrgId: adminUserInfo.CurrentOrgId,
  1771. GoodId: prescription.Package,
  1772. GoodTypeId: safe_package,
  1773. }
  1774. service.AddSigleAutoReduceRecordInfo(details)
  1775. }
  1776. } else if err == nil { //记录存在,则将耗材使用数量加1
  1777. if outInfo.ID > 0 {
  1778. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1779. }
  1780. //插入病人耗材使用记录
  1781. details := &models.AutomaticReduceDetail{
  1782. WarehouseOutId: outInfo.ID,
  1783. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1784. PatientId: patientID,
  1785. Ctime: time.Now().Unix(),
  1786. Mtime: time.Now().Unix(),
  1787. Status: 1,
  1788. RecordTime: startDate.Unix(),
  1789. OrgId: adminUserInfo.CurrentOrgId,
  1790. GoodId: prescription.Package,
  1791. GoodTypeId: safe_package,
  1792. }
  1793. service.AddSigleAutoReduceRecordInfo(details)
  1794. }
  1795. }
  1796. if prescription.ALiquid > 0 {
  1797. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, aliquid, prescription.ALiquid, out.WarehouseOutOrderNumber)
  1798. if err == gorm.ErrRecordNotFound {
  1799. warehouseOutInfo := &models.WarehouseOutInfo{
  1800. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1801. WarehouseOutId: out.ID,
  1802. Status: 1,
  1803. Ctime: time.Now().Unix(),
  1804. Remark: "",
  1805. OrgId: adminUserInfo.CurrentOrgId,
  1806. Type: 1,
  1807. Manufacturer: 0,
  1808. Dealer: 0,
  1809. IsSys: 1,
  1810. SysRecordTime: startDate.Unix(),
  1811. }
  1812. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.CurrentOrgId)
  1813. warehouseOutInfo.Price = stockInInfo.Price
  1814. warehouseOutInfo.GoodId = prescription.ALiquid
  1815. warehouseOutInfo.GoodTypeId = aliquid
  1816. warehouseOutInfo.Count = 1
  1817. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1818. if err == nil {
  1819. details := &models.AutomaticReduceDetail{
  1820. WarehouseOutId: warehouseOutInfo.ID,
  1821. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1822. PatientId: patientID,
  1823. Ctime: time.Now().Unix(),
  1824. Mtime: time.Now().Unix(),
  1825. Status: 1,
  1826. RecordTime: startDate.Unix(),
  1827. OrgId: adminUserInfo.CurrentOrgId,
  1828. GoodId: prescription.ALiquid,
  1829. GoodTypeId: aliquid,
  1830. }
  1831. service.AddSigleAutoReduceRecordInfo(details)
  1832. }
  1833. } else if err == nil { //记录存在,则将耗材使用数量加1
  1834. if outInfo.ID > 0 {
  1835. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1836. }
  1837. //插入病人耗材使用记录
  1838. details := &models.AutomaticReduceDetail{
  1839. WarehouseOutId: outInfo.ID,
  1840. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1841. PatientId: patientID,
  1842. Ctime: time.Now().Unix(),
  1843. Mtime: time.Now().Unix(),
  1844. Status: 1,
  1845. RecordTime: startDate.Unix(),
  1846. OrgId: adminUserInfo.CurrentOrgId,
  1847. GoodId: prescription.ALiquid,
  1848. GoodTypeId: aliquid,
  1849. }
  1850. service.AddSigleAutoReduceRecordInfo(details)
  1851. }
  1852. }
  1853. }
  1854. }
  1855. } else {
  1856. this.ErrorLog("上机失败,还没开处方")
  1857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  1858. return
  1859. }
  1860. }
  1861. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1862. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1863. timeLayout := "2006-01-02 15:04:05"
  1864. loc, _ := time.LoadLocation("Local")
  1865. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1866. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1867. schedulestartTime := theStartTime.Unix()
  1868. scheduleendTime := theEndTime.Unix()
  1869. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1870. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1871. if err == gorm.ErrRecordNotFound { //空床位
  1872. // 修改了床位逻辑
  1873. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  1874. if daySchedule.ID > 0 {
  1875. daySchedule.PartitionId = deviceNumber.ZoneID
  1876. daySchedule.BedId = bedID
  1877. daySchedule.ScheduleType = schedual_type
  1878. daySchedule.UpdatedTime = time.Now().Unix()
  1879. err := service.UpdateSchedule(&daySchedule)
  1880. if err != nil {
  1881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1882. return
  1883. }
  1884. }
  1885. } else if err == nil {
  1886. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1887. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  1888. if daySchedule.ID > 0 {
  1889. daySchedule.PartitionId = deviceNumber.ZoneID
  1890. daySchedule.BedId = bedID
  1891. daySchedule.ScheduleType = schedual_type
  1892. daySchedule.UpdatedTime = time.Now().Unix()
  1893. err := service.UpdateSchedule(&daySchedule)
  1894. if err != nil {
  1895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1896. return
  1897. }
  1898. }
  1899. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1901. return
  1902. }
  1903. } else if err != nil {
  1904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1905. return
  1906. }
  1907. dialysisRecord = &models.DialysisOrder{
  1908. DialysisDate: recordDate.Unix(),
  1909. UserOrgId: adminUserInfo.CurrentOrgId,
  1910. PatientId: patientID,
  1911. Stage: 1,
  1912. BedID: bedID,
  1913. StartNurse: nurseID,
  1914. Status: 1,
  1915. StartTime: startDate.Unix(),
  1916. CreatedTime: time.Now().Unix(),
  1917. UpdatedTime: time.Now().Unix(),
  1918. PunctureNurse: punctureNurseId,
  1919. Creator: adminUserInfo.AdminUser.Id,
  1920. Modifier: adminUserInfo.AdminUser.Id,
  1921. SchedualType: schedual_type,
  1922. }
  1923. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  1924. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1925. if createErr != nil {
  1926. this.ErrorLog("上机失败:%v", createErr)
  1927. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1928. return
  1929. } else if createErr == nil {
  1930. var tempdispose string
  1931. // 只针对中能建
  1932. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  1933. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1934. }
  1935. var ultrafiltration_rate float64
  1936. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  1937. if prescription.ID > 0 {
  1938. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1939. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1940. if template.TemplateId == 6 {
  1941. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1942. }
  1943. // 只针对方济医院
  1944. if template.TemplateId == 1 {
  1945. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1946. ultrafiltration_rate = value
  1947. }
  1948. }
  1949. }
  1950. record := models.MonitoringRecord{
  1951. UserOrgId: adminUserInfo.CurrentOrgId,
  1952. PatientId: patientID,
  1953. DialysisOrderId: dialysisRecord.ID,
  1954. MonitoringDate: schedulestartTime,
  1955. OperateTime: startDate.Unix(),
  1956. // MonitoringTime: recordTime,
  1957. MonitoringNurse: nurseID,
  1958. Dispose: tempdispose,
  1959. UltrafiltrationRate: ultrafiltration_rate,
  1960. UltrafiltrationVolume: 0,
  1961. Status: 1,
  1962. CreatedTime: time.Now().Unix(),
  1963. UpdatedTime: time.Now().Unix(),
  1964. }
  1965. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1966. if newdialysisRecord.ID > 0 {
  1967. err := service.CreateMonitor(&record)
  1968. if err != nil {
  1969. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1970. return
  1971. }
  1972. }
  1973. this.ServeSuccessJSON(map[string]interface{}{
  1974. "dialysis_order": dialysisRecord,
  1975. "monitor": record,
  1976. })
  1977. }
  1978. }
  1979. // /api/dialysis/finish [post]
  1980. // @param patient_id:int
  1981. // @param date:string 排班时间 (yyyy-mm-dd)
  1982. // @param nurse:int 下机护士
  1983. func (this *DialysisRecordAPIController) FinishDialysis() {
  1984. patientID, _ := this.GetInt64("patient_id")
  1985. recordDateStr := this.GetString("date")
  1986. nurseID, _ := this.GetInt64("nurse")
  1987. end_time := this.GetString("end_time")
  1988. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1990. return
  1991. }
  1992. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1993. if parseErr != nil {
  1994. this.ErrorLog("时间解析失败:%v", parseErr)
  1995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1996. return
  1997. }
  1998. //if parseEndDateErr != nil {
  1999. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  2000. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2001. // return
  2002. //}
  2003. adminUserInfo := this.GetAdminUserInfo()
  2004. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  2005. if getPatientErr != nil {
  2006. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2008. return
  2009. } else if patient == nil {
  2010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2011. return
  2012. }
  2013. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2014. if getNurseErr != nil {
  2015. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2017. return
  2018. } else if nurse == nil {
  2019. this.ErrorLog("护士不存在")
  2020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2021. return
  2022. }
  2023. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  2024. if getRecordErr != nil {
  2025. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2027. return
  2028. }
  2029. if dialysisRecord.Stage == 2 {
  2030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2031. return
  2032. }
  2033. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  2034. if parseEndDateErr != nil {
  2035. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2037. return
  2038. }
  2039. // 获取当天的第一条透析纪录
  2040. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  2041. if getMonitorRecordsErr != nil {
  2042. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2044. return
  2045. }
  2046. // 获取当前的最后一条透析纪录
  2047. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  2048. if getMonitorRecordsErr != nil {
  2049. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2051. return
  2052. }
  2053. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  2054. if getAADErr != nil {
  2055. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  2056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2057. return
  2058. }
  2059. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2060. if assessmentAfterDislysis != nil {
  2061. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2062. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2063. } else {
  2064. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2065. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2066. tempassessmentAfterDislysis.Status = 1
  2067. tempassessmentAfterDislysis.PatientId = patientID
  2068. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  2069. }
  2070. if dialysisRecord.Stage == 1 {
  2071. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  2072. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2073. fmt.Println(value)
  2074. a, b := math.Modf(value)
  2075. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2076. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2077. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2078. fmt.Println(hour)
  2079. fmt.Println(minute)
  2080. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2081. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2082. }
  2083. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2084. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2085. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2086. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2087. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2088. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2089. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2090. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2091. }
  2092. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2093. if err != nil {
  2094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2095. return
  2096. }
  2097. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  2098. if updateErr != nil {
  2099. this.ErrorLog("下机失败:%v", updateErr)
  2100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2101. return
  2102. } else {
  2103. dialysisRecord.Stage = 2
  2104. dialysisRecord.FinishNurse = nurseID
  2105. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  2106. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  2107. dialysisRecord.EndTime = endDate.Unix()
  2108. // 结束时候透析次数加1
  2109. service.UpdateSolutionByPatientId(patientID)
  2110. this.ServeSuccessJSON(map[string]interface{}{
  2111. "dialysis_order": dialysisRecord,
  2112. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2113. })
  2114. }
  2115. }
  2116. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  2117. record_id, _ := this.GetInt64("id")
  2118. nurseID, _ := this.GetInt64("nurse")
  2119. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2120. bedID, _ := this.GetInt64("bed")
  2121. start_time := this.GetString("start_time")
  2122. schedual_type, _ := this.GetInt64("schedual_type")
  2123. if record_id == 0 {
  2124. this.ErrorLog("id:%v", record_id)
  2125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2126. return
  2127. }
  2128. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  2129. if parseStartDateErr != nil {
  2130. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2131. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2132. return
  2133. }
  2134. adminUserInfo := this.GetAdminUserInfo()
  2135. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2136. if getNurseErr != nil {
  2137. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2138. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2139. return
  2140. } else if nurse == nil {
  2141. this.ErrorLog("护士不存在")
  2142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2143. return
  2144. }
  2145. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2146. if getNurseErr != nil {
  2147. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2149. return
  2150. } else if nurse == nil {
  2151. this.ErrorLog("护士不存在")
  2152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2153. return
  2154. }
  2155. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  2156. if getDeviceNumberErr != nil {
  2157. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2159. return
  2160. } else if deviceNumber == nil {
  2161. this.ErrorLog("床位号不存在")
  2162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2163. return
  2164. }
  2165. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2166. if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2167. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2168. if getPermissionErr != nil {
  2169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2170. return
  2171. } else if headNursePermission == nil {
  2172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2173. return
  2174. }
  2175. }
  2176. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2177. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2178. timeLayout := "2006-01-02 15:04:05"
  2179. loc, _ := time.LoadLocation("Local")
  2180. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2181. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2182. schedulestartTime := theStartTime.Unix()
  2183. scheduleendTime := theEndTime.Unix()
  2184. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2185. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  2186. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2187. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2188. if err == gorm.ErrRecordNotFound { //空床位
  2189. // 修改了床位逻辑
  2190. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2191. if daySchedule.ID > 0 {
  2192. daySchedule.BedId = bedID
  2193. daySchedule.PartitionId = deviceNumber.ZoneID
  2194. daySchedule.ScheduleType = schedual_type
  2195. daySchedule.UpdatedTime = time.Now().Unix()
  2196. err := service.UpdateSchedule(&daySchedule)
  2197. if err != nil {
  2198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2199. return
  2200. }
  2201. }
  2202. } else if err == nil {
  2203. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2204. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2205. if daySchedule.ID > 0 {
  2206. daySchedule.BedId = bedID
  2207. daySchedule.PartitionId = deviceNumber.ZoneID
  2208. daySchedule.ScheduleType = schedual_type
  2209. daySchedule.UpdatedTime = time.Now().Unix()
  2210. err := service.UpdateSchedule(&daySchedule)
  2211. if err != nil {
  2212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2213. return
  2214. }
  2215. }
  2216. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2218. return
  2219. }
  2220. } else if err != nil {
  2221. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2222. return
  2223. }
  2224. }
  2225. dialysisRecord := &models.DialysisOrder{
  2226. ID: record_id,
  2227. UserOrgId: adminUserInfo.CurrentOrgId,
  2228. BedID: bedID,
  2229. StartNurse: nurseID,
  2230. StartTime: startDate.Unix(),
  2231. PunctureNurse: puncture_nurse,
  2232. Creator: adminUserInfo.AdminUser.Id,
  2233. Modifier: adminUserInfo.AdminUser.Id,
  2234. SchedualType: schedual_type,
  2235. }
  2236. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2237. if updateErr != nil {
  2238. this.ErrorLog("修改上机失败:%v", updateErr)
  2239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2240. return
  2241. }
  2242. if updateErr == nil {
  2243. if tempDialysisRecord.Stage == 2 {
  2244. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2245. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2246. fmt.Println(value)
  2247. a, b := math.Modf(value)
  2248. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2249. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2250. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2251. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2252. if updateAssessmentErr != nil {
  2253. utils.ErrorLog("%v", updateAssessmentErr)
  2254. }
  2255. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  2256. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2257. this.ServeSuccessJSON(map[string]interface{}{
  2258. "dialysis_order": dialysisRecords,
  2259. "after": after,
  2260. })
  2261. } else {
  2262. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2263. this.ServeSuccessJSON(map[string]interface{}{
  2264. "dialysis_order": dialysisRecords,
  2265. })
  2266. }
  2267. }
  2268. }
  2269. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  2270. record_id, _ := c.GetInt64("id")
  2271. nurseID, _ := c.GetInt64("nurse")
  2272. end_time := c.GetString("end_time")
  2273. if record_id <= 0 || nurseID <= 0 {
  2274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2275. return
  2276. }
  2277. adminUserInfo := c.GetAdminUserInfo()
  2278. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2279. if getNurseErr != nil {
  2280. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2282. return
  2283. } else if nurse == nil {
  2284. c.ErrorLog("护士不存在")
  2285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2286. return
  2287. }
  2288. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  2289. if parseEndDateErr != nil {
  2290. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2292. return
  2293. }
  2294. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2295. if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2296. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2297. if getPermissionErr != nil {
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2299. return
  2300. } else if headNursePermission == nil {
  2301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2302. return
  2303. }
  2304. }
  2305. dialysisRecord := &models.DialysisOrder{
  2306. ID: record_id,
  2307. UserOrgId: adminUserInfo.CurrentOrgId,
  2308. EndTime: endDate.Unix(),
  2309. FinishNurse: nurseID,
  2310. FinishModifier: adminUserInfo.AdminUser.Id,
  2311. }
  2312. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2313. if updateErr != nil {
  2314. c.ErrorLog("修改下机失败:%v", updateErr)
  2315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2316. return
  2317. }
  2318. if updateErr == nil {
  2319. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2320. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2321. fmt.Println(value)
  2322. a, b := math.Modf(value)
  2323. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2324. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2325. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2326. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2327. if updateAssessmentErr != nil {
  2328. utils.ErrorLog("%v", updateAssessmentErr)
  2329. }
  2330. }
  2331. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  2332. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2333. c.ServeSuccessJSON(map[string]interface{}{
  2334. "dialysis_order": dialysisRecords,
  2335. "after": after,
  2336. })
  2337. }