dialysis_api_controller.go 223KB

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