dialysis_api_controller.go 157KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282
  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. fmt.Println(t.Weekday())
  2064. fmt.Println(week)
  2065. switch week {
  2066. case 1:
  2067. if strings.Index(advice.WeekDay, "周一") == -1 {
  2068. advice_three = append(advice_three, advice)
  2069. }
  2070. break
  2071. case 2:
  2072. if strings.Index(advice.WeekDay, "周二") == -1 {
  2073. advice_three = append(advice_three, advice)
  2074. }
  2075. break
  2076. case 3:
  2077. if strings.Index(advice.WeekDay, "周三") == -1 {
  2078. advice_three = append(advice_three, advice)
  2079. }
  2080. break
  2081. case 4:
  2082. if strings.Index(advice.WeekDay, "周四") == -1 {
  2083. advice_three = append(advice_three, advice)
  2084. }
  2085. break
  2086. case 5:
  2087. if strings.Index(advice.WeekDay, "周五") == -1 {
  2088. advice_three = append(advice_three, advice)
  2089. }
  2090. break
  2091. case 6:
  2092. if strings.Index(advice.WeekDay, "周六") == -1 {
  2093. advice_three = append(advice_three, advice)
  2094. }
  2095. break
  2096. case 0:
  2097. if strings.Index(advice.WeekDay, "周日") == -1 {
  2098. advice_three = append(advice_three, advice)
  2099. }
  2100. break
  2101. }
  2102. }
  2103. }
  2104. for _, advice := range advices_two {
  2105. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2106. now := p.Unix()
  2107. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2108. dayStr2 := "-" + dayStr
  2109. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2110. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2111. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  2112. for _, ad := range advices {
  2113. advice_three = append(advice_three, ad)
  2114. }
  2115. }
  2116. if err == nil {
  2117. c.ServeSuccessJSON(map[string]interface{}{
  2118. "status": "2",
  2119. "advices": advices,
  2120. "advices_two": RemoveRepeatedElement(advice_three),
  2121. "is_open_remind": config.IsOpenRemind,
  2122. })
  2123. }
  2124. }
  2125. }
  2126. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2127. newArr = make([]*models.DoctorAdvice, 0)
  2128. for i := 0; i < len(arr); i++ {
  2129. repeat := false
  2130. for j := i + 1; j < len(arr); j++ {
  2131. if arr[i].ID == arr[j].ID {
  2132. repeat = true
  2133. break
  2134. }
  2135. }
  2136. if !repeat {
  2137. newArr = append(newArr, arr[i])
  2138. }
  2139. }
  2140. return
  2141. }
  2142. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  2143. patient, _ := c.GetInt64("id", 0)
  2144. groupNo, _ := c.GetInt64("groupno", 0)
  2145. if patient <= 0 {
  2146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2147. return
  2148. }
  2149. adminUserInfo := c.GetMobileAdminUserInfo()
  2150. dataBody := make(map[string]interface{}, 0)
  2151. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2152. if err != nil {
  2153. utils.ErrorLog(err.Error())
  2154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2155. return
  2156. }
  2157. utils.ErrorLog("%v", dataBody)
  2158. timeLayout := "2006-01-02 15:04"
  2159. loc, _ := time.LoadLocation("Local")
  2160. timeLayout2 := "2006-01-02"
  2161. loc2, _ := time.LoadLocation("Local")
  2162. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2163. utils.ErrorLog("advice_type")
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2165. return
  2166. }
  2167. adviceType := int64(2)
  2168. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2169. utils.ErrorLog("advice_date")
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2171. return
  2172. }
  2173. adviceDate, _ := dataBody["advice_date"].(string)
  2174. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2175. AdviceDate := theTime.Unix()
  2176. RecordDate := theTime.Unix()
  2177. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2178. utils.ErrorLog("start_time")
  2179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2180. return
  2181. }
  2182. startTime, _ := dataBody["start_time"].(string)
  2183. if len(startTime) == 0 {
  2184. utils.ErrorLog("len(start_time) == 0")
  2185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2186. return
  2187. }
  2188. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  2189. if err != nil {
  2190. utils.ErrorLog(err.Error())
  2191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2192. return
  2193. }
  2194. StartTime := theTime.Unix()
  2195. Remark := ""
  2196. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2197. remark, _ := dataBody["remark"].(string)
  2198. Remark = remark
  2199. }
  2200. var advices []*models.GroupAdvice
  2201. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2202. utils.ErrorLog("advices")
  2203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2204. return
  2205. }
  2206. adviceNames := dataBody["advices"].([]interface{})
  2207. for _, adviceNameMap := range adviceNames {
  2208. adviceNameM := adviceNameMap.(map[string]interface{})
  2209. var advice models.GroupAdvice
  2210. advice.Remark = Remark
  2211. advice.AdviceType = adviceType
  2212. advice.StartTime = StartTime
  2213. advice.AdviceDate = AdviceDate
  2214. advice.RecordDate = RecordDate
  2215. advice.Status = 1
  2216. advice.CreatedTime = time.Now().Unix()
  2217. advice.UpdatedTime = time.Now().Unix()
  2218. advice.StopState = 2
  2219. advice.ExecutionState = 2
  2220. advice.UserOrgId = adminUserInfo.Org.Id
  2221. advice.PatientId = patient
  2222. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2223. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2224. utils.ErrorLog("advice_name")
  2225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2226. return
  2227. }
  2228. adviceName, _ := adviceNameM["advice_name"].(string)
  2229. if len(adviceName) == 0 {
  2230. utils.ErrorLog("len(advice_name) == 0")
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. return
  2233. }
  2234. advice.AdviceName = adviceName
  2235. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2236. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2237. advice.DrugSpec = drugSpec
  2238. }
  2239. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2240. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2241. advice.AdviceDesc = adviceDesc
  2242. }
  2243. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2244. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2245. advice.DrugSpecUnit = drugSpecUnit
  2246. }
  2247. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2248. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2249. // advice.SingleDose = singleDose
  2250. //}
  2251. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2252. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2253. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2254. }
  2255. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2256. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2257. advice.SingleDoseUnit = singleDoseUnit
  2258. }
  2259. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2260. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2261. // advice.PrescribingNumber = prescribingNumber
  2262. //}
  2263. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2264. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2265. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2266. }
  2267. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2268. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2269. advice.PrescribingNumberUnit = prescribingNumberUnit
  2270. }
  2271. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2272. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2273. advice.DeliveryWay = deliveryWay
  2274. }
  2275. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2276. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2277. advice.ExecutionFrequency = executionFrequency
  2278. }
  2279. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2280. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2281. advice.FrequencyType = frequency_type
  2282. }
  2283. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2284. day_count := int64(adviceNameM["day_count"].(float64))
  2285. advice.DayCount = day_count
  2286. }
  2287. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2288. week_day, _ := adviceNameM["week_day"].(string)
  2289. advice.WeekDay = week_day
  2290. }
  2291. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2292. way := int64(adviceNameM["way"].(float64))
  2293. advice.Way = way
  2294. }
  2295. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2296. drug_id := int64(adviceNameM["drug_id"].(float64))
  2297. advice.DrugId = drug_id
  2298. }
  2299. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2300. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2301. advice.DrugNameId = drug_name_id
  2302. }
  2303. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2304. template_id, _ := adviceNameM["template_id"].(string)
  2305. advice.TemplateId = template_id
  2306. }
  2307. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  2308. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2309. advice.ExecutionFrequency = executionFrequency
  2310. }
  2311. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2312. children := adviceNameM["child"].([]interface{})
  2313. if len(children) > 0 {
  2314. for _, childrenMap := range children {
  2315. childMap := childrenMap.(map[string]interface{})
  2316. var child models.GroupAdvice
  2317. child.Remark = Remark
  2318. child.AdviceType = adviceType
  2319. child.StartTime = StartTime
  2320. child.AdviceDate = AdviceDate
  2321. child.RecordDate = RecordDate
  2322. child.Status = 1
  2323. child.CreatedTime = time.Now().Unix()
  2324. child.UpdatedTime = time.Now().Unix()
  2325. child.StopState = 2
  2326. child.ExecutionState = 2
  2327. child.UserOrgId = adminUserInfo.Org.Id
  2328. child.PatientId = patient
  2329. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2330. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2331. utils.ErrorLog("child advice_name")
  2332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2333. return
  2334. }
  2335. childAdviceName, _ := childMap["advice_name"].(string)
  2336. if len(childAdviceName) == 0 {
  2337. utils.ErrorLog("len(child advice_name) == 0")
  2338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2339. return
  2340. }
  2341. child.AdviceName = childAdviceName
  2342. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2343. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2344. child.AdviceDesc = childAdviceDesc
  2345. }
  2346. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2347. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2348. child.DrugSpec = childDrugSpec
  2349. }
  2350. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2351. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2352. child.DrugSpecUnit = childDrugSpecUnit
  2353. }
  2354. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  2355. child.SingleDose = childMap["single_dose"].(float64)
  2356. }
  2357. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2358. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2359. child.SingleDoseUnit = childSingleDoseUnit
  2360. }
  2361. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  2362. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  2363. }
  2364. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2365. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2366. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2367. }
  2368. child.DeliveryWay = advice.DeliveryWay
  2369. child.ExecutionFrequency = advice.ExecutionFrequency
  2370. advice.Children = append(advice.Children, &child)
  2371. }
  2372. }
  2373. }
  2374. advices = append(advices, &advice)
  2375. }
  2376. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  2377. if err != nil {
  2378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2379. return
  2380. }
  2381. c.ServeSuccessJSON(map[string]interface{}{
  2382. "msg": "ok",
  2383. "advices": list,
  2384. })
  2385. return
  2386. }
  2387. func (c *DialysisAPIController) UploadDryWeight() {
  2388. patient_id, _ := c.GetInt64("id")
  2389. dry_weight, _ := c.GetFloat("dry_weight")
  2390. doctor_id, _ := c.GetInt64("doctor_id")
  2391. remark := c.GetString("remark")
  2392. adminUserInfo := c.GetMobileAdminUserInfo()
  2393. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  2394. if err == gorm.ErrRecordNotFound {
  2395. dryWeight := &models.SgjPatientDryweight{
  2396. PatientId: patient_id,
  2397. DryWeight: dry_weight,
  2398. Remakes: remark,
  2399. Ctime: time.Now().Unix(),
  2400. Mtime: time.Now().Unix(),
  2401. Creator: doctor_id,
  2402. Status: 1,
  2403. UserOrgId: adminUserInfo.Org.Id,
  2404. AdjustedValue: "/",
  2405. UserId: adminUserInfo.AdminUser.Id,
  2406. }
  2407. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2408. if createErr == nil {
  2409. c.ServeSuccessJSON(map[string]interface{}{
  2410. "msg": "提交成功",
  2411. "weight": dryWeight,
  2412. })
  2413. }
  2414. } else {
  2415. dryWeight := &models.SgjPatientDryweight{
  2416. PatientId: patient_id,
  2417. DryWeight: dry_weight,
  2418. Remakes: remark,
  2419. Ctime: time.Now().Unix(),
  2420. Mtime: time.Now().Unix(),
  2421. Creator: doctor_id,
  2422. Status: 1,
  2423. UserOrgId: adminUserInfo.Org.Id,
  2424. AdjustedValue: "/",
  2425. UserId: adminUserInfo.AdminUser.Id,
  2426. }
  2427. var value float64
  2428. value = dry_weight - weightAdjust.DryWeight
  2429. if value < 0 {
  2430. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2431. } else if value == 0 {
  2432. dryWeight.AdjustedValue = "/"
  2433. } else if value > 0 {
  2434. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2435. }
  2436. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2437. if createErr == nil {
  2438. c.ServeSuccessJSON(map[string]interface{}{
  2439. "msg": "提交成功",
  2440. "weight": dryWeight,
  2441. })
  2442. }
  2443. }
  2444. }
  2445. func (c *DialysisAPIController) GetSolution() {
  2446. patient_id, _ := c.GetInt64("patient_id")
  2447. mode_id, _ := c.GetInt64("mode_id")
  2448. adminUserInfo := c.GetMobileAdminUserInfo()
  2449. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2450. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2451. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  2452. if err != nil {
  2453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2454. return
  2455. }
  2456. c.ServeSuccessJSON(map[string]interface{}{
  2457. "solution": solution,
  2458. "prescription": prescription,
  2459. "system_prescription": system_prescription,
  2460. })
  2461. }
  2462. func (c *DialysisAPIController) GetSchedule() {
  2463. schedual_type, _ := c.GetInt64("schedual_type")
  2464. adminUserInfo := c.GetMobileAdminUserInfo()
  2465. timeLayout := "2006-01-02 15:04:05"
  2466. date := time.Now().Format("2006-01-02") + " 00:00:00"
  2467. loc, _ := time.LoadLocation("Local")
  2468. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2469. scheduleTime := theStartTime.Unix()
  2470. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  2471. c.ServeSuccessJSON(map[string]interface{}{
  2472. "number": deviceNumber,
  2473. })
  2474. }
  2475. func (c *DialysisAPIController) GetPatientId() {
  2476. id, _ := c.GetInt64("id")
  2477. patientId, _ := service.GetPatientId(id)
  2478. c.ServeSuccessJSON(map[string]interface{}{
  2479. "patient": patientId,
  2480. })
  2481. }
  2482. func (this *DialysisAPIController) GetDialysisSchedule() {
  2483. schedualDate := this.GetString("date")
  2484. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  2485. if parseDateErr != nil {
  2486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2487. return
  2488. }
  2489. adminInfo := this.GetMobileAdminUserInfo()
  2490. orgID := adminInfo.Org.Id
  2491. redis := service.RedisClient()
  2492. defer redis.Close()
  2493. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  2494. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  2495. if len(scheduals) > 0 {
  2496. //缓存数据
  2497. scheduals_json, err := json.Marshal(scheduals)
  2498. if err == nil {
  2499. redis.Set(key, scheduals_json, time.Second*30)
  2500. }
  2501. }
  2502. this.ServeSuccessJSON(map[string]interface{}{
  2503. "scheduals": scheduals,
  2504. })
  2505. }
  2506. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  2507. change_type, _ := this.GetInt64("type", 0)
  2508. record_date := this.GetString("record_time")
  2509. patient_id, _ := this.GetInt64("patient_id", 0)
  2510. timeLayout := "2006-01-02"
  2511. loc, _ := time.LoadLocation("Local")
  2512. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2513. record_time := theAdviceRecordTime.Unix()
  2514. adminUserInfo := this.GetMobileAdminUserInfo()
  2515. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  2516. if err == nil {
  2517. if len(advices) == 0 {
  2518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2519. return
  2520. } else {
  2521. this.ServeSuccessJSON(map[string]interface{}{
  2522. "advices": advices,
  2523. "schedule": sch,
  2524. })
  2525. return
  2526. }
  2527. } else {
  2528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2529. return
  2530. }
  2531. }
  2532. func (c *DialysisAPIController) CreateConsumables() {
  2533. record_date := c.GetString("record_time")
  2534. patient_id, _ := c.GetInt64("patient_id", 0)
  2535. adminUser := c.GetMobileAdminUserInfo()
  2536. timeLayout := "2006-01-02"
  2537. loc, _ := time.LoadLocation("Local")
  2538. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2539. record_time := theRecordTime.Unix()
  2540. dataBody := make(map[string]interface{}, 0)
  2541. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2542. if err != nil {
  2543. utils.ErrorLog(err.Error())
  2544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2545. return
  2546. }
  2547. var beforePrepares []*models.DialysisBeforePrepare
  2548. var updateBeforePrepares []*models.DialysisBeforePrepare
  2549. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2550. goods, _ := dataBody["goods"].([]interface{})
  2551. if len(goods) > 0 {
  2552. for _, item := range goods {
  2553. items := item.(map[string]interface{})
  2554. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2555. utils.ErrorLog("good_id")
  2556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2557. return
  2558. }
  2559. good_id := int64(items["good_id"].(float64))
  2560. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2561. utils.ErrorLog("good_type_id")
  2562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2563. return
  2564. }
  2565. good_type_id := int64(items["good_type_id"].(float64))
  2566. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2567. utils.ErrorLog("count")
  2568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2569. return
  2570. }
  2571. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2572. adminUser := c.GetMobileAdminUserInfo()
  2573. prepare := &models.DialysisBeforePrepare{
  2574. UserOrgId: adminUser.Org.Id,
  2575. PatientId: patient_id,
  2576. RecordDate: record_time,
  2577. GoodId: good_id,
  2578. GoodTypeId: good_type_id,
  2579. Count: count,
  2580. Ctime: time.Now().Unix(),
  2581. Mtime: time.Now().Unix(),
  2582. Creater: adminUser.AdminUser.Id,
  2583. Modifier: 0,
  2584. }
  2585. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  2586. if record_count == 0 {
  2587. beforePrepares = append(beforePrepares, prepare)
  2588. }
  2589. }
  2590. }
  2591. }
  2592. if len(beforePrepares) > 0 {
  2593. service.CreateDialysisBeforePrepare(beforePrepares)
  2594. }
  2595. var errs error
  2596. if dataBody["update_goods"] != nil && reflect.TypeOf(dataBody["update_goods"]).String() == "[]interface {}" {
  2597. goods, _ := dataBody["update_goods"].([]interface{})
  2598. if len(goods) > 0 {
  2599. for _, item := range goods {
  2600. items := item.(map[string]interface{})
  2601. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2602. utils.ErrorLog("record_time")
  2603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2604. return
  2605. }
  2606. record_time := int64(items["record_time"].(float64))
  2607. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2608. utils.ErrorLog("id")
  2609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2610. return
  2611. }
  2612. id := int64(items["id"].(float64))
  2613. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2614. utils.ErrorLog("patient_id")
  2615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2616. return
  2617. }
  2618. patient_id := int64(items["patient_id"].(float64))
  2619. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2620. utils.ErrorLog("creater")
  2621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2622. return
  2623. }
  2624. creater := int64(items["creater"].(float64))
  2625. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2626. utils.ErrorLog("good_id")
  2627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2628. return
  2629. }
  2630. good_id := int64(items["good_id"].(float64))
  2631. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2632. utils.ErrorLog("good_type_id")
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2634. return
  2635. }
  2636. good_type_id := int64(items["good_type_id"].(float64))
  2637. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2638. utils.ErrorLog("count")
  2639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2640. return
  2641. }
  2642. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2643. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2644. utils.ErrorLog("ctime")
  2645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2646. return
  2647. }
  2648. ctime := int64(items["ctime"].(float64))
  2649. prepare := &models.DialysisBeforePrepare{
  2650. ID: id,
  2651. UserOrgId: adminUser.Org.Id,
  2652. PatientId: patient_id,
  2653. RecordDate: record_time,
  2654. GoodId: good_id,
  2655. GoodTypeId: good_type_id,
  2656. Count: count,
  2657. Ctime: ctime,
  2658. Mtime: time.Now().Unix(),
  2659. Creater: creater,
  2660. Modifier: adminUser.AdminUser.Id,
  2661. Status: 1,
  2662. }
  2663. updateBeforePrepares = append(updateBeforePrepares, prepare)
  2664. }
  2665. }
  2666. updateBeforePrepares = RemoveRepeatedGood(updateBeforePrepares)
  2667. if len(updateBeforePrepares) > 0 {
  2668. for _, item := range updateBeforePrepares {
  2669. errs = service.UpdateDialysisBeforePrepareTwo(item)
  2670. }
  2671. }
  2672. }
  2673. if errs == nil {
  2674. c.ServeSuccessJSON(map[string]interface{}{
  2675. "msg": "提交成功",
  2676. })
  2677. return
  2678. } else {
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2680. return
  2681. }
  2682. }
  2683. func (c *DialysisAPIController) CreateStockOutInfo() {
  2684. patient_id, _ := c.GetInt64("patient_id", 0)
  2685. record_date := c.GetString("record_time")
  2686. if patient_id <= 0 {
  2687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2688. return
  2689. }
  2690. adminInfo := c.GetMobileAdminUserInfo()
  2691. timeLayout := "2006-01-02"
  2692. loc, _ := time.LoadLocation("Local")
  2693. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2694. record_time := theRecordTime.Unix()
  2695. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2696. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2697. consumables = RemoveRepeatedGood(consumables)
  2698. if record.IsOpen == 1 {
  2699. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  2700. if err == gorm.ErrRecordNotFound {
  2701. //没有记录,则创建出库单
  2702. timeStr := time.Now().Format("2006-01-02")
  2703. timeArr := strings.Split(timeStr, "-")
  2704. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  2705. total = total + 1
  2706. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2707. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2708. number = number + total
  2709. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2710. creater := adminInfo.AdminUser.Id
  2711. warehouseOut := models.WarehouseOut{
  2712. WarehouseOutOrderNumber: warehousing_out_order,
  2713. OperationTime: time.Now().Unix(),
  2714. OrgId: adminInfo.Org.Id,
  2715. Creater: creater,
  2716. Ctime: time.Now().Unix(),
  2717. Status: 1,
  2718. WarehouseOutTime: record_time,
  2719. Dealer: 0,
  2720. Manufacturer: 0,
  2721. Type: 1,
  2722. IsSys: 1,
  2723. }
  2724. err := service.AddSigleWarehouseOut(&warehouseOut)
  2725. if err != nil {
  2726. utils.TraceLog("创建出库单失败 err = %v", err)
  2727. } else {
  2728. for _, item := range consumables {
  2729. if item.Count > 0 {
  2730. warehouseOutInfo := &models.WarehouseOutInfo{
  2731. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2732. WarehouseOutId: warehouseOut.ID,
  2733. Status: 1,
  2734. Ctime: time.Now().Unix(),
  2735. Remark: "",
  2736. OrgId: adminInfo.Org.Id,
  2737. Type: 1,
  2738. Manufacturer: 0,
  2739. Dealer: 0,
  2740. IsSys: 1,
  2741. SysRecordTime: record_time,
  2742. GoodTypeId: item.GoodTypeId,
  2743. GoodId: item.GoodId,
  2744. }
  2745. warehouseOutInfo.Count = item.Count
  2746. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  2747. warehouseOutInfo.Price = stockInInfo.Price
  2748. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2749. if err == nil {
  2750. details := &models.AutomaticReduceDetail{
  2751. WarehouseOutId: warehouseOutInfo.ID,
  2752. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2753. PatientId: patient_id,
  2754. Ctime: time.Now().Unix(),
  2755. Mtime: time.Now().Unix(),
  2756. Status: 1,
  2757. RecordTime: record_time,
  2758. OrgId: adminInfo.Org.Id,
  2759. GoodId: item.GoodId,
  2760. GoodTypeId: item.GoodTypeId,
  2761. Count: item.Count,
  2762. }
  2763. service.AddSigleAutoReduceRecordInfo(details)
  2764. }
  2765. }
  2766. }
  2767. }
  2768. } else if err == nil {
  2769. for _, item := range consumables {
  2770. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  2771. if err == gorm.ErrRecordNotFound {
  2772. warehouseOutInfo := &models.WarehouseOutInfo{
  2773. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2774. WarehouseOutId: out.ID,
  2775. Status: 1,
  2776. Ctime: time.Now().Unix(),
  2777. Remark: "",
  2778. OrgId: adminInfo.Org.Id,
  2779. Type: 1,
  2780. Manufacturer: 0,
  2781. Dealer: 0,
  2782. IsSys: 1,
  2783. SysRecordTime: record_time,
  2784. }
  2785. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  2786. warehouseOutInfo.Price = stockInInfo.Price
  2787. warehouseOutInfo.GoodId = item.GoodId
  2788. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  2789. warehouseOutInfo.Count = item.Count
  2790. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2791. if err == nil {
  2792. details := &models.AutomaticReduceDetail{
  2793. WarehouseOutId: warehouseOutInfo.ID,
  2794. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2795. PatientId: patient_id,
  2796. Ctime: time.Now().Unix(),
  2797. Mtime: time.Now().Unix(),
  2798. Status: 1,
  2799. RecordTime: record_time,
  2800. OrgId: adminInfo.Org.Id,
  2801. GoodId: item.GoodId,
  2802. GoodTypeId: item.GoodTypeId,
  2803. Count: item.Count,
  2804. }
  2805. service.AddSigleAutoReduceRecordInfo(details)
  2806. }
  2807. } else if err == nil { //记录存在,则将增加数量
  2808. if outInfo.ID > 0 {
  2809. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  2810. }
  2811. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  2812. if count == 0 {
  2813. details := &models.AutomaticReduceDetail{
  2814. WarehouseOutId: outInfo.ID,
  2815. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  2816. PatientId: patient_id,
  2817. Ctime: time.Now().Unix(),
  2818. Mtime: time.Now().Unix(),
  2819. Status: 1,
  2820. RecordTime: record_time,
  2821. OrgId: adminInfo.Org.Id,
  2822. GoodId: item.GoodId,
  2823. GoodTypeId: item.GoodTypeId,
  2824. Count: item.Count,
  2825. }
  2826. service.AddSigleAutoReduceRecordInfo(details)
  2827. } else if count == 1 {
  2828. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  2829. }
  2830. }
  2831. }
  2832. }
  2833. c.ServeSuccessJSON(map[string]interface{}{
  2834. "msg": "提交成功",
  2835. })
  2836. return
  2837. } else {
  2838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  2839. return
  2840. }
  2841. }
  2842. func (c *DialysisAPIController) EditConsumables() {
  2843. patient_id, _ := c.GetInt64("patient_id", 0)
  2844. record_date := c.GetString("record_time")
  2845. if patient_id <= 0 {
  2846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2847. return
  2848. }
  2849. adminInfo := c.GetMobileAdminUserInfo()
  2850. timeLayout := "2006-01-02"
  2851. loc, _ := time.LoadLocation("Local")
  2852. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2853. record_time := theRecordTime.Unix()
  2854. dataBody := make(map[string]interface{}, 0)
  2855. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2856. if err != nil {
  2857. utils.ErrorLog(err.Error())
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2859. return
  2860. }
  2861. var beforePrepares []*models.DialysisBeforePrepare
  2862. var newBeforePrepares []*models.DialysisBeforePrepare
  2863. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2864. if record.IsOpen == 1 {
  2865. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2866. goods, _ := dataBody["goods"].([]interface{})
  2867. if len(goods) > 0 {
  2868. for _, item := range goods {
  2869. items := item.(map[string]interface{})
  2870. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2871. utils.ErrorLog("record_time")
  2872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2873. return
  2874. }
  2875. record_time := int64(items["record_time"].(float64))
  2876. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2877. utils.ErrorLog("id")
  2878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2879. return
  2880. }
  2881. id := int64(items["id"].(float64))
  2882. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2883. utils.ErrorLog("patient_id")
  2884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2885. return
  2886. }
  2887. patient_id := int64(items["patient_id"].(float64))
  2888. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2889. utils.ErrorLog("creater")
  2890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2891. return
  2892. }
  2893. creater := int64(items["creater"].(float64))
  2894. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2895. utils.ErrorLog("good_id")
  2896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2897. return
  2898. }
  2899. good_id := int64(items["good_id"].(float64))
  2900. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2901. utils.ErrorLog("good_type_id")
  2902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2903. return
  2904. }
  2905. good_type_id := int64(items["good_type_id"].(float64))
  2906. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2907. utils.ErrorLog("count")
  2908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2909. return
  2910. }
  2911. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2912. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2913. utils.ErrorLog("ctime")
  2914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2915. return
  2916. }
  2917. ctime := int64(items["ctime"].(float64))
  2918. adminUser := c.GetMobileAdminUserInfo()
  2919. prepare := &models.DialysisBeforePrepare{
  2920. ID: id,
  2921. UserOrgId: adminUser.Org.Id,
  2922. PatientId: patient_id,
  2923. RecordDate: record_time,
  2924. GoodId: good_id,
  2925. GoodTypeId: good_type_id,
  2926. Count: count,
  2927. Ctime: ctime,
  2928. Mtime: time.Now().Unix(),
  2929. Creater: creater,
  2930. Modifier: adminUser.AdminUser.Id,
  2931. Status: 1,
  2932. }
  2933. beforePrepares = append(beforePrepares, prepare)
  2934. }
  2935. }
  2936. }
  2937. consumables_source, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2938. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  2939. goods, _ := dataBody["new_goods"].([]interface{})
  2940. if len(goods) > 0 {
  2941. for _, item := range goods {
  2942. items := item.(map[string]interface{})
  2943. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2944. utils.ErrorLog("good_id")
  2945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2946. return
  2947. }
  2948. good_id := int64(items["good_id"].(float64))
  2949. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2950. utils.ErrorLog("good_type_id")
  2951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2952. return
  2953. }
  2954. good_type_id := int64(items["good_type_id"].(float64))
  2955. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2956. utils.ErrorLog("count")
  2957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2958. return
  2959. }
  2960. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2961. adminUser := c.GetMobileAdminUserInfo()
  2962. prepare := &models.DialysisBeforePrepare{
  2963. UserOrgId: adminUser.Org.Id,
  2964. PatientId: patient_id,
  2965. RecordDate: record_time,
  2966. GoodId: good_id,
  2967. GoodTypeId: good_type_id,
  2968. Count: count,
  2969. Ctime: time.Now().Unix(),
  2970. Mtime: time.Now().Unix(),
  2971. Creater: adminUser.AdminUser.Id,
  2972. Modifier: 0,
  2973. }
  2974. newBeforePrepares = append(newBeforePrepares, prepare)
  2975. }
  2976. newBeforePrepares = RemoveRepeatedGood(newBeforePrepares)
  2977. }
  2978. service.CreateDialysisBeforePrepare(newBeforePrepares)
  2979. }
  2980. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  2981. if err == gorm.ErrRecordNotFound {
  2982. //没有记录,则创建出库单
  2983. timeStr := time.Now().Format("2006-01-02")
  2984. timeArr := strings.Split(timeStr, "-")
  2985. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  2986. total = total + 1
  2987. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2988. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2989. number = number + total
  2990. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2991. creater := adminInfo.AdminUser.Id
  2992. warehouseOut := models.WarehouseOut{
  2993. WarehouseOutOrderNumber: warehousing_out_order,
  2994. OperationTime: time.Now().Unix(),
  2995. OrgId: adminInfo.Org.Id,
  2996. Creater: creater,
  2997. Ctime: time.Now().Unix(),
  2998. Status: 1,
  2999. WarehouseOutTime: record_time,
  3000. Dealer: 0,
  3001. Manufacturer: 0,
  3002. Type: 1,
  3003. IsSys: 1,
  3004. }
  3005. err := service.AddSigleWarehouseOut(&warehouseOut)
  3006. if err != nil {
  3007. utils.TraceLog("创建出库单失败 err = %v", err)
  3008. } else {
  3009. for _, item := range beforePrepares {
  3010. if item.Count > 0 {
  3011. warehouseOutInfo := &models.WarehouseOutInfo{
  3012. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3013. WarehouseOutId: warehouseOut.ID,
  3014. Count: 1,
  3015. Status: 1,
  3016. Ctime: time.Now().Unix(),
  3017. Remark: "",
  3018. OrgId: adminInfo.Org.Id,
  3019. Type: 1,
  3020. Manufacturer: 0,
  3021. Dealer: 0,
  3022. IsSys: 1,
  3023. SysRecordTime: record_time,
  3024. GoodTypeId: item.GoodTypeId,
  3025. GoodId: item.GoodId,
  3026. }
  3027. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3028. warehouseOutInfo.Price = stockInInfo.Price
  3029. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3030. if err == nil {
  3031. details := &models.AutomaticReduceDetail{
  3032. WarehouseOutId: warehouseOutInfo.ID,
  3033. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3034. PatientId: patient_id,
  3035. Ctime: time.Now().Unix(),
  3036. Mtime: time.Now().Unix(),
  3037. Status: 1,
  3038. RecordTime: record_time,
  3039. OrgId: adminInfo.Org.Id,
  3040. GoodId: item.GoodId,
  3041. GoodTypeId: item.GoodTypeId,
  3042. }
  3043. service.AddSigleAutoReduceRecordInfo(details)
  3044. }
  3045. }
  3046. }
  3047. }
  3048. } else if err == nil {
  3049. if len(newBeforePrepares) > 0 { //新增
  3050. for _, item := range newBeforePrepares {
  3051. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3052. if err == gorm.ErrRecordNotFound {
  3053. warehouseOutInfo := &models.WarehouseOutInfo{
  3054. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3055. WarehouseOutId: out.ID,
  3056. Status: 1,
  3057. Ctime: time.Now().Unix(),
  3058. Remark: "",
  3059. OrgId: adminInfo.Org.Id,
  3060. Type: 1,
  3061. Manufacturer: 0,
  3062. Dealer: 0,
  3063. IsSys: 1,
  3064. SysRecordTime: record_time,
  3065. }
  3066. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3067. warehouseOutInfo.Price = stockInInfo.Price
  3068. warehouseOutInfo.GoodId = item.GoodId
  3069. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3070. warehouseOutInfo.Count = item.Count
  3071. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3072. if err == nil {
  3073. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3074. if count == 0 {
  3075. details := &models.AutomaticReduceDetail{
  3076. WarehouseOutId: warehouseOutInfo.ID,
  3077. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3078. PatientId: patient_id,
  3079. Ctime: time.Now().Unix(),
  3080. Mtime: time.Now().Unix(),
  3081. Status: 1,
  3082. RecordTime: record_time,
  3083. OrgId: adminInfo.Org.Id,
  3084. GoodId: item.GoodId,
  3085. GoodTypeId: item.GoodTypeId,
  3086. Count: item.Count,
  3087. }
  3088. service.AddSigleAutoReduceRecordInfo(details)
  3089. } else if count == 1 {
  3090. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3091. }
  3092. }
  3093. } else if err == nil { //记录存在,则将加数量
  3094. if outInfo.ID > 0 {
  3095. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3096. }
  3097. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3098. if count == 0 {
  3099. details := &models.AutomaticReduceDetail{
  3100. WarehouseOutId: outInfo.ID,
  3101. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3102. PatientId: patient_id,
  3103. Ctime: time.Now().Unix(),
  3104. Mtime: time.Now().Unix(),
  3105. Status: 1,
  3106. RecordTime: record_time,
  3107. OrgId: adminInfo.Org.Id,
  3108. GoodId: item.GoodId,
  3109. GoodTypeId: item.GoodTypeId,
  3110. Count: item.Count,
  3111. }
  3112. service.AddSigleAutoReduceRecordInfo(details)
  3113. } else if count == 1 {
  3114. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3115. }
  3116. //details := &models.AutomaticReduceDetail{
  3117. // WarehouseOutId: outInfo.ID,
  3118. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3119. // PatientId: patient_id,
  3120. // Ctime: time.Now().Unix(),
  3121. // Mtime: time.Now().Unix(),
  3122. // Status: 1,
  3123. // RecordTime: record_time,
  3124. // OrgId: adminInfo.Org.Id,
  3125. // GoodId: item.GoodId,
  3126. // GoodTypeId: item.GoodTypeId,
  3127. // Count: item.Count,
  3128. //}
  3129. //service.AddSigleAutoReduceRecordInfo(details)
  3130. }
  3131. }
  3132. }
  3133. if len(beforePrepares) > 0 { //修改
  3134. for _, consumable := range consumables_source {
  3135. for _, before := range beforePrepares {
  3136. if consumable.GoodId == before.GoodId {
  3137. if consumable.Count != before.Count {
  3138. _, out := service.FindStockOutOrderNumberByTime(record_time, adminInfo.Org.Id)
  3139. //_, out := service.FindOldOrderInfoByGoodId(record_time, adminInfo.Org.Id)
  3140. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3141. err, newOut := service.FindOrderInfoByGoodId(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id)
  3142. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3143. warehouseOutInfo := &models.WarehouseOutInfo{
  3144. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3145. WarehouseOutId: out.ID,
  3146. Count: before.Count,
  3147. Status: 1,
  3148. Ctime: time.Now().Unix(),
  3149. Remark: "",
  3150. OrgId: adminInfo.Org.Id,
  3151. Type: 1,
  3152. Manufacturer: 0,
  3153. Dealer: 0,
  3154. IsSys: 1,
  3155. SysRecordTime: record_time,
  3156. }
  3157. stockInInfo, _ := service.FindLastStockInInfoRecord(before.GoodId, adminInfo.Org.Id)
  3158. warehouseOutInfo.Price = stockInInfo.Price
  3159. warehouseOutInfo.GoodId = before.GoodId
  3160. warehouseOutInfo.GoodTypeId = before.GoodTypeId
  3161. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3162. if err == nil {
  3163. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3164. user, err := service.FindGoodUserById(before.GoodTypeId, before.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3165. if err == gorm.ErrRecordNotFound {
  3166. details := &models.AutomaticReduceDetail{
  3167. WarehouseOutId: warehouseOutInfo.ID,
  3168. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3169. PatientId: patient_id,
  3170. Ctime: time.Now().Unix(),
  3171. Mtime: time.Now().Unix(),
  3172. Status: 1,
  3173. RecordTime: record_time,
  3174. OrgId: adminInfo.Org.Id,
  3175. GoodId: consumable.GoodId,
  3176. GoodTypeId: consumable.GoodTypeId,
  3177. Count: before.Count,
  3178. }
  3179. service.AddSigleAutoReduceRecordInfo(details)
  3180. } else if err == nil {
  3181. if user.ID > 0 {
  3182. //service.UpdateOrderInfoDetails( consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, a_liquid, warehouseOutInfo)
  3183. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, warehouseOutInfo)
  3184. }
  3185. }
  3186. }
  3187. } else if err == nil { //存在,则更改使用人商品信息
  3188. fmt.Println("333333333")
  3189. //处理原来的数据
  3190. if newOut.ID > 0 {
  3191. if consumable.Count > before.Count { // 减少
  3192. num := int64(0)
  3193. if consumable.Count-before.Count > 0 {
  3194. num = consumable.Count - before.Count
  3195. } else {
  3196. num = before.Count - consumable.Count
  3197. }
  3198. service.UpdateOrderCountSub(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, num)
  3199. } else if consumable.Count < before.Count { //增加
  3200. service.UpdateOrderCountAdd(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, before.Count-consumable.Count)
  3201. }
  3202. user, err := service.FindGoodUserById(consumable.GoodTypeId, consumable.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3203. if err == gorm.ErrRecordNotFound {
  3204. details := &models.AutomaticReduceDetail{
  3205. WarehouseOutId: newOut.ID,
  3206. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  3207. PatientId: patient_id,
  3208. Ctime: time.Now().Unix(),
  3209. Mtime: time.Now().Unix(),
  3210. Status: 1,
  3211. RecordTime: record_time,
  3212. OrgId: adminInfo.Org.Id,
  3213. GoodId: consumable.GoodId,
  3214. GoodTypeId: consumable.GoodTypeId,
  3215. Count: before.Count,
  3216. }
  3217. service.AddSigleAutoReduceRecordInfo(details)
  3218. } else if err == nil {
  3219. if user.ID > 0 {
  3220. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, &newOut)
  3221. }
  3222. }
  3223. }
  3224. }
  3225. fmt.Println("444444444")
  3226. }
  3227. }
  3228. }
  3229. }
  3230. }
  3231. }
  3232. fmt.Println("655555555")
  3233. var errs error
  3234. if len(beforePrepares) > 0 {
  3235. for _, item := range beforePrepares {
  3236. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3237. }
  3238. }
  3239. if errs == nil {
  3240. c.ServeSuccessJSON(map[string]interface{}{
  3241. "msg": "修改成功",
  3242. })
  3243. return
  3244. } else {
  3245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3246. return
  3247. }
  3248. } else {
  3249. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3250. goods, _ := dataBody["goods"].([]interface{})
  3251. if len(goods) > 0 {
  3252. for _, item := range goods {
  3253. items := item.(map[string]interface{})
  3254. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3255. utils.ErrorLog("record_time")
  3256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3257. return
  3258. }
  3259. record_time := int64(items["record_time"].(float64))
  3260. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3261. utils.ErrorLog("id")
  3262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3263. return
  3264. }
  3265. id := int64(items["id"].(float64))
  3266. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3267. utils.ErrorLog("patient_id")
  3268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3269. return
  3270. }
  3271. patient_id := int64(items["patient_id"].(float64))
  3272. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3273. utils.ErrorLog("creater")
  3274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3275. return
  3276. }
  3277. creater := int64(items["creater"].(float64))
  3278. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3279. utils.ErrorLog("good_id")
  3280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3281. return
  3282. }
  3283. good_id := int64(items["good_id"].(float64))
  3284. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3285. utils.ErrorLog("good_type_id")
  3286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3287. return
  3288. }
  3289. good_type_id := int64(items["good_type_id"].(float64))
  3290. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3291. utils.ErrorLog("count")
  3292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3293. return
  3294. }
  3295. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3296. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3297. utils.ErrorLog("ctime")
  3298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3299. return
  3300. }
  3301. ctime := int64(items["ctime"].(float64))
  3302. adminUser := c.GetMobileAdminUserInfo()
  3303. prepare := &models.DialysisBeforePrepare{
  3304. ID: id,
  3305. UserOrgId: adminUser.Org.Id,
  3306. PatientId: patient_id,
  3307. RecordDate: record_time,
  3308. GoodId: good_id,
  3309. GoodTypeId: good_type_id,
  3310. Count: count,
  3311. Ctime: ctime,
  3312. Mtime: time.Now().Unix(),
  3313. Creater: creater,
  3314. Modifier: adminUser.AdminUser.Id,
  3315. Status: 1,
  3316. }
  3317. beforePrepares = append(beforePrepares, prepare)
  3318. }
  3319. }
  3320. }
  3321. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3322. goods, _ := dataBody["new_goods"].([]interface{})
  3323. if len(goods) > 0 {
  3324. for _, item := range goods {
  3325. items := item.(map[string]interface{})
  3326. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3327. utils.ErrorLog("good_id")
  3328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3329. return
  3330. }
  3331. good_id := int64(items["good_id"].(float64))
  3332. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3333. utils.ErrorLog("good_type_id")
  3334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3335. return
  3336. }
  3337. good_type_id := int64(items["good_type_id"].(float64))
  3338. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3339. utils.ErrorLog("count")
  3340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3341. return
  3342. }
  3343. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3344. adminUser := c.GetMobileAdminUserInfo()
  3345. prepare := &models.DialysisBeforePrepare{
  3346. UserOrgId: adminUser.Org.Id,
  3347. PatientId: patient_id,
  3348. RecordDate: record_time,
  3349. GoodId: good_id,
  3350. GoodTypeId: good_type_id,
  3351. Count: count,
  3352. Ctime: time.Now().Unix(),
  3353. Mtime: time.Now().Unix(),
  3354. Creater: adminUser.AdminUser.Id,
  3355. Modifier: 0,
  3356. }
  3357. newBeforePrepares = append(newBeforePrepares, prepare)
  3358. }
  3359. }
  3360. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3361. }
  3362. var errs error
  3363. if len(beforePrepares) > 0 {
  3364. for _, item := range beforePrepares {
  3365. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3366. }
  3367. }
  3368. if errs == nil {
  3369. c.ServeSuccessJSON(map[string]interface{}{
  3370. "msg": "修改成功",
  3371. })
  3372. return
  3373. } else {
  3374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3375. return
  3376. }
  3377. }
  3378. }
  3379. func (c *DialysisAPIController) GetDialysisGoods() {
  3380. schedualDate := c.GetString("schedule_date")
  3381. schedule_type, _ := c.GetInt64("schedule_type")
  3382. partition_id, _ := c.GetInt64("partition_id")
  3383. page, _ := c.GetInt("page")
  3384. patient_id, _ := c.GetInt64("patient_id")
  3385. schedualEndDate := int64(0)
  3386. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3387. if parseDateErr != nil && len(schedualDate) != 0 {
  3388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3389. return
  3390. }
  3391. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3392. if parseDateErr != nil && len(schedualDate) != 0 {
  3393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3394. return
  3395. }
  3396. schedualEndDate = endDate.Unix()
  3397. adminUser := c.GetMobileAdminUserInfo()
  3398. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  3399. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3400. if err == gorm.ErrRecordNotFound {
  3401. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3402. if patient_id != 0 {
  3403. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3404. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3405. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3406. item.LastAutomaticReduceDetail = goodUser
  3407. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3408. }
  3409. }
  3410. c.ServeSuccessJSON(map[string]interface{}{
  3411. "dialysis_goods": dialysisGoods,
  3412. "good_type": goodTypes,
  3413. "total": total,
  3414. })
  3415. return
  3416. } else if err == nil {
  3417. //获取当天排班的每个患者的库存使用情况
  3418. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3419. if patient_id != 0 {
  3420. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3421. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3422. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3423. fmt.Println(goodUser)
  3424. fmt.Println(lastGoodUserDetial)
  3425. item.LastAutomaticReduceDetail = goodUser
  3426. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3427. }
  3428. }
  3429. if err == nil {
  3430. c.ServeSuccessJSON(map[string]interface{}{
  3431. "dialysis_goods": dialysisGoods,
  3432. "good_type": goodTypes,
  3433. "total": total,
  3434. })
  3435. return
  3436. } else {
  3437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3438. return
  3439. }
  3440. } else if err != nil {
  3441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3442. return
  3443. }
  3444. }
  3445. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  3446. start_time := c.GetString("start_time")
  3447. end_time := c.GetString("end_time")
  3448. timeLayout := "2006-01-02"
  3449. loc, _ := time.LoadLocation("Local")
  3450. var theStartTime int64
  3451. if len(start_time) > 0 {
  3452. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3453. if err != nil {
  3454. utils.ErrorLog(err.Error())
  3455. }
  3456. theStartTime = theTime.Unix()
  3457. }
  3458. var theEndtTime int64
  3459. if len(end_time) > 0 {
  3460. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3461. if err != nil {
  3462. utils.ErrorLog(err.Error())
  3463. }
  3464. theEndtTime = theTime.Unix()
  3465. }
  3466. adminUser := c.GetMobileAdminUserInfo()
  3467. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  3468. if err == nil {
  3469. c.ServeSuccessJSON(map[string]interface{}{
  3470. "stock_out": outInfo,
  3471. })
  3472. return
  3473. } else {
  3474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3475. return
  3476. }
  3477. }
  3478. func (c *DialysisAPIController) GetStockInGoodInfo() {
  3479. patient_id, _ := c.GetInt64("patient_id", 0)
  3480. record_time := c.GetString("record_time")
  3481. adminUser := c.GetMobileAdminUserInfo()
  3482. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  3483. if parseDateErr != nil && len(record_time) != 0 {
  3484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3485. return
  3486. }
  3487. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3488. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3489. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  3490. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  3491. c.ServeSuccessJSON(map[string]interface{}{
  3492. "good_type": goodTypes,
  3493. "good_user": goodUser,
  3494. "good_info": good_info,
  3495. "last_good_user": lastGoodUserDetial,
  3496. })
  3497. return
  3498. }
  3499. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  3500. patient_id, _ := c.GetInt64("patient_id", 0)
  3501. record_date := c.GetString("record_time")
  3502. if patient_id <= 0 {
  3503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3504. return
  3505. }
  3506. adminInfo := c.GetMobileAdminUserInfo()
  3507. timeLayout := "2006-01-02"
  3508. loc, _ := time.LoadLocation("Local")
  3509. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3510. record_time := theRecordTime.Unix()
  3511. dataBody := make(map[string]interface{}, 0)
  3512. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3513. if err != nil {
  3514. utils.ErrorLog(err.Error())
  3515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3516. return
  3517. }
  3518. var beforePrepares []*models.DialysisBeforePrepare
  3519. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3520. goods, _ := dataBody["goods"].([]interface{})
  3521. if len(goods) > 0 {
  3522. for _, item := range goods {
  3523. items := item.(map[string]interface{})
  3524. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3525. utils.ErrorLog("good_id")
  3526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3527. return
  3528. }
  3529. good_id := int64(items["good_id"].(float64))
  3530. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3531. utils.ErrorLog("good_type_id")
  3532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3533. return
  3534. }
  3535. good_type_id := int64(items["good_type_id"].(float64))
  3536. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3537. utils.ErrorLog("count")
  3538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3539. return
  3540. }
  3541. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3542. adminUser := c.GetMobileAdminUserInfo()
  3543. prepare := &models.DialysisBeforePrepare{
  3544. UserOrgId: adminUser.Org.Id,
  3545. PatientId: patient_id,
  3546. RecordDate: record_time,
  3547. GoodId: good_id,
  3548. GoodTypeId: good_type_id,
  3549. Count: count,
  3550. Ctime: time.Now().Unix(),
  3551. Mtime: time.Now().Unix(),
  3552. Creater: adminUser.AdminUser.Id,
  3553. Modifier: 0,
  3554. }
  3555. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  3556. if record_count == 0 {
  3557. beforePrepares = append(beforePrepares, prepare)
  3558. } else if record_count == 1 {
  3559. service.UpdateDialysisBeforePrepareTwo(prepare)
  3560. }
  3561. }
  3562. }
  3563. }
  3564. beforePrepares = RemoveRepeatedGood(beforePrepares)
  3565. if len(beforePrepares) > 0 {
  3566. service.CreateDialysisBeforePrepare(beforePrepares)
  3567. }
  3568. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3569. consumables = RemoveRepeatedGood(consumables)
  3570. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3571. if record.IsOpen == 1 {
  3572. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3573. if err == gorm.ErrRecordNotFound {
  3574. //没有记录,则创建出库单
  3575. timeStr := time.Now().Format("2006-01-02")
  3576. timeArr := strings.Split(timeStr, "-")
  3577. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3578. total = total + 1
  3579. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3580. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3581. number = number + total
  3582. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3583. creater := adminInfo.AdminUser.Id
  3584. warehouseOut := models.WarehouseOut{
  3585. WarehouseOutOrderNumber: warehousing_out_order,
  3586. OperationTime: time.Now().Unix(),
  3587. OrgId: adminInfo.Org.Id,
  3588. Creater: creater,
  3589. Ctime: time.Now().Unix(),
  3590. Status: 1,
  3591. WarehouseOutTime: record_time,
  3592. Dealer: 0,
  3593. Manufacturer: 0,
  3594. Type: 1,
  3595. IsSys: 1,
  3596. }
  3597. err := service.AddSigleWarehouseOut(&warehouseOut)
  3598. if err != nil {
  3599. utils.TraceLog("创建出库单失败 err = %v", err)
  3600. } else {
  3601. for _, item := range consumables {
  3602. if item.Count > 0 {
  3603. warehouseOutInfo := &models.WarehouseOutInfo{
  3604. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3605. WarehouseOutId: warehouseOut.ID,
  3606. Status: 1,
  3607. Ctime: time.Now().Unix(),
  3608. Remark: "",
  3609. OrgId: adminInfo.Org.Id,
  3610. Type: 1,
  3611. Manufacturer: 0,
  3612. Dealer: 0,
  3613. IsSys: 1,
  3614. SysRecordTime: record_time,
  3615. GoodTypeId: item.GoodTypeId,
  3616. GoodId: item.GoodId,
  3617. }
  3618. warehouseOutInfo.Count = item.Count
  3619. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3620. warehouseOutInfo.Price = stockInInfo.Price
  3621. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3622. if err == nil {
  3623. details := &models.AutomaticReduceDetail{
  3624. WarehouseOutId: warehouseOutInfo.ID,
  3625. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3626. PatientId: patient_id,
  3627. Ctime: time.Now().Unix(),
  3628. Mtime: time.Now().Unix(),
  3629. Status: 1,
  3630. RecordTime: record_time,
  3631. OrgId: adminInfo.Org.Id,
  3632. GoodId: item.GoodId,
  3633. GoodTypeId: item.GoodTypeId,
  3634. Count: item.Count,
  3635. }
  3636. service.AddSigleAutoReduceRecordInfo(details)
  3637. }
  3638. }
  3639. }
  3640. }
  3641. } else if err == nil {
  3642. for _, item := range consumables {
  3643. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3644. if err == gorm.ErrRecordNotFound {
  3645. warehouseOutInfo := &models.WarehouseOutInfo{
  3646. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3647. WarehouseOutId: out.ID,
  3648. Status: 1,
  3649. Ctime: time.Now().Unix(),
  3650. Remark: "",
  3651. OrgId: adminInfo.Org.Id,
  3652. Type: 1,
  3653. Manufacturer: 0,
  3654. Dealer: 0,
  3655. IsSys: 1,
  3656. SysRecordTime: record_time,
  3657. }
  3658. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3659. warehouseOutInfo.Price = stockInInfo.Price
  3660. warehouseOutInfo.GoodId = item.GoodId
  3661. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3662. warehouseOutInfo.Count = item.Count
  3663. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3664. if err == nil {
  3665. details := &models.AutomaticReduceDetail{
  3666. WarehouseOutId: warehouseOutInfo.ID,
  3667. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3668. PatientId: patient_id,
  3669. Ctime: time.Now().Unix(),
  3670. Mtime: time.Now().Unix(),
  3671. Status: 1,
  3672. RecordTime: record_time,
  3673. OrgId: adminInfo.Org.Id,
  3674. GoodId: item.GoodId,
  3675. GoodTypeId: item.GoodTypeId,
  3676. Count: item.Count,
  3677. }
  3678. service.AddSigleAutoReduceRecordInfo(details)
  3679. }
  3680. } else if err == nil { //记录存在,则将增加数量
  3681. if outInfo.ID > 0 {
  3682. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3683. }
  3684. details := &models.AutomaticReduceDetail{
  3685. WarehouseOutId: outInfo.ID,
  3686. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3687. PatientId: patient_id,
  3688. Ctime: time.Now().Unix(),
  3689. Mtime: time.Now().Unix(),
  3690. Status: 1,
  3691. RecordTime: record_time,
  3692. OrgId: adminInfo.Org.Id,
  3693. GoodId: item.GoodId,
  3694. GoodTypeId: item.GoodTypeId,
  3695. Count: item.Count,
  3696. }
  3697. service.AddSigleAutoReduceRecordInfo(details)
  3698. }
  3699. }
  3700. }
  3701. c.ServeSuccessJSON(map[string]interface{}{
  3702. "msg": "提交成功",
  3703. })
  3704. return
  3705. } else {
  3706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  3707. return
  3708. }
  3709. }
  3710. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  3711. newArr = make([]*models.DialysisBeforePrepare, 0)
  3712. for i := 0; i < len(arr); i++ {
  3713. repeat := false
  3714. for j := i + 1; j < len(arr); j++ {
  3715. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  3716. repeat = true
  3717. break
  3718. }
  3719. }
  3720. if !repeat {
  3721. newArr = append(newArr, arr[i])
  3722. }
  3723. }
  3724. return
  3725. }
  3726. func (c *DialysisAPIController) GetAllDrug() {
  3727. patient_id, _ := c.GetInt64("patient_id", 0)
  3728. adminInfo := c.GetMobileAdminUserInfo()
  3729. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3730. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  3731. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  3732. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  3733. c.ServeSuccessJSON(map[string]interface{}{
  3734. "base_drug_config": drugStockConfig,
  3735. "private_drug_config": privateDrugConfig,
  3736. "base_drug_list": drugList,
  3737. "private_drug_list": privateDrugList,
  3738. })
  3739. }
  3740. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  3741. newArr = make([]*models.DialysisBeforePrepare, 0)
  3742. for i := 0; i < len(arr); i++ {
  3743. repeat := false
  3744. for j := i + 1; j < len(arr); j++ {
  3745. if arr[i].GoodId == arr[j].GoodId {
  3746. repeat = true
  3747. break
  3748. }
  3749. }
  3750. if !repeat {
  3751. newArr = append(newArr, arr[i])
  3752. }
  3753. }
  3754. return
  3755. }