dialysis_record_api_controller.go 108KB

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