dialysis_api_controller.go 219KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  41. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  42. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  43. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  44. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  45. }
  46. func (c *DialysisApiController) PostPrescription() {
  47. patient, _ := c.GetInt64("patient", 0)
  48. recordDateStr := c.GetString("record_date")
  49. if patient <= 0 {
  50. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  51. return
  52. }
  53. adminUserInfo := c.GetAdminUserInfo()
  54. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  55. if patientInfo.ID == 0 {
  56. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  57. return
  58. }
  59. if len(recordDateStr) == 0 {
  60. recordDateStr = time.Now().Format("2006-01-02")
  61. }
  62. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  63. if parseDateErr != nil {
  64. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  65. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  66. return
  67. }
  68. mode_id, _ := c.GetInt64("mode_id", 0)
  69. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  70. dialyzer, _ := c.GetInt64("dialyzer", 0)
  71. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  72. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  73. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  74. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  75. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  76. replacement_way, _ := c.GetInt64("replacement_way", 0)
  77. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  78. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  79. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  80. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  81. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  82. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  83. kalium, _ := c.GetFloat("kalium", 0)
  84. sodium, _ := c.GetFloat("sodium", 0)
  85. replacement_total, _ := c.GetFloat("replacement_total", 0)
  86. calcium, _ := c.GetFloat("calcium", 0)
  87. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  88. glucose, _ := c.GetFloat("glucose", 0)
  89. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  90. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  91. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  92. conductivity, _ := c.GetFloat("conductivity", 0)
  93. remark := c.GetString("remark")
  94. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  95. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  96. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  97. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  98. body_fluid, _ := c.GetInt64("body_fluid", 0)
  99. special_medicine, _ := c.GetInt64("special_medicine", 0)
  100. special_medicine_other := c.GetString("special_medicine_other")
  101. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  102. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  103. blood_access, _ := c.GetInt64("blood_access", 0)
  104. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  105. body_fluid_other := c.GetString("body_fluid_other")
  106. target_ktv, _ := c.GetFloat("target_ktv", 0)
  107. niprocart, _ := c.GetInt64("niprocart", 0)
  108. jms, _ := c.GetInt64("jms", 0)
  109. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  110. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  111. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  112. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  113. filtryzer, _ := c.GetInt64("filtryzer", 0)
  114. dialyzers, _ := c.GetInt64("dialyzers", 0)
  115. injector, _ := c.GetInt64("injector", 0)
  116. bloodlines, _ := c.GetInt64("bloodlines", 0)
  117. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  118. safe_package, _ := c.GetInt64("package", 0)
  119. a_liquid, _ := c.GetInt64("a_liquid", 0)
  120. var prescription_doctor int64
  121. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  122. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  123. if template.TemplateId == 2 || template.TemplateId == 6 {
  124. if appRole.UserType == 3 {
  125. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  126. if getPermissionErr != nil {
  127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  128. return
  129. } else if headNursePermission == nil {
  130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  131. return
  132. }
  133. }
  134. }
  135. if appRole.UserType == 2 || appRole.UserType == 1 {
  136. prescription_doctor = appRole.AdminUserId
  137. } else {
  138. prescription_doctor = 0
  139. }
  140. prescription := models.DialysisPrescription{
  141. UserOrgId: adminUserInfo.CurrentOrgId,
  142. PatientId: patient,
  143. RecordDate: recordDate.Unix(),
  144. ModeId: mode_id,
  145. DialysisDuration: dialysis_duration,
  146. Dialyzer: dialyzer,
  147. ReplacementTotal: replacement_total,
  148. PerfusionApparatus: perfusion_apparatus,
  149. BloodFlowVolume: blood_flow_volume,
  150. DewaterAmount: dewater_amount,
  151. DisplaceLiqui: displace_liqui,
  152. ReplacementWay: replacement_way,
  153. Anticoagulant: anticoagulant,
  154. AnticoagulantShouji: anticoagulant_shouji,
  155. AnticoagulantWeichi: anticoagulant_weichi,
  156. AnticoagulantZongliang: anticoagulant_zongliang,
  157. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  158. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  159. Kalium: kalium,
  160. Sodium: sodium,
  161. Calcium: calcium,
  162. Bicarbonate: bicarbonate,
  163. Glucose: glucose,
  164. // DryWeight: dry_weight,
  165. DialysateFlow: dialysate_flow,
  166. DialysateTemperature: dialysate_temperature,
  167. Conductivity: conductivity,
  168. Remark: remark,
  169. PrescriptionDoctor: prescription_doctor,
  170. Status: 1,
  171. CreatedTime: time.Now().Unix(),
  172. UpdatedTime: time.Now().Unix(),
  173. DialysisDurationMinute: dialysisDurationMinute,
  174. DialysisDurationHour: dialysisDurationHour,
  175. TargetUltrafiltration: targetUltrafiltration,
  176. DialysateFormulation: dialysateFormulation,
  177. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  178. BodyFluid: body_fluid,
  179. SpecialMedicine: special_medicine,
  180. SpecialMedicineOther: special_medicine_other,
  181. DisplaceLiquiPart: displace_liqui_part,
  182. DisplaceLiquiValue: displace_liqui_value,
  183. BloodAccess: blood_access,
  184. Ultrafiltration: ultrafiltration,
  185. BodyFluidOther: body_fluid_other,
  186. TargetKtv: target_ktv,
  187. Niprocart: niprocart,
  188. Jms: jms,
  189. FistulaNeedleSet: fistula_needle_set,
  190. FistulaNeedleSet16: fistula_needle_set_16,
  191. Hemoperfusion: hemoperfusion,
  192. DialyserSterilised: dialyser_sterilised,
  193. Filtryzer: filtryzer,
  194. Dialyzers: dialyzers,
  195. Injector: injector,
  196. Bloodlines: bloodlines,
  197. TubingHemodialysis: tubing_hemodialysis,
  198. Package: safe_package,
  199. ALiquid: a_liquid,
  200. }
  201. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  202. if dialysisPrescription.ID == 0 { //新增
  203. if mode_id > 0 {
  204. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  205. }
  206. prescription.Creater = adminUserInfo.AdminUser.Id
  207. err := service.AddSigleRecord(&prescription)
  208. if err == nil {
  209. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  210. if updateErr != nil {
  211. utils.ErrorLog("%v", updateErr)
  212. }
  213. c.ServeSuccessJSON(map[string]interface{}{
  214. "prescription": &prescription,
  215. })
  216. } else {
  217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  218. }
  219. } else { //修改
  220. if mode_id > 0 {
  221. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  222. }
  223. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  224. if template.TemplateId == 1 {
  225. if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  226. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  227. if getPermissionErr != nil {
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  229. return
  230. } else if headNursePermission == nil {
  231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  232. return
  233. }
  234. }
  235. }
  236. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  237. if record.IsOpen == 1 {
  238. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  239. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  240. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  241. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  242. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  243. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  244. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  245. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  246. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  247. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  248. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  249. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  250. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  251. err, order := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  252. if err == nil {
  253. if order.ID > 0 {
  254. if dialysisPrescription.Niprocart != niprocart {
  255. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  256. //1.用上机透析日期查出当天的订单
  257. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  258. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  259. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  260. //判断前端更改后的商品id的出库记录在数据库中是否存在
  261. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  262. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  263. warehouseOutInfo := &models.WarehouseOutInfo{
  264. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  265. WarehouseOutId: out.ID,
  266. Count: 1,
  267. Status: 1,
  268. Ctime: time.Now().Unix(),
  269. Remark: "",
  270. OrgId: adminUserInfo.CurrentOrgId,
  271. Type: 1,
  272. Manufacturer: 0,
  273. Dealer: 0,
  274. IsSys: 1,
  275. SysRecordTime: order.StartTime,
  276. }
  277. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.CurrentOrgId)
  278. warehouseOutInfo.Price = stockInInfo.Price
  279. warehouseOutInfo.GoodId = niprocart
  280. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  281. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  282. if err == nil {
  283. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  284. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  285. if err == gorm.ErrRecordNotFound {
  286. details := &models.AutomaticReduceDetail{
  287. WarehouseOutId: warehouseOutInfo.ID,
  288. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  289. PatientId: patient,
  290. Ctime: time.Now().Unix(),
  291. Mtime: time.Now().Unix(),
  292. Status: 1,
  293. RecordTime: order.StartTime,
  294. OrgId: adminUserInfo.CurrentOrgId,
  295. GoodId: niprocart,
  296. GoodTypeId: niprocart_good_type_id,
  297. }
  298. service.AddSigleAutoReduceRecordInfo(details)
  299. } else if err == nil {
  300. if user.ID > 0 {
  301. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, warehouseOutInfo)
  302. }
  303. }
  304. }
  305. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  306. if newOut.ID > 0 {
  307. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  308. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  309. if err == gorm.ErrRecordNotFound {
  310. details := &models.AutomaticReduceDetail{
  311. WarehouseOutId: newOut.ID,
  312. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  313. PatientId: patient,
  314. Ctime: time.Now().Unix(),
  315. Mtime: time.Now().Unix(),
  316. Status: 1,
  317. RecordTime: order.StartTime,
  318. OrgId: adminUserInfo.CurrentOrgId,
  319. GoodId: niprocart,
  320. GoodTypeId: niprocart_good_type_id,
  321. }
  322. service.AddSigleAutoReduceRecordInfo(details)
  323. } else if err == nil {
  324. if user.ID > 0 {
  325. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, &newOut)
  326. }
  327. }
  328. }
  329. }
  330. }
  331. if dialysisPrescription.Jms != jms {
  332. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  333. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  334. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  335. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  336. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  337. //判断前端更改后的商品id的出库记录在数据库中是否存在
  338. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  339. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  340. warehouseOutInfo := &models.WarehouseOutInfo{
  341. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  342. WarehouseOutId: out.ID,
  343. Count: 1,
  344. Status: 1,
  345. Ctime: time.Now().Unix(),
  346. Remark: "",
  347. OrgId: adminUserInfo.CurrentOrgId,
  348. Type: 1,
  349. Manufacturer: 0,
  350. Dealer: 0,
  351. IsSys: 1,
  352. SysRecordTime: order.StartTime,
  353. }
  354. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.CurrentOrgId)
  355. warehouseOutInfo.Price = stockInInfo.Price
  356. warehouseOutInfo.GoodId = jms
  357. warehouseOutInfo.GoodTypeId = jms_good_type_id
  358. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  359. if err == nil {
  360. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  361. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  362. if err == gorm.ErrRecordNotFound {
  363. details := &models.AutomaticReduceDetail{
  364. WarehouseOutId: warehouseOutInfo.ID,
  365. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  366. PatientId: patient,
  367. Ctime: time.Now().Unix(),
  368. Mtime: time.Now().Unix(),
  369. Status: 1,
  370. RecordTime: order.StartTime,
  371. OrgId: adminUserInfo.CurrentOrgId,
  372. GoodId: jms,
  373. GoodTypeId: jms_good_type_id,
  374. }
  375. service.AddSigleAutoReduceRecordInfo(details)
  376. } else if err == nil {
  377. if user.ID > 0 {
  378. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, warehouseOutInfo)
  379. }
  380. }
  381. }
  382. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  383. if newOut.ID > 0 {
  384. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  385. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  386. if err == gorm.ErrRecordNotFound {
  387. details := &models.AutomaticReduceDetail{
  388. WarehouseOutId: newOut.ID,
  389. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  390. PatientId: patient,
  391. Ctime: time.Now().Unix(),
  392. Mtime: time.Now().Unix(),
  393. Status: 1,
  394. RecordTime: order.StartTime,
  395. OrgId: adminUserInfo.CurrentOrgId,
  396. GoodId: jms,
  397. GoodTypeId: jms_good_type_id,
  398. }
  399. service.AddSigleAutoReduceRecordInfo(details)
  400. } else if err == nil {
  401. if user.ID > 0 {
  402. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, &newOut)
  403. }
  404. }
  405. }
  406. }
  407. }
  408. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  409. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  410. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  411. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  412. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  413. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  414. //判断前端更改后的商品id的出库记录在数据库中是否存在
  415. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  416. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  417. warehouseOutInfo := &models.WarehouseOutInfo{
  418. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  419. WarehouseOutId: out.ID,
  420. Count: 1,
  421. Status: 1,
  422. Ctime: time.Now().Unix(),
  423. Remark: "",
  424. OrgId: adminUserInfo.CurrentOrgId,
  425. Type: 1,
  426. Manufacturer: 0,
  427. Dealer: 0,
  428. IsSys: 1,
  429. SysRecordTime: order.StartTime,
  430. }
  431. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.CurrentOrgId)
  432. warehouseOutInfo.Price = stockInInfo.Price
  433. warehouseOutInfo.GoodId = fistula_needle_set
  434. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  435. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  436. if err == nil {
  437. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  438. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  439. if err == gorm.ErrRecordNotFound {
  440. details := &models.AutomaticReduceDetail{
  441. WarehouseOutId: warehouseOutInfo.ID,
  442. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  443. PatientId: patient,
  444. Ctime: time.Now().Unix(),
  445. Mtime: time.Now().Unix(),
  446. Status: 1,
  447. RecordTime: order.StartTime,
  448. OrgId: adminUserInfo.CurrentOrgId,
  449. GoodId: fistula_needle_set,
  450. GoodTypeId: fistula_needle_set_good_type_id,
  451. }
  452. service.AddSigleAutoReduceRecordInfo(details)
  453. } else if err == nil {
  454. if user.ID > 0 {
  455. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  456. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, warehouseOutInfo)
  457. }
  458. }
  459. }
  460. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  461. if newOut.ID > 0 {
  462. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  463. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  464. if err == gorm.ErrRecordNotFound {
  465. details := &models.AutomaticReduceDetail{
  466. WarehouseOutId: newOut.ID,
  467. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  468. PatientId: patient,
  469. Ctime: time.Now().Unix(),
  470. Mtime: time.Now().Unix(),
  471. Status: 1,
  472. RecordTime: order.StartTime,
  473. OrgId: adminUserInfo.CurrentOrgId,
  474. GoodId: fistula_needle_set,
  475. GoodTypeId: fistula_needle_set_good_type_id,
  476. }
  477. service.AddSigleAutoReduceRecordInfo(details)
  478. } else if err == nil {
  479. if user.ID > 0 {
  480. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  481. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, &newOut)
  482. }
  483. }
  484. }
  485. }
  486. }
  487. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  488. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  489. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  490. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  491. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  492. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  493. //判断前端更改后的商品id的出库记录在数据库中是否存在
  494. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  495. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  496. warehouseOutInfo := &models.WarehouseOutInfo{
  497. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  498. WarehouseOutId: out.ID,
  499. Count: 1,
  500. Status: 1,
  501. Ctime: time.Now().Unix(),
  502. Remark: "",
  503. OrgId: adminUserInfo.CurrentOrgId,
  504. Type: 1,
  505. Manufacturer: 0,
  506. Dealer: 0,
  507. IsSys: 1,
  508. SysRecordTime: order.StartTime,
  509. }
  510. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.CurrentOrgId)
  511. warehouseOutInfo.Price = stockInInfo.Price
  512. warehouseOutInfo.GoodId = fistula_needle_set_16
  513. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  514. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  515. if err == nil {
  516. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  517. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  518. if err == gorm.ErrRecordNotFound {
  519. details := &models.AutomaticReduceDetail{
  520. WarehouseOutId: warehouseOutInfo.ID,
  521. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  522. PatientId: patient,
  523. Ctime: time.Now().Unix(),
  524. Mtime: time.Now().Unix(),
  525. Status: 1,
  526. RecordTime: order.StartTime,
  527. OrgId: adminUserInfo.CurrentOrgId,
  528. GoodId: fistula_needle_set_16,
  529. GoodTypeId: fistula_needle_set_16_good_type_id,
  530. }
  531. service.AddSigleAutoReduceRecordInfo(details)
  532. } else if err == nil {
  533. if user.ID > 0 {
  534. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, warehouseOutInfo)
  535. }
  536. }
  537. }
  538. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  539. if newOut.ID > 0 {
  540. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  541. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  542. if err == gorm.ErrRecordNotFound {
  543. details := &models.AutomaticReduceDetail{
  544. WarehouseOutId: newOut.ID,
  545. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  546. PatientId: patient,
  547. Ctime: time.Now().Unix(),
  548. Mtime: time.Now().Unix(),
  549. Status: 1,
  550. RecordTime: order.StartTime,
  551. OrgId: adminUserInfo.CurrentOrgId,
  552. GoodId: fistula_needle_set_16,
  553. GoodTypeId: fistula_needle_set_16_good_type_id,
  554. }
  555. service.AddSigleAutoReduceRecordInfo(details)
  556. } else if err == nil {
  557. if user.ID > 0 {
  558. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, &newOut)
  559. }
  560. }
  561. }
  562. }
  563. }
  564. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  565. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  566. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  567. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  568. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  569. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  570. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  571. //判断前端更改后的商品id的出库记录在数据库中是否存在
  572. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  573. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  574. warehouseOutInfo := &models.WarehouseOutInfo{
  575. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  576. WarehouseOutId: out.ID,
  577. Count: 1,
  578. Status: 1,
  579. Ctime: time.Now().Unix(),
  580. Remark: "",
  581. OrgId: adminUserInfo.CurrentOrgId,
  582. Type: 1,
  583. Manufacturer: 0,
  584. Dealer: 0,
  585. IsSys: 1,
  586. SysRecordTime: order.StartTime,
  587. }
  588. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.CurrentOrgId)
  589. warehouseOutInfo.Price = stockInInfo.Price
  590. warehouseOutInfo.GoodId = hemoperfusion
  591. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  592. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  593. if err == nil {
  594. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  595. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  596. if err == gorm.ErrRecordNotFound {
  597. details := &models.AutomaticReduceDetail{
  598. WarehouseOutId: warehouseOutInfo.ID,
  599. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  600. PatientId: patient,
  601. Ctime: time.Now().Unix(),
  602. Mtime: time.Now().Unix(),
  603. Status: 1,
  604. RecordTime: order.StartTime,
  605. OrgId: adminUserInfo.CurrentOrgId,
  606. GoodId: hemoperfusion,
  607. GoodTypeId: hemoperfusion_good_type_id,
  608. }
  609. service.AddSigleAutoReduceRecordInfo(details)
  610. } else if err == nil {
  611. if user.ID > 0 {
  612. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, warehouseOutInfo)
  613. }
  614. }
  615. }
  616. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  617. if newOut.ID > 0 {
  618. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  619. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  620. if err == gorm.ErrRecordNotFound {
  621. details := &models.AutomaticReduceDetail{
  622. WarehouseOutId: newOut.ID,
  623. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  624. PatientId: patient,
  625. Ctime: time.Now().Unix(),
  626. Mtime: time.Now().Unix(),
  627. Status: 1,
  628. RecordTime: order.StartTime,
  629. OrgId: adminUserInfo.CurrentOrgId,
  630. GoodId: hemoperfusion,
  631. GoodTypeId: hemoperfusion_good_type_id,
  632. }
  633. service.AddSigleAutoReduceRecordInfo(details)
  634. } else if err == nil {
  635. if user.ID > 0 {
  636. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, &newOut)
  637. }
  638. }
  639. }
  640. }
  641. }
  642. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  643. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.CurrentOrgId)
  644. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  645. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  646. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  647. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  648. //判断前端更改后的商品id的出库记录在数据库中是否存在
  649. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  650. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  651. warehouseOutInfo := &models.WarehouseOutInfo{
  652. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  653. WarehouseOutId: out.WarehouseOutId,
  654. Count: 1,
  655. Status: 1,
  656. Ctime: time.Now().Unix(),
  657. Remark: "",
  658. OrgId: adminUserInfo.CurrentOrgId,
  659. Type: 1,
  660. Manufacturer: 0,
  661. Dealer: 0,
  662. IsSys: 1,
  663. SysRecordTime: order.StartTime,
  664. }
  665. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.CurrentOrgId)
  666. warehouseOutInfo.Price = stockInInfo.Price
  667. warehouseOutInfo.GoodId = dialyser_sterilised
  668. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  669. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  670. if err == nil {
  671. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  672. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  673. if err == gorm.ErrRecordNotFound {
  674. details := &models.AutomaticReduceDetail{
  675. WarehouseOutId: warehouseOutInfo.ID,
  676. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  677. PatientId: patient,
  678. Ctime: time.Now().Unix(),
  679. Mtime: time.Now().Unix(),
  680. Status: 1,
  681. RecordTime: order.StartTime,
  682. OrgId: adminUserInfo.CurrentOrgId,
  683. GoodId: dialyser_sterilised,
  684. GoodTypeId: dialyser_sterilised_good_type_id,
  685. }
  686. service.AddSigleAutoReduceRecordInfo(details)
  687. } else if err == nil {
  688. if user.ID > 0 {
  689. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  690. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, warehouseOutInfo)
  691. }
  692. }
  693. }
  694. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  695. if newOut.ID > 0 {
  696. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  697. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  698. if err == gorm.ErrRecordNotFound {
  699. details := &models.AutomaticReduceDetail{
  700. WarehouseOutId: newOut.ID,
  701. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  702. PatientId: patient,
  703. Ctime: time.Now().Unix(),
  704. Mtime: time.Now().Unix(),
  705. Status: 1,
  706. RecordTime: order.StartTime,
  707. OrgId: adminUserInfo.CurrentOrgId,
  708. GoodId: dialyser_sterilised,
  709. GoodTypeId: dialyser_sterilised_good_type_id,
  710. }
  711. service.AddSigleAutoReduceRecordInfo(details)
  712. } else if err == nil {
  713. if user.ID > 0 {
  714. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, &newOut)
  715. }
  716. }
  717. }
  718. }
  719. }
  720. if dialysisPrescription.Filtryzer != filtryzer {
  721. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  722. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  723. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  724. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  725. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  726. //判断前端更改后的商品id的出库记录在数据库中是否存在
  727. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  728. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  729. warehouseOutInfo := &models.WarehouseOutInfo{
  730. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  731. WarehouseOutId: out.ID,
  732. Count: 1,
  733. Status: 1,
  734. Ctime: time.Now().Unix(),
  735. Remark: "",
  736. OrgId: adminUserInfo.CurrentOrgId,
  737. Type: 1,
  738. Manufacturer: 0,
  739. Dealer: 0,
  740. IsSys: 1,
  741. SysRecordTime: order.StartTime,
  742. }
  743. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.CurrentOrgId)
  744. warehouseOutInfo.Price = stockInInfo.Price
  745. warehouseOutInfo.GoodId = filtryzer
  746. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  747. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  748. if err == nil {
  749. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  750. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  751. if err == gorm.ErrRecordNotFound {
  752. details := &models.AutomaticReduceDetail{
  753. WarehouseOutId: warehouseOutInfo.ID,
  754. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  755. PatientId: patient,
  756. Ctime: time.Now().Unix(),
  757. Mtime: time.Now().Unix(),
  758. Status: 1,
  759. RecordTime: order.StartTime,
  760. OrgId: adminUserInfo.CurrentOrgId,
  761. GoodId: filtryzer,
  762. GoodTypeId: filtryzer_good_type_id,
  763. }
  764. service.AddSigleAutoReduceRecordInfo(details)
  765. } else if err == nil {
  766. if user.ID > 0 {
  767. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, warehouseOutInfo)
  768. }
  769. }
  770. }
  771. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  772. if newOut.ID > 0 {
  773. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  774. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  775. if err == gorm.ErrRecordNotFound {
  776. details := &models.AutomaticReduceDetail{
  777. WarehouseOutId: newOut.ID,
  778. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  779. PatientId: patient,
  780. Ctime: time.Now().Unix(),
  781. Mtime: time.Now().Unix(),
  782. Status: 1,
  783. RecordTime: order.StartTime,
  784. OrgId: adminUserInfo.CurrentOrgId,
  785. GoodId: filtryzer,
  786. GoodTypeId: filtryzer_good_type_id,
  787. }
  788. service.AddSigleAutoReduceRecordInfo(details)
  789. } else if err == nil {
  790. if user.ID > 0 {
  791. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, &newOut)
  792. }
  793. }
  794. }
  795. }
  796. }
  797. if dialysisPrescription.Dialyzers != dialyzers {
  798. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  799. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  800. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  801. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  802. //判断前端更改后的商品id的出库记录在数据库中是否存在
  803. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  804. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  805. warehouseOutInfo := &models.WarehouseOutInfo{
  806. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  807. WarehouseOutId: out.ID,
  808. Count: 1,
  809. Status: 1,
  810. Ctime: time.Now().Unix(),
  811. Remark: "",
  812. OrgId: adminUserInfo.CurrentOrgId,
  813. Type: 1,
  814. Manufacturer: 0,
  815. Dealer: 0,
  816. IsSys: 1,
  817. SysRecordTime: order.StartTime,
  818. }
  819. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.CurrentOrgId)
  820. warehouseOutInfo.Price = stockInInfo.Price
  821. warehouseOutInfo.GoodId = dialyzers
  822. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  823. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  824. if err == nil {
  825. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  826. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  827. if err == gorm.ErrRecordNotFound {
  828. details := &models.AutomaticReduceDetail{
  829. WarehouseOutId: warehouseOutInfo.ID,
  830. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  831. PatientId: patient,
  832. Ctime: time.Now().Unix(),
  833. Mtime: time.Now().Unix(),
  834. Status: 1,
  835. RecordTime: order.StartTime,
  836. OrgId: adminUserInfo.CurrentOrgId,
  837. GoodId: dialyzers,
  838. GoodTypeId: dialyzers_good_type_id,
  839. }
  840. service.AddSigleAutoReduceRecordInfo(details)
  841. } else if err == nil {
  842. if user.ID > 0 {
  843. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, warehouseOutInfo)
  844. }
  845. }
  846. }
  847. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  848. if newOut.ID > 0 {
  849. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  850. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  851. if err == gorm.ErrRecordNotFound {
  852. details := &models.AutomaticReduceDetail{
  853. WarehouseOutId: newOut.ID,
  854. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  855. PatientId: patient,
  856. Ctime: time.Now().Unix(),
  857. Mtime: time.Now().Unix(),
  858. Status: 1,
  859. RecordTime: order.StartTime,
  860. OrgId: adminUserInfo.CurrentOrgId,
  861. GoodId: dialyzers,
  862. GoodTypeId: dialyzers_good_type_id,
  863. }
  864. service.AddSigleAutoReduceRecordInfo(details)
  865. } else if err == nil {
  866. if user.ID > 0 {
  867. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, &newOut)
  868. }
  869. }
  870. }
  871. }
  872. }
  873. if dialysisPrescription.Injector != injector {
  874. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  875. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  876. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  877. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  878. //判断前端更改后的商品id的出库记录在数据库中是否存在
  879. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  880. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  881. warehouseOutInfo := &models.WarehouseOutInfo{
  882. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  883. WarehouseOutId: out.ID,
  884. Count: 1,
  885. Status: 1,
  886. Ctime: time.Now().Unix(),
  887. Remark: "",
  888. OrgId: adminUserInfo.CurrentOrgId,
  889. Type: 1,
  890. Manufacturer: 0,
  891. Dealer: 0,
  892. IsSys: 1,
  893. SysRecordTime: order.StartTime,
  894. }
  895. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.CurrentOrgId)
  896. warehouseOutInfo.Price = stockInInfo.Price
  897. warehouseOutInfo.GoodId = injector
  898. warehouseOutInfo.GoodTypeId = injector_good_type_id
  899. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  900. if err == nil {
  901. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  902. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  903. if err == gorm.ErrRecordNotFound {
  904. details := &models.AutomaticReduceDetail{
  905. WarehouseOutId: warehouseOutInfo.ID,
  906. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  907. PatientId: patient,
  908. Ctime: time.Now().Unix(),
  909. Mtime: time.Now().Unix(),
  910. Status: 1,
  911. RecordTime: order.StartTime,
  912. OrgId: adminUserInfo.CurrentOrgId,
  913. GoodId: injector,
  914. GoodTypeId: injector_good_type_id,
  915. }
  916. service.AddSigleAutoReduceRecordInfo(details)
  917. } else if err == nil {
  918. if user.ID > 0 {
  919. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, warehouseOutInfo)
  920. }
  921. }
  922. }
  923. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  924. if newOut.ID > 0 {
  925. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  926. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  927. if err == gorm.ErrRecordNotFound {
  928. details := &models.AutomaticReduceDetail{
  929. WarehouseOutId: newOut.ID,
  930. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  931. PatientId: patient,
  932. Ctime: time.Now().Unix(),
  933. Mtime: time.Now().Unix(),
  934. Status: 1,
  935. RecordTime: order.StartTime,
  936. OrgId: adminUserInfo.CurrentOrgId,
  937. GoodId: injector,
  938. GoodTypeId: injector_good_type_id,
  939. }
  940. service.AddSigleAutoReduceRecordInfo(details)
  941. } else if err == nil {
  942. if user.ID > 0 {
  943. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, &newOut)
  944. }
  945. }
  946. }
  947. }
  948. }
  949. if dialysisPrescription.Bloodlines != bloodlines {
  950. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  951. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  952. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  953. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  954. //判断前端更改后的商品id的出库记录在数据库中是否存在
  955. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  956. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  957. warehouseOutInfo := &models.WarehouseOutInfo{
  958. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  959. WarehouseOutId: out.ID,
  960. Count: 1,
  961. Status: 1,
  962. Ctime: time.Now().Unix(),
  963. Remark: "",
  964. OrgId: adminUserInfo.CurrentOrgId,
  965. Type: 1,
  966. Manufacturer: 0,
  967. Dealer: 0,
  968. IsSys: 1,
  969. SysRecordTime: order.StartTime,
  970. }
  971. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.CurrentOrgId)
  972. warehouseOutInfo.Price = stockInInfo.Price
  973. warehouseOutInfo.GoodId = bloodlines
  974. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  975. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  976. if err == nil {
  977. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  978. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  979. if err == gorm.ErrRecordNotFound {
  980. details := &models.AutomaticReduceDetail{
  981. WarehouseOutId: warehouseOutInfo.ID,
  982. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  983. PatientId: patient,
  984. Ctime: time.Now().Unix(),
  985. Mtime: time.Now().Unix(),
  986. Status: 1,
  987. RecordTime: order.StartTime,
  988. OrgId: adminUserInfo.CurrentOrgId,
  989. GoodId: bloodlines,
  990. GoodTypeId: bloodlines_good_type_id,
  991. }
  992. service.AddSigleAutoReduceRecordInfo(details)
  993. } else if err == nil {
  994. if user.ID > 0 {
  995. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, warehouseOutInfo)
  996. }
  997. }
  998. }
  999. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1000. if newOut.ID > 0 {
  1001. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1002. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1003. if err == gorm.ErrRecordNotFound {
  1004. details := &models.AutomaticReduceDetail{
  1005. WarehouseOutId: newOut.ID,
  1006. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1007. PatientId: patient,
  1008. Ctime: time.Now().Unix(),
  1009. Mtime: time.Now().Unix(),
  1010. Status: 1,
  1011. RecordTime: order.StartTime,
  1012. OrgId: adminUserInfo.CurrentOrgId,
  1013. GoodId: bloodlines,
  1014. GoodTypeId: bloodlines_good_type_id,
  1015. }
  1016. service.AddSigleAutoReduceRecordInfo(details)
  1017. } else if err == nil {
  1018. if user.ID > 0 {
  1019. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, &newOut)
  1020. }
  1021. }
  1022. }
  1023. }
  1024. }
  1025. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  1026. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1027. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1028. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1029. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1030. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1031. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1032. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1033. warehouseOutInfo := &models.WarehouseOutInfo{
  1034. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1035. WarehouseOutId: out.ID,
  1036. Count: 1,
  1037. Status: 1,
  1038. Ctime: time.Now().Unix(),
  1039. Remark: "",
  1040. OrgId: adminUserInfo.CurrentOrgId,
  1041. Type: 1,
  1042. Manufacturer: 0,
  1043. Dealer: 0,
  1044. IsSys: 1,
  1045. SysRecordTime: order.StartTime,
  1046. }
  1047. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.CurrentOrgId)
  1048. warehouseOutInfo.Price = stockInInfo.Price
  1049. warehouseOutInfo.GoodId = tubing_hemodialysis
  1050. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  1051. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1052. if err == nil {
  1053. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1054. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1055. if err == gorm.ErrRecordNotFound {
  1056. details := &models.AutomaticReduceDetail{
  1057. WarehouseOutId: warehouseOutInfo.ID,
  1058. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1059. PatientId: patient,
  1060. Ctime: time.Now().Unix(),
  1061. Mtime: time.Now().Unix(),
  1062. Status: 1,
  1063. RecordTime: order.StartTime,
  1064. OrgId: adminUserInfo.CurrentOrgId,
  1065. GoodId: tubing_hemodialysis,
  1066. GoodTypeId: tubingHemodialysis_good_type_id,
  1067. }
  1068. service.AddSigleAutoReduceRecordInfo(details)
  1069. } else if err == nil {
  1070. if user.ID > 0 {
  1071. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, warehouseOutInfo)
  1072. }
  1073. }
  1074. }
  1075. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1076. if newOut.ID > 0 {
  1077. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1078. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1079. if err == gorm.ErrRecordNotFound {
  1080. details := &models.AutomaticReduceDetail{
  1081. WarehouseOutId: newOut.ID,
  1082. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1083. PatientId: patient,
  1084. Ctime: time.Now().Unix(),
  1085. Mtime: time.Now().Unix(),
  1086. Status: 1,
  1087. RecordTime: order.StartTime,
  1088. OrgId: adminUserInfo.CurrentOrgId,
  1089. GoodId: tubing_hemodialysis,
  1090. GoodTypeId: tubingHemodialysis_good_type_id,
  1091. }
  1092. service.AddSigleAutoReduceRecordInfo(details)
  1093. } else if err == nil {
  1094. if user.ID > 0 {
  1095. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, &newOut)
  1096. }
  1097. }
  1098. }
  1099. }
  1100. }
  1101. if dialysisPrescription.Package != safe_package {
  1102. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1103. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1104. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1105. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1106. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1107. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1108. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1109. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1110. warehouseOutInfo := &models.WarehouseOutInfo{
  1111. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1112. WarehouseOutId: out.ID,
  1113. Count: 1,
  1114. Status: 1,
  1115. Ctime: time.Now().Unix(),
  1116. Remark: "",
  1117. OrgId: adminUserInfo.CurrentOrgId,
  1118. Type: 1,
  1119. Manufacturer: 0,
  1120. Dealer: 0,
  1121. IsSys: 1,
  1122. SysRecordTime: order.StartTime,
  1123. }
  1124. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.CurrentOrgId)
  1125. warehouseOutInfo.Price = stockInInfo.Price
  1126. warehouseOutInfo.GoodId = safe_package
  1127. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  1128. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1129. if err == nil {
  1130. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1131. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1132. if err == gorm.ErrRecordNotFound {
  1133. details := &models.AutomaticReduceDetail{
  1134. WarehouseOutId: warehouseOutInfo.ID,
  1135. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1136. PatientId: patient,
  1137. Ctime: time.Now().Unix(),
  1138. Mtime: time.Now().Unix(),
  1139. Status: 1,
  1140. RecordTime: order.StartTime,
  1141. OrgId: adminUserInfo.CurrentOrgId,
  1142. GoodId: safe_package,
  1143. GoodTypeId: safe_package_good_type_id,
  1144. }
  1145. service.AddSigleAutoReduceRecordInfo(details)
  1146. } else if err == nil {
  1147. if user.ID > 0 {
  1148. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, warehouseOutInfo)
  1149. }
  1150. }
  1151. }
  1152. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1153. if newOut.ID > 0 {
  1154. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1155. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1156. if err == gorm.ErrRecordNotFound {
  1157. details := &models.AutomaticReduceDetail{
  1158. WarehouseOutId: newOut.ID,
  1159. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1160. PatientId: patient,
  1161. Ctime: time.Now().Unix(),
  1162. Mtime: time.Now().Unix(),
  1163. Status: 1,
  1164. RecordTime: order.StartTime,
  1165. OrgId: adminUserInfo.CurrentOrgId,
  1166. GoodId: safe_package,
  1167. GoodTypeId: safe_package_good_type_id,
  1168. }
  1169. service.AddSigleAutoReduceRecordInfo(details)
  1170. } else if err == nil {
  1171. if user.ID > 0 {
  1172. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, &newOut)
  1173. }
  1174. }
  1175. }
  1176. }
  1177. }
  1178. if dialysisPrescription.ALiquid != a_liquid {
  1179. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1180. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1181. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1182. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1183. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1184. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1185. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1186. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1187. warehouseOutInfo := &models.WarehouseOutInfo{
  1188. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1189. WarehouseOutId: out.ID,
  1190. Count: 1,
  1191. Status: 1,
  1192. Ctime: time.Now().Unix(),
  1193. Remark: "",
  1194. OrgId: adminUserInfo.CurrentOrgId,
  1195. Type: 1,
  1196. Manufacturer: 0,
  1197. Dealer: 0,
  1198. IsSys: 1,
  1199. SysRecordTime: order.StartTime,
  1200. }
  1201. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.CurrentOrgId)
  1202. warehouseOutInfo.Price = stockInInfo.Price
  1203. warehouseOutInfo.GoodId = a_liquid
  1204. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  1205. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1206. if err == nil {
  1207. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1208. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1209. if err == gorm.ErrRecordNotFound {
  1210. details := &models.AutomaticReduceDetail{
  1211. WarehouseOutId: warehouseOutInfo.ID,
  1212. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1213. PatientId: patient,
  1214. Ctime: time.Now().Unix(),
  1215. Mtime: time.Now().Unix(),
  1216. Status: 1,
  1217. RecordTime: order.StartTime,
  1218. OrgId: adminUserInfo.CurrentOrgId,
  1219. GoodId: a_liquid,
  1220. GoodTypeId: aliquid_good_type_id,
  1221. }
  1222. service.AddSigleAutoReduceRecordInfo(details)
  1223. } else if err == nil {
  1224. if user.ID > 0 {
  1225. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, warehouseOutInfo)
  1226. }
  1227. }
  1228. }
  1229. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1230. if newOut.ID > 0 {
  1231. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1232. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1233. if err == gorm.ErrRecordNotFound {
  1234. details := &models.AutomaticReduceDetail{
  1235. WarehouseOutId: newOut.ID,
  1236. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1237. PatientId: patient,
  1238. Ctime: time.Now().Unix(),
  1239. Mtime: time.Now().Unix(),
  1240. Status: 1,
  1241. RecordTime: order.StartTime,
  1242. OrgId: adminUserInfo.CurrentOrgId,
  1243. GoodId: a_liquid,
  1244. GoodTypeId: aliquid_good_type_id,
  1245. }
  1246. service.AddSigleAutoReduceRecordInfo(details)
  1247. } else if err == nil {
  1248. if user.ID > 0 {
  1249. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, &newOut)
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. prescription.Creater = adminUserInfo.AdminUser.Id
  1259. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1260. prescription.UpdatedTime = time.Now().Unix()
  1261. prescription.Modifier = adminUserInfo.AdminUser.Id
  1262. prescription.ID = dialysisPrescription.ID
  1263. updateErr := service.UpDateDialysisPrescription(&prescription)
  1264. if updateErr == nil {
  1265. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  1266. if updateErr != nil {
  1267. utils.ErrorLog("%v", updateErr)
  1268. }
  1269. c.ServeSuccessJSON(map[string]interface{}{
  1270. "prescription": &prescription,
  1271. })
  1272. } else {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1274. }
  1275. }
  1276. }
  1277. func (c *DialysisApiController) PostSoulution() {
  1278. patient, _ := c.GetInt64("patient", 0)
  1279. recordDateStr := c.GetString("record_date")
  1280. if patient <= 0 {
  1281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1282. return
  1283. }
  1284. adminUserInfo := c.GetAdminUserInfo()
  1285. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1286. if patientInfo.ID == 0 {
  1287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1288. return
  1289. }
  1290. if len(recordDateStr) == 0 {
  1291. recordDateStr = time.Now().Format("2006-01-02")
  1292. }
  1293. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1294. if parseDateErr != nil {
  1295. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1297. return
  1298. }
  1299. mode_id, _ := c.GetInt64("mode_id", 0)
  1300. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1301. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1302. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1303. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1304. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1305. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1306. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1307. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1308. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1309. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1310. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1311. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1312. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1313. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1314. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1315. kalium, _ := c.GetFloat("kalium", 0)
  1316. sodium, _ := c.GetFloat("sodium", 0)
  1317. calcium, _ := c.GetFloat("calcium", 0)
  1318. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1319. glucose, _ := c.GetFloat("glucose", 0)
  1320. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1321. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1322. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1323. conductivity, _ := c.GetFloat("conductivity", 0)
  1324. remark := c.GetString("remark")
  1325. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1326. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1327. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1328. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1329. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1330. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1331. special_medicine_other := c.GetString("special_medicine_other")
  1332. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1333. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1334. blood_access, _ := c.GetInt64("blood_access", 0)
  1335. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1336. body_fluid_other := c.GetString("body_fluid_other")
  1337. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1338. niprocart, _ := c.GetInt64("niprocart", 0)
  1339. jms, _ := c.GetInt64("jms", 0)
  1340. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1341. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1342. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1343. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1344. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1345. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1346. injector, _ := c.GetInt64("injector", 0)
  1347. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1348. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1349. safe_package, _ := c.GetInt64("package", 0)
  1350. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1351. var prescription_doctor int64
  1352. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1353. if appRole.UserType == 2 || appRole.UserType == 1 {
  1354. prescription_doctor = appRole.AdminUserId
  1355. } else {
  1356. prescription_doctor = 0
  1357. }
  1358. if mode_id > 0 {
  1359. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1360. }
  1361. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1362. if template.TemplateId == 2 || template.TemplateId == 6 {
  1363. if appRole.UserType == 3 {
  1364. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1365. if getPermissionErr != nil {
  1366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1367. return
  1368. } else if headNursePermission == nil {
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1370. return
  1371. }
  1372. }
  1373. }
  1374. prescription := models.DialysisPrescription{
  1375. UserOrgId: adminUserInfo.CurrentOrgId,
  1376. PatientId: patient,
  1377. RecordDate: recordDate.Unix(),
  1378. ModeId: mode_id,
  1379. DialysisDuration: dialysis_duration,
  1380. Dialyzer: dialyzer,
  1381. PerfusionApparatus: perfusion_apparatus,
  1382. BloodFlowVolume: blood_flow_volume,
  1383. DewaterAmount: dewater_amount,
  1384. DisplaceLiqui: displace_liqui,
  1385. ReplacementWay: replacement_way,
  1386. Anticoagulant: anticoagulant,
  1387. AnticoagulantShouji: anticoagulant_shouji,
  1388. AnticoagulantWeichi: anticoagulant_weichi,
  1389. AnticoagulantZongliang: anticoagulant_zongliang,
  1390. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1391. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1392. Kalium: kalium,
  1393. Sodium: sodium,
  1394. Calcium: calcium,
  1395. Bicarbonate: bicarbonate,
  1396. Glucose: glucose,
  1397. // DryWeight: dry_weight,
  1398. DialysateFlow: dialysate_flow,
  1399. DialysateTemperature: dialysate_temperature,
  1400. Conductivity: conductivity,
  1401. Remark: remark,
  1402. PrescriptionDoctor: prescription_doctor,
  1403. Status: 1,
  1404. CreatedTime: time.Now().Unix(),
  1405. UpdatedTime: time.Now().Unix(),
  1406. DialysisDurationMinute: dialysisDurationMinute,
  1407. DialysisDurationHour: dialysisDurationHour,
  1408. TargetUltrafiltration: targetUltrafiltration,
  1409. DialysateFormulation: dialysateFormulation,
  1410. ReplacementTotal: replacement_total,
  1411. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1412. BodyFluid: body_fluid,
  1413. SpecialMedicine: special_medicine,
  1414. SpecialMedicineOther: special_medicine_other,
  1415. DisplaceLiquiPart: displace_liqui_part,
  1416. DisplaceLiquiValue: displace_liqui_value,
  1417. BloodAccess: blood_access,
  1418. Ultrafiltration: ultrafiltration,
  1419. BodyFluidOther: body_fluid_other,
  1420. TargetKtv: target_ktv,
  1421. Niprocart: niprocart,
  1422. Jms: jms,
  1423. FistulaNeedleSet: fistula_needle_set,
  1424. FistulaNeedleSet16: fistula_needle_set_16,
  1425. Hemoperfusion: hemoperfusion,
  1426. DialyserSterilised: dialyser_sterilised,
  1427. Filtryzer: filtryzer,
  1428. Dialyzers: dialyzers,
  1429. Injector: injector,
  1430. Bloodlines: bloodlines,
  1431. TubingHemodialysis: tubing_hemodialysis,
  1432. Package: safe_package,
  1433. ALiquid: a_liquid,
  1434. }
  1435. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1436. if dialysisPrescription.ID == 0 { //新增
  1437. prescription.Creater = adminUserInfo.AdminUser.Id
  1438. } else { //修改
  1439. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1440. if template.TemplateId == 1 {
  1441. if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1442. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1443. if getPermissionErr != nil {
  1444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1445. return
  1446. } else if headNursePermission == nil {
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1448. return
  1449. }
  1450. }
  1451. }
  1452. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1453. if record.IsOpen == 1 {
  1454. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  1455. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  1456. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  1457. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  1458. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  1459. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  1460. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  1461. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  1462. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  1463. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  1464. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  1465. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  1466. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  1467. err, order := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1468. if err == nil {
  1469. if order.ID > 0 {
  1470. if dialysisPrescription.Niprocart != niprocart {
  1471. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1472. //1.用上机透析日期查出当天的订单
  1473. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1474. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1475. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1476. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1477. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1478. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1479. warehouseOutInfo := &models.WarehouseOutInfo{
  1480. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1481. WarehouseOutId: out.ID,
  1482. Count: 1,
  1483. Status: 1,
  1484. Ctime: time.Now().Unix(),
  1485. Remark: "",
  1486. OrgId: adminUserInfo.CurrentOrgId,
  1487. Type: 1,
  1488. Manufacturer: 0,
  1489. Dealer: 0,
  1490. IsSys: 1,
  1491. SysRecordTime: order.StartTime,
  1492. }
  1493. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.CurrentOrgId)
  1494. warehouseOutInfo.Price = stockInInfo.Price
  1495. warehouseOutInfo.GoodId = niprocart
  1496. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  1497. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1498. if err == nil {
  1499. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1500. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1501. if err == gorm.ErrRecordNotFound {
  1502. details := &models.AutomaticReduceDetail{
  1503. WarehouseOutId: warehouseOutInfo.ID,
  1504. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1505. PatientId: patient,
  1506. Ctime: time.Now().Unix(),
  1507. Mtime: time.Now().Unix(),
  1508. Status: 1,
  1509. RecordTime: order.StartTime,
  1510. OrgId: adminUserInfo.CurrentOrgId,
  1511. GoodId: niprocart,
  1512. GoodTypeId: niprocart_good_type_id,
  1513. }
  1514. service.AddSigleAutoReduceRecordInfo(details)
  1515. } else if err == nil {
  1516. if user.ID > 0 {
  1517. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, warehouseOutInfo)
  1518. }
  1519. }
  1520. }
  1521. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1522. if newOut.ID > 0 {
  1523. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1524. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1525. if err == gorm.ErrRecordNotFound {
  1526. details := &models.AutomaticReduceDetail{
  1527. WarehouseOutId: newOut.ID,
  1528. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1529. PatientId: patient,
  1530. Ctime: time.Now().Unix(),
  1531. Mtime: time.Now().Unix(),
  1532. Status: 1,
  1533. RecordTime: order.StartTime,
  1534. OrgId: adminUserInfo.CurrentOrgId,
  1535. GoodId: niprocart,
  1536. GoodTypeId: niprocart_good_type_id,
  1537. }
  1538. service.AddSigleAutoReduceRecordInfo(details)
  1539. } else if err == nil {
  1540. if user.ID > 0 {
  1541. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, &newOut)
  1542. }
  1543. }
  1544. }
  1545. }
  1546. }
  1547. if dialysisPrescription.Jms != jms {
  1548. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1549. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1550. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1551. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1552. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  1553. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1554. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1555. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1556. warehouseOutInfo := &models.WarehouseOutInfo{
  1557. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1558. WarehouseOutId: out.ID,
  1559. Count: 1,
  1560. Status: 1,
  1561. Ctime: time.Now().Unix(),
  1562. Remark: "",
  1563. OrgId: adminUserInfo.CurrentOrgId,
  1564. Type: 1,
  1565. Manufacturer: 0,
  1566. Dealer: 0,
  1567. IsSys: 1,
  1568. SysRecordTime: order.StartTime,
  1569. }
  1570. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.CurrentOrgId)
  1571. warehouseOutInfo.Price = stockInInfo.Price
  1572. warehouseOutInfo.GoodId = jms
  1573. warehouseOutInfo.GoodTypeId = jms_good_type_id
  1574. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1575. if err == nil {
  1576. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1577. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1578. if err == gorm.ErrRecordNotFound {
  1579. details := &models.AutomaticReduceDetail{
  1580. WarehouseOutId: warehouseOutInfo.ID,
  1581. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1582. PatientId: patient,
  1583. Ctime: time.Now().Unix(),
  1584. Mtime: time.Now().Unix(),
  1585. Status: 1,
  1586. RecordTime: order.StartTime,
  1587. OrgId: adminUserInfo.CurrentOrgId,
  1588. GoodId: jms,
  1589. GoodTypeId: jms_good_type_id,
  1590. }
  1591. service.AddSigleAutoReduceRecordInfo(details)
  1592. } else if err == nil {
  1593. if user.ID > 0 {
  1594. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, warehouseOutInfo)
  1595. }
  1596. }
  1597. }
  1598. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1599. if newOut.ID > 0 {
  1600. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1601. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1602. if err == gorm.ErrRecordNotFound {
  1603. details := &models.AutomaticReduceDetail{
  1604. WarehouseOutId: newOut.ID,
  1605. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1606. PatientId: patient,
  1607. Ctime: time.Now().Unix(),
  1608. Mtime: time.Now().Unix(),
  1609. Status: 1,
  1610. RecordTime: order.StartTime,
  1611. OrgId: adminUserInfo.CurrentOrgId,
  1612. GoodId: jms,
  1613. GoodTypeId: jms_good_type_id,
  1614. }
  1615. service.AddSigleAutoReduceRecordInfo(details)
  1616. } else if err == nil {
  1617. if user.ID > 0 {
  1618. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, &newOut)
  1619. }
  1620. }
  1621. }
  1622. }
  1623. }
  1624. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  1625. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1626. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1627. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1628. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1629. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  1630. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1631. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1632. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1633. warehouseOutInfo := &models.WarehouseOutInfo{
  1634. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1635. WarehouseOutId: out.ID,
  1636. Count: 1,
  1637. Status: 1,
  1638. Ctime: time.Now().Unix(),
  1639. Remark: "",
  1640. OrgId: adminUserInfo.CurrentOrgId,
  1641. Type: 1,
  1642. Manufacturer: 0,
  1643. Dealer: 0,
  1644. IsSys: 1,
  1645. SysRecordTime: order.StartTime,
  1646. }
  1647. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.CurrentOrgId)
  1648. warehouseOutInfo.Price = stockInInfo.Price
  1649. warehouseOutInfo.GoodId = fistula_needle_set
  1650. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  1651. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1652. if err == nil {
  1653. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1654. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1655. if err == gorm.ErrRecordNotFound {
  1656. details := &models.AutomaticReduceDetail{
  1657. WarehouseOutId: warehouseOutInfo.ID,
  1658. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1659. PatientId: patient,
  1660. Ctime: time.Now().Unix(),
  1661. Mtime: time.Now().Unix(),
  1662. Status: 1,
  1663. RecordTime: order.StartTime,
  1664. OrgId: adminUserInfo.CurrentOrgId,
  1665. GoodId: fistula_needle_set,
  1666. GoodTypeId: fistula_needle_set_good_type_id,
  1667. }
  1668. service.AddSigleAutoReduceRecordInfo(details)
  1669. } else if err == nil {
  1670. if user.ID > 0 {
  1671. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1672. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, warehouseOutInfo)
  1673. }
  1674. }
  1675. }
  1676. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1677. if newOut.ID > 0 {
  1678. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1679. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1680. if err == gorm.ErrRecordNotFound {
  1681. details := &models.AutomaticReduceDetail{
  1682. WarehouseOutId: newOut.ID,
  1683. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1684. PatientId: patient,
  1685. Ctime: time.Now().Unix(),
  1686. Mtime: time.Now().Unix(),
  1687. Status: 1,
  1688. RecordTime: order.StartTime,
  1689. OrgId: adminUserInfo.CurrentOrgId,
  1690. GoodId: fistula_needle_set,
  1691. GoodTypeId: fistula_needle_set_good_type_id,
  1692. }
  1693. service.AddSigleAutoReduceRecordInfo(details)
  1694. } else if err == nil {
  1695. if user.ID > 0 {
  1696. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1697. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, &newOut)
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  1704. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1705. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1706. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1707. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1708. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1709. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1710. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1711. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1712. warehouseOutInfo := &models.WarehouseOutInfo{
  1713. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1714. WarehouseOutId: out.ID,
  1715. Count: 1,
  1716. Status: 1,
  1717. Ctime: time.Now().Unix(),
  1718. Remark: "",
  1719. OrgId: adminUserInfo.CurrentOrgId,
  1720. Type: 1,
  1721. Manufacturer: 0,
  1722. Dealer: 0,
  1723. IsSys: 1,
  1724. SysRecordTime: order.StartTime,
  1725. }
  1726. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.CurrentOrgId)
  1727. warehouseOutInfo.Price = stockInInfo.Price
  1728. warehouseOutInfo.GoodId = fistula_needle_set_16
  1729. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  1730. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1731. if err == nil {
  1732. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1733. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1734. if err == gorm.ErrRecordNotFound {
  1735. details := &models.AutomaticReduceDetail{
  1736. WarehouseOutId: warehouseOutInfo.ID,
  1737. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1738. PatientId: patient,
  1739. Ctime: time.Now().Unix(),
  1740. Mtime: time.Now().Unix(),
  1741. Status: 1,
  1742. RecordTime: order.StartTime,
  1743. OrgId: adminUserInfo.CurrentOrgId,
  1744. GoodId: fistula_needle_set_16,
  1745. GoodTypeId: fistula_needle_set_16_good_type_id,
  1746. }
  1747. service.AddSigleAutoReduceRecordInfo(details)
  1748. } else if err == nil {
  1749. if user.ID > 0 {
  1750. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, warehouseOutInfo)
  1751. }
  1752. }
  1753. }
  1754. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1755. if newOut.ID > 0 {
  1756. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1757. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1758. if err == gorm.ErrRecordNotFound {
  1759. details := &models.AutomaticReduceDetail{
  1760. WarehouseOutId: newOut.ID,
  1761. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1762. PatientId: patient,
  1763. Ctime: time.Now().Unix(),
  1764. Mtime: time.Now().Unix(),
  1765. Status: 1,
  1766. RecordTime: order.StartTime,
  1767. OrgId: adminUserInfo.CurrentOrgId,
  1768. GoodId: fistula_needle_set_16,
  1769. GoodTypeId: fistula_needle_set_16_good_type_id,
  1770. }
  1771. service.AddSigleAutoReduceRecordInfo(details)
  1772. } else if err == nil {
  1773. if user.ID > 0 {
  1774. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, &newOut)
  1775. }
  1776. }
  1777. }
  1778. }
  1779. }
  1780. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  1781. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1782. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1783. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1784. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1785. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  1786. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1787. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1788. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1789. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1790. warehouseOutInfo := &models.WarehouseOutInfo{
  1791. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1792. WarehouseOutId: out.ID,
  1793. Count: 1,
  1794. Status: 1,
  1795. Ctime: time.Now().Unix(),
  1796. Remark: "",
  1797. OrgId: adminUserInfo.CurrentOrgId,
  1798. Type: 1,
  1799. Manufacturer: 0,
  1800. Dealer: 0,
  1801. IsSys: 1,
  1802. SysRecordTime: order.StartTime,
  1803. }
  1804. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.CurrentOrgId)
  1805. warehouseOutInfo.Price = stockInInfo.Price
  1806. warehouseOutInfo.GoodId = hemoperfusion
  1807. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  1808. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1809. if err == nil {
  1810. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1811. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1812. if err == gorm.ErrRecordNotFound {
  1813. details := &models.AutomaticReduceDetail{
  1814. WarehouseOutId: warehouseOutInfo.ID,
  1815. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1816. PatientId: patient,
  1817. Ctime: time.Now().Unix(),
  1818. Mtime: time.Now().Unix(),
  1819. Status: 1,
  1820. RecordTime: order.StartTime,
  1821. OrgId: adminUserInfo.CurrentOrgId,
  1822. GoodId: hemoperfusion,
  1823. GoodTypeId: hemoperfusion_good_type_id,
  1824. }
  1825. service.AddSigleAutoReduceRecordInfo(details)
  1826. } else if err == nil {
  1827. if user.ID > 0 {
  1828. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, warehouseOutInfo)
  1829. }
  1830. }
  1831. }
  1832. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1833. if newOut.ID > 0 {
  1834. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1835. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1836. if err == gorm.ErrRecordNotFound {
  1837. details := &models.AutomaticReduceDetail{
  1838. WarehouseOutId: newOut.ID,
  1839. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1840. PatientId: patient,
  1841. Ctime: time.Now().Unix(),
  1842. Mtime: time.Now().Unix(),
  1843. Status: 1,
  1844. RecordTime: order.StartTime,
  1845. OrgId: adminUserInfo.CurrentOrgId,
  1846. GoodId: hemoperfusion,
  1847. GoodTypeId: hemoperfusion_good_type_id,
  1848. }
  1849. service.AddSigleAutoReduceRecordInfo(details)
  1850. } else if err == nil {
  1851. if user.ID > 0 {
  1852. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, &newOut)
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  1859. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.CurrentOrgId)
  1860. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1861. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1862. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  1863. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1864. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1865. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1866. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1867. warehouseOutInfo := &models.WarehouseOutInfo{
  1868. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1869. WarehouseOutId: out.WarehouseOutId,
  1870. Count: 1,
  1871. Status: 1,
  1872. Ctime: time.Now().Unix(),
  1873. Remark: "",
  1874. OrgId: adminUserInfo.CurrentOrgId,
  1875. Type: 1,
  1876. Manufacturer: 0,
  1877. Dealer: 0,
  1878. IsSys: 1,
  1879. SysRecordTime: order.StartTime,
  1880. }
  1881. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.CurrentOrgId)
  1882. warehouseOutInfo.Price = stockInInfo.Price
  1883. warehouseOutInfo.GoodId = dialyser_sterilised
  1884. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  1885. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1886. if err == nil {
  1887. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1888. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1889. if err == gorm.ErrRecordNotFound {
  1890. details := &models.AutomaticReduceDetail{
  1891. WarehouseOutId: warehouseOutInfo.ID,
  1892. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1893. PatientId: patient,
  1894. Ctime: time.Now().Unix(),
  1895. Mtime: time.Now().Unix(),
  1896. Status: 1,
  1897. RecordTime: order.StartTime,
  1898. OrgId: adminUserInfo.CurrentOrgId,
  1899. GoodId: dialyser_sterilised,
  1900. GoodTypeId: dialyser_sterilised_good_type_id,
  1901. }
  1902. service.AddSigleAutoReduceRecordInfo(details)
  1903. } else if err == nil {
  1904. if user.ID > 0 {
  1905. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1906. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, warehouseOutInfo)
  1907. }
  1908. }
  1909. }
  1910. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1911. if newOut.ID > 0 {
  1912. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1913. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1914. if err == gorm.ErrRecordNotFound {
  1915. details := &models.AutomaticReduceDetail{
  1916. WarehouseOutId: newOut.ID,
  1917. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1918. PatientId: patient,
  1919. Ctime: time.Now().Unix(),
  1920. Mtime: time.Now().Unix(),
  1921. Status: 1,
  1922. RecordTime: order.StartTime,
  1923. OrgId: adminUserInfo.CurrentOrgId,
  1924. GoodId: dialyser_sterilised,
  1925. GoodTypeId: dialyser_sterilised_good_type_id,
  1926. }
  1927. service.AddSigleAutoReduceRecordInfo(details)
  1928. } else if err == nil {
  1929. if user.ID > 0 {
  1930. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, &newOut)
  1931. }
  1932. }
  1933. }
  1934. }
  1935. }
  1936. if dialysisPrescription.Filtryzer != filtryzer {
  1937. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1938. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1939. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1940. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1941. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  1942. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1943. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1944. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1945. warehouseOutInfo := &models.WarehouseOutInfo{
  1946. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1947. WarehouseOutId: out.ID,
  1948. Count: 1,
  1949. Status: 1,
  1950. Ctime: time.Now().Unix(),
  1951. Remark: "",
  1952. OrgId: adminUserInfo.CurrentOrgId,
  1953. Type: 1,
  1954. Manufacturer: 0,
  1955. Dealer: 0,
  1956. IsSys: 1,
  1957. SysRecordTime: order.StartTime,
  1958. }
  1959. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.CurrentOrgId)
  1960. warehouseOutInfo.Price = stockInInfo.Price
  1961. warehouseOutInfo.GoodId = filtryzer
  1962. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  1963. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1964. if err == nil {
  1965. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1966. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1967. if err == gorm.ErrRecordNotFound {
  1968. details := &models.AutomaticReduceDetail{
  1969. WarehouseOutId: warehouseOutInfo.ID,
  1970. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1971. PatientId: patient,
  1972. Ctime: time.Now().Unix(),
  1973. Mtime: time.Now().Unix(),
  1974. Status: 1,
  1975. RecordTime: order.StartTime,
  1976. OrgId: adminUserInfo.CurrentOrgId,
  1977. GoodId: filtryzer,
  1978. GoodTypeId: filtryzer_good_type_id,
  1979. }
  1980. service.AddSigleAutoReduceRecordInfo(details)
  1981. } else if err == nil {
  1982. if user.ID > 0 {
  1983. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, warehouseOutInfo)
  1984. }
  1985. }
  1986. }
  1987. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1988. if newOut.ID > 0 {
  1989. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1990. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1991. if err == gorm.ErrRecordNotFound {
  1992. details := &models.AutomaticReduceDetail{
  1993. WarehouseOutId: newOut.ID,
  1994. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1995. PatientId: patient,
  1996. Ctime: time.Now().Unix(),
  1997. Mtime: time.Now().Unix(),
  1998. Status: 1,
  1999. RecordTime: order.StartTime,
  2000. OrgId: adminUserInfo.CurrentOrgId,
  2001. GoodId: filtryzer,
  2002. GoodTypeId: filtryzer_good_type_id,
  2003. }
  2004. service.AddSigleAutoReduceRecordInfo(details)
  2005. } else if err == nil {
  2006. if user.ID > 0 {
  2007. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, &newOut)
  2008. }
  2009. }
  2010. }
  2011. }
  2012. }
  2013. if dialysisPrescription.Dialyzers != dialyzers {
  2014. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2015. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2016. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2017. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2018. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2019. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2020. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2021. warehouseOutInfo := &models.WarehouseOutInfo{
  2022. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2023. WarehouseOutId: out.ID,
  2024. Count: 1,
  2025. Status: 1,
  2026. Ctime: time.Now().Unix(),
  2027. Remark: "",
  2028. OrgId: adminUserInfo.CurrentOrgId,
  2029. Type: 1,
  2030. Manufacturer: 0,
  2031. Dealer: 0,
  2032. IsSys: 1,
  2033. SysRecordTime: order.StartTime,
  2034. }
  2035. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.CurrentOrgId)
  2036. warehouseOutInfo.Price = stockInInfo.Price
  2037. warehouseOutInfo.GoodId = dialyzers
  2038. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  2039. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2040. if err == nil {
  2041. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2042. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2043. if err == gorm.ErrRecordNotFound {
  2044. details := &models.AutomaticReduceDetail{
  2045. WarehouseOutId: warehouseOutInfo.ID,
  2046. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2047. PatientId: patient,
  2048. Ctime: time.Now().Unix(),
  2049. Mtime: time.Now().Unix(),
  2050. Status: 1,
  2051. RecordTime: order.StartTime,
  2052. OrgId: adminUserInfo.CurrentOrgId,
  2053. GoodId: dialyzers,
  2054. GoodTypeId: dialyzers_good_type_id,
  2055. }
  2056. service.AddSigleAutoReduceRecordInfo(details)
  2057. } else if err == nil {
  2058. if user.ID > 0 {
  2059. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, warehouseOutInfo)
  2060. }
  2061. }
  2062. }
  2063. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2064. if newOut.ID > 0 {
  2065. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2066. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2067. if err == gorm.ErrRecordNotFound {
  2068. details := &models.AutomaticReduceDetail{
  2069. WarehouseOutId: newOut.ID,
  2070. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2071. PatientId: patient,
  2072. Ctime: time.Now().Unix(),
  2073. Mtime: time.Now().Unix(),
  2074. Status: 1,
  2075. RecordTime: order.StartTime,
  2076. OrgId: adminUserInfo.CurrentOrgId,
  2077. GoodId: dialyzers,
  2078. GoodTypeId: dialyzers_good_type_id,
  2079. }
  2080. service.AddSigleAutoReduceRecordInfo(details)
  2081. } else if err == nil {
  2082. if user.ID > 0 {
  2083. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, &newOut)
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. if dialysisPrescription.Injector != injector {
  2090. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2091. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2092. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2093. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2094. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2095. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2096. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2097. warehouseOutInfo := &models.WarehouseOutInfo{
  2098. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2099. WarehouseOutId: out.ID,
  2100. Count: 1,
  2101. Status: 1,
  2102. Ctime: time.Now().Unix(),
  2103. Remark: "",
  2104. OrgId: adminUserInfo.CurrentOrgId,
  2105. Type: 1,
  2106. Manufacturer: 0,
  2107. Dealer: 0,
  2108. IsSys: 1,
  2109. SysRecordTime: order.StartTime,
  2110. }
  2111. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.CurrentOrgId)
  2112. warehouseOutInfo.Price = stockInInfo.Price
  2113. warehouseOutInfo.GoodId = injector
  2114. warehouseOutInfo.GoodTypeId = injector_good_type_id
  2115. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2116. if err == nil {
  2117. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2118. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2119. if err == gorm.ErrRecordNotFound {
  2120. details := &models.AutomaticReduceDetail{
  2121. WarehouseOutId: warehouseOutInfo.ID,
  2122. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2123. PatientId: patient,
  2124. Ctime: time.Now().Unix(),
  2125. Mtime: time.Now().Unix(),
  2126. Status: 1,
  2127. RecordTime: order.StartTime,
  2128. OrgId: adminUserInfo.CurrentOrgId,
  2129. GoodId: injector,
  2130. GoodTypeId: injector_good_type_id,
  2131. }
  2132. service.AddSigleAutoReduceRecordInfo(details)
  2133. } else if err == nil {
  2134. if user.ID > 0 {
  2135. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, warehouseOutInfo)
  2136. }
  2137. }
  2138. }
  2139. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2140. if newOut.ID > 0 {
  2141. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2142. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2143. if err == gorm.ErrRecordNotFound {
  2144. details := &models.AutomaticReduceDetail{
  2145. WarehouseOutId: newOut.ID,
  2146. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2147. PatientId: patient,
  2148. Ctime: time.Now().Unix(),
  2149. Mtime: time.Now().Unix(),
  2150. Status: 1,
  2151. RecordTime: order.StartTime,
  2152. OrgId: adminUserInfo.CurrentOrgId,
  2153. GoodId: injector,
  2154. GoodTypeId: injector_good_type_id,
  2155. }
  2156. service.AddSigleAutoReduceRecordInfo(details)
  2157. } else if err == nil {
  2158. if user.ID > 0 {
  2159. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, &newOut)
  2160. }
  2161. }
  2162. }
  2163. }
  2164. }
  2165. if dialysisPrescription.Bloodlines != bloodlines {
  2166. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2167. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2168. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2169. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2170. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2171. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2172. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2173. warehouseOutInfo := &models.WarehouseOutInfo{
  2174. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2175. WarehouseOutId: out.ID,
  2176. Count: 1,
  2177. Status: 1,
  2178. Ctime: time.Now().Unix(),
  2179. Remark: "",
  2180. OrgId: adminUserInfo.CurrentOrgId,
  2181. Type: 1,
  2182. Manufacturer: 0,
  2183. Dealer: 0,
  2184. IsSys: 1,
  2185. SysRecordTime: order.StartTime,
  2186. }
  2187. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.CurrentOrgId)
  2188. warehouseOutInfo.Price = stockInInfo.Price
  2189. warehouseOutInfo.GoodId = bloodlines
  2190. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  2191. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2192. if err == nil {
  2193. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2194. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2195. if err == gorm.ErrRecordNotFound {
  2196. details := &models.AutomaticReduceDetail{
  2197. WarehouseOutId: warehouseOutInfo.ID,
  2198. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2199. PatientId: patient,
  2200. Ctime: time.Now().Unix(),
  2201. Mtime: time.Now().Unix(),
  2202. Status: 1,
  2203. RecordTime: order.StartTime,
  2204. OrgId: adminUserInfo.CurrentOrgId,
  2205. GoodId: bloodlines,
  2206. GoodTypeId: bloodlines_good_type_id,
  2207. }
  2208. service.AddSigleAutoReduceRecordInfo(details)
  2209. } else if err == nil {
  2210. if user.ID > 0 {
  2211. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, warehouseOutInfo)
  2212. }
  2213. }
  2214. }
  2215. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2216. if newOut.ID > 0 {
  2217. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2218. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2219. if err == gorm.ErrRecordNotFound {
  2220. details := &models.AutomaticReduceDetail{
  2221. WarehouseOutId: newOut.ID,
  2222. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2223. PatientId: patient,
  2224. Ctime: time.Now().Unix(),
  2225. Mtime: time.Now().Unix(),
  2226. Status: 1,
  2227. RecordTime: order.StartTime,
  2228. OrgId: adminUserInfo.CurrentOrgId,
  2229. GoodId: bloodlines,
  2230. GoodTypeId: bloodlines_good_type_id,
  2231. }
  2232. service.AddSigleAutoReduceRecordInfo(details)
  2233. } else if err == nil {
  2234. if user.ID > 0 {
  2235. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, &newOut)
  2236. }
  2237. }
  2238. }
  2239. }
  2240. }
  2241. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  2242. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2243. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2244. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2245. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2246. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2247. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2248. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2249. warehouseOutInfo := &models.WarehouseOutInfo{
  2250. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2251. WarehouseOutId: out.ID,
  2252. Count: 1,
  2253. Status: 1,
  2254. Ctime: time.Now().Unix(),
  2255. Remark: "",
  2256. OrgId: adminUserInfo.CurrentOrgId,
  2257. Type: 1,
  2258. Manufacturer: 0,
  2259. Dealer: 0,
  2260. IsSys: 1,
  2261. SysRecordTime: order.StartTime,
  2262. }
  2263. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.CurrentOrgId)
  2264. warehouseOutInfo.Price = stockInInfo.Price
  2265. warehouseOutInfo.GoodId = tubing_hemodialysis
  2266. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  2267. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2268. if err == nil {
  2269. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2270. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2271. if err == gorm.ErrRecordNotFound {
  2272. details := &models.AutomaticReduceDetail{
  2273. WarehouseOutId: warehouseOutInfo.ID,
  2274. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2275. PatientId: patient,
  2276. Ctime: time.Now().Unix(),
  2277. Mtime: time.Now().Unix(),
  2278. Status: 1,
  2279. RecordTime: order.StartTime,
  2280. OrgId: adminUserInfo.CurrentOrgId,
  2281. GoodId: tubing_hemodialysis,
  2282. GoodTypeId: tubingHemodialysis_good_type_id,
  2283. }
  2284. service.AddSigleAutoReduceRecordInfo(details)
  2285. } else if err == nil {
  2286. if user.ID > 0 {
  2287. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, warehouseOutInfo)
  2288. }
  2289. }
  2290. }
  2291. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2292. if newOut.ID > 0 {
  2293. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2294. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2295. if err == gorm.ErrRecordNotFound {
  2296. details := &models.AutomaticReduceDetail{
  2297. WarehouseOutId: newOut.ID,
  2298. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2299. PatientId: patient,
  2300. Ctime: time.Now().Unix(),
  2301. Mtime: time.Now().Unix(),
  2302. Status: 1,
  2303. RecordTime: order.StartTime,
  2304. OrgId: adminUserInfo.CurrentOrgId,
  2305. GoodId: tubing_hemodialysis,
  2306. GoodTypeId: tubingHemodialysis_good_type_id,
  2307. }
  2308. service.AddSigleAutoReduceRecordInfo(details)
  2309. } else if err == nil {
  2310. if user.ID > 0 {
  2311. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, &newOut)
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. if dialysisPrescription.Package != safe_package {
  2318. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2319. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2320. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2321. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2322. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2323. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2324. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2325. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2326. warehouseOutInfo := &models.WarehouseOutInfo{
  2327. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2328. WarehouseOutId: out.ID,
  2329. Count: 1,
  2330. Status: 1,
  2331. Ctime: time.Now().Unix(),
  2332. Remark: "",
  2333. OrgId: adminUserInfo.CurrentOrgId,
  2334. Type: 1,
  2335. Manufacturer: 0,
  2336. Dealer: 0,
  2337. IsSys: 1,
  2338. SysRecordTime: order.StartTime,
  2339. }
  2340. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.CurrentOrgId)
  2341. warehouseOutInfo.Price = stockInInfo.Price
  2342. warehouseOutInfo.GoodId = safe_package
  2343. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  2344. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2345. if err == nil {
  2346. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2347. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2348. if err == gorm.ErrRecordNotFound {
  2349. details := &models.AutomaticReduceDetail{
  2350. WarehouseOutId: warehouseOutInfo.ID,
  2351. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2352. PatientId: patient,
  2353. Ctime: time.Now().Unix(),
  2354. Mtime: time.Now().Unix(),
  2355. Status: 1,
  2356. RecordTime: order.StartTime,
  2357. OrgId: adminUserInfo.CurrentOrgId,
  2358. GoodId: safe_package,
  2359. GoodTypeId: safe_package_good_type_id,
  2360. }
  2361. service.AddSigleAutoReduceRecordInfo(details)
  2362. } else if err == nil {
  2363. if user.ID > 0 {
  2364. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, warehouseOutInfo)
  2365. }
  2366. }
  2367. }
  2368. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2369. if newOut.ID > 0 {
  2370. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2371. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2372. if err == gorm.ErrRecordNotFound {
  2373. details := &models.AutomaticReduceDetail{
  2374. WarehouseOutId: newOut.ID,
  2375. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2376. PatientId: patient,
  2377. Ctime: time.Now().Unix(),
  2378. Mtime: time.Now().Unix(),
  2379. Status: 1,
  2380. RecordTime: order.StartTime,
  2381. OrgId: adminUserInfo.CurrentOrgId,
  2382. GoodId: safe_package,
  2383. GoodTypeId: safe_package_good_type_id,
  2384. }
  2385. service.AddSigleAutoReduceRecordInfo(details)
  2386. } else if err == nil {
  2387. if user.ID > 0 {
  2388. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, &newOut)
  2389. }
  2390. }
  2391. }
  2392. }
  2393. }
  2394. if dialysisPrescription.ALiquid != a_liquid {
  2395. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2396. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2397. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2398. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2399. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2400. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2401. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2402. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2403. warehouseOutInfo := &models.WarehouseOutInfo{
  2404. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2405. WarehouseOutId: out.ID,
  2406. Count: 1,
  2407. Status: 1,
  2408. Ctime: time.Now().Unix(),
  2409. Remark: "",
  2410. OrgId: adminUserInfo.CurrentOrgId,
  2411. Type: 1,
  2412. Manufacturer: 0,
  2413. Dealer: 0,
  2414. IsSys: 1,
  2415. SysRecordTime: order.StartTime,
  2416. }
  2417. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.CurrentOrgId)
  2418. warehouseOutInfo.Price = stockInInfo.Price
  2419. warehouseOutInfo.GoodId = a_liquid
  2420. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  2421. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2422. if err == nil {
  2423. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2424. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2425. if err == gorm.ErrRecordNotFound {
  2426. details := &models.AutomaticReduceDetail{
  2427. WarehouseOutId: warehouseOutInfo.ID,
  2428. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2429. PatientId: patient,
  2430. Ctime: time.Now().Unix(),
  2431. Mtime: time.Now().Unix(),
  2432. Status: 1,
  2433. RecordTime: order.StartTime,
  2434. OrgId: adminUserInfo.CurrentOrgId,
  2435. GoodId: a_liquid,
  2436. GoodTypeId: aliquid_good_type_id,
  2437. }
  2438. service.AddSigleAutoReduceRecordInfo(details)
  2439. } else if err == nil {
  2440. if user.ID > 0 {
  2441. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, warehouseOutInfo)
  2442. }
  2443. }
  2444. }
  2445. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2446. if newOut.ID > 0 {
  2447. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2448. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2449. if err == gorm.ErrRecordNotFound {
  2450. details := &models.AutomaticReduceDetail{
  2451. WarehouseOutId: newOut.ID,
  2452. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2453. PatientId: patient,
  2454. Ctime: time.Now().Unix(),
  2455. Mtime: time.Now().Unix(),
  2456. Status: 1,
  2457. RecordTime: order.StartTime,
  2458. OrgId: adminUserInfo.CurrentOrgId,
  2459. GoodId: a_liquid,
  2460. GoodTypeId: aliquid_good_type_id,
  2461. }
  2462. service.AddSigleAutoReduceRecordInfo(details)
  2463. } else if err == nil {
  2464. if user.ID > 0 {
  2465. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, &newOut)
  2466. }
  2467. }
  2468. }
  2469. }
  2470. }
  2471. }
  2472. }
  2473. }
  2474. prescription.Creater = adminUserInfo.AdminUser.Id
  2475. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2476. prescription.UpdatedTime = time.Now().Unix()
  2477. prescription.Modifier = adminUserInfo.AdminUser.Id
  2478. prescription.ID = dialysisPrescription.ID
  2479. }
  2480. solution := models.DialysisSolution{
  2481. RegistrarsId: adminUserInfo.AdminUser.Id,
  2482. UserOrgId: adminUserInfo.CurrentOrgId,
  2483. Doctor: prescription_doctor,
  2484. PatientId: patient,
  2485. ModeId: mode_id,
  2486. DialysisDuration: dialysis_duration,
  2487. PerfusionApparatus: perfusion_apparatus,
  2488. BloodFlowVolume: blood_flow_volume,
  2489. Dewater: dewater_amount,
  2490. DisplaceLiqui: displace_liqui,
  2491. ReplacementWay: replacement_way,
  2492. Anticoagulant: anticoagulant,
  2493. AnticoagulantShouji: anticoagulant_shouji,
  2494. AnticoagulantWeichi: anticoagulant_weichi,
  2495. AnticoagulantZongliang: anticoagulant_zongliang,
  2496. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2497. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2498. Kalium: kalium,
  2499. Sodium: sodium,
  2500. Calcium: calcium,
  2501. Bicarbonate: bicarbonate,
  2502. Glucose: glucose,
  2503. // DryWeight: dry_weight,
  2504. DialysateFlow: dialysate_flow,
  2505. DialysateTemperature: dialysate_temperature,
  2506. Conductivity: conductivity,
  2507. Remark: remark,
  2508. Status: 1,
  2509. CreatedTime: time.Now().Unix(),
  2510. UpdatedTime: time.Now().Unix(),
  2511. DialysisDurationMinute: dialysisDurationMinute,
  2512. DialysisDurationHour: dialysisDurationHour,
  2513. TargetUltrafiltration: targetUltrafiltration,
  2514. DialysateFormulation: dialysateFormulation,
  2515. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2516. BodyFluid: body_fluid,
  2517. SpecialMedicine: special_medicine,
  2518. SpecialMedicineOther: special_medicine_other,
  2519. DisplaceLiquiPart: displace_liqui_part,
  2520. DisplaceLiquiValue: displace_liqui_value,
  2521. BloodAccess: blood_access,
  2522. Ultrafiltration: ultrafiltration,
  2523. BodyFluidOther: body_fluid_other,
  2524. ReplacementTotal: replacement_total,
  2525. TargetKtv: target_ktv,
  2526. }
  2527. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  2528. if err == nil {
  2529. c.ServeSuccessJSON(map[string]interface{}{
  2530. "solution": &solution,
  2531. "prescription": &prescription,
  2532. })
  2533. } else {
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2535. }
  2536. }
  2537. func (c *DialysisApiController) PostDouleCheck() {
  2538. id, _ := c.GetInt64("patient", 0)
  2539. recordDateStr := c.GetString("record_date")
  2540. checkTimeStr := c.GetString("check_time")
  2541. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  2542. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  2543. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  2544. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  2545. dialysis_item_desc := c.GetString("dialysis_item_desc")
  2546. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  2547. vascular_access_desc := c.GetString("vascular_access_desc")
  2548. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  2549. collator, _ := c.GetInt64("collator", 0)
  2550. if id <= 0 {
  2551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2552. return
  2553. }
  2554. adminUserInfo := c.GetAdminUserInfo()
  2555. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  2556. if patient.ID == 0 {
  2557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2558. return
  2559. }
  2560. if len(recordDateStr) == 0 {
  2561. recordDateStr = time.Now().Format("2006-01-02")
  2562. }
  2563. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2564. if parseDateErr != nil {
  2565. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2567. return
  2568. }
  2569. if len(checkTimeStr) == 0 {
  2570. checkTimeStr = time.Now().Format("2006-01-02 15:04")
  2571. }
  2572. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  2573. doubleCheck := models.DoubleCheck{
  2574. UserOrgId: adminUserInfo.CurrentOrgId,
  2575. PatientId: id,
  2576. DialysisItemCheck: dialysis_item_check,
  2577. DialysisParameterCheck: dialysis_parameter_check,
  2578. VascularAccessVerification: vascular_access_verification,
  2579. PipelineConnectionCheck: pipeline_connection_check,
  2580. DialysisItemDesc: dialysis_item_desc,
  2581. DialysisParameterDesc: dialysis_parameter_desc,
  2582. VascularAccessDesc: vascular_access_desc,
  2583. PipelineConnectionDesc: pipeline_connection_desc,
  2584. Collator: collator,
  2585. Status: 1,
  2586. CreatedTime: time.Now().Unix(),
  2587. UpdatedTime: time.Now().Unix(),
  2588. CheckDate: recordDate.Unix(),
  2589. }
  2590. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2591. if check.ID == 0 { //新增
  2592. doubleCheck.FirstCheckTime = checkDate.Unix()
  2593. doubleCheck.Creater = adminUserInfo.AdminUser.Id
  2594. err := service.AddSigleDoubleCheck(&doubleCheck)
  2595. if err == nil {
  2596. c.ServeSuccessJSON(map[string]interface{}{
  2597. "doubleCheck": doubleCheck,
  2598. })
  2599. } else {
  2600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2601. }
  2602. } else { //修改
  2603. if check.Modifier != 0 {
  2604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
  2605. } else {
  2606. if adminUserInfo.AdminUser.Id == check.Creater {
  2607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
  2608. return
  2609. }
  2610. doubleCheck.FirstCheckTime = check.FirstCheckTime
  2611. doubleCheck.CheckTime = checkDate.Unix()
  2612. doubleCheck.Creater = check.Creater
  2613. doubleCheck.CreatedTime = check.CreatedTime
  2614. doubleCheck.UpdatedTime = time.Now().Unix()
  2615. doubleCheck.Modifier = adminUserInfo.AdminUser.Id
  2616. doubleCheck.ID = check.ID
  2617. err := service.UpdateDoubleCheck(&doubleCheck)
  2618. if err == nil {
  2619. c.ServeSuccessJSON(map[string]interface{}{
  2620. "doubleCheck": doubleCheck,
  2621. })
  2622. } else {
  2623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2624. }
  2625. }
  2626. }
  2627. }
  2628. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  2629. id, _ := c.GetInt64("patient", 0)
  2630. recordDateStr := c.GetString("record_date")
  2631. way, _ := c.GetInt64("way", 0)
  2632. consciousness, _ := c.GetInt64("consciousness", 0)
  2633. appetite, _ := c.GetInt64("appetite", 0)
  2634. condition, _ := c.GetInt64("condition", 0)
  2635. posture, _ := c.GetInt64("posture")
  2636. score := c.GetString("score")
  2637. sick_condition, _ := c.GetInt64("sick_condition", 0)
  2638. danger_level, _ := c.GetInt64("danger_level", 0)
  2639. intake, _ := c.GetInt64("intake", 0)
  2640. nutrition, _ := c.GetInt64("nutrition", 0)
  2641. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  2642. psychological_assessment_other := c.GetString("psychological_assessment_other")
  2643. sick_condition_other := c.GetString("sick_condition_other")
  2644. precaution, _ := c.GetInt64("precaution", 0)
  2645. precaution_other := c.GetString("precaution_other")
  2646. psychological_other := c.GetString("psychological_other")
  2647. admission_number := c.GetString("admission_number")
  2648. if id <= 0 {
  2649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2650. return
  2651. }
  2652. adminUserInfo := c.GetAdminUserInfo()
  2653. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  2654. if patient.ID == 0 {
  2655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2656. return
  2657. }
  2658. if len(recordDateStr) == 0 {
  2659. recordDateStr = time.Now().Format("2006-01-02")
  2660. }
  2661. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2662. if parseDateErr != nil {
  2663. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2665. return
  2666. }
  2667. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2668. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  2669. UserOrgId: adminUserInfo.CurrentOrgId,
  2670. PatientId: id,
  2671. RecordDate: recordDate.Unix(),
  2672. Way: way,
  2673. Consciousness: consciousness,
  2674. Appetite: appetite,
  2675. Condition: condition,
  2676. SickCondition: sick_condition,
  2677. DangerLevel: danger_level,
  2678. Intake: intake,
  2679. Nutrition: nutrition,
  2680. PsychologicalAssessment: psychological_assessment,
  2681. PsychologicalAssessmentOther: psychological_assessment_other,
  2682. SickConditionOther: sick_condition_other,
  2683. Posture: posture,
  2684. CreatedTime: time.Now().Unix(),
  2685. UpdateTime: time.Now().Unix(),
  2686. Status: 1,
  2687. Score: score,
  2688. Precaution: precaution,
  2689. PrecautionOther: precaution_other,
  2690. PsychologicalOther: psychological_other,
  2691. AdmissionNumber: admission_number,
  2692. }
  2693. if receiveTreatment.ID == 0 { //新增
  2694. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  2695. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  2696. if err == nil {
  2697. c.ServeSuccessJSON(map[string]interface{}{
  2698. "receiveTreatmentAsses": receiveTreatmentAsses,
  2699. })
  2700. } else {
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2702. }
  2703. } else { //修改
  2704. if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  2705. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2706. if getPermissionErr != nil {
  2707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2708. return
  2709. } else if headNursePermission == nil {
  2710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2711. return
  2712. }
  2713. }
  2714. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  2715. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  2716. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  2717. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  2718. receiveTreatmentAsses.ID = receiveTreatment.ID
  2719. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  2720. if err == nil {
  2721. c.ServeSuccessJSON(map[string]interface{}{
  2722. "receiveTreatmentAsses": receiveTreatmentAsses,
  2723. })
  2724. } else {
  2725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2726. }
  2727. }
  2728. }
  2729. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  2730. patient, _ := c.GetInt64("patient", 0)
  2731. recordDateStr := c.GetString("record_date")
  2732. fmt.Println(recordDateStr)
  2733. if patient <= 0 {
  2734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2735. return
  2736. }
  2737. adminUserInfo := c.GetAdminUserInfo()
  2738. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2739. if patientInfo.ID == 0 {
  2740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2741. return
  2742. }
  2743. if len(recordDateStr) == 0 {
  2744. recordDateStr = time.Now().Format("2006-01-02")
  2745. }
  2746. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2747. if parseDateErr != nil {
  2748. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2750. return
  2751. }
  2752. // data := make(map[string]interface{}, 0)
  2753. var data models.AssessmentAfterDislysis
  2754. var err error
  2755. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  2756. fmt.Println(err)
  2757. if err != nil {
  2758. c.ErrorLog("数据解析错误:%v", err)
  2759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2760. return
  2761. }
  2762. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2763. assessment.DialysisOrderId = data.DialysisOrderId
  2764. assessment.Evaluator = adminUserInfo.AdminUser.Id
  2765. assessment.Status = 1
  2766. assessment.WeightAfter = data.WeightAfter
  2767. assessment.WeightLoss = data.WeightLoss
  2768. assessment.Temperature = data.Temperature
  2769. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  2770. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  2771. assessment.PulseFrequency = data.PulseFrequency
  2772. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  2773. assessment.ActualDisplacement = data.ActualDisplacement
  2774. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  2775. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  2776. assessment.Cruor = data.Cruor
  2777. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  2778. assessment.DialysisIntakes = data.DialysisIntakes
  2779. assessment.InternalFistula = data.InternalFistula
  2780. assessment.BloodAccessPartId = data.BloodAccessPartId
  2781. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  2782. assessment.Catheter = data.Catheter
  2783. assessment.Complication = data.Complication
  2784. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  2785. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  2786. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  2787. assessment.PatientGose = data.PatientGose
  2788. assessment.InpatientDepartment = data.InpatientDepartment
  2789. assessment.ObservationContent = data.ObservationContent
  2790. assessment.ObservationContentOther = data.ObservationContentOther
  2791. assessment.Remark = data.Remark
  2792. assessment.BreathingRate = data.BreathingRate
  2793. assessment.DialysisProcess = data.DialysisProcess
  2794. assessment.InAdvanceMinute = data.InAdvanceMinute
  2795. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  2796. assessment.InAdvanceReason = data.InAdvanceReason
  2797. assessment.HemostasisOpera = data.HemostasisOpera
  2798. assessment.HemostasisMinute = data.HemostasisMinute
  2799. assessment.TremorNoise = data.TremorNoise
  2800. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  2801. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  2802. assessment.ArterialTube = data.ArterialTube
  2803. assessment.IntravenousTube = data.IntravenousTube
  2804. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  2805. assessment.Dialyzer = data.Dialyzer
  2806. assessment.IsEat = data.IsEat
  2807. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2808. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2809. if evaluation.ID > 0 {
  2810. if evaluation.WeightBefore > 0 && assessment.WeightAfter > 0 {
  2811. if (evaluation.WeightBefore-evaluation.AdditionalWeight)-(assessment.WeightAfter-assessment.AdditionalWeight) > 0 {
  2812. assessment.WeightLoss = (evaluation.WeightBefore - evaluation.AdditionalWeight) - (assessment.WeightAfter - assessment.AdditionalWeight)
  2813. } else {
  2814. assessment.WeightLoss = 0
  2815. }
  2816. }
  2817. }
  2818. if assessment.ID > 0 {
  2819. if appRole.UserType == 3 {
  2820. if assessment.Creater != adminUserInfo.AdminUser.Id && assessment.Creater != 0 {
  2821. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2822. if getPermissionErr != nil {
  2823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2824. return
  2825. } else if headNursePermission == nil {
  2826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2827. return
  2828. }
  2829. }
  2830. }
  2831. if appRole.UserType == 2 || appRole.UserType == 1 {
  2832. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2833. assessment.AssessmentTime = time.Now().Unix()
  2834. } else {
  2835. assessment.Modifier = adminUserInfo.AdminUser.Id
  2836. assessment.Creater = adminUserInfo.AdminUser.Id
  2837. }
  2838. assessment.UpdatedTime = time.Now().Unix()
  2839. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  2840. } else {
  2841. if appRole.UserType == 2 || appRole.UserType == 1 {
  2842. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2843. assessment.AssessmentTime = time.Now().Unix()
  2844. } else {
  2845. assessment.Creater = adminUserInfo.AdminUser.Id
  2846. }
  2847. assessment.CreatedTime = time.Now().Unix()
  2848. assessment.UpdatedTime = time.Now().Unix()
  2849. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  2850. assessment.PatientId = patient
  2851. assessment.AssessmentDate = recordDate.Unix()
  2852. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  2853. }
  2854. if err != nil {
  2855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2856. return
  2857. }
  2858. c.ServeSuccessJSON(map[string]interface{}{
  2859. "AssessmentAfterDislysis": &assessment,
  2860. })
  2861. }
  2862. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  2863. patient, _ := c.GetInt64("patient", 0)
  2864. recordDateStr := c.GetString("record_date")
  2865. if patient <= 0 {
  2866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2867. return
  2868. }
  2869. adminUserInfo := c.GetAdminUserInfo()
  2870. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2871. if patientInfo.ID == 0 {
  2872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2873. return
  2874. }
  2875. if len(recordDateStr) == 0 {
  2876. recordDateStr = time.Now().Format("2006-01-02")
  2877. }
  2878. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2879. if parseDateErr != nil {
  2880. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2882. return
  2883. }
  2884. weight_before, _ := c.GetFloat("weight_before", 0)
  2885. dry_weight, _ := c.GetFloat("dry_weight", 0)
  2886. additional_weight, _ := c.GetFloat("additional_weight", 0)
  2887. temperature, _ := c.GetFloat("temperature", 0)
  2888. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2889. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2890. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2891. last_post_dialysis := c.GetString("last_post_dialysis")
  2892. dialysis_interphase := c.GetString("dialysis_interphase")
  2893. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  2894. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  2895. bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  2896. internalFistula := c.GetString("internal_fistula")
  2897. internal_fistula_skin := c.GetString("internal_fistula_skin")
  2898. catheter := c.GetString("catheter")
  2899. catheter_bend, _ := c.GetInt("catheter_bend")
  2900. complication := c.GetString("complication")
  2901. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  2902. hemorrhage := c.GetString("hemorrhage")
  2903. hemorrhage_other := c.GetString("hemorrhage_other")
  2904. remark := c.GetString("remark")
  2905. puncture_method := c.GetString("puncture_method")
  2906. dialysis_count, _ := c.GetInt64("dialysis_count", 0)
  2907. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  2908. emergency_treatment_other := c.GetString("emergency_treatment_other")
  2909. ductus_arantii := c.GetString("ductus_arantii")
  2910. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  2911. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  2912. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  2913. puncture_way, _ := c.GetInt64("puncture_way", 0)
  2914. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  2915. internal_fistula_other := c.GetString("internal_fistula_other")
  2916. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2917. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  2918. is_infect, _ := c.GetInt64("is_infect", 0)
  2919. exposed, _ := c.GetFloat("exposed", 0)
  2920. skin, _ := c.GetInt64("skin", 0)
  2921. skin_other := c.GetString("skin_other")
  2922. infect_other := c.GetString("infect_other")
  2923. ductus_arantii_other := c.GetString("ductus_arantii_other")
  2924. machine_type := c.GetString("machine_type")
  2925. puncture_needle := c.GetString("puncture_needle")
  2926. assessmentBeforeDislysis := models.PredialysisEvaluation{
  2927. DialysisCount: dialysis_count,
  2928. EmergencyTreatment: emergency_treatment,
  2929. EmergencyTreatmentOther: emergency_treatment_other,
  2930. DuctusArantii: ductus_arantii,
  2931. VenousCatheterization: venous_catheterization,
  2932. VenousCatheterizationPart: venous_catheterization_part,
  2933. VenousCatheterizationPartOther: venous_catheterization_part_other,
  2934. PunctureWay: puncture_way,
  2935. BloodAccessInternalFistula: blood_access_internal_fistula,
  2936. BloodAccessNoise: blood_access_noise,
  2937. InternalFistulaOther: internal_fistula_other,
  2938. Evaluator: adminUserInfo.AdminUser.Id,
  2939. UserOrgId: adminUserInfo.CurrentOrgId,
  2940. PatientId: patient,
  2941. AssessmentDate: recordDate.Unix(),
  2942. Temperature: temperature,
  2943. PulseFrequency: pulse_frequency,
  2944. SystolicBloodPressure: systolic_blood_pressure,
  2945. DiastolicBloodPressure: diastolic_blood_pressure,
  2946. WeightBefore: weight_before,
  2947. DryWeight: dry_weight,
  2948. AdditionalWeight: additional_weight,
  2949. DialysisInterphase: dialysis_interphase,
  2950. LastPostDialysis: last_post_dialysis,
  2951. SymptomBeforeDialysis: symptom_before_dialysis,
  2952. InternalFistula: internalFistula,
  2953. InternalFistulaSkin: internal_fistula_skin,
  2954. Catheter: catheter,
  2955. CatheterBend: catheter_bend,
  2956. Complication: complication,
  2957. CreatedTime: time.Now().Unix(),
  2958. Status: 1,
  2959. Remark: remark,
  2960. IsHemorrhage: is_hemorrhage,
  2961. Hemorrhage: hemorrhage,
  2962. HemorrhageOther: hemorrhage_other,
  2963. BloodAccessPartId: bloodAccessPartId,
  2964. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2965. PunctureMethod: puncture_method,
  2966. BreathingRate: breathing_rate,
  2967. IsInfect: is_infect,
  2968. Exposed: exposed,
  2969. Skin: skin,
  2970. SkinOther: skin_other,
  2971. InfectOther: infect_other,
  2972. DuctusArantiiOther: ductus_arantii_other,
  2973. MachineType: machine_type,
  2974. PunctureNeedle: puncture_needle,
  2975. }
  2976. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2977. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2978. if evaluation.ID == 0 { //新增
  2979. if appRole.UserType == 2 || appRole.UserType == 1 {
  2980. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2981. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2982. } else {
  2983. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2984. }
  2985. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2986. if err == nil {
  2987. c.ServeSuccessJSON(map[string]interface{}{
  2988. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2989. })
  2990. } else {
  2991. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2993. }
  2994. } else { //修改
  2995. if appRole.UserType == 3 {
  2996. if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2997. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2998. if getPermissionErr != nil {
  2999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3000. return
  3001. } else if headNursePermission == nil {
  3002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3003. return
  3004. }
  3005. }
  3006. }
  3007. if appRole.UserType == 2 || appRole.UserType == 1 {
  3008. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3009. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  3010. } else {
  3011. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  3012. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  3013. }
  3014. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  3015. assessmentBeforeDislysis.ID = evaluation.ID
  3016. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  3017. //
  3018. //新增逻辑
  3019. var dewater_amount float64
  3020. dewater_amount = 0
  3021. if evaluation.DryWeight > 0 {
  3022. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3023. if dewater_amount <= 0 {
  3024. dewater_amount = 0
  3025. }
  3026. } else {
  3027. dewater_amount = 0
  3028. }
  3029. // 计算透析处方的相关超滤量
  3030. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3031. var lastDialysisPrescribe *models.DialysisPrescription
  3032. var dialysisSolution *models.DialysisSolution
  3033. var dialysisPrescribe *models.DialysisPrescription
  3034. var mode_id int64
  3035. if schedual != nil {
  3036. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  3037. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  3038. // 获取透析模版
  3039. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  3040. mode_id = schedual.ModeId
  3041. } else {
  3042. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  3043. // 获取透析模版
  3044. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3045. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  3046. if dialysisPrescribe == nil && dialysisSolution != nil {
  3047. mode_id = dialysisSolution.ModeId
  3048. }
  3049. if dialysisPrescribe == nil && dialysisSolution == nil {
  3050. mode_id = 0
  3051. }
  3052. }
  3053. // 插入透析处方
  3054. if dialysisPrescribe == nil && dialysisSolution != nil {
  3055. var newprescribe models.DialysisPrescription
  3056. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  3057. newprescribe.PatientId = dialysisSolution.PatientId
  3058. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  3059. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  3060. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  3061. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  3062. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  3063. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  3064. newprescribe.ModeId = dialysisSolution.ModeId
  3065. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  3066. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  3067. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  3068. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  3069. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  3070. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  3071. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  3072. newprescribe.Glucose = dialysisSolution.Glucose
  3073. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  3074. newprescribe.Kalium = dialysisSolution.Kalium
  3075. newprescribe.Sodium = dialysisSolution.Sodium
  3076. newprescribe.Calcium = dialysisSolution.Calcium
  3077. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  3078. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  3079. newprescribe.Conductivity = dialysisSolution.Conductivity
  3080. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  3081. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  3082. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  3083. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  3084. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  3085. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  3086. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  3087. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  3088. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  3089. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  3090. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  3091. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  3092. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  3093. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  3094. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  3095. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  3096. newprescribe.CreatedTime = time.Now().Unix()
  3097. newprescribe.UpdatedTime = time.Now().Unix()
  3098. newprescribe.RecordDate = recordDate.Unix()
  3099. newprescribe.DewaterAmount = dewater_amount
  3100. newprescribe.TargetUltrafiltration = dewater_amount
  3101. newprescribe.Status = 1
  3102. err := service.AddSigleRecord(&newprescribe)
  3103. if err != nil {
  3104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3105. }
  3106. }
  3107. if dialysisPrescribe == nil && dialysisSolution == nil {
  3108. if lastDialysisPrescribe != nil {
  3109. var newprescribe models.DialysisPrescription
  3110. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  3111. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  3112. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3113. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3114. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3115. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3116. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3117. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3118. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3119. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3120. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3121. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3122. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3123. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3124. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3125. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3126. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3127. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3128. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3129. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3130. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3131. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3132. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3133. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3134. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3135. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3136. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3137. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3138. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3139. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3140. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3141. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3142. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3143. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3144. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3145. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3146. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3147. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3148. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3149. newprescribe.CreatedTime = time.Now().Unix()
  3150. newprescribe.UpdatedTime = time.Now().Unix()
  3151. newprescribe.RecordDate = recordDate.Unix()
  3152. newprescribe.DewaterAmount = dewater_amount
  3153. newprescribe.TargetUltrafiltration = dewater_amount
  3154. newprescribe.Status = 1
  3155. err := service.AddSigleRecord(&newprescribe)
  3156. if err != nil {
  3157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3158. }
  3159. } else {
  3160. var newprescribe models.DialysisPrescription
  3161. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  3162. newprescribe.PatientId = patient
  3163. newprescribe.ModeId = mode_id
  3164. newprescribe.CreatedTime = time.Now().Unix()
  3165. newprescribe.UpdatedTime = time.Now().Unix()
  3166. newprescribe.RecordDate = recordDate.Unix()
  3167. newprescribe.DewaterAmount = dewater_amount
  3168. newprescribe.TargetUltrafiltration = dewater_amount
  3169. newprescribe.Status = 1
  3170. err := service.AddSigleRecord(&newprescribe)
  3171. if err != nil {
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3173. }
  3174. }
  3175. }
  3176. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  3177. if err == nil {
  3178. c.ServeSuccessJSON(map[string]interface{}{
  3179. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  3180. })
  3181. } else {
  3182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3183. }
  3184. }
  3185. }
  3186. func (c *DialysisApiController) PostTreatmentSummary() {
  3187. patient, _ := c.GetInt64("patient", 0)
  3188. recordDateStr := c.GetString("record_date")
  3189. if patient <= 0 {
  3190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3191. return
  3192. }
  3193. adminUserInfo := c.GetAdminUserInfo()
  3194. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3195. if patientInfo.ID == 0 {
  3196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3197. return
  3198. }
  3199. if len(recordDateStr) == 0 {
  3200. recordDateStr = time.Now().Format("2006-01-02")
  3201. }
  3202. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3203. if parseDateErr != nil {
  3204. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3206. return
  3207. }
  3208. mission := c.GetString("mission")
  3209. dialysis_summary := c.GetString("dialysis_summary")
  3210. sj_nurse := adminUserInfo.AdminUser.Id
  3211. zl_nurse := adminUserInfo.AdminUser.Id
  3212. hd_nurse := adminUserInfo.AdminUser.Id
  3213. xj_nurse := adminUserInfo.AdminUser.Id
  3214. zl_doctor := adminUserInfo.AdminUser.Id
  3215. treatmentSummary := models.TreatmentSummary{
  3216. UserOrgId: adminUserInfo.CurrentOrgId,
  3217. PatientId: patient,
  3218. AssessmentDate: recordDate.Unix(),
  3219. Mission: mission,
  3220. DialysisSummary: dialysis_summary,
  3221. SjNurse: sj_nurse,
  3222. ZlNurse: zl_nurse,
  3223. HdNurse: hd_nurse,
  3224. XjNurse: xj_nurse,
  3225. ZlDoctor: zl_doctor,
  3226. Status: 1,
  3227. CreatedTime: time.Now().Unix(),
  3228. }
  3229. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  3230. if tempTreatmentSummary.ID == 0 { //新增
  3231. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  3232. err := service.AddSigleSummaryRecord(&treatmentSummary)
  3233. if err == nil {
  3234. c.ServeSuccessJSON(map[string]interface{}{
  3235. "summary": treatmentSummary,
  3236. })
  3237. } else {
  3238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3239. }
  3240. } else { //修改
  3241. if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  3242. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3243. if getPermissionErr != nil {
  3244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3245. return
  3246. } else if headNursePermission == nil {
  3247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3248. return
  3249. }
  3250. }
  3251. treatmentSummary.Creater = tempTreatmentSummary.Creater
  3252. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  3253. treatmentSummary.UpdatedTime = time.Now().Unix()
  3254. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  3255. treatmentSummary.ID = tempTreatmentSummary.ID
  3256. err := service.UpdateSummeRecord(&treatmentSummary)
  3257. if err == nil {
  3258. c.ServeSuccessJSON(map[string]interface{}{
  3259. "summary": treatmentSummary,
  3260. })
  3261. } else {
  3262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3263. }
  3264. }
  3265. }
  3266. func (c *DialysisApiController) GetDeviceList() {
  3267. adminUserInfo := c.GetAdminUserInfo()
  3268. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  3269. c.ServeSuccessJSON(map[string]interface{}{
  3270. "device": device,
  3271. })
  3272. }
  3273. func (c *DialysisApiController) GetAllDeviceZone() {
  3274. adminUserInfo := c.GetAdminUserInfo()
  3275. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  3276. if err == nil {
  3277. c.ServeSuccessJSON(map[string]interface{}{
  3278. "zone": zone,
  3279. })
  3280. }
  3281. }
  3282. func (c *DialysisApiController) GetDialysisWatch() {
  3283. page, _ := c.GetInt64("page", 1)
  3284. limit, _ := c.GetInt64("limit", 10)
  3285. schedulType, _ := c.GetInt64("schedul_type", 0)
  3286. startTime, _ := c.GetInt64("schedul_time", 0)
  3287. partitionType, _ := c.GetInt64("partition_type", 0)
  3288. keywords := c.GetString("keywords")
  3289. adminUserInfo := c.GetAdminUserInfo()
  3290. if len(keywords) > 0 {
  3291. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  3292. if err == nil {
  3293. c.ServeSuccessJSON(map[string]interface{}{
  3294. "schedule": dialysisSchedule,
  3295. "total": total,
  3296. })
  3297. } else {
  3298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3299. }
  3300. } else {
  3301. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3302. if err == nil {
  3303. c.ServeSuccessJSON(map[string]interface{}{
  3304. "schedule": dialysisSchedule,
  3305. "total": total,
  3306. })
  3307. } else {
  3308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3309. }
  3310. }
  3311. }
  3312. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3313. patientId, _ := c.GetInt64("id", 0)
  3314. record_date, _ := c.GetInt64("record_date", 0)
  3315. adminUserInfo := c.GetAdminUserInfo()
  3316. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3317. var dialysisStatus int64
  3318. if dialysisOrder == nil { //没有透析记录
  3319. dialysisStatus = 0 //未透析
  3320. } else {
  3321. dialysisStatus = dialysisOrder.Stage
  3322. }
  3323. //用户基本信息
  3324. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3325. //接诊评估
  3326. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3327. //透前评估
  3328. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3329. //临时医嘱
  3330. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3331. //双人核对
  3332. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3333. //透析监测
  3334. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3335. //透后评估
  3336. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3337. //透析小结
  3338. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3339. //透析处方
  3340. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3341. if dialysisPrescription.ID == 0 {
  3342. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3343. c.ServeSuccessJSON(map[string]interface{}{
  3344. "patientInfo": schedualPatientInfo,
  3345. "dialysisPrescription": solution,
  3346. "receiverTreatmentAccess": receiverTreatmentAccess,
  3347. "predialysisEvaluation": PredialysisEvaluation,
  3348. "doctorAdvice": DoctorAdvice,
  3349. "doubleCheck": DoubleCheck,
  3350. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3351. "treatmentSummary": TreatmentSummary,
  3352. "monitorRecord": Record,
  3353. "dialysisStatus": dialysisStatus,
  3354. "dialysisOrder": dialysisOrder,
  3355. "isSolution": 1,
  3356. })
  3357. } else {
  3358. c.ServeSuccessJSON(map[string]interface{}{
  3359. "patientInfo": schedualPatientInfo,
  3360. "dialysisPrescription": dialysisPrescription,
  3361. "receiverTreatmentAccess": receiverTreatmentAccess,
  3362. "predialysisEvaluation": PredialysisEvaluation,
  3363. "doctorAdvice": DoctorAdvice,
  3364. "doubleCheck": DoubleCheck,
  3365. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3366. "treatmentSummary": TreatmentSummary,
  3367. "monitorRecord": Record,
  3368. "dialysisStatus": dialysisStatus,
  3369. "dialysisOrder": dialysisOrder,
  3370. "isSolution": 2,
  3371. })
  3372. }
  3373. }
  3374. func (c *DialysisApiController) CreateDoctorAdvice() {
  3375. patient, _ := c.GetInt64("id", 0)
  3376. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3377. record_date, _ := c.GetInt64("record_date", 0)
  3378. if patient <= 0 {
  3379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3380. return
  3381. }
  3382. adminUserInfo := c.GetAdminUserInfo()
  3383. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3384. if patientInfo.ID == 0 {
  3385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3386. return
  3387. }
  3388. var advice models.DoctorAdvice
  3389. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3390. if code > 0 {
  3391. c.ServeFailJSONWithSGJErrorCode(code)
  3392. return
  3393. }
  3394. if advice.ParentId > 0 {
  3395. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3396. if old.ID == 0 || old.PatientId != patient {
  3397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3398. return
  3399. }
  3400. if old.StopState == 1 || old.ExecutionState == 1 {
  3401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3402. return
  3403. }
  3404. if old.ParentId > 0 {
  3405. advice.ParentId = old.ParentId
  3406. }
  3407. advice.StartTime = old.StartTime
  3408. advice.AdviceDoctor = old.AdviceDoctor
  3409. advice.DeliveryWay = old.DeliveryWay
  3410. advice.ExecutionFrequency = old.ExecutionFrequency
  3411. }
  3412. advice.RecordDate = record_date
  3413. advice.DialysisOrderId = dialysis_id
  3414. advice.Status = 1
  3415. advice.CreatedTime = time.Now().Unix()
  3416. advice.UpdatedTime = time.Now().Unix()
  3417. advice.StopState = 2
  3418. advice.ExecutionState = 2
  3419. advice.AdviceType = 2
  3420. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3421. advice.PatientId = patient
  3422. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3423. err := service.CreateDoctorAdvice(&advice)
  3424. if err != nil {
  3425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3426. return
  3427. }
  3428. for _, subAdvice := range subAdivice {
  3429. subAdvice.ParentId = advice.ID
  3430. subAdvice.PatientId = patient
  3431. subAdvice.RecordDate = record_date
  3432. subAdvice.CreatedTime = time.Now().Unix()
  3433. subAdvice.UpdatedTime = time.Now().Unix()
  3434. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3435. }
  3436. service.CreateSubDoctorAdvice(subAdivice)
  3437. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3438. c.ServeSuccessJSON(map[string]interface{}{
  3439. "msg": "ok",
  3440. "advice": advice,
  3441. "subAdvice": subAdivices,
  3442. })
  3443. return
  3444. }
  3445. func (c *DialysisApiController) EditDoctorAdvice() {
  3446. patient, _ := c.GetInt64("patient", 0)
  3447. id, _ := c.GetInt64("id", 0)
  3448. parent_id, _ := c.GetInt64("parent_id", 0)
  3449. execution_time := c.GetString("execution_time")
  3450. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3451. // checker, _ := c.GetInt64("checker", 0)
  3452. if id <= 0 || patient <= 0 {
  3453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3454. return
  3455. }
  3456. adminUserInfo := c.GetAdminUserInfo()
  3457. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3458. if advice.ID == 0 || advice.PatientId != patient {
  3459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3460. return
  3461. }
  3462. if len(execution_time) <= 0 {
  3463. utils.ErrorLog("execution_time")
  3464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3465. return
  3466. }
  3467. execution_staff := adminUserInfo.AdminUser.Id
  3468. checker := adminUserInfo.AdminUser.Id
  3469. timeLayout2 := "2006-01-02 15:04"
  3470. loc, _ := time.LoadLocation("Local")
  3471. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3472. if errs != nil {
  3473. utils.ErrorLog(errs.Error())
  3474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3475. return
  3476. }
  3477. advices := models.DoctorAdvice{
  3478. ExecutionStaff: execution_staff,
  3479. ExecutionTime: theTime.Unix(),
  3480. Checker: checker,
  3481. UpdatedTime: time.Now().Unix(),
  3482. }
  3483. var err error
  3484. if parent_id > 0 {
  3485. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3486. } else {
  3487. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3488. }
  3489. if err != nil {
  3490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3491. return
  3492. }
  3493. c.ServeSuccessJSON(map[string]interface{}{
  3494. "msg": "ok",
  3495. "advice": advice,
  3496. })
  3497. return
  3498. }
  3499. func (c *DialysisApiController) GetDoctorAdvice() {
  3500. patient, _ := c.GetInt64("patient_id", 0)
  3501. parent_id, _ := c.GetInt64("parent_id", 0)
  3502. adviceId, _ := c.GetInt64("id", 0)
  3503. if patient <= 0 {
  3504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3505. return
  3506. }
  3507. dminUserInfo := c.GetAdminUserInfo()
  3508. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3509. if patientInfo.ID == 0 {
  3510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3511. return
  3512. }
  3513. var subAdvice []*models.DoctorAdvice
  3514. var advice models.DoctorAdvice
  3515. if parent_id > 0 {
  3516. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3517. if advice.ID == 0 || advice.PatientId != patient {
  3518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3519. return
  3520. }
  3521. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3522. } else {
  3523. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3524. if advice.ID == 0 || advice.PatientId != patient {
  3525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3526. return
  3527. }
  3528. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3529. }
  3530. c.ServeSuccessJSON(map[string]interface{}{
  3531. "msg": "ok",
  3532. "advice": advice,
  3533. "subAdvice": subAdvice,
  3534. })
  3535. }
  3536. func (this *DialysisApiController) DelMonitor() {
  3537. recordID, _ := this.GetInt64("record_id")
  3538. patientID, _ := this.GetInt64("patient_id")
  3539. if recordID <= 0 || patientID <= 0 {
  3540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3541. return
  3542. }
  3543. adminInfo := this.GetAdminUserInfo()
  3544. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3545. if getPatientErr != nil {
  3546. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3547. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3548. return
  3549. } else if patient == nil {
  3550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3551. return
  3552. }
  3553. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3554. if getMonitorErr != nil {
  3555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3556. return
  3557. }
  3558. if monitor != nil {
  3559. if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3560. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3561. if getPermissionErr != nil {
  3562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3563. return
  3564. } else if headNursePermission == nil {
  3565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3566. return
  3567. }
  3568. }
  3569. }
  3570. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3571. if err != nil {
  3572. this.ErrorLog("删除透析监测记录失败:%v", err)
  3573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3574. return
  3575. }
  3576. this.ServeSuccessJSON(map[string]interface{}{
  3577. "record_id": monitor.ID,
  3578. })
  3579. }
  3580. func (c *DialysisApiController) CreateMonitor() {
  3581. patient, _ := c.GetInt64("id", 0)
  3582. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3583. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3584. operate_time, _ := c.GetInt64("operate_time", 0)
  3585. // monitoring_time := c.GetString("monitoring_time")
  3586. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3587. breathing_rated, _ := c.GetFloat("breathing_rated", 0)
  3588. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3589. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3590. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3591. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3592. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3593. venous_pressure_unit := c.GetString("venous_pressure_unit")
  3594. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3595. transmembrane_pressure_unit := c.GetString("transmembrane_pressure_unit")
  3596. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3597. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3598. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3599. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3600. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3601. temperature, _ := c.GetFloat("temperature", 0)
  3602. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3603. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3604. conductivity, _ := c.GetFloat("conductivity", 0)
  3605. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3606. ktv, _ := c.GetFloat("ktv", 0)
  3607. symptom := c.GetString("symptom")
  3608. dispose := c.GetString("dispose")
  3609. result := c.GetString("results")
  3610. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3611. monitoring_date = monitoring_date / 1000
  3612. // operate_time = operate_time / 1000
  3613. if patient <= 0 {
  3614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3615. return
  3616. }
  3617. adminUserInfo := c.GetAdminUserInfo()
  3618. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3619. if patientInfo.ID == 0 {
  3620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3621. return
  3622. }
  3623. monitorRecord := models.MonitoringRecord{
  3624. PatientId: patient,
  3625. MonitoringDate: monitoring_date,
  3626. DialysisOrderId: dialysis_order_id,
  3627. OperateTime: operate_time,
  3628. // MonitoringTime: monitoring_time,
  3629. PulseFrequency: pulse_frequency,
  3630. BreathingRate: breathing_rated,
  3631. SystolicBloodPressure: systolic_blood_pressure,
  3632. DiastolicBloodPressure: diastolic_blood_pressure,
  3633. BloodPressureType: blood_pressure_type,
  3634. BloodFlowVolume: blood_flow_volume,
  3635. VenousPressure: venous_pressure,
  3636. VenousPressureUnit: venous_pressure_unit,
  3637. TransmembranePressure: transmembrane_pressure,
  3638. TransmembranePressureUnit: transmembrane_pressure_unit,
  3639. UltrafiltrationRate: ultrafiltration_rate,
  3640. UltrafiltrationVolume: ultrafiltration_volume,
  3641. SodiumConcentration: sodium_concentration,
  3642. ArterialPressure: arterial_pressure,
  3643. DialysateTemperature: dialysate_temperature,
  3644. Temperature: temperature,
  3645. ReplacementRate: replacement_rate,
  3646. DisplacementQuantity: displacement_quantity,
  3647. Ktv: ktv,
  3648. Symptom: symptom,
  3649. Dispose: dispose,
  3650. Result: result,
  3651. MonitoringNurse: monitoring_nurse,
  3652. Status: 1,
  3653. CreatedTime: time.Now().Unix(),
  3654. UpdatedTime: time.Now().Unix(),
  3655. UserOrgId: adminUserInfo.CurrentOrgId,
  3656. Conductivity: conductivity,
  3657. DisplacementFlowQuantity: displacement_flow_quantity,
  3658. }
  3659. err := service.CreateMonitor(&monitorRecord)
  3660. if err != nil {
  3661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3662. return
  3663. }
  3664. c.ServeSuccessJSON(map[string]interface{}{
  3665. "msg": "ok",
  3666. "monitor": monitorRecord,
  3667. })
  3668. return
  3669. }
  3670. // 已弃用
  3671. // func (c *DialysisApiController) CreateRecordData() {
  3672. // patient, _ := c.GetInt64("id", 0)
  3673. // status, _ := c.GetInt64("status", 0)
  3674. // now := time.Now()
  3675. // year, month, day := now.Date()
  3676. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3677. // todayTimeStamp := today_time.Unix()
  3678. // if patient <= 0 {
  3679. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3680. // return
  3681. // }
  3682. // adminUserInfo := c.GetAdminUserInfo()
  3683. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3684. // if patientInfo.ID == 0 {
  3685. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3686. // return
  3687. // }
  3688. // record := &models.DialysisOrder{
  3689. // DialysisDate: todayTimeStamp,
  3690. // UserOrgId: adminUserInfo.CurrentOrgId,
  3691. // PatientId: patient,
  3692. // Stage: status,
  3693. // Status: 1,
  3694. // CreatedTime: time.Now().Unix(),
  3695. // UpdatedTime: time.Now().Unix(),
  3696. // }
  3697. // if status == 1 {
  3698. // //创建透析记录
  3699. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3700. // if err == nil {
  3701. // c.ServeSuccessJSON(map[string]interface{}{
  3702. // "dialysisOrder": record,
  3703. // })
  3704. // } else {
  3705. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3706. // }
  3707. // } else {
  3708. // record_id, _ := c.GetInt64("record_id", 0)
  3709. // //修改透析记录状态
  3710. // errs := service.ModifyDialysisRecord(record_id)
  3711. // //结束时候透析次数加1
  3712. // service.UpdateSolutionByPatientId(patient)
  3713. // if errs == nil {
  3714. // c.ServeSuccessJSON(map[string]interface{}{
  3715. // "dialysisOrder": record,
  3716. // })
  3717. // } else {
  3718. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3719. // }
  3720. // }
  3721. // }
  3722. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3723. dataBody := make(map[string]interface{}, 0)
  3724. err := json.Unmarshal(data, &dataBody)
  3725. if err != nil {
  3726. utils.ErrorLog(err.Error())
  3727. code = enums.ErrorCodeParamWrong
  3728. return
  3729. }
  3730. timeLayout := "2006-01-02 "
  3731. timeLayout2 := "2006-01-02 15:04"
  3732. loc, _ := time.LoadLocation("Local")
  3733. if action == "create" {
  3734. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3735. utils.ErrorLog("advice_type")
  3736. code = enums.ErrorCodeParamWrong
  3737. return
  3738. }
  3739. adviceType := int64(dataBody["advice_type"].(float64))
  3740. if adviceType != 1 && adviceType != 2 {
  3741. utils.ErrorLog("advice_type != 1&&2")
  3742. code = enums.ErrorCodeParamWrong
  3743. return
  3744. }
  3745. advice.AdviceType = adviceType
  3746. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3747. utils.ErrorLog("advice_date")
  3748. code = enums.ErrorCodeParamWrong
  3749. return
  3750. }
  3751. adviceDate, _ := dataBody["advice_date"].(string)
  3752. if len(adviceDate) == 0 {
  3753. utils.ErrorLog("len(adviceDate) == 0")
  3754. code = enums.ErrorCodeParamWrong
  3755. return
  3756. }
  3757. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3758. if err != nil {
  3759. utils.ErrorLog(err.Error())
  3760. code = enums.ErrorCodeParamWrong
  3761. return
  3762. }
  3763. advice.AdviceDate = theTime.Unix()
  3764. }
  3765. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3766. utils.ErrorLog("start_time")
  3767. code = enums.ErrorCodeParamWrong
  3768. return
  3769. }
  3770. startDate, _ := dataBody["start_time"].(string)
  3771. if len(startDate) == 0 {
  3772. utils.ErrorLog("len(startDate) == 0")
  3773. code = enums.ErrorCodeParamWrong
  3774. return
  3775. }
  3776. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  3777. if err != nil {
  3778. utils.ErrorLog(err.Error())
  3779. code = enums.ErrorCodeParamWrong
  3780. return
  3781. }
  3782. advice.StartTime = theTime.Unix()
  3783. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3784. utils.ErrorLog("advice_name")
  3785. code = enums.ErrorCodeParamWrong
  3786. return
  3787. }
  3788. adviceName, _ := dataBody["advice_name"].(string)
  3789. if len(adviceName) == 0 {
  3790. utils.ErrorLog("len(advice_name) == 0")
  3791. code = enums.ErrorCodeParamWrong
  3792. return
  3793. }
  3794. advice.AdviceName = adviceName
  3795. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3796. utils.ErrorLog("delivery_way")
  3797. code = enums.ErrorCodeParamWrong
  3798. return
  3799. }
  3800. deliveryWay, _ := dataBody["delivery_way"].(string)
  3801. if len(deliveryWay) == 0 {
  3802. utils.ErrorLog("len(deliveryWay) == 0")
  3803. code = enums.ErrorCodeParamWrong
  3804. return
  3805. }
  3806. advice.DeliveryWay = deliveryWay
  3807. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3808. utils.ErrorLog("execution_frequency")
  3809. code = enums.ErrorCodeParamWrong
  3810. return
  3811. }
  3812. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3813. if len(execution_frequency) == 0 {
  3814. utils.ErrorLog("len(execution_frequency) == 0")
  3815. code = enums.ErrorCodeParamWrong
  3816. return
  3817. }
  3818. advice.ExecutionFrequency = execution_frequency
  3819. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3820. adviceDsc, _ := dataBody["advice_desc"].(string)
  3821. advice.AdviceDesc = adviceDsc
  3822. }
  3823. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3824. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3825. advice.DrugSpecUnit = drugSpecUnit
  3826. }
  3827. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3828. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3829. advice.SingleDose = singleDose
  3830. }
  3831. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3832. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3833. advice.SingleDoseUnit = singleDoseUnit
  3834. }
  3835. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3836. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3837. advice.PrescribingNumber = prescribingNumber
  3838. }
  3839. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3840. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3841. advice.PrescribingNumberUnit = prescribingNumberUnit
  3842. }
  3843. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3844. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3845. if len(thisContagions) > 0 {
  3846. for _, item := range thisContagions {
  3847. items := item.(map[string]interface{})
  3848. advice_name, _ := items["advice_name"].(string)
  3849. advice_desc, _ := items["advice_desc"].(string)
  3850. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3851. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3852. single_dose_unit, _ := items["single_dose_unit"].(string)
  3853. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3854. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3855. advice := &models.DoctorAdvice{
  3856. AdviceName: advice_name,
  3857. AdviceDesc: advice_desc,
  3858. SingleDose: single_dose,
  3859. SingleDoseUnit: single_dose_unit,
  3860. DrugSpecUnit: drug_spec_unit,
  3861. PrescribingNumber: prescribing_number,
  3862. PrescribingNumberUnit: prescribing_number_unit,
  3863. }
  3864. subAdvice = append(subAdvice, advice)
  3865. }
  3866. }
  3867. }
  3868. return
  3869. }
  3870. func (c *DialysisApiController) GetDialysisOrder() {
  3871. xtno := c.GetString("xtno")
  3872. xtdate := c.GetString("xtdate")
  3873. timeLayout := "2006-01-02"
  3874. loc, _ := time.LoadLocation("Local")
  3875. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3876. if err != nil {
  3877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3878. return
  3879. }
  3880. xttime := theTime.Unix()
  3881. operatorIDs := make([]int64, 0)
  3882. adminUserInfo := c.GetAdminUserInfo()
  3883. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3884. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  3885. //透析单
  3886. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3887. if dialysisOrder != nil {
  3888. if dialysisOrder.FinishNurse > 0 {
  3889. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3890. }
  3891. if dialysisOrder.StartNurse > 0 {
  3892. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3893. }
  3894. }
  3895. //透前评估
  3896. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3897. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3898. //透后评估
  3899. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3900. if AssessmentAfterDislysis.Modifier > 0 {
  3901. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3902. }
  3903. //透析处方
  3904. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3905. if dialysisPrescription.PrescriptionDoctor > 0 {
  3906. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3907. }
  3908. //获取病人的透析模式
  3909. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3910. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3911. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3912. //fmt.Print("nurse------------", err)
  3913. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3914. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3915. //获取透析处方
  3916. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3917. //获取临时医嘱
  3918. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3919. //获取医嘱内容
  3920. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3921. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3922. //fmt.Print("err---------------------------------",err)
  3923. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3924. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3925. //获取上次的透后体重
  3926. assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3927. //获取透析次数
  3928. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3929. if len(DoctorAdvice) > 0 {
  3930. for _, item := range DoctorAdvice {
  3931. if item.AdviceDoctor > 0 {
  3932. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3933. }
  3934. if item.ExecutionStaff > 0 {
  3935. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3936. }
  3937. if item.Checker > 0 {
  3938. operatorIDs = append(operatorIDs, item.Checker)
  3939. }
  3940. }
  3941. }
  3942. //透析监测
  3943. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3944. //透析检测
  3945. monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3946. //透析小结
  3947. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3948. //接诊评估
  3949. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3950. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3951. //相关操作对应的操作人
  3952. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3953. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3954. c.ServeSuccessJSON(map[string]interface{}{
  3955. "xtdate": xtdate,
  3956. "users": adminUser,
  3957. "patientInfo": patientInfo,
  3958. "PredialysisEvaluation": PredialysisEvaluation,
  3959. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3960. "dialysisPrescription": dialysisPrescription,
  3961. "advices": DoctorAdvice,
  3962. "monitors": Record,
  3963. "summary": TreatmentSummary,
  3964. "receiverTreatmentAccess": receiverTreatmentAccess,
  3965. "dialysisOrder": dialysisOrder,
  3966. "operators": operators,
  3967. "org_template_info": templateInfo,
  3968. "check": check,
  3969. "schedule": schedule,
  3970. "dialysisway": dialysisway,
  3971. "order": order,
  3972. "doctorAdvice": doctorAdvice,
  3973. "doctor": doctor,
  3974. "nurse": nurse,
  3975. "doctorAdevieInfo": doctorAdevieInfo,
  3976. "total": total,
  3977. "startNuse": startNuse,
  3978. "DoctorName": DoctorName,
  3979. "monitor": monitor,
  3980. "assessmentAfterDislysis": assessmentAfterDislysis,
  3981. "predialysName": predialysName,
  3982. "FinishNuse": FinishNuse,
  3983. })
  3984. }
  3985. //
  3986. func (c *DialysisApiController) GetLongAdvice() {
  3987. patient_id, _ := c.GetInt64("patient_id")
  3988. adminUserInfo := c.GetAdminUserInfo()
  3989. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3990. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3991. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3992. c.ServeSuccessJSON(map[string]interface{}{
  3993. "status": "1",
  3994. })
  3995. return
  3996. } else { //开启推送提醒
  3997. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3998. var advice_three []*models.DoctorAdvice
  3999. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4000. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id)
  4001. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id)
  4002. for _, advice := range advices {
  4003. if advice.FrequencyType == 3 {
  4004. t := time.Now()
  4005. week := int(t.Weekday())
  4006. switch week {
  4007. case 1:
  4008. if strings.Index(advice.WeekDay, "周一") == -1 {
  4009. advice_three = append(advice_three, advice)
  4010. }
  4011. break
  4012. case 2:
  4013. if strings.Index(advice.WeekDay, "周二") == -1 {
  4014. advice_three = append(advice_three, advice)
  4015. }
  4016. break
  4017. case 3:
  4018. if strings.Index(advice.WeekDay, "周三") == -1 {
  4019. advice_three = append(advice_three, advice)
  4020. }
  4021. break
  4022. case 4:
  4023. if strings.Index(advice.WeekDay, "周四") == -1 {
  4024. advice_three = append(advice_three, advice)
  4025. }
  4026. break
  4027. case 5:
  4028. if strings.Index(advice.WeekDay, "周五") == -1 {
  4029. advice_three = append(advice_three, advice)
  4030. }
  4031. break
  4032. case 6:
  4033. if strings.Index(advice.WeekDay, "周六") == -1 {
  4034. advice_three = append(advice_three, advice)
  4035. }
  4036. break
  4037. case 0:
  4038. if strings.Index(advice.WeekDay, "周日") == -1 {
  4039. advice_three = append(advice_three, advice)
  4040. }
  4041. break
  4042. }
  4043. }
  4044. }
  4045. for _, advice := range advices_two {
  4046. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4047. now := p.Unix()
  4048. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4049. dayStr2 := "-" + dayStr
  4050. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4051. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4052. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4053. for _, ad := range advices {
  4054. advice_three = append(advice_three, ad)
  4055. }
  4056. }
  4057. if err == nil {
  4058. c.ServeSuccessJSON(map[string]interface{}{
  4059. "status": "2",
  4060. "advices": advices,
  4061. "advices_two": RemoveRepeatedElement(advice_three),
  4062. "is_open_remind": config.IsOpenRemind,
  4063. })
  4064. }
  4065. }
  4066. }
  4067. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4068. newArr = make([]*models.DoctorAdvice, 0)
  4069. for i := 0; i < len(arr); i++ {
  4070. repeat := false
  4071. for j := i + 1; j < len(arr); j++ {
  4072. if arr[i].ID == arr[j].ID {
  4073. repeat = true
  4074. break
  4075. }
  4076. }
  4077. if !repeat {
  4078. newArr = append(newArr, arr[i])
  4079. }
  4080. }
  4081. return
  4082. }
  4083. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4084. patient, _ := c.GetInt64("id", 0)
  4085. groupNo, _ := c.GetInt64("groupno", 0)
  4086. if patient <= 0 {
  4087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4088. return
  4089. }
  4090. adminUserInfo := c.GetAdminUserInfo()
  4091. dataBody := make(map[string]interface{}, 0)
  4092. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4093. if err != nil {
  4094. utils.ErrorLog(err.Error())
  4095. return
  4096. }
  4097. utils.ErrorLog("%v", dataBody)
  4098. timeLayout := "2006-01-02 15:04"
  4099. loc, _ := time.LoadLocation("Local")
  4100. timeLayout2 := "2006-01-02"
  4101. loc2, _ := time.LoadLocation("Local")
  4102. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4103. utils.ErrorLog("advice_type")
  4104. return
  4105. }
  4106. adviceType := int64(2)
  4107. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4108. utils.ErrorLog("advice_date")
  4109. return
  4110. }
  4111. adviceDate, _ := dataBody["advice_date"].(string)
  4112. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4113. AdviceDate := theTime.Unix()
  4114. RecordDate := theTime.Unix()
  4115. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4116. utils.ErrorLog("start_time")
  4117. return
  4118. }
  4119. startTime, _ := dataBody["start_time"].(string)
  4120. if len(startTime) == 0 {
  4121. utils.ErrorLog("len(start_time) == 0")
  4122. return
  4123. }
  4124. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4125. if err != nil {
  4126. utils.ErrorLog(err.Error())
  4127. return
  4128. }
  4129. StartTime := theTime.Unix()
  4130. Remark := ""
  4131. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4132. remark, _ := dataBody["remark"].(string)
  4133. Remark = remark
  4134. }
  4135. var advices []*models.GroupAdvice
  4136. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4137. utils.ErrorLog("advices")
  4138. return
  4139. }
  4140. adviceNames := dataBody["advices"].([]interface{})
  4141. for _, adviceNameMap := range adviceNames {
  4142. adviceNameM := adviceNameMap.(map[string]interface{})
  4143. var advice models.GroupAdvice
  4144. advice.Remark = Remark
  4145. advice.AdviceType = adviceType
  4146. advice.StartTime = StartTime
  4147. advice.AdviceDate = AdviceDate
  4148. advice.RecordDate = RecordDate
  4149. advice.Status = 1
  4150. advice.CreatedTime = time.Now().Unix()
  4151. advice.UpdatedTime = time.Now().Unix()
  4152. advice.StopState = 2
  4153. advice.ExecutionState = 2
  4154. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4155. advice.PatientId = patient
  4156. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4157. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4158. utils.ErrorLog("advice_name")
  4159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4160. return
  4161. }
  4162. adviceName, _ := adviceNameM["advice_name"].(string)
  4163. if len(adviceName) == 0 {
  4164. utils.ErrorLog("len(advice_name) == 0")
  4165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4166. return
  4167. }
  4168. advice.AdviceName = adviceName
  4169. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4170. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4171. advice.DrugSpec = drugSpec
  4172. }
  4173. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4174. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4175. advice.AdviceDesc = adviceDesc
  4176. }
  4177. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4178. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4179. advice.DrugSpecUnit = drugSpecUnit
  4180. }
  4181. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4182. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4183. // advice.SingleDose = singleDose
  4184. //}
  4185. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4186. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4187. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4188. }
  4189. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4190. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4191. advice.SingleDoseUnit = singleDoseUnit
  4192. }
  4193. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4194. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4195. // advice.PrescribingNumber = prescribingNumber
  4196. //}
  4197. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4198. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4199. }
  4200. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4201. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4202. advice.PrescribingNumberUnit = prescribingNumberUnit
  4203. }
  4204. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4205. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4206. advice.DeliveryWay = deliveryWay
  4207. }
  4208. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4209. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4210. advice.ExecutionFrequency = executionFrequency
  4211. }
  4212. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4213. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4214. advice.FrequencyType = frequency_type
  4215. }
  4216. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4217. day_count := int64(adviceNameM["day_count"].(float64))
  4218. advice.DayCount = day_count
  4219. }
  4220. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4221. week_day, _ := adviceNameM["week_day"].(string)
  4222. advice.WeekDay = week_day
  4223. }
  4224. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4225. template_id, _ := adviceNameM["template_id"].(string)
  4226. advice.TemplateId = template_id
  4227. }
  4228. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4229. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4230. advice.ExecutionFrequency = executionFrequency
  4231. }
  4232. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4233. children := adviceNameM["child"].([]interface{})
  4234. if len(children) > 0 {
  4235. for _, childrenMap := range children {
  4236. childMap := childrenMap.(map[string]interface{})
  4237. var child models.GroupAdvice
  4238. child.Remark = Remark
  4239. child.AdviceType = adviceType
  4240. child.StartTime = StartTime
  4241. child.AdviceDate = AdviceDate
  4242. child.RecordDate = RecordDate
  4243. child.Status = 1
  4244. child.CreatedTime = time.Now().Unix()
  4245. child.UpdatedTime = time.Now().Unix()
  4246. child.StopState = 2
  4247. child.ExecutionState = 2
  4248. child.UserOrgId = adminUserInfo.CurrentOrgId
  4249. child.PatientId = patient
  4250. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4251. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4252. utils.ErrorLog("child advice_name")
  4253. return
  4254. }
  4255. childAdviceName, _ := childMap["advice_name"].(string)
  4256. if len(childAdviceName) == 0 {
  4257. utils.ErrorLog("len(child advice_name) == 0")
  4258. return
  4259. }
  4260. child.AdviceName = childAdviceName
  4261. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4262. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4263. child.AdviceDesc = childAdviceDesc
  4264. }
  4265. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4266. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4267. child.DrugSpec = childDrugSpec
  4268. }
  4269. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4270. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4271. child.DrugSpecUnit = childDrugSpecUnit
  4272. }
  4273. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4274. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4275. child.SingleDose = childSingleDose
  4276. }
  4277. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4278. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4279. child.SingleDoseUnit = childSingleDoseUnit
  4280. }
  4281. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4282. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4283. child.PrescribingNumber = childPrescribingNumber
  4284. }
  4285. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4286. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4287. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4288. }
  4289. child.DeliveryWay = advice.DeliveryWay
  4290. child.ExecutionFrequency = advice.ExecutionFrequency
  4291. advice.Children = append(advice.Children, &child)
  4292. }
  4293. }
  4294. }
  4295. advices = append(advices, &advice)
  4296. }
  4297. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4298. if err != nil {
  4299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4300. return
  4301. }
  4302. c.ServeSuccessJSON(map[string]interface{}{
  4303. "msg": "ok",
  4304. "advices": list,
  4305. })
  4306. return
  4307. }
  4308. func (c *DialysisApiController) GetSolution() {
  4309. patient_id, _ := c.GetInt64("patient_id")
  4310. mode_id, _ := c.GetInt64("mode_id")
  4311. adminUserInfo := c.GetAdminUserInfo()
  4312. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4313. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4314. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, mode_id)
  4315. if err != nil {
  4316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4317. return
  4318. }
  4319. c.ServeSuccessJSON(map[string]interface{}{
  4320. "solution": solution,
  4321. "prescription": prescription,
  4322. "system_prescription": system_prescription,
  4323. })
  4324. }
  4325. func (c *DialysisApiController) GetSchedule() {
  4326. schedual_type, _ := c.GetInt64("schedual_type")
  4327. adminUserInfo := c.GetAdminUserInfo()
  4328. timeLayout := "2006-01-02 15:04:05"
  4329. date := time.Now().Format("2006-01-02") + " 00:00:00"
  4330. loc, _ := time.LoadLocation("Local")
  4331. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  4332. scheduleTime := theStartTime.Unix()
  4333. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  4334. c.ServeSuccessJSON(map[string]interface{}{
  4335. "number": deviceNumber,
  4336. })
  4337. }
  4338. func (this *DialysisApiController) GetTodayMonitor() {
  4339. thisTime := time.Now()
  4340. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4341. timeLayout := "2006-01-02 15:04:05"
  4342. loc, _ := time.LoadLocation("Local")
  4343. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4344. theAssessmentDateTime := theStartTime.Unix()
  4345. patientID, _ := this.GetInt64("patient_id")
  4346. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4347. adminInfo := this.GetAdminUserInfo()
  4348. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4349. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4350. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  4351. var ultrafiltration_rate float64
  4352. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4353. if prescription.ID > 0 {
  4354. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4355. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4356. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  4357. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4358. }
  4359. // 只针对方济医院
  4360. if template.TemplateId == 1 {
  4361. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4362. ultrafiltration_rate = value
  4363. }
  4364. }
  4365. }
  4366. record.UltrafiltrationRate = ultrafiltration_rate
  4367. record.UltrafiltrationVolume = 0
  4368. if template.TemplateId == 1 {
  4369. if ultrafiltration_rate > 0 {
  4370. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4371. record.UltrafiltrationVolume = value
  4372. }
  4373. }
  4374. if template.TemplateId == 6 {
  4375. if ultrafiltration_rate > 0 {
  4376. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4377. record.UltrafiltrationVolume = ultrafiltration_volume
  4378. }
  4379. }
  4380. this.ServeSuccessJSON(map[string]interface{}{
  4381. "monitor": record,
  4382. })
  4383. }
  4384. func (c *DialysisApiController) UploadDryWeight() {
  4385. patient_id, _ := c.GetInt64("id")
  4386. dry_weight, _ := c.GetFloat("dry_weight")
  4387. doctor_id, _ := c.GetInt64("doctor_id")
  4388. remark := c.GetString("remark")
  4389. adminUserInfo := c.GetAdminUserInfo()
  4390. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  4391. fmt.Println(err)
  4392. if err == gorm.ErrRecordNotFound {
  4393. dryWeight := &models.SgjPatientDryweight{
  4394. PatientId: patient_id,
  4395. DryWeight: dry_weight,
  4396. Remakes: remark,
  4397. Ctime: time.Now().Unix(),
  4398. Mtime: time.Now().Unix(),
  4399. Creator: doctor_id,
  4400. Status: 1,
  4401. UserOrgId: adminUserInfo.CurrentOrgId,
  4402. AdjustedValue: "/",
  4403. UserId: adminUserInfo.AdminUser.Id,
  4404. }
  4405. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4406. if createErr == nil {
  4407. c.ServeSuccessJSON(map[string]interface{}{
  4408. "msg": "提交成功",
  4409. "weight": dryWeight,
  4410. })
  4411. }
  4412. } else {
  4413. dryWeight := &models.SgjPatientDryweight{
  4414. PatientId: patient_id,
  4415. DryWeight: dry_weight,
  4416. Remakes: remark,
  4417. Ctime: time.Now().Unix(),
  4418. Mtime: time.Now().Unix(),
  4419. Creator: doctor_id,
  4420. Status: 1,
  4421. UserOrgId: adminUserInfo.CurrentOrgId,
  4422. AdjustedValue: "/",
  4423. UserId: adminUserInfo.AdminUser.Id,
  4424. }
  4425. var value float64
  4426. value = dry_weight - weightAdjust.DryWeight
  4427. fmt.Println(value)
  4428. if value < 0 {
  4429. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4430. } else if value == 0 {
  4431. dryWeight.AdjustedValue = "/"
  4432. } else if value > 0 {
  4433. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4434. }
  4435. fmt.Println(value)
  4436. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4437. if createErr == nil {
  4438. c.ServeSuccessJSON(map[string]interface{}{
  4439. "msg": "提交成功",
  4440. "weight": dryWeight,
  4441. })
  4442. }
  4443. }
  4444. }