dialysis_api_controller.go 223KB

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