dialysis_record_api_controller.go 107KB

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