dialysis_api_controller.go 157KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "XT_New/enums"
  11. "XT_New/models"
  12. "XT_New/service"
  13. "XT_New/utils"
  14. "math"
  15. )
  16. // type DialysisTestAPIController struct {
  17. // MobileBaseAPIController
  18. // }
  19. // [get]/m/api/test
  20. // func (this *DialysisTestAPIController) Test() {
  21. // orgID := int64(3907)
  22. // now := time.Now()
  23. // nextWeek := now.AddDate(0, 0, 7)
  24. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  25. // nextTwoWeek := now.AddDate(0, 0, 14)
  26. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  27. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  28. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  29. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  30. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  31. // return
  32. // }
  33. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  34. // if exchangeErr != nil {
  35. // this.ErrorLog("%v", exchangeErr)
  36. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  37. // return
  38. // }
  39. // this.ServeSuccessJSON(map[string]interface{}{
  40. // // "now": now,
  41. // // "next_week": nextWeek,f
  42. // // "next_week_mon": nextWeekMon,
  43. // // "next_week_sun": nextWeekSun,
  44. // // "next_two_week_mon": nextTwoWeekMon,
  45. // // "next_two_week_sun": nextTwoWeekSun,
  46. // "next_week_schs": nextWeekSchs,
  47. // "next_two_week_schs": nextTwoWeekSchs,
  48. // })
  49. // }
  50. type DialysisAPIController struct {
  51. MobileBaseAPIAuthController
  52. }
  53. // /m/api/scheduals [get]
  54. // @param type:int
  55. // @param date:string
  56. func (this *DialysisAPIController) Scheduals() {
  57. schedualType, _ := this.GetInt64("type")
  58. schedualDate := this.GetString("date")
  59. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  60. schedualType = 0
  61. }
  62. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  63. if parseDateErr != nil {
  64. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  65. return
  66. }
  67. adminInfo := this.GetMobileAdminUserInfo()
  68. orgID := adminInfo.Org.Id
  69. redis := service.RedisClient()
  70. defer redis.Close()
  71. // cur_date := time.Now().Format("2006-01-02")
  72. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  73. scheduals_json_str, _ := redis.Get(key).Result()
  74. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  75. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  76. if err != nil {
  77. this.ErrorLog("获取排班信息失败:%v", err)
  78. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  79. } else {
  80. if len(scheduals) > 0 {
  81. //缓存数据
  82. scheduals_json, err := json.Marshal(scheduals)
  83. if err == nil {
  84. redis.Set(key, scheduals_json, time.Second*30)
  85. }
  86. }
  87. this.ServeSuccessJSON(map[string]interface{}{
  88. "scheduals": scheduals,
  89. })
  90. }
  91. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  92. var dat []map[string]interface{}
  93. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  94. } else {
  95. }
  96. this.ServeSuccessJSON(map[string]interface{}{
  97. "scheduals": dat,
  98. "redis": "true",
  99. "date": schedualDate,
  100. })
  101. }
  102. }
  103. // /m/api/waiting_scheduals [get]
  104. // @param date:string
  105. func (this *DialysisAPIController) WaitingScheduals() {
  106. schedualDate := this.GetString("date")
  107. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  108. if parseDateErr != nil && len(schedualDate) != 0 {
  109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  110. return
  111. }
  112. adminInfo := this.GetMobileAdminUserInfo()
  113. orgID := adminInfo.Org.Id
  114. redis := service.RedisClient()
  115. defer redis.Close()
  116. // cur_date := time.Now().Format("2006-01-02")
  117. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  118. wait_scheduals, _ := redis.Get(key).Result()
  119. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  120. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  121. if err != nil {
  122. this.ErrorLog("获取排班信息失败:%v", err)
  123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  124. } else {
  125. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  126. for _, s := range scheduals {
  127. returnScheduals = append(returnScheduals, s)
  128. }
  129. if len(returnScheduals) > 0 {
  130. //缓存数据
  131. wait_scheduals_json, err := json.Marshal(scheduals)
  132. if err == nil {
  133. redis.Set(key, wait_scheduals_json, time.Second*30)
  134. }
  135. }
  136. this.ServeSuccessJSON(map[string]interface{}{
  137. "scheduals": scheduals,
  138. })
  139. }
  140. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  141. var dat []map[string]interface{}
  142. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  143. } else {
  144. }
  145. this.ServeSuccessJSON(map[string]interface{}{
  146. "scheduals": dat,
  147. "redis": "true",
  148. "date": schedualDate,
  149. })
  150. }
  151. }
  152. //else{
  153. // fmt.Println("33333333")
  154. //
  155. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  156. // if err != nil {
  157. // this.ErrorLog("获取排班信息失败:%v", err)
  158. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  159. // } else {
  160. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  161. // for _, s := range scheduals {
  162. //
  163. // returnScheduals = append(returnScheduals, s)
  164. // }
  165. //
  166. // this.ServeSuccessJSON(map[string]interface{}{
  167. // "scheduals": returnScheduals,
  168. // })
  169. // }
  170. //
  171. // }
  172. //if err == nil{
  173. //
  174. //
  175. //
  176. //
  177. //
  178. //}else{
  179. //}
  180. // /m/api/dialysis/record [get]
  181. // @param patient_id:int
  182. // @param date:string (yyyy-MM-dd)
  183. func (this *DialysisAPIController) DialysisRecord() {
  184. patientID, _ := this.GetInt64("patient_id")
  185. recordDateStr := this.GetString("date")
  186. if patientID <= 0 {
  187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. if len(recordDateStr) == 0 {
  191. recordDateStr = time.Now().Format("2006-01-02")
  192. }
  193. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  194. if parseDateErr != nil {
  195. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  197. return
  198. }
  199. adminInfo := this.GetMobileAdminUserInfo()
  200. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  201. if getPatientErr != nil {
  202. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  204. return
  205. } else if patient == nil {
  206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  207. return
  208. }
  209. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  210. // this.TraceLog("==================================%+v", schedual)
  211. if getSchedualErr != nil {
  212. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  214. return
  215. }
  216. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  217. if getRTARErr != nil {
  218. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  220. return
  221. }
  222. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  223. if getPEErr != nil {
  224. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  226. return
  227. }
  228. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  229. if getLPEErr != nil {
  230. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  232. return
  233. }
  234. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  235. if getDoctorAdvicesErr != nil {
  236. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  238. return
  239. }
  240. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  241. if getDialysisOrderErr != nil {
  242. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  244. return
  245. }
  246. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  247. if getDoubleCheckErr != nil {
  248. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  250. return
  251. }
  252. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  253. if getMonitorRecordsErr != nil {
  254. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  256. return
  257. }
  258. var lastMonitorRecord *models.MonitoringRecord
  259. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  260. if getLastErr != nil {
  261. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  263. return
  264. }
  265. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  266. if getAADErr != nil {
  267. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  268. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  269. return
  270. }
  271. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  272. if getLAADErr != nil {
  273. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  275. return
  276. }
  277. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  278. if getTreatmentSummaryErr != nil {
  279. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  281. return
  282. }
  283. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  284. //if getDialysisPrescribeErr != nil {
  285. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  286. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  287. // return
  288. //}
  289. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  290. //if getDialysisSolutionErr != nil {
  291. // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  292. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  293. // return
  294. //}
  295. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  296. //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
  297. //if getDialysisPrescribeErr != nil {
  298. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  299. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  300. // return
  301. //}
  302. //获取系统透析处方模版
  303. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  304. //if getSystemDialysisPrescribeErr != nil {
  305. // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  306. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  307. // return
  308. //}
  309. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  310. //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  311. if getLPEErr != nil {
  312. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  314. return
  315. }
  316. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  317. if getDryErr != nil {
  318. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  320. return
  321. }
  322. //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  323. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  324. //goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  325. //goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  326. operators, _ := service.GetAllStarfEs(adminInfo.Org.Id)
  327. //consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())
  328. //lastConsumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())
  329. returnData := map[string]interface{}{
  330. "patient": patient,
  331. "schedual": schedual,
  332. "prescription": dialysisPrescribe,
  333. "solution": dialysisSolution,
  334. "last_prescription": lastDialysisPrescribe,
  335. "receiver_treatment_access": receiverTreatmentAccess,
  336. "predialysis_evaluation": predialysisEvaluation,
  337. "doctor_advices": doctorAdvices,
  338. "double_check": doubleCheck,
  339. "assessment_after_dislysis": assessmentAfterDislysis,
  340. "treatment_summary": treatmentSummary,
  341. "monitor_records": monitorRecords,
  342. "dialysis_order": dialysisOrder,
  343. "operators": operators,
  344. "last_predialysis_evaluation": lastPredialysisEvaluation,
  345. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  346. "last_monitor_record": lastMonitorRecord,
  347. "config": gobalConfig,
  348. "dry_weight": lastDryWeightDislysis,
  349. "system_prescription": systemDialysisPrescribe,
  350. }
  351. this.ServeSuccessJSON(returnData)
  352. }
  353. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  354. adminInfo := c.GetMobileAdminUserInfo()
  355. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  356. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  357. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  358. returnData := map[string]interface{}{
  359. "admin_users": adminUsers,
  360. "devices": devices,
  361. "device_numbers": device_numbers,
  362. }
  363. c.ServeSuccessJSON(returnData)
  364. }
  365. func (c *DialysisAPIController) PostAtreatmentInfo() {
  366. id, _ := c.GetInt64("patient", 0)
  367. recordDateStr := c.GetString("record_date")
  368. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  369. summaryContent := c.GetString("summaryContent")
  370. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  371. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  372. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  373. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  374. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  375. nursingRecord := c.GetString("nursing_record")
  376. fmt.Println("护理记录", nursingRecord)
  377. specialRecord := c.GetString("special_record")
  378. fmt.Println("特殊记录", specialRecord)
  379. adminUserInfo := c.GetMobileAdminUserInfo()
  380. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  381. checkStaffId = adminUserInfo.AdminUser.Id
  382. deboardNurseId = adminUserInfo.AdminUser.Id
  383. treatDoctor = adminUserInfo.AdminUser.Id
  384. if id <= 0 {
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  386. return
  387. }
  388. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  389. if patient.ID == 0 {
  390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  391. return
  392. }
  393. if len(recordDateStr) == 0 {
  394. recordDateStr = time.Now().Format("2006-01-02")
  395. }
  396. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  397. if parseDateErr != nil {
  398. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  400. return
  401. }
  402. //now := time.Now()
  403. //year, month, day := now.Date()
  404. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  405. //todayTimeStamp := today_time.Unix()
  406. summary := models.TreatmentSummary{
  407. UserOrgId: adminUserInfo.Org.Id,
  408. PatientId: id,
  409. AssessmentDate: recordDate.Unix(),
  410. Mission: propagandaAndEducationContent,
  411. DialysisSummary: summaryContent,
  412. SjNurse: changeMedicalNurseId,
  413. ZlNurse: treatNurseId,
  414. HdNurse: checkStaffId,
  415. XjNurse: deboardNurseId,
  416. ZlDoctor: treatDoctor,
  417. CreatedTime: time.Now().Unix(),
  418. Status: 1,
  419. NursingRecord: nursingRecord,
  420. SpecialRecord: specialRecord,
  421. }
  422. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  423. if treatmentSummary.ID == 0 { //新增
  424. summary.Creater = adminUserInfo.AdminUser.Id
  425. service.AddSigleSummaryRecord(&summary)
  426. c.ServeSuccessJSON(map[string]interface{}{
  427. "summary": summary,
  428. })
  429. } else { //修改
  430. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  431. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  432. // if getPermissionErr != nil {
  433. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  434. // return
  435. // } else if headNursePermission == nil {
  436. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  437. // return
  438. // }
  439. //}
  440. summary.Creater = treatmentSummary.Creater
  441. summary.CreatedTime = treatmentSummary.CreatedTime
  442. summary.Modifier = adminUserInfo.AdminUser.Id
  443. summary.ID = treatmentSummary.ID
  444. service.UpdateSummeRecord(&summary)
  445. c.ServeSuccessJSON(map[string]interface{}{
  446. "summary": summary,
  447. })
  448. }
  449. }
  450. func (c *DialysisAPIController) PostDoubleCheck() {
  451. id, _ := c.GetInt64("patient", 0)
  452. recordDateStr := c.GetString("record_date")
  453. checkTimeStr := c.GetString("check_time")
  454. firstCheckTimeStr := c.GetString("first_check_time")
  455. creater, _ := c.GetInt64("creater", 0)
  456. modifier, _ := c.GetInt64("modifier", 0)
  457. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  458. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  459. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  460. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  461. dialysis_item_desc := c.GetString("dialysis_item_desc")
  462. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  463. vascular_access_desc := c.GetString("vascular_access_desc")
  464. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  465. collator, _ := c.GetInt64("collator", 0)
  466. if id <= 0 {
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  468. return
  469. }
  470. adminUserInfo := c.GetMobileAdminUserInfo()
  471. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  472. if patient.ID == 0 {
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  474. return
  475. }
  476. if len(recordDateStr) == 0 {
  477. recordDateStr = time.Now().Format("2006-01-02")
  478. }
  479. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  480. if parseDateErr != nil {
  481. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  483. return
  484. }
  485. var checkDate int64
  486. if len(checkTimeStr) == 0 {
  487. checkDate = 0
  488. } else {
  489. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  490. checkDate = checkDateUnix.Unix()
  491. }
  492. var firstCheckDate int64
  493. if len(firstCheckTimeStr) == 0 {
  494. firstCheckDate = 0
  495. } else {
  496. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  497. firstCheckDate = firstCheckDateUnix.Unix()
  498. }
  499. //now := time.Now()
  500. //year, month, day := now.Date()
  501. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  502. //todayTimeStamp := today_time.Unix()
  503. doubleCheck := models.DoubleCheck{
  504. UserOrgId: adminUserInfo.Org.Id,
  505. PatientId: id,
  506. DialysisItemCheck: dialysis_item_check,
  507. DialysisParameterCheck: dialysis_parameter_check,
  508. VascularAccessVerification: vascular_access_verification,
  509. PipelineConnectionCheck: pipeline_connection_check,
  510. DialysisItemDesc: dialysis_item_desc,
  511. DialysisParameterDesc: dialysis_parameter_desc,
  512. VascularAccessDesc: vascular_access_desc,
  513. PipelineConnectionDesc: pipeline_connection_desc,
  514. Collator: collator,
  515. Status: 1,
  516. CreatedTime: time.Now().Unix(),
  517. CheckDate: recordDate.Unix(),
  518. UpdatedTime: time.Now().Unix(),
  519. }
  520. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  521. if check.ID == 0 { //新增
  522. doubleCheck.FirstCheckTime = firstCheckDate
  523. doubleCheck.CheckTime = checkDate
  524. doubleCheck.Creater = creater
  525. doubleCheck.Modifier = modifier
  526. err := service.AddSigleDoubleCheck(&doubleCheck)
  527. if err == nil {
  528. c.ServeSuccessJSON(map[string]interface{}{
  529. "doubleCheck": &doubleCheck,
  530. })
  531. }
  532. } else { //修改
  533. doubleCheck.FirstCheckTime = firstCheckDate
  534. doubleCheck.CheckTime = checkDate
  535. doubleCheck.Creater = creater
  536. doubleCheck.Modifier = modifier
  537. doubleCheck.CreatedTime = check.CreatedTime
  538. doubleCheck.ID = check.ID
  539. err := service.UpdateDoubleCheck(&doubleCheck)
  540. if err == nil {
  541. c.ServeSuccessJSON(map[string]interface{}{
  542. "doubleCheck": &doubleCheck,
  543. })
  544. }
  545. }
  546. }
  547. func (c *DialysisAPIController) PostAcceptsAssessment() {
  548. id, _ := c.GetInt64("patient", 0)
  549. recordDateStr := c.GetString("record_date")
  550. way, _ := c.GetInt64("way", 0)
  551. consciousness, _ := c.GetInt64("consciousness", 0)
  552. appetite, _ := c.GetInt64("appetite", 0)
  553. condition, _ := c.GetInt64("condition", 0)
  554. posture, _ := c.GetInt64("posture")
  555. sick_condition, _ := c.GetInt64("sick_condition", 0)
  556. danger_level, _ := c.GetInt64("danger_level", 0)
  557. intake, _ := c.GetInt64("intake", 0)
  558. nutrition, _ := c.GetInt64("nutrition", 0)
  559. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  560. psychological_assessment_other := c.GetString("psychological_assessment_other")
  561. score := c.GetString("score")
  562. sick_condition_other := c.GetString("sick_condition_other")
  563. //precaution, _ := c.GetInt64("precaution", 0)
  564. precaution := c.GetString("precaution")
  565. precaution_other := c.GetString("precaution_other")
  566. psychological_other := c.GetString("psychological_other")
  567. admission_number := c.GetString("admission_number")
  568. if id <= 0 {
  569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  570. return
  571. }
  572. adminUserInfo := c.GetMobileAdminUserInfo()
  573. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  574. if patient.ID == 0 {
  575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  576. return
  577. }
  578. //now := time.Now()
  579. //year, month, day := now.Date()
  580. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  581. //todayTimeStamp := today_time.Unix()
  582. if len(recordDateStr) == 0 {
  583. recordDateStr = time.Now().Format("2006-01-02")
  584. }
  585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  586. if parseDateErr != nil {
  587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  592. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  593. UserOrgId: adminUserInfo.Org.Id,
  594. PatientId: id,
  595. RecordDate: recordDate.Unix(),
  596. Way: way,
  597. Consciousness: consciousness,
  598. Appetite: appetite,
  599. Condition: condition,
  600. SickCondition: sick_condition,
  601. DangerLevel: danger_level,
  602. Intake: intake,
  603. Nutrition: nutrition,
  604. PsychologicalAssessment: psychological_assessment,
  605. PsychologicalAssessmentOther: psychological_assessment_other,
  606. SickConditionOther: sick_condition_other,
  607. Posture: posture,
  608. CreatedTime: time.Now().Unix(),
  609. UpdateTime: time.Now().Unix(),
  610. Status: 1,
  611. Score: score,
  612. Precaution: precaution,
  613. PrecautionOther: precaution_other,
  614. PsychologicalOther: psychological_other,
  615. AdmissionNumber: admission_number,
  616. }
  617. if receiveTreatment.ID == 0 { //新增
  618. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  619. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  620. if err == nil {
  621. c.ServeSuccessJSON(map[string]interface{}{
  622. "receiveTreatmentAsses": receiveTreatmentAsses,
  623. })
  624. }
  625. } else { //修改
  626. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  627. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  628. // if getPermissionErr != nil {
  629. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  630. // return
  631. // } else if headNursePermission == nil {
  632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  633. // return
  634. // }
  635. //}
  636. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  637. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  638. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  639. receiveTreatmentAsses.ID = receiveTreatment.ID
  640. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  641. if err == nil {
  642. c.ServeSuccessJSON(map[string]interface{}{
  643. "receiveTreatmentAsses": receiveTreatmentAsses,
  644. })
  645. }
  646. }
  647. }
  648. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  649. id, _ := c.GetInt64("patient", 0)
  650. recordDateStr := c.GetString("record_date")
  651. weightAfter, _ := c.GetFloat("weight_after", 0)
  652. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  653. weightReduce, _ := c.GetFloat("weight_loss", 0)
  654. temperature, _ := c.GetFloat("temperature", 0)
  655. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  656. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  657. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  658. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  659. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  660. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  661. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  662. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  663. cruor := c.GetString("cruor")
  664. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  665. internalFistula := c.GetString("internal_fistula")
  666. catheter := c.GetString("catheter")
  667. complications := c.GetString("complication")
  668. remark := c.GetString("remark")
  669. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  670. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  671. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  672. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  673. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  674. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  675. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  676. patientGose, _ := c.GetInt64("patient_gose", 0)
  677. inpatientDepartment := c.GetString("inpatient_department")
  678. observationContent := c.GetString("observation_content")
  679. observationContentOther := c.GetString("observation_content_other")
  680. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  681. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  682. in_advance_reason := c.GetString("in_advance_reason")
  683. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  684. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  685. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  686. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  687. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  688. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  689. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  690. dialyzer, _ := c.GetInt64("dialyzer", 0)
  691. in_advance_reason_other := c.GetString("in_advance_reason_other")
  692. is_eat, _ := c.GetInt64("is_eat", 0)
  693. cvc_a, _ := c.GetFloat("cvc_a", 0)
  694. cvc_v, _ := c.GetFloat("cvc_v", 0)
  695. channels, _ := c.GetInt64("channel", 0)
  696. return_blood, _ := c.GetInt64("return_blood", 0)
  697. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  698. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  699. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  700. blood_flow, _ := c.GetInt64("blood_flow", 0)
  701. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  702. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  703. sealing_fluid_special := c.GetString("sealing_fluid_special")
  704. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  705. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  706. setting_pressure := c.GetString("setting_pressure")
  707. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  708. diastolic_pressure := c.GetString("diastolic_pressure")
  709. if id <= 0 {
  710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  711. return
  712. }
  713. adminUserInfo := c.GetMobileAdminUserInfo()
  714. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  715. if patient.ID == 0 {
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  717. return
  718. }
  719. if len(recordDateStr) == 0 {
  720. recordDateStr = time.Now().Format("2006-01-02")
  721. }
  722. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  723. if parseDateErr != nil {
  724. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  726. return
  727. }
  728. //now := time.Now()
  729. //year, month, day := now.Date()
  730. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  731. //todayTimeStamp := today_time.Unix()
  732. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  733. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  734. UserOrgId: adminUserInfo.Org.Id,
  735. PatientId: id,
  736. AssessmentDate: recordDate.Unix(),
  737. Temperature: temperature,
  738. PulseFrequency: pulse_frequency,
  739. BreathingRate: breathing_rate,
  740. SystolicBloodPressure: systolic_blood_pressure,
  741. DiastolicBloodPressure: diastolic_blood_pressure,
  742. ActualUltrafiltration: actual_ultrafiltration,
  743. ActualDisplacement: actual_displacement,
  744. ActualTreatmentHour: actualtreatHour,
  745. ActualTreatmentMinute: actualtreatmin,
  746. WeightAfter: weightAfter,
  747. AdditionalWeight: additionalWeight,
  748. WeightLoss: weightReduce,
  749. Cruor: cruor,
  750. SymptomAfterDialysis: symptomsAfterDialysi,
  751. InternalFistula: internalFistula,
  752. Catheter: catheter,
  753. Complication: complications,
  754. DialysisIntakes: dialysateVolume,
  755. CreatedTime: time.Now().Unix(),
  756. Status: 1,
  757. Remark: remark,
  758. BloodAccessPartId: blood_access_part_id,
  759. BloodAccessPartOperaId: blood_access_part_opera_id,
  760. DialysisIntakesUnit: dialysis_intakes_unit,
  761. PuncturePointOozingBlood: puncturePointOozingBlood,
  762. PuncturePointHaematoma: puncturePointHaematoma,
  763. InternalFistulaTremorAc: internalFistulaTremorAc,
  764. PatientGose: patientGose,
  765. InpatientDepartment: inpatientDepartment,
  766. ObservationContent: observationContent,
  767. ObservationContentOther: observationContentOther,
  768. DialysisProcess: dialysis_process,
  769. InAdvanceMinute: in_advance_minute,
  770. InAdvanceReason: in_advance_reason,
  771. HemostasisMinute: hemostasis_minute,
  772. HemostasisOpera: hemostasis_opera,
  773. TremorNoise: tremor_noise,
  774. DisequilibriumSyndrome: disequilibrium_syndrome,
  775. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  776. ArterialTube: arterial_tube,
  777. IntravenousTube: intravenous_tube,
  778. Dialyzer: dialyzer,
  779. InAdvanceReasonOther: in_advance_reason_other,
  780. IsEat: is_eat,
  781. CvcA: cvc_a,
  782. CvcV: cvc_v,
  783. Channel: channels,
  784. ReturnBlood: return_blood,
  785. RehydrationVolume: rehydration_volume,
  786. DialysisDuring: dialysis_during,
  787. StrokeVolume: stroke_volume,
  788. BloodFlow: blood_flow,
  789. SealingFluidDispose: sealing_fluid_dispose,
  790. SealingFluidSpecial: sealing_fluid_special,
  791. DosageOfAnticoagulants: dosage_of_anticoagulants,
  792. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  793. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  794. SettingPressure: setting_pressure,
  795. DiastolicPressure: diastolic_pressure,
  796. }
  797. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  798. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  799. if assessmentAfter.ID == 0 { //新增
  800. if appRole.UserType == 2 || appRole.UserType == 1 {
  801. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  802. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  803. } else {
  804. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  805. }
  806. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  807. if err == nil {
  808. c.ServeSuccessJSON(map[string]interface{}{
  809. "assessmentAfterDislysis": assessmentAfterDislysis,
  810. })
  811. }
  812. } else { //修改
  813. if appRole.UserType == 2 || appRole.UserType == 1 {
  814. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  815. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  816. } else {
  817. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  818. if assessmentAfterDislysis.Creater == 0 {
  819. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  820. }
  821. }
  822. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  823. assessmentAfterDislysis.ID = assessmentAfter.ID
  824. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  825. if err == nil {
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "assessmentAfterDislysis": assessmentAfterDislysis,
  828. })
  829. }
  830. }
  831. }
  832. func (c *DialysisAPIController) PostDialysisPrescription() {
  833. id, _ := c.GetInt64("patient", 0)
  834. recordDateStr := c.GetString("record_date")
  835. if id <= 0 {
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  837. return
  838. }
  839. adminUserInfo := c.GetMobileAdminUserInfo()
  840. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  841. if patient.ID == 0 {
  842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  843. return
  844. }
  845. if len(recordDateStr) == 0 {
  846. recordDateStr = time.Now().Format("2006-01-02")
  847. }
  848. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  849. if parseDateErr != nil {
  850. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  852. return
  853. }
  854. mode_id, _ := c.GetInt64("mode_id", 0)
  855. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  856. dialyzer, _ := c.GetInt64("dialyzer", 0)
  857. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  858. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  859. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  860. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  861. replacement_total, _ := c.GetFloat("replacement_total", 0)
  862. replacement_way, _ := c.GetInt64("replacement_way", 0)
  863. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  864. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  865. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  866. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  867. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  868. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  869. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  870. kalium, _ := c.GetFloat("kalium", 0)
  871. sodium, _ := c.GetFloat("sodium", 0)
  872. calcium, _ := c.GetFloat("calcium", 0)
  873. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  874. glucose, _ := c.GetFloat("glucose", 0)
  875. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  876. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  877. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  878. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  879. conductivity, _ := c.GetFloat("conductivity", 0)
  880. remark := c.GetString("remark")
  881. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  882. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  883. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  884. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  885. body_fluid, _ := c.GetInt64("body_fluid", 0)
  886. special_medicine, _ := c.GetInt64("special_medicine", 0)
  887. special_medicine_other := c.GetString("special_medicine_other")
  888. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  889. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  890. blood_access, _ := c.GetInt64("blood_access", 0)
  891. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  892. body_fluid_other := c.GetString("body_fluid_other")
  893. niprocart, _ := c.GetInt64("niprocart", 0)
  894. jms, _ := c.GetInt64("jms", 0)
  895. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  896. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  897. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  898. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  899. filtryzer, _ := c.GetInt64("filtryzer", 0)
  900. target_ktv, _ := c.GetFloat("target_ktv", 0)
  901. dialyzers, _ := c.GetInt64("dialyzers", 0)
  902. injector, _ := c.GetInt64("injector", 0)
  903. bloodlines, _ := c.GetInt64("bloodlines", 0)
  904. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  905. safe_package, _ := c.GetInt64("package", 0)
  906. a_liquid, _ := c.GetInt64("a_liquid", 0)
  907. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  908. fmt.Println("预冲量====", pre_impulse)
  909. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  910. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  911. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  912. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  913. //
  914. //if template.TemplateId == 2 || template.TemplateId == 6 {
  915. // if appRole.UserType == 3 {
  916. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  917. // if getPermissionErr != nil {
  918. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  919. // return
  920. // } else if headNursePermission == nil {
  921. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  922. // return
  923. // }
  924. // }
  925. //}
  926. //TODO 需要根据角色去判断
  927. prescription := models.DialysisPrescription{
  928. UserOrgId: adminUserInfo.Org.Id,
  929. PatientId: id,
  930. RecordDate: recordDate.Unix(),
  931. ModeId: mode_id,
  932. DialysisDuration: dialysis_duration,
  933. Dialyzer: dialyzer,
  934. PerfusionApparatus: perfusion_apparatus,
  935. BloodFlowVolume: blood_flow_volume,
  936. DewaterAmount: dewater_amount,
  937. DisplaceLiqui: displace_liqui,
  938. ReplacementWay: replacement_way,
  939. Anticoagulant: anticoagulant,
  940. AnticoagulantShouji: anticoagulant_shouji,
  941. AnticoagulantWeichi: anticoagulant_weichi,
  942. AnticoagulantZongliang: anticoagulant_zongliang,
  943. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  944. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  945. Kalium: kalium,
  946. Sodium: sodium,
  947. Calcium: calcium,
  948. Bicarbonate: bicarbonate,
  949. Glucose: glucose,
  950. // DryWeight: dry_weight,
  951. DialysateFlow: dialysate_flow,
  952. DialysateTemperature: dialysate_temperature,
  953. // PrescriptionDoctor: prescription_doctor,
  954. ReplacementTotal: replacement_total,
  955. Conductivity: conductivity,
  956. Remark: remark,
  957. Status: 1,
  958. CreatedTime: time.Now().Unix(),
  959. UpdatedTime: time.Now().Unix(),
  960. DialysisDurationMinute: dialysisDurationMinute,
  961. DialysisDurationHour: dialysisDurationHour,
  962. TargetUltrafiltration: targetUltrafiltration,
  963. DialysateFormulation: dialysateFormulation,
  964. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  965. BodyFluid: body_fluid,
  966. SpecialMedicine: special_medicine,
  967. SpecialMedicineOther: special_medicine_other,
  968. DisplaceLiquiPart: displace_liqui_part,
  969. DisplaceLiquiValue: displace_liqui_value,
  970. BloodAccess: blood_access,
  971. Ultrafiltration: ultrafiltration,
  972. BodyFluidOther: body_fluid_other,
  973. Niprocart: niprocart,
  974. Jms: jms,
  975. FistulaNeedleSet: fistula_needle_set,
  976. FistulaNeedleSet16: fistula_needle_set_16,
  977. Hemoperfusion: hemoperfusion,
  978. DialyserSterilised: dialyser_sterilised,
  979. Filtryzer: filtryzer,
  980. Dialyzers: dialyzers,
  981. Injector: injector,
  982. Bloodlines: bloodlines,
  983. TubingHemodialysis: tubing_hemodialysis,
  984. Package: safe_package,
  985. ALiquid: a_liquid,
  986. TargetKtv: target_ktv,
  987. PreImpulse: pre_impulse,
  988. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  989. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  990. }
  991. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  992. if dialysisPrescription.ID == 0 { //新增
  993. //if mode_id > 0 {
  994. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  995. //}
  996. if appRole.UserType == 2 || appRole.UserType == 1 {
  997. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  998. }
  999. prescription.Creater = adminUserInfo.AdminUser.Id
  1000. err := service.AddSigleRecord(&prescription)
  1001. if err == nil {
  1002. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1003. if updateErr != nil {
  1004. utils.ErrorLog("%v", updateErr)
  1005. }
  1006. c.ServeSuccessJSON(map[string]interface{}{
  1007. "prescription": prescription,
  1008. })
  1009. }
  1010. } else { //修改
  1011. //if mode_id > 0 {
  1012. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1013. //}
  1014. //if template.TemplateId == 1 {
  1015. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1016. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1017. // if getPermissionErr != nil {
  1018. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1019. // return
  1020. // } else if headNursePermission == nil {
  1021. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1022. // return
  1023. // }
  1024. // }
  1025. //}
  1026. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1027. prescription.Modifier = adminUserInfo.AdminUser.Id
  1028. if appRole.UserType == 2 || appRole.UserType == 1 {
  1029. prescription_doctor := adminUserInfo.AdminUser.Id
  1030. prescription.PrescriptionDoctor = prescription_doctor
  1031. } else {
  1032. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1033. }
  1034. if dialysisPrescription.Creater == 0 { //体重称
  1035. prescription.Creater = adminUserInfo.AdminUser.Id
  1036. } else {
  1037. prescription.Creater = dialysisPrescription.Creater
  1038. }
  1039. prescription.ID = dialysisPrescription.ID
  1040. err := service.UpDateDialysisPrescription(&prescription)
  1041. if err == nil {
  1042. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1043. if updateErr != nil {
  1044. utils.ErrorLog("%v", updateErr)
  1045. }
  1046. c.ServeSuccessJSON(map[string]interface{}{
  1047. "prescription": prescription,
  1048. })
  1049. }
  1050. }
  1051. }
  1052. func (c *DialysisAPIController) Finish() {
  1053. id, _ := c.GetInt64("patient", 0)
  1054. recordDateStr := c.GetString("record_date")
  1055. nurseID, _ := c.GetInt64("nurse")
  1056. end_time := c.GetString("end_time")
  1057. if id <= 0 || nurseID <= 0 {
  1058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1059. return
  1060. }
  1061. adminUserInfo := c.GetMobileAdminUserInfo()
  1062. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1063. if patient.ID == 0 {
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1065. return
  1066. }
  1067. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1068. if getNurseErr != nil {
  1069. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1071. return
  1072. } else if nurse == nil {
  1073. c.ErrorLog("护士不存在")
  1074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1075. return
  1076. }
  1077. if len(recordDateStr) == 0 {
  1078. recordDateStr = time.Now().Format("2006-01-02")
  1079. }
  1080. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1081. if parseDateErr != nil {
  1082. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1084. return
  1085. }
  1086. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1087. if parseEndDateErr != nil {
  1088. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1090. return
  1091. }
  1092. //now := time.Now()
  1093. //year, month, day := now.Date()
  1094. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1095. //todayTimeStamp := today_time.Unix()
  1096. // 获取当天的第一条透析纪录
  1097. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1098. if getMonitorRecordsErr != nil {
  1099. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1101. return
  1102. }
  1103. // 获取当前的最后一条透析纪录
  1104. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  1105. if getMonitorRecordsErr != nil {
  1106. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1108. return
  1109. }
  1110. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1111. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1112. if getAADErr != nil {
  1113. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1115. return
  1116. }
  1117. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1118. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1119. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1120. if assessmentAfterDislysis != nil {
  1121. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1122. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1123. } else {
  1124. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1125. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1126. tempassessmentAfterDislysis.Status = 1
  1127. tempassessmentAfterDislysis.PatientId = id
  1128. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1129. }
  1130. if dialysisOrder.Stage == 1 {
  1131. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1132. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1133. fmt.Println(value)
  1134. a, b := math.Modf(value)
  1135. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1136. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1137. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1138. fmt.Println(hour)
  1139. fmt.Println(minute)
  1140. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1141. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1142. }
  1143. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1144. //var num1 int64
  1145. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1146. //fmt.Println(num1)
  1147. //sub := float64(num1 / 3600)
  1148. //fmt.Println(sub)
  1149. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1150. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1151. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1152. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1153. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1154. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1155. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1156. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1157. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1158. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1159. }
  1160. if lastAssessmentAfterDislysis != nil {
  1161. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1162. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1163. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1164. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1165. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1166. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1167. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1168. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1169. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1170. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1171. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1172. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1173. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1174. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1175. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1176. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1177. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1178. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1179. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1180. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1181. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1182. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1183. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1184. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1185. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1186. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1187. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1188. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1189. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1190. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1191. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1192. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1193. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1194. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1195. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1196. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1197. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1198. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1199. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1200. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1201. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1202. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1203. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1204. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1205. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1206. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1207. }
  1208. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1209. if err != nil {
  1210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1211. return
  1212. }
  1213. if dialysisOrder == nil {
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1215. return
  1216. }
  1217. if dialysisOrder.Stage == 2 {
  1218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1219. return
  1220. }
  1221. if dialysisOrder.Stage == 1 {
  1222. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  1223. //结束时候透析次数加1
  1224. service.UpdateSolutionByPatientId(id)
  1225. dialysisOrder.Stage = 2
  1226. dialysisOrder.FinishNurse = nurseID
  1227. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1228. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1229. dialysisOrder.EndTime = endDate.Unix()
  1230. if err == nil {
  1231. c.ServeSuccessJSON(map[string]interface{}{
  1232. "dialysisOrder": dialysisOrder,
  1233. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1234. })
  1235. } else {
  1236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1237. }
  1238. }
  1239. }
  1240. func (c *DialysisAPIController) GetAllZone() {
  1241. adminUserInfo := c.GetMobileAdminUserInfo()
  1242. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1243. if err == nil {
  1244. c.ServeSuccessJSON(map[string]interface{}{
  1245. "zone": zone,
  1246. })
  1247. }
  1248. }
  1249. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1250. adminUserInfo := c.GetMobileAdminUserInfo()
  1251. page, _ := c.GetInt64("page", 1)
  1252. limit, _ := c.GetInt64("limit", 10)
  1253. schedulType, _ := c.GetInt64("schedul_type", 0)
  1254. startTime, _ := c.GetInt64("schedul_time", 0)
  1255. partitionType, _ := c.GetInt64("partition_type", 0)
  1256. keywords := c.GetString("keywords")
  1257. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1258. if err == nil {
  1259. c.ServeSuccessJSON(map[string]interface{}{
  1260. "schedule": dialysisSchedule,
  1261. })
  1262. }
  1263. return
  1264. }
  1265. // /m/api/dialysis/start [post]
  1266. // @param patient_id:int
  1267. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1268. // @param nurse:int 上机护士
  1269. // @param bed:int 床位号
  1270. func (this *DialysisAPIController) StartDialysis() {
  1271. patientID, _ := this.GetInt64("patient_id")
  1272. recordDateStr := this.GetString("record_date")
  1273. nurseID, _ := this.GetInt64("nurse")
  1274. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1275. blood_drawing, _ := this.GetInt64("blood_drawing")
  1276. schedual_type, _ := this.GetInt64("schedual_type")
  1277. bedID, _ := this.GetInt64("bed")
  1278. start_time := this.GetString("start_time")
  1279. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1280. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1282. return
  1283. }
  1284. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1285. if parseStartDateErr != nil {
  1286. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1288. return
  1289. }
  1290. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1291. if parseErr != nil {
  1292. this.ErrorLog("时间解析失败:%v", parseErr)
  1293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1294. return
  1295. }
  1296. adminUserInfo := this.GetMobileAdminUserInfo()
  1297. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1298. if getPatientErr != nil {
  1299. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1301. return
  1302. } else if patient == nil {
  1303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1304. return
  1305. }
  1306. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1307. if getNurseErr != nil {
  1308. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1310. return
  1311. } else if nurse == nil {
  1312. this.ErrorLog("护士不存在")
  1313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1314. return
  1315. }
  1316. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1317. if getNurseErr != nil {
  1318. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1320. return
  1321. } else if nurse == nil {
  1322. this.ErrorLog("护士不存在")
  1323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1327. if getDeviceNumberErr != nil {
  1328. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1330. return
  1331. } else if deviceNumber == nil {
  1332. this.ErrorLog("床位号不存在")
  1333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1334. return
  1335. }
  1336. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1337. if getRecordErr != nil {
  1338. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1340. return
  1341. } else if dialysisRecord != nil {
  1342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  1343. return
  1344. }
  1345. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1346. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1347. timeLayout := "2006-01-02 15:04:05"
  1348. loc, _ := time.LoadLocation("Local")
  1349. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1350. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1351. schedulestartTime := theStartTime.Unix()
  1352. scheduleendTime := theEndTime.Unix()
  1353. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1354. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1355. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1356. //查询该床位是否有人用了
  1357. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1358. if err == gorm.ErrRecordNotFound { //空床位
  1359. // 修改了床位逻辑
  1360. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1361. if daySchedule.ID > 0 {
  1362. daySchedule.PartitionId = deviceNumber.ZoneID
  1363. daySchedule.BedId = bedID
  1364. daySchedule.ScheduleType = schedual_type
  1365. daySchedule.UpdatedTime = time.Now().Unix()
  1366. err := service.UpdateSchedule(&daySchedule)
  1367. if err != nil {
  1368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1369. return
  1370. }
  1371. }
  1372. } else if err == nil {
  1373. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1374. if order_err == nil {
  1375. if order.ID > 0 { //该机位被其他人占用了
  1376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1377. return
  1378. } else {
  1379. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1380. if daySchedule.ID > 0 {
  1381. daySchedule.PartitionId = deviceNumber.ZoneID
  1382. daySchedule.BedId = bedID
  1383. daySchedule.ScheduleType = schedual_type
  1384. daySchedule.UpdatedTime = time.Now().Unix()
  1385. err := service.UpdateSchedule(&daySchedule)
  1386. if err != nil {
  1387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1388. return
  1389. }
  1390. }
  1391. }
  1392. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  1393. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1394. if daySchedule.ID > 0 {
  1395. daySchedule.PartitionId = deviceNumber.ZoneID
  1396. daySchedule.BedId = bedID
  1397. daySchedule.ScheduleType = schedual_type
  1398. daySchedule.UpdatedTime = time.Now().Unix()
  1399. err := service.UpdateSchedule(&daySchedule)
  1400. if err != nil {
  1401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1402. return
  1403. }
  1404. }
  1405. }
  1406. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1408. return
  1409. }
  1410. } else if err != nil {
  1411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1412. return
  1413. }
  1414. dialysisRecord = &models.DialysisOrder{
  1415. DialysisDate: recordDate.Unix(),
  1416. UserOrgId: adminUserInfo.Org.Id,
  1417. PatientId: patientID,
  1418. Stage: 1,
  1419. BedID: bedID,
  1420. StartNurse: nurseID,
  1421. Status: 1,
  1422. StartTime: startDate.Unix(),
  1423. CreatedTime: time.Now().Unix(),
  1424. UpdatedTime: time.Now().Unix(),
  1425. PunctureNurse: puncture_nurse,
  1426. Creator: adminUserInfo.AdminUser.Id,
  1427. Modifier: adminUserInfo.AdminUser.Id,
  1428. SchedualType: schedual_type,
  1429. WashpipeNurse: washpipe_nurse,
  1430. }
  1431. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  1432. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1433. var tempdispose string
  1434. // 只针对中能建
  1435. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  1436. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1437. }
  1438. var ultrafiltration_rate float64
  1439. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  1440. if prescription.ID > 0 {
  1441. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1442. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1443. if template.TemplateId == 6 { //adminUserInfo.Org.Id == 9538
  1444. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1445. }
  1446. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  1447. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1448. }
  1449. // 只针对方济医院
  1450. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  1451. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1452. ultrafiltration_rate = value
  1453. }
  1454. }
  1455. }
  1456. record := models.MonitoringRecord{
  1457. UserOrgId: adminUserInfo.Org.Id,
  1458. PatientId: patientID,
  1459. DialysisOrderId: dialysisRecord.ID,
  1460. MonitoringDate: schedulestartTime,
  1461. OperateTime: startDate.Unix(),
  1462. // MonitoringTime: recordTime,
  1463. MonitoringNurse: nurseID,
  1464. Dispose: tempdispose,
  1465. UltrafiltrationRate: ultrafiltration_rate,
  1466. UltrafiltrationVolume: 0,
  1467. Status: 1,
  1468. CreatedTime: time.Now().Unix(),
  1469. UpdatedTime: time.Now().Unix(),
  1470. }
  1471. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1472. if newdialysisRecord.ID > 0 {
  1473. err := service.CreateMonitor(&record)
  1474. if err != nil {
  1475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1476. return
  1477. }
  1478. }
  1479. if createErr != nil {
  1480. this.ErrorLog("上机失败:%v", createErr)
  1481. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1482. return
  1483. }
  1484. this.ServeSuccessJSON(map[string]interface{}{
  1485. "dialysis_order": newdialysisRecord,
  1486. "monitor": record,
  1487. })
  1488. }
  1489. func (c *DialysisAPIController) PostSolution() {
  1490. id, _ := c.GetInt64("patient", 0)
  1491. recordDateStr := c.GetString("record_date")
  1492. if id <= 0 {
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1494. return
  1495. }
  1496. adminUserInfo := c.GetMobileAdminUserInfo()
  1497. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1498. if patient.ID == 0 {
  1499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1500. return
  1501. }
  1502. if len(recordDateStr) == 0 {
  1503. recordDateStr = time.Now().Format("2006-01-02")
  1504. }
  1505. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1506. if parseDateErr != nil {
  1507. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1509. return
  1510. }
  1511. mode_id, _ := c.GetInt64("mode_id", 0)
  1512. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1513. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1514. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1515. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1516. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1517. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1518. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1519. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1520. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1521. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1522. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1523. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1524. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1525. kalium, _ := c.GetFloat("kalium", 0)
  1526. sodium, _ := c.GetFloat("sodium", 0)
  1527. calcium, _ := c.GetFloat("calcium", 0)
  1528. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1529. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1530. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1531. glucose, _ := c.GetFloat("glucose", 0)
  1532. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1533. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1534. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1535. conductivity, _ := c.GetFloat("conductivity", 0)
  1536. remark := c.GetString("remark")
  1537. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1538. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1539. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1540. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1541. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1542. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1543. special_medicine_other := c.GetString("special_medicine_other")
  1544. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1545. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1546. blood_access, _ := c.GetInt64("blood_access", 0)
  1547. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1548. body_fluid_other := c.GetString("body_fluid_other")
  1549. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1550. niprocart, _ := c.GetInt64("niprocart", 0)
  1551. jms, _ := c.GetInt64("jms", 0)
  1552. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1553. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1554. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1555. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1556. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1557. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1558. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1559. injector, _ := c.GetInt64("injector", 0)
  1560. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1561. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1562. safe_package, _ := c.GetInt64("package", 0)
  1563. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1564. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1565. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1566. if mode_id > 0 {
  1567. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1568. }
  1569. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1570. //
  1571. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1572. // if appRole.UserType == 3 {
  1573. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1574. // if getPermissionErr != nil {
  1575. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1576. // return
  1577. // } else if headNursePermission == nil {
  1578. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1579. // return
  1580. // }
  1581. // }
  1582. //}
  1583. prescription := models.DialysisPrescription{
  1584. UserOrgId: adminUserInfo.Org.Id,
  1585. PatientId: id,
  1586. RecordDate: recordDate.Unix(),
  1587. ModeId: mode_id,
  1588. DialysisDuration: dialysis_duration,
  1589. Dialyzer: dialyzer,
  1590. PerfusionApparatus: perfusion_apparatus,
  1591. BloodFlowVolume: blood_flow_volume,
  1592. DewaterAmount: dewater_amount,
  1593. DisplaceLiqui: displace_liqui,
  1594. ReplacementWay: replacement_way,
  1595. Anticoagulant: anticoagulant,
  1596. AnticoagulantShouji: anticoagulant_shouji,
  1597. AnticoagulantWeichi: anticoagulant_weichi,
  1598. AnticoagulantZongliang: anticoagulant_zongliang,
  1599. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1600. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1601. Kalium: kalium,
  1602. Sodium: sodium,
  1603. Calcium: calcium,
  1604. Bicarbonate: bicarbonate,
  1605. Glucose: glucose,
  1606. // DryWeight: dry_weight,
  1607. DialysateFlow: dialysate_flow,
  1608. DialysateTemperature: dialysate_temperature,
  1609. Conductivity: conductivity,
  1610. Remark: remark,
  1611. Status: 1,
  1612. CreatedTime: time.Now().Unix(),
  1613. UpdatedTime: time.Now().Unix(),
  1614. DialysisDurationMinute: dialysisDurationMinute,
  1615. DialysisDurationHour: dialysisDurationHour,
  1616. TargetUltrafiltration: targetUltrafiltration,
  1617. DialysateFormulation: dialysateFormulation,
  1618. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1619. BodyFluid: body_fluid,
  1620. SpecialMedicine: special_medicine,
  1621. SpecialMedicineOther: special_medicine_other,
  1622. DisplaceLiquiPart: displace_liqui_part,
  1623. DisplaceLiquiValue: displace_liqui_value,
  1624. BloodAccess: blood_access,
  1625. Ultrafiltration: ultrafiltration,
  1626. BodyFluidOther: body_fluid_other,
  1627. ReplacementTotal: replacement_total,
  1628. Niprocart: niprocart,
  1629. Jms: jms,
  1630. FistulaNeedleSet: fistula_needle_set,
  1631. FistulaNeedleSet16: fistula_needle_set_16,
  1632. Hemoperfusion: hemoperfusion,
  1633. DialyserSterilised: dialyser_sterilised,
  1634. Filtryzer: filtryzer,
  1635. TargetKtv: target_ktv,
  1636. Dialyzers: dialyzers,
  1637. Injector: injector,
  1638. Bloodlines: bloodlines,
  1639. TubingHemodialysis: tubing_hemodialysis,
  1640. Package: safe_package,
  1641. ALiquid: a_liquid,
  1642. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1643. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1644. }
  1645. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1646. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1647. //
  1648. if appRole.UserType == 2 || appRole.UserType == 1 {
  1649. prescription_doctor = adminUserInfo.AdminUser.Id
  1650. prescription.PrescriptionDoctor = prescription_doctor
  1651. }
  1652. if dialysisPrescription.ID == 0 { //新增
  1653. prescription.Creater = adminUserInfo.AdminUser.Id
  1654. } else { //修改
  1655. if dialysisPrescription.Creater == 0 {
  1656. prescription.Creater = adminUserInfo.AdminUser.Id
  1657. } else {
  1658. prescription.Creater = dialysisPrescription.Creater
  1659. }
  1660. //if/**/
  1661. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1662. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  1663. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1664. // if getPermissionErr != nil {
  1665. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1666. // return
  1667. // } else if headNursePermission == nil {
  1668. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1669. // return
  1670. // }
  1671. //}
  1672. //prescription.Creater = dialysisPrescription.Creater
  1673. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1674. prescription.Modifier = adminUserInfo.AdminUser.Id
  1675. prescription.ID = dialysisPrescription.ID
  1676. }
  1677. solution := models.DialysisSolution{
  1678. RegistrarsId: adminUserInfo.AdminUser.Id,
  1679. UserOrgId: adminUserInfo.Org.Id,
  1680. Doctor: prescription_doctor,
  1681. PatientId: id,
  1682. ModeId: mode_id,
  1683. DialysisDuration: dialysis_duration,
  1684. PerfusionApparatus: perfusion_apparatus,
  1685. BloodFlowVolume: blood_flow_volume,
  1686. Dewater: dewater_amount,
  1687. DisplaceLiqui: displace_liqui,
  1688. ReplacementWay: replacement_way,
  1689. Anticoagulant: anticoagulant,
  1690. AnticoagulantShouji: anticoagulant_shouji,
  1691. AnticoagulantWeichi: anticoagulant_weichi,
  1692. AnticoagulantZongliang: anticoagulant_zongliang,
  1693. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1694. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1695. Kalium: kalium,
  1696. Sodium: sodium,
  1697. Calcium: calcium,
  1698. Bicarbonate: bicarbonate,
  1699. Glucose: glucose,
  1700. // DryWeight: dry_weight,
  1701. DialysateFlow: dialysate_flow,
  1702. DialysateTemperature: dialysate_temperature,
  1703. Conductivity: conductivity,
  1704. Remark: remark,
  1705. Status: 1,
  1706. CreatedTime: time.Now().Unix(),
  1707. UpdatedTime: time.Now().Unix(),
  1708. DialysisDurationMinute: dialysisDurationMinute,
  1709. DialysisDurationHour: dialysisDurationHour,
  1710. TargetUltrafiltration: targetUltrafiltration,
  1711. DialysateFormulation: dialysateFormulation,
  1712. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1713. BodyFluid: body_fluid,
  1714. SpecialMedicine: special_medicine,
  1715. SpecialMedicineOther: special_medicine_other,
  1716. DisplaceLiquiPart: displace_liqui_part,
  1717. DisplaceLiquiValue: displace_liqui_value,
  1718. BloodAccess: blood_access,
  1719. Ultrafiltration: ultrafiltration,
  1720. BodyFluidOther: body_fluid_other,
  1721. ReplacementTotal: replacement_total,
  1722. TargetKtv: target_ktv,
  1723. }
  1724. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1725. c.ServeSuccessJSON(map[string]interface{}{
  1726. "solution": &solution,
  1727. "prescription": &prescription,
  1728. })
  1729. }
  1730. func (c *DialysisAPIController) GetAcceptsAssessment() {
  1731. patient, _ := c.GetInt64("patient", 0)
  1732. adminUserInfo := c.GetMobileAdminUserInfo()
  1733. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  1734. c.ServeSuccessJSON(map[string]interface{}{
  1735. "receiveTreatmentAsses": receiveTreatmentAsses,
  1736. })
  1737. }
  1738. func (this *DialysisAPIController) PostSignInfo() {
  1739. patientID, _ := this.GetInt64("patient_id")
  1740. recordDateStr := this.GetString("date")
  1741. if patientID <= 0 {
  1742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1743. return
  1744. }
  1745. if len(recordDateStr) == 0 {
  1746. recordDateStr = time.Now().Format("2006-01-02")
  1747. }
  1748. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1749. if parseDateErr != nil {
  1750. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1752. return
  1753. }
  1754. adminInfo := this.GetMobileAdminUserInfo()
  1755. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  1756. if err != nil {
  1757. this.ErrorLog("签名失败:%v", err)
  1758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1759. return
  1760. }
  1761. this.ServeSuccessJSON(map[string]interface{}{
  1762. "doctor_id": adminInfo.AdminUser.Id,
  1763. })
  1764. }
  1765. func (this *DialysisAPIController) GetLastMonitorRecord() {
  1766. patientID, _ := this.GetInt64("patient_id")
  1767. adminInfo := this.GetMobileAdminUserInfo()
  1768. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  1769. this.ServeSuccessJSON(map[string]interface{}{
  1770. "monitor": record,
  1771. })
  1772. }
  1773. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  1774. thisTime := time.Now()
  1775. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1776. timeLayout := "2006-01-02 15:04:05"
  1777. loc, _ := time.LoadLocation("Local")
  1778. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1779. theAssessmentDateTime := theStartTime.Unix()
  1780. patientID, _ := this.GetInt64("patient_id")
  1781. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  1782. adminInfo := this.GetMobileAdminUserInfo()
  1783. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  1784. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  1785. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  1786. var ultrafiltration_rate float64
  1787. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  1788. if prescription.ID > 0 {
  1789. fmt.Println("444444444")
  1790. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1791. fmt.Println("4444444445555")
  1792. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1793. if template.TemplateId == 6 {
  1794. fmt.Println("12222222")
  1795. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1796. record.UltrafiltrationRate = ultrafiltration_rate
  1797. }
  1798. if template.TemplateId == 20 || template.TemplateId == 22 {
  1799. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1800. record.UltrafiltrationRate = ultrafiltration_rate
  1801. }
  1802. // 只针对方济医院
  1803. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  1804. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1805. ultrafiltration_rate = value
  1806. record.UltrafiltrationRate = ultrafiltration_rate
  1807. }
  1808. }
  1809. }
  1810. // record.UltrafiltrationRate = ultrafiltration_rate
  1811. record.UltrafiltrationVolume = 0
  1812. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  1813. if ultrafiltration_rate > 0 {
  1814. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  1815. record.UltrafiltrationVolume = value
  1816. }
  1817. }
  1818. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 { //adminInfo.Org.Id == 9538
  1819. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  1820. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  1821. record.UltrafiltrationVolume = ultrafiltration_volume
  1822. }
  1823. }
  1824. this.ServeSuccessJSON(map[string]interface{}{
  1825. "monitor": record,
  1826. })
  1827. }
  1828. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  1829. record_id, _ := this.GetInt64("id")
  1830. nurseID, _ := this.GetInt64("nurse")
  1831. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1832. bedID, _ := this.GetInt64("bed")
  1833. start_time := this.GetString("start_time")
  1834. schedual_type, _ := this.GetInt64("schedual_type")
  1835. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1836. if record_id == 0 {
  1837. this.ErrorLog("id:%v", record_id)
  1838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1839. return
  1840. }
  1841. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1842. if parseStartDateErr != nil {
  1843. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1844. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1845. return
  1846. }
  1847. adminUserInfo := this.GetMobileAdminUserInfo()
  1848. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1849. if getNurseErr != nil {
  1850. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1852. return
  1853. } else if nurse == nil {
  1854. this.ErrorLog("护士不存在")
  1855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1856. return
  1857. }
  1858. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1859. if getNurseErr != nil {
  1860. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1862. return
  1863. } else if nurse == nil {
  1864. this.ErrorLog("护士不存在")
  1865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1866. return
  1867. }
  1868. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1869. if getDeviceNumberErr != nil {
  1870. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1872. return
  1873. } else if deviceNumber == nil {
  1874. this.ErrorLog("床位号不存在")
  1875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1876. return
  1877. }
  1878. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1879. //
  1880. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1881. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1882. // if getPermissionErr != nil {
  1883. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1884. // return
  1885. // } else if headNursePermission == nil {
  1886. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1887. // return
  1888. // }
  1889. //}
  1890. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1891. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1892. timeLayout := "2006-01-02 15:04:05"
  1893. loc, _ := time.LoadLocation("Local")
  1894. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1895. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1896. schedulestartTime := theStartTime.Unix()
  1897. scheduleendTime := theEndTime.Unix()
  1898. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1899. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1900. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1901. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1902. if err == gorm.ErrRecordNotFound { //空床位
  1903. // 修改了床位逻辑
  1904. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1905. if daySchedule.ID > 0 {
  1906. daySchedule.BedId = bedID
  1907. daySchedule.PartitionId = deviceNumber.ZoneID
  1908. daySchedule.ScheduleType = schedual_type
  1909. daySchedule.UpdatedTime = time.Now().Unix()
  1910. err := service.UpdateSchedule(&daySchedule)
  1911. if err != nil {
  1912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1913. return
  1914. }
  1915. }
  1916. } else if err == nil {
  1917. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1918. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1919. if daySchedule.ID > 0 {
  1920. daySchedule.BedId = bedID
  1921. daySchedule.PartitionId = deviceNumber.ZoneID
  1922. daySchedule.ScheduleType = schedual_type
  1923. daySchedule.UpdatedTime = time.Now().Unix()
  1924. err := service.UpdateSchedule(&daySchedule)
  1925. if err != nil {
  1926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1927. return
  1928. }
  1929. }
  1930. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1932. return
  1933. }
  1934. } else if err != nil {
  1935. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1936. return
  1937. }
  1938. }
  1939. dialysisRecord := &models.DialysisOrder{
  1940. ID: record_id,
  1941. UserOrgId: adminUserInfo.Org.Id,
  1942. BedID: bedID,
  1943. StartNurse: nurseID,
  1944. StartTime: startDate.Unix(),
  1945. PunctureNurse: puncture_nurse,
  1946. Creator: adminUserInfo.AdminUser.Id,
  1947. Modifier: adminUserInfo.AdminUser.Id,
  1948. WashpipeNurse: washpipe_nurse,
  1949. SchedualType: schedual_type,
  1950. }
  1951. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1952. if updateErr != nil {
  1953. this.ErrorLog("修改上机失败:%v", updateErr)
  1954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1955. return
  1956. }
  1957. if updateErr == nil {
  1958. if tempDialysisRecord.Stage == 2 {
  1959. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1960. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1961. fmt.Println(value)
  1962. a, b := math.Modf(value)
  1963. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1964. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1965. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1966. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1967. if updateAssessmentErr != nil {
  1968. utils.ErrorLog("%v", updateAssessmentErr)
  1969. }
  1970. }
  1971. }
  1972. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1973. this.ServeSuccessJSON(map[string]interface{}{
  1974. "dialysis_order": dialysisRecords,
  1975. })
  1976. }
  1977. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  1978. record_id, _ := c.GetInt64("id")
  1979. nurseID, _ := c.GetInt64("nurse")
  1980. end_time := c.GetString("end_time")
  1981. if record_id <= 0 || nurseID <= 0 {
  1982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1983. return
  1984. }
  1985. adminUserInfo := c.GetMobileAdminUserInfo()
  1986. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1987. if getNurseErr != nil {
  1988. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1990. return
  1991. } else if nurse == nil {
  1992. c.ErrorLog("护士不存在")
  1993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1994. return
  1995. }
  1996. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1997. if parseEndDateErr != nil {
  1998. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2000. return
  2001. }
  2002. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2003. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2004. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2005. // if getPermissionErr != nil {
  2006. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2007. // return
  2008. // } else if headNursePermission == nil {
  2009. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2010. // return
  2011. // }
  2012. //}
  2013. dialysisRecord := &models.DialysisOrder{
  2014. ID: record_id,
  2015. UserOrgId: adminUserInfo.Org.Id,
  2016. EndTime: endDate.Unix(),
  2017. FinishNurse: nurseID,
  2018. FinishModifier: adminUserInfo.AdminUser.Id,
  2019. }
  2020. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2021. if updateErr != nil {
  2022. c.ErrorLog("修改下机失败:%v", updateErr)
  2023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2024. return
  2025. }
  2026. if updateErr == nil {
  2027. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2028. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2029. a, b := math.Modf(value)
  2030. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2031. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2032. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2033. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2034. if updateAssessmentErr != nil {
  2035. utils.ErrorLog("%v", updateAssessmentErr)
  2036. }
  2037. }
  2038. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2039. c.ServeSuccessJSON(map[string]interface{}{
  2040. "dialysis_order": dialysisRecords,
  2041. })
  2042. }
  2043. func (c *DialysisAPIController) GetLongAdvice() {
  2044. patient_id, _ := c.GetInt64("id")
  2045. adminUserInfo := c.GetMobileAdminUserInfo()
  2046. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  2047. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2048. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2049. c.ServeSuccessJSON(map[string]interface{}{
  2050. "status": "1",
  2051. })
  2052. return
  2053. } else { //开启推送提醒
  2054. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2055. var advice_three []*models.DoctorAdvice
  2056. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2057. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  2058. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  2059. for _, advice := range advices {
  2060. if advice.FrequencyType == 3 {
  2061. t := time.Now()
  2062. week := int(t.Weekday())
  2063. switch week {
  2064. case 1:
  2065. if strings.Index(advice.WeekDay, "周一") == -1 {
  2066. advice_three = append(advice_three, advice)
  2067. }
  2068. break
  2069. case 2:
  2070. if strings.Index(advice.WeekDay, "周二") == -1 {
  2071. advice_three = append(advice_three, advice)
  2072. }
  2073. break
  2074. case 3:
  2075. if strings.Index(advice.WeekDay, "周三") == -1 {
  2076. advice_three = append(advice_three, advice)
  2077. }
  2078. break
  2079. case 4:
  2080. if strings.Index(advice.WeekDay, "周四") == -1 {
  2081. advice_three = append(advice_three, advice)
  2082. }
  2083. break
  2084. case 5:
  2085. if strings.Index(advice.WeekDay, "周五") == -1 {
  2086. advice_three = append(advice_three, advice)
  2087. }
  2088. break
  2089. case 6:
  2090. if strings.Index(advice.WeekDay, "周六") == -1 {
  2091. advice_three = append(advice_three, advice)
  2092. }
  2093. break
  2094. case 0:
  2095. if strings.Index(advice.WeekDay, "周日") == -1 {
  2096. advice_three = append(advice_three, advice)
  2097. }
  2098. break
  2099. }
  2100. }
  2101. }
  2102. for _, advice := range advices_two {
  2103. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2104. now := p.Unix()
  2105. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2106. dayStr2 := "-" + dayStr
  2107. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2108. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2109. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  2110. for _, ad := range advices {
  2111. advice_three = append(advice_three, ad)
  2112. }
  2113. }
  2114. if err == nil {
  2115. c.ServeSuccessJSON(map[string]interface{}{
  2116. "status": "2",
  2117. "advices": advices,
  2118. "advices_two": RemoveRepeatedElement(advice_three),
  2119. "is_open_remind": config.IsOpenRemind,
  2120. })
  2121. }
  2122. }
  2123. }
  2124. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2125. newArr = make([]*models.DoctorAdvice, 0)
  2126. for i := 0; i < len(arr); i++ {
  2127. repeat := false
  2128. for j := i + 1; j < len(arr); j++ {
  2129. if arr[i].ID == arr[j].ID {
  2130. repeat = true
  2131. break
  2132. }
  2133. }
  2134. if !repeat {
  2135. newArr = append(newArr, arr[i])
  2136. }
  2137. }
  2138. return
  2139. }
  2140. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  2141. patient, _ := c.GetInt64("id", 0)
  2142. groupNo, _ := c.GetInt64("groupno", 0)
  2143. if patient <= 0 {
  2144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2145. return
  2146. }
  2147. adminUserInfo := c.GetMobileAdminUserInfo()
  2148. dataBody := make(map[string]interface{}, 0)
  2149. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2150. if err != nil {
  2151. utils.ErrorLog(err.Error())
  2152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2153. return
  2154. }
  2155. utils.ErrorLog("%v", dataBody)
  2156. timeLayout := "2006-01-02 15:04"
  2157. loc, _ := time.LoadLocation("Local")
  2158. timeLayout2 := "2006-01-02"
  2159. loc2, _ := time.LoadLocation("Local")
  2160. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2161. utils.ErrorLog("advice_type")
  2162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2163. return
  2164. }
  2165. adviceType := int64(2)
  2166. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2167. utils.ErrorLog("advice_date")
  2168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2169. return
  2170. }
  2171. adviceDate, _ := dataBody["advice_date"].(string)
  2172. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2173. AdviceDate := theTime.Unix()
  2174. RecordDate := theTime.Unix()
  2175. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2176. utils.ErrorLog("start_time")
  2177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2178. return
  2179. }
  2180. startTime, _ := dataBody["start_time"].(string)
  2181. if len(startTime) == 0 {
  2182. utils.ErrorLog("len(start_time) == 0")
  2183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2184. return
  2185. }
  2186. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  2187. if err != nil {
  2188. utils.ErrorLog(err.Error())
  2189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2190. return
  2191. }
  2192. StartTime := theTime.Unix()
  2193. Remark := ""
  2194. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2195. remark, _ := dataBody["remark"].(string)
  2196. Remark = remark
  2197. }
  2198. var advices []*models.GroupAdvice
  2199. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2200. utils.ErrorLog("advices")
  2201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2202. return
  2203. }
  2204. adviceNames := dataBody["advices"].([]interface{})
  2205. for _, adviceNameMap := range adviceNames {
  2206. adviceNameM := adviceNameMap.(map[string]interface{})
  2207. var advice models.GroupAdvice
  2208. advice.Remark = Remark
  2209. advice.AdviceType = adviceType
  2210. advice.StartTime = StartTime
  2211. advice.AdviceDate = AdviceDate
  2212. advice.RecordDate = RecordDate
  2213. advice.Status = 1
  2214. advice.CreatedTime = time.Now().Unix()
  2215. advice.UpdatedTime = time.Now().Unix()
  2216. advice.StopState = 2
  2217. advice.ExecutionState = 2
  2218. advice.UserOrgId = adminUserInfo.Org.Id
  2219. advice.PatientId = patient
  2220. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2221. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2222. utils.ErrorLog("advice_name")
  2223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2224. return
  2225. }
  2226. adviceName, _ := adviceNameM["advice_name"].(string)
  2227. if len(adviceName) == 0 {
  2228. utils.ErrorLog("len(advice_name) == 0")
  2229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2230. return
  2231. }
  2232. advice.AdviceName = adviceName
  2233. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2234. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2235. advice.DrugSpec = drugSpec
  2236. }
  2237. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2238. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2239. advice.AdviceDesc = adviceDesc
  2240. }
  2241. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2242. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2243. advice.DrugSpecUnit = drugSpecUnit
  2244. }
  2245. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2246. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2247. // advice.SingleDose = singleDose
  2248. //}
  2249. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2250. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2251. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2252. }
  2253. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2254. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2255. advice.SingleDoseUnit = singleDoseUnit
  2256. }
  2257. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2258. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2259. // advice.PrescribingNumber = prescribingNumber
  2260. //}
  2261. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2262. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2263. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2264. }
  2265. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2266. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2267. advice.PrescribingNumberUnit = prescribingNumberUnit
  2268. }
  2269. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2270. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2271. advice.DeliveryWay = deliveryWay
  2272. }
  2273. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2274. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2275. advice.ExecutionFrequency = executionFrequency
  2276. }
  2277. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2278. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2279. advice.FrequencyType = frequency_type
  2280. }
  2281. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2282. day_count := int64(adviceNameM["day_count"].(float64))
  2283. advice.DayCount = day_count
  2284. }
  2285. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2286. week_day, _ := adviceNameM["week_day"].(string)
  2287. advice.WeekDay = week_day
  2288. }
  2289. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2290. way := int64(adviceNameM["way"].(float64))
  2291. advice.Way = way
  2292. }
  2293. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2294. drug_id := int64(adviceNameM["drug_id"].(float64))
  2295. advice.DrugId = drug_id
  2296. }
  2297. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2298. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2299. advice.DrugNameId = drug_name_id
  2300. }
  2301. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2302. template_id, _ := adviceNameM["template_id"].(string)
  2303. advice.TemplateId = template_id
  2304. }
  2305. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  2306. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2307. advice.ExecutionFrequency = executionFrequency
  2308. }
  2309. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2310. children := adviceNameM["child"].([]interface{})
  2311. if len(children) > 0 {
  2312. for _, childrenMap := range children {
  2313. childMap := childrenMap.(map[string]interface{})
  2314. var child models.GroupAdvice
  2315. child.Remark = Remark
  2316. child.AdviceType = adviceType
  2317. child.StartTime = StartTime
  2318. child.AdviceDate = AdviceDate
  2319. child.RecordDate = RecordDate
  2320. child.Status = 1
  2321. child.CreatedTime = time.Now().Unix()
  2322. child.UpdatedTime = time.Now().Unix()
  2323. child.StopState = 2
  2324. child.ExecutionState = 2
  2325. child.UserOrgId = adminUserInfo.Org.Id
  2326. child.PatientId = patient
  2327. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2328. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2329. utils.ErrorLog("child advice_name")
  2330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2331. return
  2332. }
  2333. childAdviceName, _ := childMap["advice_name"].(string)
  2334. if len(childAdviceName) == 0 {
  2335. utils.ErrorLog("len(child advice_name) == 0")
  2336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2337. return
  2338. }
  2339. child.AdviceName = childAdviceName
  2340. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2341. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2342. child.AdviceDesc = childAdviceDesc
  2343. }
  2344. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2345. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2346. child.DrugSpec = childDrugSpec
  2347. }
  2348. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2349. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2350. child.DrugSpecUnit = childDrugSpecUnit
  2351. }
  2352. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  2353. child.SingleDose = childMap["single_dose"].(float64)
  2354. }
  2355. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2356. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2357. child.SingleDoseUnit = childSingleDoseUnit
  2358. }
  2359. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  2360. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  2361. }
  2362. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2363. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2364. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2365. }
  2366. child.DeliveryWay = advice.DeliveryWay
  2367. child.ExecutionFrequency = advice.ExecutionFrequency
  2368. advice.Children = append(advice.Children, &child)
  2369. }
  2370. }
  2371. }
  2372. advices = append(advices, &advice)
  2373. }
  2374. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  2375. if err != nil {
  2376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2377. return
  2378. }
  2379. c.ServeSuccessJSON(map[string]interface{}{
  2380. "msg": "ok",
  2381. "advices": list,
  2382. })
  2383. return
  2384. }
  2385. func (c *DialysisAPIController) UploadDryWeight() {
  2386. patient_id, _ := c.GetInt64("id")
  2387. dry_weight, _ := c.GetFloat("dry_weight")
  2388. doctor_id, _ := c.GetInt64("doctor_id")
  2389. remark := c.GetString("remark")
  2390. adminUserInfo := c.GetMobileAdminUserInfo()
  2391. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  2392. if err == gorm.ErrRecordNotFound {
  2393. dryWeight := &models.SgjPatientDryweight{
  2394. PatientId: patient_id,
  2395. DryWeight: dry_weight,
  2396. Remakes: remark,
  2397. Ctime: time.Now().Unix(),
  2398. Mtime: time.Now().Unix(),
  2399. Creator: doctor_id,
  2400. Status: 1,
  2401. UserOrgId: adminUserInfo.Org.Id,
  2402. AdjustedValue: "/",
  2403. UserId: adminUserInfo.AdminUser.Id,
  2404. }
  2405. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2406. if createErr == nil {
  2407. c.ServeSuccessJSON(map[string]interface{}{
  2408. "msg": "提交成功",
  2409. "weight": dryWeight,
  2410. })
  2411. }
  2412. } else {
  2413. dryWeight := &models.SgjPatientDryweight{
  2414. PatientId: patient_id,
  2415. DryWeight: dry_weight,
  2416. Remakes: remark,
  2417. Ctime: time.Now().Unix(),
  2418. Mtime: time.Now().Unix(),
  2419. Creator: doctor_id,
  2420. Status: 1,
  2421. UserOrgId: adminUserInfo.Org.Id,
  2422. AdjustedValue: "/",
  2423. UserId: adminUserInfo.AdminUser.Id,
  2424. }
  2425. var value float64
  2426. value = dry_weight - weightAdjust.DryWeight
  2427. if value < 0 {
  2428. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2429. } else if value == 0 {
  2430. dryWeight.AdjustedValue = "/"
  2431. } else if value > 0 {
  2432. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2433. }
  2434. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2435. if createErr == nil {
  2436. c.ServeSuccessJSON(map[string]interface{}{
  2437. "msg": "提交成功",
  2438. "weight": dryWeight,
  2439. })
  2440. }
  2441. }
  2442. }
  2443. func (c *DialysisAPIController) GetSolution() {
  2444. patient_id, _ := c.GetInt64("patient_id")
  2445. mode_id, _ := c.GetInt64("mode_id")
  2446. adminUserInfo := c.GetMobileAdminUserInfo()
  2447. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2448. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2449. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  2450. if err != nil {
  2451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2452. return
  2453. }
  2454. c.ServeSuccessJSON(map[string]interface{}{
  2455. "solution": solution,
  2456. "prescription": prescription,
  2457. "system_prescription": system_prescription,
  2458. })
  2459. }
  2460. func (c *DialysisAPIController) GetSchedule() {
  2461. schedual_type, _ := c.GetInt64("schedual_type")
  2462. adminUserInfo := c.GetMobileAdminUserInfo()
  2463. timeLayout := "2006-01-02 15:04:05"
  2464. date := time.Now().Format("2006-01-02") + " 00:00:00"
  2465. loc, _ := time.LoadLocation("Local")
  2466. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2467. scheduleTime := theStartTime.Unix()
  2468. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  2469. c.ServeSuccessJSON(map[string]interface{}{
  2470. "number": deviceNumber,
  2471. })
  2472. }
  2473. func (c *DialysisAPIController) GetPatientId() {
  2474. id, _ := c.GetInt64("id")
  2475. patientId, _ := service.GetPatientId(id)
  2476. c.ServeSuccessJSON(map[string]interface{}{
  2477. "patient": patientId,
  2478. })
  2479. }
  2480. func (this *DialysisAPIController) GetDialysisSchedule() {
  2481. schedualDate := this.GetString("date")
  2482. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  2483. if parseDateErr != nil {
  2484. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2485. return
  2486. }
  2487. adminInfo := this.GetMobileAdminUserInfo()
  2488. orgID := adminInfo.Org.Id
  2489. redis := service.RedisClient()
  2490. defer redis.Close()
  2491. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  2492. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  2493. if len(scheduals) > 0 {
  2494. //缓存数据
  2495. scheduals_json, err := json.Marshal(scheduals)
  2496. if err == nil {
  2497. redis.Set(key, scheduals_json, time.Second*30)
  2498. }
  2499. }
  2500. this.ServeSuccessJSON(map[string]interface{}{
  2501. "scheduals": scheduals,
  2502. })
  2503. }
  2504. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  2505. change_type, _ := this.GetInt64("type", 0)
  2506. record_date := this.GetString("record_time")
  2507. patient_id, _ := this.GetInt64("patient_id", 0)
  2508. timeLayout := "2006-01-02"
  2509. loc, _ := time.LoadLocation("Local")
  2510. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2511. record_time := theAdviceRecordTime.Unix()
  2512. adminUserInfo := this.GetMobileAdminUserInfo()
  2513. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  2514. if err == nil {
  2515. if len(advices) == 0 {
  2516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2517. return
  2518. } else {
  2519. this.ServeSuccessJSON(map[string]interface{}{
  2520. "advices": advices,
  2521. "schedule": sch,
  2522. })
  2523. return
  2524. }
  2525. } else {
  2526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2527. return
  2528. }
  2529. }
  2530. func (c *DialysisAPIController) CreateConsumables() {
  2531. record_date := c.GetString("record_time")
  2532. patient_id, _ := c.GetInt64("patient_id", 0)
  2533. adminUser := c.GetMobileAdminUserInfo()
  2534. timeLayout := "2006-01-02"
  2535. loc, _ := time.LoadLocation("Local")
  2536. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2537. record_time := theRecordTime.Unix()
  2538. dataBody := make(map[string]interface{}, 0)
  2539. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2540. if err != nil {
  2541. utils.ErrorLog(err.Error())
  2542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2543. return
  2544. }
  2545. var beforePrepares []*models.DialysisBeforePrepare
  2546. var updateBeforePrepares []*models.DialysisBeforePrepare
  2547. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2548. goods, _ := dataBody["goods"].([]interface{})
  2549. if len(goods) > 0 {
  2550. for _, item := range goods {
  2551. items := item.(map[string]interface{})
  2552. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2553. utils.ErrorLog("good_id")
  2554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2555. return
  2556. }
  2557. good_id := int64(items["good_id"].(float64))
  2558. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2559. utils.ErrorLog("good_type_id")
  2560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2561. return
  2562. }
  2563. good_type_id := int64(items["good_type_id"].(float64))
  2564. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2565. utils.ErrorLog("count")
  2566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2567. return
  2568. }
  2569. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2570. adminUser := c.GetMobileAdminUserInfo()
  2571. prepare := &models.DialysisBeforePrepare{
  2572. UserOrgId: adminUser.Org.Id,
  2573. PatientId: patient_id,
  2574. RecordDate: record_time,
  2575. GoodId: good_id,
  2576. GoodTypeId: good_type_id,
  2577. Count: count,
  2578. Ctime: time.Now().Unix(),
  2579. Mtime: time.Now().Unix(),
  2580. Creater: adminUser.AdminUser.Id,
  2581. Modifier: 0,
  2582. }
  2583. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  2584. if record_count == 0 {
  2585. beforePrepares = append(beforePrepares, prepare)
  2586. }
  2587. }
  2588. }
  2589. }
  2590. if len(beforePrepares) > 0 {
  2591. service.CreateDialysisBeforePrepare(beforePrepares)
  2592. }
  2593. var errs error
  2594. if dataBody["update_goods"] != nil && reflect.TypeOf(dataBody["update_goods"]).String() == "[]interface {}" {
  2595. goods, _ := dataBody["update_goods"].([]interface{})
  2596. if len(goods) > 0 {
  2597. for _, item := range goods {
  2598. items := item.(map[string]interface{})
  2599. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2600. utils.ErrorLog("record_time")
  2601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2602. return
  2603. }
  2604. record_time := int64(items["record_time"].(float64))
  2605. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2606. utils.ErrorLog("id")
  2607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2608. return
  2609. }
  2610. id := int64(items["id"].(float64))
  2611. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2612. utils.ErrorLog("patient_id")
  2613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2614. return
  2615. }
  2616. patient_id := int64(items["patient_id"].(float64))
  2617. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2618. utils.ErrorLog("creater")
  2619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2620. return
  2621. }
  2622. creater := int64(items["creater"].(float64))
  2623. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2624. utils.ErrorLog("good_id")
  2625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2626. return
  2627. }
  2628. good_id := int64(items["good_id"].(float64))
  2629. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2630. utils.ErrorLog("good_type_id")
  2631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2632. return
  2633. }
  2634. good_type_id := int64(items["good_type_id"].(float64))
  2635. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2636. utils.ErrorLog("count")
  2637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2638. return
  2639. }
  2640. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2641. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2642. utils.ErrorLog("ctime")
  2643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2644. return
  2645. }
  2646. ctime := int64(items["ctime"].(float64))
  2647. prepare := &models.DialysisBeforePrepare{
  2648. ID: id,
  2649. UserOrgId: adminUser.Org.Id,
  2650. PatientId: patient_id,
  2651. RecordDate: record_time,
  2652. GoodId: good_id,
  2653. GoodTypeId: good_type_id,
  2654. Count: count,
  2655. Ctime: ctime,
  2656. Mtime: time.Now().Unix(),
  2657. Creater: creater,
  2658. Modifier: adminUser.AdminUser.Id,
  2659. Status: 1,
  2660. }
  2661. updateBeforePrepares = append(updateBeforePrepares, prepare)
  2662. }
  2663. }
  2664. updateBeforePrepares = RemoveRepeatedGood(updateBeforePrepares)
  2665. if len(updateBeforePrepares) > 0 {
  2666. for _, item := range updateBeforePrepares {
  2667. errs = service.UpdateDialysisBeforePrepareTwo(item)
  2668. }
  2669. }
  2670. }
  2671. if errs == nil {
  2672. c.ServeSuccessJSON(map[string]interface{}{
  2673. "msg": "提交成功",
  2674. })
  2675. return
  2676. } else {
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2678. return
  2679. }
  2680. }
  2681. func (c *DialysisAPIController) CreateStockOutInfo() {
  2682. patient_id, _ := c.GetInt64("patient_id", 0)
  2683. record_date := c.GetString("record_time")
  2684. if patient_id <= 0 {
  2685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2686. return
  2687. }
  2688. adminInfo := c.GetMobileAdminUserInfo()
  2689. timeLayout := "2006-01-02"
  2690. loc, _ := time.LoadLocation("Local")
  2691. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2692. record_time := theRecordTime.Unix()
  2693. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2694. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2695. consumables = RemoveRepeatedGood(consumables)
  2696. if record.IsOpen == 1 {
  2697. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  2698. if err == gorm.ErrRecordNotFound {
  2699. //没有记录,则创建出库单
  2700. timeStr := time.Now().Format("2006-01-02")
  2701. timeArr := strings.Split(timeStr, "-")
  2702. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  2703. total = total + 1
  2704. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2705. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2706. number = number + total
  2707. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2708. creater := adminInfo.AdminUser.Id
  2709. warehouseOut := models.WarehouseOut{
  2710. WarehouseOutOrderNumber: warehousing_out_order,
  2711. OperationTime: time.Now().Unix(),
  2712. OrgId: adminInfo.Org.Id,
  2713. Creater: creater,
  2714. Ctime: time.Now().Unix(),
  2715. Status: 1,
  2716. WarehouseOutTime: record_time,
  2717. Dealer: 0,
  2718. Manufacturer: 0,
  2719. Type: 1,
  2720. IsSys: 1,
  2721. }
  2722. err := service.AddSigleWarehouseOut(&warehouseOut)
  2723. if err != nil {
  2724. utils.TraceLog("创建出库单失败 err = %v", err)
  2725. } else {
  2726. for _, item := range consumables {
  2727. if item.Count > 0 {
  2728. warehouseOutInfo := &models.WarehouseOutInfo{
  2729. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2730. WarehouseOutId: warehouseOut.ID,
  2731. Status: 1,
  2732. Ctime: time.Now().Unix(),
  2733. Remark: "",
  2734. OrgId: adminInfo.Org.Id,
  2735. Type: 1,
  2736. Manufacturer: 0,
  2737. Dealer: 0,
  2738. IsSys: 1,
  2739. SysRecordTime: record_time,
  2740. GoodTypeId: item.GoodTypeId,
  2741. GoodId: item.GoodId,
  2742. }
  2743. warehouseOutInfo.Count = item.Count
  2744. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  2745. warehouseOutInfo.Price = stockInInfo.Price
  2746. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2747. if err == nil {
  2748. details := &models.AutomaticReduceDetail{
  2749. WarehouseOutId: warehouseOutInfo.ID,
  2750. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2751. PatientId: patient_id,
  2752. Ctime: time.Now().Unix(),
  2753. Mtime: time.Now().Unix(),
  2754. Status: 1,
  2755. RecordTime: record_time,
  2756. OrgId: adminInfo.Org.Id,
  2757. GoodId: item.GoodId,
  2758. GoodTypeId: item.GoodTypeId,
  2759. Count: item.Count,
  2760. }
  2761. service.AddSigleAutoReduceRecordInfo(details)
  2762. }
  2763. }
  2764. }
  2765. }
  2766. } else if err == nil {
  2767. for _, item := range consumables {
  2768. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  2769. if err == gorm.ErrRecordNotFound {
  2770. warehouseOutInfo := &models.WarehouseOutInfo{
  2771. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2772. WarehouseOutId: out.ID,
  2773. Status: 1,
  2774. Ctime: time.Now().Unix(),
  2775. Remark: "",
  2776. OrgId: adminInfo.Org.Id,
  2777. Type: 1,
  2778. Manufacturer: 0,
  2779. Dealer: 0,
  2780. IsSys: 1,
  2781. SysRecordTime: record_time,
  2782. }
  2783. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  2784. warehouseOutInfo.Price = stockInInfo.Price
  2785. warehouseOutInfo.GoodId = item.GoodId
  2786. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  2787. warehouseOutInfo.Count = item.Count
  2788. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2789. if err == nil {
  2790. details := &models.AutomaticReduceDetail{
  2791. WarehouseOutId: warehouseOutInfo.ID,
  2792. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2793. PatientId: patient_id,
  2794. Ctime: time.Now().Unix(),
  2795. Mtime: time.Now().Unix(),
  2796. Status: 1,
  2797. RecordTime: record_time,
  2798. OrgId: adminInfo.Org.Id,
  2799. GoodId: item.GoodId,
  2800. GoodTypeId: item.GoodTypeId,
  2801. Count: item.Count,
  2802. }
  2803. service.AddSigleAutoReduceRecordInfo(details)
  2804. }
  2805. } else if err == nil { //记录存在,则将增加数量
  2806. if outInfo.ID > 0 {
  2807. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  2808. }
  2809. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  2810. if count == 0 {
  2811. details := &models.AutomaticReduceDetail{
  2812. WarehouseOutId: outInfo.ID,
  2813. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  2814. PatientId: patient_id,
  2815. Ctime: time.Now().Unix(),
  2816. Mtime: time.Now().Unix(),
  2817. Status: 1,
  2818. RecordTime: record_time,
  2819. OrgId: adminInfo.Org.Id,
  2820. GoodId: item.GoodId,
  2821. GoodTypeId: item.GoodTypeId,
  2822. Count: item.Count,
  2823. }
  2824. service.AddSigleAutoReduceRecordInfo(details)
  2825. } else if count == 1 {
  2826. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  2827. }
  2828. }
  2829. }
  2830. }
  2831. c.ServeSuccessJSON(map[string]interface{}{
  2832. "msg": "提交成功",
  2833. })
  2834. return
  2835. } else {
  2836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  2837. return
  2838. }
  2839. }
  2840. func (c *DialysisAPIController) EditConsumables() {
  2841. patient_id, _ := c.GetInt64("patient_id", 0)
  2842. record_date := c.GetString("record_time")
  2843. if patient_id <= 0 {
  2844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2845. return
  2846. }
  2847. adminInfo := c.GetMobileAdminUserInfo()
  2848. timeLayout := "2006-01-02"
  2849. loc, _ := time.LoadLocation("Local")
  2850. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2851. record_time := theRecordTime.Unix()
  2852. dataBody := make(map[string]interface{}, 0)
  2853. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2854. if err != nil {
  2855. utils.ErrorLog(err.Error())
  2856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2857. return
  2858. }
  2859. var beforePrepares []*models.DialysisBeforePrepare
  2860. var newBeforePrepares []*models.DialysisBeforePrepare
  2861. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2862. if record.IsOpen == 1 {
  2863. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2864. goods, _ := dataBody["goods"].([]interface{})
  2865. if len(goods) > 0 {
  2866. for _, item := range goods {
  2867. items := item.(map[string]interface{})
  2868. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2869. utils.ErrorLog("record_time")
  2870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2871. return
  2872. }
  2873. record_time := int64(items["record_time"].(float64))
  2874. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2875. utils.ErrorLog("id")
  2876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2877. return
  2878. }
  2879. id := int64(items["id"].(float64))
  2880. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2881. utils.ErrorLog("patient_id")
  2882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2883. return
  2884. }
  2885. patient_id := int64(items["patient_id"].(float64))
  2886. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2887. utils.ErrorLog("creater")
  2888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2889. return
  2890. }
  2891. creater := int64(items["creater"].(float64))
  2892. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2893. utils.ErrorLog("good_id")
  2894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2895. return
  2896. }
  2897. good_id := int64(items["good_id"].(float64))
  2898. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2899. utils.ErrorLog("good_type_id")
  2900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2901. return
  2902. }
  2903. good_type_id := int64(items["good_type_id"].(float64))
  2904. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2905. utils.ErrorLog("count")
  2906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2907. return
  2908. }
  2909. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2910. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2911. utils.ErrorLog("ctime")
  2912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2913. return
  2914. }
  2915. ctime := int64(items["ctime"].(float64))
  2916. adminUser := c.GetMobileAdminUserInfo()
  2917. prepare := &models.DialysisBeforePrepare{
  2918. ID: id,
  2919. UserOrgId: adminUser.Org.Id,
  2920. PatientId: patient_id,
  2921. RecordDate: record_time,
  2922. GoodId: good_id,
  2923. GoodTypeId: good_type_id,
  2924. Count: count,
  2925. Ctime: ctime,
  2926. Mtime: time.Now().Unix(),
  2927. Creater: creater,
  2928. Modifier: adminUser.AdminUser.Id,
  2929. Status: 1,
  2930. }
  2931. beforePrepares = append(beforePrepares, prepare)
  2932. }
  2933. }
  2934. }
  2935. consumables_source, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2936. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  2937. goods, _ := dataBody["new_goods"].([]interface{})
  2938. if len(goods) > 0 {
  2939. for _, item := range goods {
  2940. items := item.(map[string]interface{})
  2941. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2942. utils.ErrorLog("good_id")
  2943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2944. return
  2945. }
  2946. good_id := int64(items["good_id"].(float64))
  2947. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2948. utils.ErrorLog("good_type_id")
  2949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2950. return
  2951. }
  2952. good_type_id := int64(items["good_type_id"].(float64))
  2953. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2954. utils.ErrorLog("count")
  2955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2956. return
  2957. }
  2958. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2959. adminUser := c.GetMobileAdminUserInfo()
  2960. prepare := &models.DialysisBeforePrepare{
  2961. UserOrgId: adminUser.Org.Id,
  2962. PatientId: patient_id,
  2963. RecordDate: record_time,
  2964. GoodId: good_id,
  2965. GoodTypeId: good_type_id,
  2966. Count: count,
  2967. Ctime: time.Now().Unix(),
  2968. Mtime: time.Now().Unix(),
  2969. Creater: adminUser.AdminUser.Id,
  2970. Modifier: 0,
  2971. }
  2972. newBeforePrepares = append(newBeforePrepares, prepare)
  2973. }
  2974. newBeforePrepares = RemoveRepeatedGood(newBeforePrepares)
  2975. }
  2976. service.CreateDialysisBeforePrepare(newBeforePrepares)
  2977. }
  2978. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  2979. if err == gorm.ErrRecordNotFound {
  2980. //没有记录,则创建出库单
  2981. timeStr := time.Now().Format("2006-01-02")
  2982. timeArr := strings.Split(timeStr, "-")
  2983. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  2984. total = total + 1
  2985. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2986. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2987. number = number + total
  2988. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2989. creater := adminInfo.AdminUser.Id
  2990. warehouseOut := models.WarehouseOut{
  2991. WarehouseOutOrderNumber: warehousing_out_order,
  2992. OperationTime: time.Now().Unix(),
  2993. OrgId: adminInfo.Org.Id,
  2994. Creater: creater,
  2995. Ctime: time.Now().Unix(),
  2996. Status: 1,
  2997. WarehouseOutTime: record_time,
  2998. Dealer: 0,
  2999. Manufacturer: 0,
  3000. Type: 1,
  3001. IsSys: 1,
  3002. }
  3003. err := service.AddSigleWarehouseOut(&warehouseOut)
  3004. if err != nil {
  3005. utils.TraceLog("创建出库单失败 err = %v", err)
  3006. } else {
  3007. for _, item := range beforePrepares {
  3008. if item.Count > 0 {
  3009. warehouseOutInfo := &models.WarehouseOutInfo{
  3010. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3011. WarehouseOutId: warehouseOut.ID,
  3012. Count: 1,
  3013. Status: 1,
  3014. Ctime: time.Now().Unix(),
  3015. Remark: "",
  3016. OrgId: adminInfo.Org.Id,
  3017. Type: 1,
  3018. Manufacturer: 0,
  3019. Dealer: 0,
  3020. IsSys: 1,
  3021. SysRecordTime: record_time,
  3022. GoodTypeId: item.GoodTypeId,
  3023. GoodId: item.GoodId,
  3024. }
  3025. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3026. warehouseOutInfo.Price = stockInInfo.Price
  3027. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3028. if err == nil {
  3029. details := &models.AutomaticReduceDetail{
  3030. WarehouseOutId: warehouseOutInfo.ID,
  3031. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3032. PatientId: patient_id,
  3033. Ctime: time.Now().Unix(),
  3034. Mtime: time.Now().Unix(),
  3035. Status: 1,
  3036. RecordTime: record_time,
  3037. OrgId: adminInfo.Org.Id,
  3038. GoodId: item.GoodId,
  3039. GoodTypeId: item.GoodTypeId,
  3040. }
  3041. service.AddSigleAutoReduceRecordInfo(details)
  3042. }
  3043. }
  3044. }
  3045. }
  3046. } else if err == nil {
  3047. if len(newBeforePrepares) > 0 { //新增
  3048. for _, item := range newBeforePrepares {
  3049. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3050. if err == gorm.ErrRecordNotFound {
  3051. warehouseOutInfo := &models.WarehouseOutInfo{
  3052. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3053. WarehouseOutId: out.ID,
  3054. Status: 1,
  3055. Ctime: time.Now().Unix(),
  3056. Remark: "",
  3057. OrgId: adminInfo.Org.Id,
  3058. Type: 1,
  3059. Manufacturer: 0,
  3060. Dealer: 0,
  3061. IsSys: 1,
  3062. SysRecordTime: record_time,
  3063. }
  3064. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3065. warehouseOutInfo.Price = stockInInfo.Price
  3066. warehouseOutInfo.GoodId = item.GoodId
  3067. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3068. warehouseOutInfo.Count = item.Count
  3069. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3070. if err == nil {
  3071. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3072. if count == 0 {
  3073. details := &models.AutomaticReduceDetail{
  3074. WarehouseOutId: warehouseOutInfo.ID,
  3075. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3076. PatientId: patient_id,
  3077. Ctime: time.Now().Unix(),
  3078. Mtime: time.Now().Unix(),
  3079. Status: 1,
  3080. RecordTime: record_time,
  3081. OrgId: adminInfo.Org.Id,
  3082. GoodId: item.GoodId,
  3083. GoodTypeId: item.GoodTypeId,
  3084. Count: item.Count,
  3085. }
  3086. service.AddSigleAutoReduceRecordInfo(details)
  3087. } else if count == 1 {
  3088. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3089. }
  3090. }
  3091. } else if err == nil { //记录存在,则将加数量
  3092. if outInfo.ID > 0 {
  3093. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3094. }
  3095. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3096. if count == 0 {
  3097. details := &models.AutomaticReduceDetail{
  3098. WarehouseOutId: outInfo.ID,
  3099. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3100. PatientId: patient_id,
  3101. Ctime: time.Now().Unix(),
  3102. Mtime: time.Now().Unix(),
  3103. Status: 1,
  3104. RecordTime: record_time,
  3105. OrgId: adminInfo.Org.Id,
  3106. GoodId: item.GoodId,
  3107. GoodTypeId: item.GoodTypeId,
  3108. Count: item.Count,
  3109. }
  3110. service.AddSigleAutoReduceRecordInfo(details)
  3111. } else if count == 1 {
  3112. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3113. }
  3114. //details := &models.AutomaticReduceDetail{
  3115. // WarehouseOutId: outInfo.ID,
  3116. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3117. // PatientId: patient_id,
  3118. // Ctime: time.Now().Unix(),
  3119. // Mtime: time.Now().Unix(),
  3120. // Status: 1,
  3121. // RecordTime: record_time,
  3122. // OrgId: adminInfo.Org.Id,
  3123. // GoodId: item.GoodId,
  3124. // GoodTypeId: item.GoodTypeId,
  3125. // Count: item.Count,
  3126. //}
  3127. //service.AddSigleAutoReduceRecordInfo(details)
  3128. }
  3129. }
  3130. }
  3131. if len(beforePrepares) > 0 { //修改
  3132. for _, consumable := range consumables_source {
  3133. for _, before := range beforePrepares {
  3134. if consumable.GoodId == before.GoodId {
  3135. fmt.Println(consumable.Count)
  3136. fmt.Println(before.Count)
  3137. if consumable.Count != before.Count {
  3138. fmt.Println("111111111")
  3139. _, out := service.FindStockOutOrderNumberByTime(record_time, adminInfo.Org.Id)
  3140. //_, out := service.FindOldOrderInfoByGoodId(record_time, adminInfo.Org.Id)
  3141. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3142. err, newOut := service.FindOrderInfoByGoodId(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id)
  3143. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3144. fmt.Println("222222222")
  3145. warehouseOutInfo := &models.WarehouseOutInfo{
  3146. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3147. WarehouseOutId: out.ID,
  3148. Count: before.Count,
  3149. Status: 1,
  3150. Ctime: time.Now().Unix(),
  3151. Remark: "",
  3152. OrgId: adminInfo.Org.Id,
  3153. Type: 1,
  3154. Manufacturer: 0,
  3155. Dealer: 0,
  3156. IsSys: 1,
  3157. SysRecordTime: record_time,
  3158. }
  3159. stockInInfo, _ := service.FindLastStockInInfoRecord(before.GoodId, adminInfo.Org.Id)
  3160. warehouseOutInfo.Price = stockInInfo.Price
  3161. warehouseOutInfo.GoodId = before.GoodId
  3162. warehouseOutInfo.GoodTypeId = before.GoodTypeId
  3163. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3164. if err == nil {
  3165. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3166. user, err := service.FindGoodUserById(before.GoodTypeId, before.GoodId, patient_id, adminInfo.Org.Id, out.WarehouseOutOrderNumber)
  3167. if err == gorm.ErrRecordNotFound {
  3168. details := &models.AutomaticReduceDetail{
  3169. WarehouseOutId: warehouseOutInfo.ID,
  3170. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3171. PatientId: patient_id,
  3172. Ctime: time.Now().Unix(),
  3173. Mtime: time.Now().Unix(),
  3174. Status: 1,
  3175. RecordTime: record_time,
  3176. OrgId: adminInfo.Org.Id,
  3177. GoodId: consumable.GoodId,
  3178. GoodTypeId: consumable.GoodTypeId,
  3179. Count: before.Count,
  3180. }
  3181. service.AddSigleAutoReduceRecordInfo(details)
  3182. } else if err == nil {
  3183. if user.ID > 0 {
  3184. //service.UpdateOrderInfoDetails( consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, a_liquid, warehouseOutInfo)
  3185. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, warehouseOutInfo)
  3186. }
  3187. }
  3188. }
  3189. } else if err == nil { //存在,则更改使用人商品信息
  3190. fmt.Println("333333333")
  3191. //处理原来的数据
  3192. if newOut.ID > 0 {
  3193. if consumable.Count > before.Count { // 减少
  3194. num := int64(0)
  3195. if consumable.Count-before.Count > 0 {
  3196. num = consumable.Count - before.Count
  3197. } else {
  3198. num = before.Count - consumable.Count
  3199. }
  3200. service.UpdateOrderCountSub(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, num)
  3201. } else if consumable.Count < before.Count { //增加
  3202. service.UpdateOrderCountAdd(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, before.Count-consumable.Count)
  3203. }
  3204. user, err := service.FindGoodUserById(consumable.GoodTypeId, consumable.GoodId, patient_id, adminInfo.Org.Id, out.WarehouseOutOrderNumber)
  3205. if err == gorm.ErrRecordNotFound {
  3206. details := &models.AutomaticReduceDetail{
  3207. WarehouseOutId: newOut.ID,
  3208. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  3209. PatientId: patient_id,
  3210. Ctime: time.Now().Unix(),
  3211. Mtime: time.Now().Unix(),
  3212. Status: 1,
  3213. RecordTime: record_time,
  3214. OrgId: adminInfo.Org.Id,
  3215. GoodId: consumable.GoodId,
  3216. GoodTypeId: consumable.GoodTypeId,
  3217. Count: before.Count,
  3218. }
  3219. service.AddSigleAutoReduceRecordInfo(details)
  3220. } else if err == nil {
  3221. if user.ID > 0 {
  3222. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, &newOut)
  3223. }
  3224. }
  3225. }
  3226. }
  3227. fmt.Println("444444444")
  3228. }
  3229. }
  3230. }
  3231. }
  3232. }
  3233. }
  3234. fmt.Println("655555555")
  3235. var errs error
  3236. if len(beforePrepares) > 0 {
  3237. for _, item := range beforePrepares {
  3238. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3239. }
  3240. }
  3241. if errs == nil {
  3242. c.ServeSuccessJSON(map[string]interface{}{
  3243. "msg": "修改成功",
  3244. })
  3245. return
  3246. } else {
  3247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3248. return
  3249. }
  3250. } else {
  3251. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3252. goods, _ := dataBody["goods"].([]interface{})
  3253. if len(goods) > 0 {
  3254. for _, item := range goods {
  3255. items := item.(map[string]interface{})
  3256. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3257. utils.ErrorLog("record_time")
  3258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3259. return
  3260. }
  3261. record_time := int64(items["record_time"].(float64))
  3262. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3263. utils.ErrorLog("id")
  3264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3265. return
  3266. }
  3267. id := int64(items["id"].(float64))
  3268. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3269. utils.ErrorLog("patient_id")
  3270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3271. return
  3272. }
  3273. patient_id := int64(items["patient_id"].(float64))
  3274. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3275. utils.ErrorLog("creater")
  3276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3277. return
  3278. }
  3279. creater := int64(items["creater"].(float64))
  3280. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3281. utils.ErrorLog("good_id")
  3282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3283. return
  3284. }
  3285. good_id := int64(items["good_id"].(float64))
  3286. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3287. utils.ErrorLog("good_type_id")
  3288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3289. return
  3290. }
  3291. good_type_id := int64(items["good_type_id"].(float64))
  3292. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3293. utils.ErrorLog("count")
  3294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3295. return
  3296. }
  3297. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3298. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3299. utils.ErrorLog("ctime")
  3300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3301. return
  3302. }
  3303. ctime := int64(items["ctime"].(float64))
  3304. adminUser := c.GetMobileAdminUserInfo()
  3305. prepare := &models.DialysisBeforePrepare{
  3306. ID: id,
  3307. UserOrgId: adminUser.Org.Id,
  3308. PatientId: patient_id,
  3309. RecordDate: record_time,
  3310. GoodId: good_id,
  3311. GoodTypeId: good_type_id,
  3312. Count: count,
  3313. Ctime: ctime,
  3314. Mtime: time.Now().Unix(),
  3315. Creater: creater,
  3316. Modifier: adminUser.AdminUser.Id,
  3317. Status: 1,
  3318. }
  3319. beforePrepares = append(beforePrepares, prepare)
  3320. }
  3321. }
  3322. }
  3323. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3324. goods, _ := dataBody["new_goods"].([]interface{})
  3325. if len(goods) > 0 {
  3326. for _, item := range goods {
  3327. items := item.(map[string]interface{})
  3328. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3329. utils.ErrorLog("good_id")
  3330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3331. return
  3332. }
  3333. good_id := int64(items["good_id"].(float64))
  3334. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3335. utils.ErrorLog("good_type_id")
  3336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3337. return
  3338. }
  3339. good_type_id := int64(items["good_type_id"].(float64))
  3340. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3341. utils.ErrorLog("count")
  3342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3343. return
  3344. }
  3345. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3346. adminUser := c.GetMobileAdminUserInfo()
  3347. prepare := &models.DialysisBeforePrepare{
  3348. UserOrgId: adminUser.Org.Id,
  3349. PatientId: patient_id,
  3350. RecordDate: record_time,
  3351. GoodId: good_id,
  3352. GoodTypeId: good_type_id,
  3353. Count: count,
  3354. Ctime: time.Now().Unix(),
  3355. Mtime: time.Now().Unix(),
  3356. Creater: adminUser.AdminUser.Id,
  3357. Modifier: 0,
  3358. }
  3359. newBeforePrepares = append(newBeforePrepares, prepare)
  3360. }
  3361. }
  3362. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3363. }
  3364. var errs error
  3365. if len(beforePrepares) > 0 {
  3366. for _, item := range beforePrepares {
  3367. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3368. }
  3369. }
  3370. if errs == nil {
  3371. c.ServeSuccessJSON(map[string]interface{}{
  3372. "msg": "修改成功",
  3373. })
  3374. return
  3375. } else {
  3376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3377. return
  3378. }
  3379. }
  3380. }
  3381. func (c *DialysisAPIController) GetDialysisGoods() {
  3382. schedualDate := c.GetString("schedule_date")
  3383. schedule_type, _ := c.GetInt64("schedule_type")
  3384. partition_id, _ := c.GetInt64("partition_id")
  3385. page, _ := c.GetInt("page")
  3386. patient_id, _ := c.GetInt64("patient_id")
  3387. schedualEndDate := int64(0)
  3388. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3389. if parseDateErr != nil && len(schedualDate) != 0 {
  3390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3391. return
  3392. }
  3393. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3394. if parseDateErr != nil && len(schedualDate) != 0 {
  3395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3396. return
  3397. }
  3398. schedualEndDate = endDate.Unix()
  3399. adminUser := c.GetMobileAdminUserInfo()
  3400. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  3401. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3402. if err == gorm.ErrRecordNotFound {
  3403. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3404. if patient_id != 0 {
  3405. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3406. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3407. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3408. item.LastAutomaticReduceDetail = goodUser
  3409. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3410. }
  3411. }
  3412. c.ServeSuccessJSON(map[string]interface{}{
  3413. "dialysis_goods": dialysisGoods,
  3414. "good_type": goodTypes,
  3415. "total": total,
  3416. })
  3417. return
  3418. } else if err == nil {
  3419. //获取当天排班的每个患者的库存使用情况
  3420. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3421. if patient_id != 0 {
  3422. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3423. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3424. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3425. fmt.Println(goodUser)
  3426. fmt.Println(lastGoodUserDetial)
  3427. item.LastAutomaticReduceDetail = goodUser
  3428. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3429. }
  3430. }
  3431. if err == nil {
  3432. c.ServeSuccessJSON(map[string]interface{}{
  3433. "dialysis_goods": dialysisGoods,
  3434. "good_type": goodTypes,
  3435. "total": total,
  3436. })
  3437. return
  3438. } else {
  3439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3440. return
  3441. }
  3442. } else if err != nil {
  3443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3444. return
  3445. }
  3446. }
  3447. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  3448. start_time := c.GetString("start_time")
  3449. end_time := c.GetString("end_time")
  3450. timeLayout := "2006-01-02"
  3451. loc, _ := time.LoadLocation("Local")
  3452. var theStartTime int64
  3453. if len(start_time) > 0 {
  3454. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3455. if err != nil {
  3456. utils.ErrorLog(err.Error())
  3457. }
  3458. theStartTime = theTime.Unix()
  3459. }
  3460. var theEndtTime int64
  3461. if len(end_time) > 0 {
  3462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3463. if err != nil {
  3464. utils.ErrorLog(err.Error())
  3465. }
  3466. theEndtTime = theTime.Unix()
  3467. }
  3468. adminUser := c.GetMobileAdminUserInfo()
  3469. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  3470. if err == nil {
  3471. c.ServeSuccessJSON(map[string]interface{}{
  3472. "stock_out": outInfo,
  3473. })
  3474. return
  3475. } else {
  3476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3477. return
  3478. }
  3479. }
  3480. func (c *DialysisAPIController) GetStockInGoodInfo() {
  3481. patient_id, _ := c.GetInt64("patient_id", 0)
  3482. record_time := c.GetString("record_time")
  3483. adminUser := c.GetMobileAdminUserInfo()
  3484. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  3485. if parseDateErr != nil && len(record_time) != 0 {
  3486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3487. return
  3488. }
  3489. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3490. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3491. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  3492. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  3493. c.ServeSuccessJSON(map[string]interface{}{
  3494. "good_type": goodTypes,
  3495. "good_user": goodUser,
  3496. "good_info": good_info,
  3497. "last_good_user": lastGoodUserDetial,
  3498. })
  3499. return
  3500. }
  3501. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  3502. patient_id, _ := c.GetInt64("patient_id", 0)
  3503. record_date := c.GetString("record_time")
  3504. if patient_id <= 0 {
  3505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3506. return
  3507. }
  3508. adminInfo := c.GetMobileAdminUserInfo()
  3509. timeLayout := "2006-01-02"
  3510. loc, _ := time.LoadLocation("Local")
  3511. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3512. record_time := theRecordTime.Unix()
  3513. dataBody := make(map[string]interface{}, 0)
  3514. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3515. if err != nil {
  3516. utils.ErrorLog(err.Error())
  3517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3518. return
  3519. }
  3520. var beforePrepares []*models.DialysisBeforePrepare
  3521. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3522. goods, _ := dataBody["goods"].([]interface{})
  3523. if len(goods) > 0 {
  3524. for _, item := range goods {
  3525. items := item.(map[string]interface{})
  3526. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3527. utils.ErrorLog("good_id")
  3528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3529. return
  3530. }
  3531. good_id := int64(items["good_id"].(float64))
  3532. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3533. utils.ErrorLog("good_type_id")
  3534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3535. return
  3536. }
  3537. good_type_id := int64(items["good_type_id"].(float64))
  3538. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3539. utils.ErrorLog("count")
  3540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3541. return
  3542. }
  3543. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3544. adminUser := c.GetMobileAdminUserInfo()
  3545. prepare := &models.DialysisBeforePrepare{
  3546. UserOrgId: adminUser.Org.Id,
  3547. PatientId: patient_id,
  3548. RecordDate: record_time,
  3549. GoodId: good_id,
  3550. GoodTypeId: good_type_id,
  3551. Count: count,
  3552. Ctime: time.Now().Unix(),
  3553. Mtime: time.Now().Unix(),
  3554. Creater: adminUser.AdminUser.Id,
  3555. Modifier: 0,
  3556. }
  3557. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  3558. if record_count == 0 {
  3559. beforePrepares = append(beforePrepares, prepare)
  3560. } else if record_count == 1 {
  3561. service.UpdateDialysisBeforePrepareTwo(prepare)
  3562. }
  3563. }
  3564. }
  3565. }
  3566. beforePrepares = RemoveRepeatedGood(beforePrepares)
  3567. if len(beforePrepares) > 0 {
  3568. service.CreateDialysisBeforePrepare(beforePrepares)
  3569. }
  3570. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3571. consumables = RemoveRepeatedGood(consumables)
  3572. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3573. if record.IsOpen == 1 {
  3574. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3575. if err == gorm.ErrRecordNotFound {
  3576. //没有记录,则创建出库单
  3577. timeStr := time.Now().Format("2006-01-02")
  3578. timeArr := strings.Split(timeStr, "-")
  3579. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3580. total = total + 1
  3581. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3582. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3583. number = number + total
  3584. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3585. creater := adminInfo.AdminUser.Id
  3586. warehouseOut := models.WarehouseOut{
  3587. WarehouseOutOrderNumber: warehousing_out_order,
  3588. OperationTime: time.Now().Unix(),
  3589. OrgId: adminInfo.Org.Id,
  3590. Creater: creater,
  3591. Ctime: time.Now().Unix(),
  3592. Status: 1,
  3593. WarehouseOutTime: record_time,
  3594. Dealer: 0,
  3595. Manufacturer: 0,
  3596. Type: 1,
  3597. IsSys: 1,
  3598. }
  3599. err := service.AddSigleWarehouseOut(&warehouseOut)
  3600. if err != nil {
  3601. utils.TraceLog("创建出库单失败 err = %v", err)
  3602. } else {
  3603. for _, item := range consumables {
  3604. if item.Count > 0 {
  3605. warehouseOutInfo := &models.WarehouseOutInfo{
  3606. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3607. WarehouseOutId: warehouseOut.ID,
  3608. Status: 1,
  3609. Ctime: time.Now().Unix(),
  3610. Remark: "",
  3611. OrgId: adminInfo.Org.Id,
  3612. Type: 1,
  3613. Manufacturer: 0,
  3614. Dealer: 0,
  3615. IsSys: 1,
  3616. SysRecordTime: record_time,
  3617. GoodTypeId: item.GoodTypeId,
  3618. GoodId: item.GoodId,
  3619. }
  3620. warehouseOutInfo.Count = item.Count
  3621. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3622. warehouseOutInfo.Price = stockInInfo.Price
  3623. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3624. if err == nil {
  3625. details := &models.AutomaticReduceDetail{
  3626. WarehouseOutId: warehouseOutInfo.ID,
  3627. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3628. PatientId: patient_id,
  3629. Ctime: time.Now().Unix(),
  3630. Mtime: time.Now().Unix(),
  3631. Status: 1,
  3632. RecordTime: record_time,
  3633. OrgId: adminInfo.Org.Id,
  3634. GoodId: item.GoodId,
  3635. GoodTypeId: item.GoodTypeId,
  3636. Count: item.Count,
  3637. }
  3638. service.AddSigleAutoReduceRecordInfo(details)
  3639. }
  3640. }
  3641. }
  3642. }
  3643. } else if err == nil {
  3644. for _, item := range consumables {
  3645. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3646. if err == gorm.ErrRecordNotFound {
  3647. warehouseOutInfo := &models.WarehouseOutInfo{
  3648. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3649. WarehouseOutId: out.ID,
  3650. Status: 1,
  3651. Ctime: time.Now().Unix(),
  3652. Remark: "",
  3653. OrgId: adminInfo.Org.Id,
  3654. Type: 1,
  3655. Manufacturer: 0,
  3656. Dealer: 0,
  3657. IsSys: 1,
  3658. SysRecordTime: record_time,
  3659. }
  3660. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3661. warehouseOutInfo.Price = stockInInfo.Price
  3662. warehouseOutInfo.GoodId = item.GoodId
  3663. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3664. warehouseOutInfo.Count = item.Count
  3665. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3666. if err == nil {
  3667. details := &models.AutomaticReduceDetail{
  3668. WarehouseOutId: warehouseOutInfo.ID,
  3669. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3670. PatientId: patient_id,
  3671. Ctime: time.Now().Unix(),
  3672. Mtime: time.Now().Unix(),
  3673. Status: 1,
  3674. RecordTime: record_time,
  3675. OrgId: adminInfo.Org.Id,
  3676. GoodId: item.GoodId,
  3677. GoodTypeId: item.GoodTypeId,
  3678. Count: item.Count,
  3679. }
  3680. service.AddSigleAutoReduceRecordInfo(details)
  3681. }
  3682. } else if err == nil { //记录存在,则将增加数量
  3683. if outInfo.ID > 0 {
  3684. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3685. }
  3686. details := &models.AutomaticReduceDetail{
  3687. WarehouseOutId: outInfo.ID,
  3688. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3689. PatientId: patient_id,
  3690. Ctime: time.Now().Unix(),
  3691. Mtime: time.Now().Unix(),
  3692. Status: 1,
  3693. RecordTime: record_time,
  3694. OrgId: adminInfo.Org.Id,
  3695. GoodId: item.GoodId,
  3696. GoodTypeId: item.GoodTypeId,
  3697. Count: item.Count,
  3698. }
  3699. service.AddSigleAutoReduceRecordInfo(details)
  3700. }
  3701. }
  3702. }
  3703. c.ServeSuccessJSON(map[string]interface{}{
  3704. "msg": "提交成功",
  3705. })
  3706. return
  3707. } else {
  3708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  3709. return
  3710. }
  3711. }
  3712. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  3713. newArr = make([]*models.DialysisBeforePrepare, 0)
  3714. for i := 0; i < len(arr); i++ {
  3715. repeat := false
  3716. for j := i + 1; j < len(arr); j++ {
  3717. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  3718. repeat = true
  3719. break
  3720. }
  3721. }
  3722. if !repeat {
  3723. newArr = append(newArr, arr[i])
  3724. }
  3725. }
  3726. return
  3727. }
  3728. func (c *DialysisAPIController) GetAllDrug() {
  3729. patient_id, _ := c.GetInt64("patient_id", 0)
  3730. adminInfo := c.GetMobileAdminUserInfo()
  3731. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3732. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  3733. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  3734. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  3735. c.ServeSuccessJSON(map[string]interface{}{
  3736. "base_drug_config": drugStockConfig,
  3737. "private_drug_config": privateDrugConfig,
  3738. "base_drug_list": drugList,
  3739. "private_drug_list": privateDrugList,
  3740. })
  3741. }