dialysis_api_controller.go 219KB

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