dialysis_api_controller.go 226KB

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