dialysis_record_api_controller.go 107KB

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