12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934 |
- package controllers
-
- import (
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "math"
- "reflect"
- "strconv"
- "strings"
-
- //"strings"
- "time"
-
- "XT_New/enums"
-
- "github.com/astaxie/beego"
- )
-
- type DialysisApiController struct {
- BaseAuthAPIController
- }
-
- func DialysisApiRegistRouters() {
- beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
- beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
- beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
- beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
- beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
- beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
- beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
- beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
- beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
- beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
- beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
- beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
- beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
- beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
- beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
- beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
- beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
-
- beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
- beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
-
- beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
-
- beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
-
- beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
-
- beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
-
- }
-
- func (c *DialysisApiController) PostPrescription() {
- patient, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mode_id, _ := c.GetInt64("mode_id", 0)
- dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
- perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- dewater_amount, _ := c.GetFloat("dewater_amount", 0)
- displace_liqui, _ := c.GetFloat("displace_liqui", 0)
- replacement_way, _ := c.GetInt64("replacement_way", 0)
- anticoagulant, _ := c.GetInt64("anticoagulant", 0)
- anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
- anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
- anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
- anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
- anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
- kalium, _ := c.GetFloat("kalium", 0)
- sodium, _ := c.GetFloat("sodium", 0)
- replacement_total, _ := c.GetFloat("replacement_total", 0)
-
- calcium, _ := c.GetFloat("calcium", 0)
- bicarbonate, _ := c.GetFloat("bicarbonate", 0)
- glucose, _ := c.GetFloat("glucose", 0)
- // dry_weight, _ := c.GetFloat("dry_weight", 0)
- dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
- remark := c.GetString("remark")
- dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
- dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
- targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
- dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
- body_fluid, _ := c.GetInt64("body_fluid", 0)
- special_medicine, _ := c.GetInt64("special_medicine", 0)
- special_medicine_other := c.GetString("special_medicine_other")
- displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
- displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
- blood_access, _ := c.GetInt64("blood_access", 0)
- ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
- body_fluid_other := c.GetString("body_fluid_other")
- target_ktv, _ := c.GetFloat("target_ktv", 0)
-
- niprocart, _ := c.GetInt64("niprocart", 0)
- jms, _ := c.GetInt64("jms", 0)
- fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
- fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
- hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
- dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
- filtryzer, _ := c.GetInt64("filtryzer", 0)
-
- dialyzers, _ := c.GetInt64("dialyzers", 0)
- injector, _ := c.GetInt64("injector", 0)
- bloodlines, _ := c.GetInt64("bloodlines", 0)
- tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
- safe_package, _ := c.GetInt64("package", 0)
- a_liquid, _ := c.GetInt64("a_liquid", 0)
-
- var prescription_doctor int64
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
-
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor = appRole.AdminUserId
- } else {
- prescription_doctor = 0
- }
-
- prescription := models.DialysisPrescription{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: patient,
- RecordDate: recordDate.Unix(),
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- Dialyzer: dialyzer,
- ReplacementTotal: replacement_total,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- DewaterAmount: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- PrescriptionDoctor: prescription_doctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- TargetKtv: target_ktv,
- Niprocart: niprocart,
- Jms: jms,
- FistulaNeedleSet: fistula_needle_set,
- FistulaNeedleSet16: fistula_needle_set_16,
- Hemoperfusion: hemoperfusion,
- DialyserSterilised: dialyser_sterilised,
- Filtryzer: filtryzer,
- Dialyzers: dialyzers,
- Injector: injector,
- Bloodlines: bloodlines,
- TubingHemodialysis: tubing_hemodialysis,
- Package: safe_package,
- ALiquid: a_liquid,
- }
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- if dialysisPrescription.ID == 0 { //新增
- if mode_id > 0 {
- service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- }
-
- prescription.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleRecord(&prescription)
- if err == nil {
- updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
- if updateErr != nil {
- utils.ErrorLog("%v", updateErr)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": &prescription,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
-
- }
-
- } else { //修改
- if mode_id > 0 {
- service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- }
-
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
- //if template.TemplateId == 1 {
- // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
- if record.IsOpen == 1 {
- niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
- jms_good_type_id, _ := beego.AppConfig.Int64("jms")
- fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
- fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
- hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
- dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
- filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
-
- dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
- injector_good_type_id, _ := beego.AppConfig.Int64("injector")
- bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
- tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
- safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
- aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
-
- err, order := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
-
- if err == nil {
- if order.ID > 0 {
- if dialysisPrescription.Niprocart != niprocart {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
-
- //1.用上机透析日期查出当天的订单
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = niprocart
- warehouseOutInfo.GoodTypeId = niprocart_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: niprocart,
- GoodTypeId: niprocart_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: niprocart,
- GoodTypeId: niprocart_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, &newOut)
- }
- }
- }
- }
- }
- if dialysisPrescription.Jms != jms {
- //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = jms
- warehouseOutInfo.GoodTypeId = jms_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: jms,
- GoodTypeId: jms_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
-
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: jms,
- GoodTypeId: jms_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, &newOut)
- }
- }
-
- }
- }
- }
- if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = fistula_needle_set
- warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: fistula_needle_set,
- GoodTypeId: fistula_needle_set_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: fistula_needle_set,
- GoodTypeId: fistula_needle_set_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, &newOut)
-
- }
- }
- }
- }
-
- }
- if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = fistula_needle_set_16
- warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
-
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: fistula_needle_set_16,
- GoodTypeId: fistula_needle_set_16_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: fistula_needle_set_16,
- GoodTypeId: fistula_needle_set_16_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Hemoperfusion != hemoperfusion {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = hemoperfusion
- warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: hemoperfusion,
- GoodTypeId: hemoperfusion_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, warehouseOutInfo)
- }
- }
-
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: hemoperfusion,
- GoodTypeId: hemoperfusion_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
- _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.WarehouseOutId,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = dialyser_sterilised
- warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
-
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: dialyser_sterilised,
- GoodTypeId: dialyser_sterilised_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
- service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, warehouseOutInfo)
-
- }
- }
-
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: dialyser_sterilised,
- GoodTypeId: dialyser_sterilised_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Filtryzer != filtryzer {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = filtryzer
- warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: filtryzer,
- GoodTypeId: filtryzer_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: filtryzer,
- GoodTypeId: filtryzer_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Dialyzers != dialyzers {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = dialyzers
- warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: dialyzers,
- GoodTypeId: dialyzers_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: dialyzers,
- GoodTypeId: dialyzers_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Injector != injector {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = injector
- warehouseOutInfo.GoodTypeId = injector_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: injector,
- GoodTypeId: injector_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: injector,
- GoodTypeId: injector_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, &newOut)
- }
- }
-
- }
- }
-
- }
- if dialysisPrescription.Bloodlines != bloodlines {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = bloodlines
- warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: bloodlines,
- GoodTypeId: bloodlines_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: bloodlines,
- GoodTypeId: bloodlines_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = tubing_hemodialysis
- warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: tubing_hemodialysis,
- GoodTypeId: tubingHemodialysis_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: tubing_hemodialysis,
- GoodTypeId: tubingHemodialysis_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, &newOut)
-
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Package != safe_package {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = safe_package
- warehouseOutInfo.GoodTypeId = safe_package_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: safe_package,
- GoodTypeId: safe_package_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: safe_package,
- GoodTypeId: safe_package_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.ALiquid != a_liquid {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = a_liquid
- warehouseOutInfo.GoodTypeId = aliquid_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: a_liquid,
- GoodTypeId: aliquid_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: a_liquid,
- GoodTypeId: aliquid_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, &newOut)
- }
- }
- }
- }
-
- }
-
- }
- }
- }
-
- prescription.Creater = adminUserInfo.AdminUser.Id
- prescription.CreatedTime = dialysisPrescription.CreatedTime
- prescription.UpdatedTime = time.Now().Unix()
- prescription.Modifier = adminUserInfo.AdminUser.Id
- prescription.ID = dialysisPrescription.ID
-
- updateErr := service.UpDateDialysisPrescription(&prescription)
- if updateErr == nil {
- updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
- if updateErr != nil {
- utils.ErrorLog("%v", updateErr)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": &prescription,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
-
- }
-
- }
- func (c *DialysisApiController) PostSoulution() {
- patient, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mode_id, _ := c.GetInt64("mode_id", 0)
- dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- replacement_total, _ := c.GetFloat("replacement_total", 0)
- dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
-
- dewater_amount, _ := c.GetFloat("dewater_amount", 0)
- displace_liqui, _ := c.GetFloat("displace_liqui", 0)
- replacement_way, _ := c.GetInt64("replacement_way", 0)
- anticoagulant, _ := c.GetInt64("anticoagulant", 0)
- anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
- anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
- anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
- anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
- anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
- kalium, _ := c.GetFloat("kalium", 0)
- sodium, _ := c.GetFloat("sodium", 0)
- calcium, _ := c.GetFloat("calcium", 0)
- bicarbonate, _ := c.GetFloat("bicarbonate", 0)
- glucose, _ := c.GetFloat("glucose", 0)
- // dry_weight, _ := c.GetFloat("dry_weight", 0)
- dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
- remark := c.GetString("remark")
- dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
- dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
- targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
- dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
- body_fluid, _ := c.GetInt64("body_fluid", 0)
- special_medicine, _ := c.GetInt64("special_medicine", 0)
- special_medicine_other := c.GetString("special_medicine_other")
- displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
- displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
- blood_access, _ := c.GetInt64("blood_access", 0)
- ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
- body_fluid_other := c.GetString("body_fluid_other")
- target_ktv, _ := c.GetFloat("target_ktv", 0)
-
- niprocart, _ := c.GetInt64("niprocart", 0)
- jms, _ := c.GetInt64("jms", 0)
- fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
- fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
- hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
- dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
- filtryzer, _ := c.GetInt64("filtryzer", 0)
-
- dialyzers, _ := c.GetInt64("dialyzers", 0)
- injector, _ := c.GetInt64("injector", 0)
- bloodlines, _ := c.GetInt64("bloodlines", 0)
- tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
- safe_package, _ := c.GetInt64("package", 0)
- a_liquid, _ := c.GetInt64("a_liquid", 0)
-
- var prescription_doctor int64
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor = appRole.AdminUserId
- } else {
- prescription_doctor = 0
- }
-
- if mode_id > 0 {
- service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- }
-
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
- //
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- prescription := models.DialysisPrescription{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: patient,
- RecordDate: recordDate.Unix(),
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- Dialyzer: dialyzer,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- DewaterAmount: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- PrescriptionDoctor: prescription_doctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- ReplacementTotal: replacement_total,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- TargetKtv: target_ktv,
- Niprocart: niprocart,
- Jms: jms,
- FistulaNeedleSet: fistula_needle_set,
- FistulaNeedleSet16: fistula_needle_set_16,
- Hemoperfusion: hemoperfusion,
- DialyserSterilised: dialyser_sterilised,
- Filtryzer: filtryzer,
- Dialyzers: dialyzers,
- Injector: injector,
- Bloodlines: bloodlines,
- TubingHemodialysis: tubing_hemodialysis,
- Package: safe_package,
- ALiquid: a_liquid,
- }
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- if dialysisPrescription.ID == 0 { //新增
- prescription.Creater = adminUserInfo.AdminUser.Id
- } else { //修改
-
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
- //if template.TemplateId == 1 {
- // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
- if record.IsOpen == 1 {
- niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
- jms_good_type_id, _ := beego.AppConfig.Int64("jms")
- fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
- fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
- hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
- dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
- filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
-
- dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
- injector_good_type_id, _ := beego.AppConfig.Int64("injector")
- bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
- tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
- safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
- aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
-
- err, order := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
-
- if err == nil {
- if order.ID > 0 {
- if dialysisPrescription.Niprocart != niprocart {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
-
- //1.用上机透析日期查出当天的订单
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = niprocart
- warehouseOutInfo.GoodTypeId = niprocart_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: niprocart,
- GoodTypeId: niprocart_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: niprocart,
- GoodTypeId: niprocart_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, &newOut)
- }
- }
- }
- }
- }
- if dialysisPrescription.Jms != jms {
- //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = jms
- warehouseOutInfo.GoodTypeId = jms_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: jms,
- GoodTypeId: jms_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
-
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: jms,
- GoodTypeId: jms_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, &newOut)
- }
- }
-
- }
- }
- }
- if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = fistula_needle_set
- warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: fistula_needle_set,
- GoodTypeId: fistula_needle_set_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: fistula_needle_set,
- GoodTypeId: fistula_needle_set_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
- service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, &newOut)
-
- }
- }
- }
- }
-
- }
- if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = fistula_needle_set_16
- warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
-
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: fistula_needle_set_16,
- GoodTypeId: fistula_needle_set_16_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: fistula_needle_set_16,
- GoodTypeId: fistula_needle_set_16_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Hemoperfusion != hemoperfusion {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = hemoperfusion
- warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: hemoperfusion,
- GoodTypeId: hemoperfusion_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, warehouseOutInfo)
- }
- }
-
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: hemoperfusion,
- GoodTypeId: hemoperfusion_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
- _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
- //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.WarehouseOutId,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = dialyser_sterilised
- warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
-
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: dialyser_sterilised,
- GoodTypeId: dialyser_sterilised_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
- service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, warehouseOutInfo)
-
- }
- }
-
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: dialyser_sterilised,
- GoodTypeId: dialyser_sterilised_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
-
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Filtryzer != filtryzer {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = filtryzer
- warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: filtryzer,
- GoodTypeId: filtryzer_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: filtryzer,
- GoodTypeId: filtryzer_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Dialyzers != dialyzers {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = dialyzers
- warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: dialyzers,
- GoodTypeId: dialyzers_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: dialyzers,
- GoodTypeId: dialyzers_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Injector != injector {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = injector
- warehouseOutInfo.GoodTypeId = injector_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: injector,
- GoodTypeId: injector_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: injector,
- GoodTypeId: injector_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, &newOut)
- }
- }
-
- }
- }
-
- }
- if dialysisPrescription.Bloodlines != bloodlines {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = bloodlines
- warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: bloodlines,
- GoodTypeId: bloodlines_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: bloodlines,
- GoodTypeId: bloodlines_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = tubing_hemodialysis
- warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: tubing_hemodialysis,
- GoodTypeId: tubingHemodialysis_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, warehouseOutInfo)
-
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: tubing_hemodialysis,
- GoodTypeId: tubingHemodialysis_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, &newOut)
-
- }
- }
- }
- }
-
- }
- if dialysisPrescription.Package != safe_package {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = safe_package
- warehouseOutInfo.GoodTypeId = safe_package_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: safe_package,
- GoodTypeId: safe_package_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: safe_package,
- GoodTypeId: safe_package_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, &newOut)
- }
- }
- }
- }
-
- }
- if dialysisPrescription.ALiquid != a_liquid {
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
-
- //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
- service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
-
- //判断前端更改后的商品id的出库记录在数据库中是否存在
- err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
- if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
-
- Count: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 1,
- SysRecordTime: order.StartTime,
- }
- stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.CurrentOrgId)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.GoodId = a_liquid
- warehouseOutInfo.GoodTypeId = aliquid_good_type_id
- err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- if err == nil {
- //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
- user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: a_liquid,
- GoodTypeId: aliquid_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, warehouseOutInfo)
- }
- }
- }
- } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
- if newOut.ID > 0 {
- service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
- user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
- if err == gorm.ErrRecordNotFound {
- details := &models.AutomaticReduceDetail{
- WarehouseOutId: newOut.ID,
- WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
- PatientId: patient,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: order.StartTime,
- OrgId: adminUserInfo.CurrentOrgId,
- GoodId: a_liquid,
- GoodTypeId: aliquid_good_type_id,
- }
- service.AddSigleAutoReduceRecordInfo(details)
- } else if err == nil {
- if user.ID > 0 {
- service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, &newOut)
- }
- }
- }
- }
-
- }
-
- }
- }
- }
-
- prescription.Creater = adminUserInfo.AdminUser.Id
- prescription.CreatedTime = dialysisPrescription.CreatedTime
- prescription.UpdatedTime = time.Now().Unix()
- prescription.Modifier = adminUserInfo.AdminUser.Id
-
- prescription.ID = dialysisPrescription.ID
-
- }
-
- solution := models.DialysisSolution{
- RegistrarsId: adminUserInfo.AdminUser.Id,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Doctor: prescription_doctor,
- PatientId: patient,
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- Dewater: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- ReplacementTotal: replacement_total,
- TargetKtv: target_ktv,
- }
- err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": &solution,
- "prescription": &prescription,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
-
- }
- func (c *DialysisApiController) PostDouleCheck() {
-
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- checkTimeStr := c.GetString("check_time")
-
- dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
- dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
- vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
- pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
- dialysis_item_desc := c.GetString("dialysis_item_desc")
- dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
- vascular_access_desc := c.GetString("vascular_access_desc")
- pipeline_connection_desc := c.GetString("pipeline_connection_desc")
- collator, _ := c.GetInt64("collator", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(checkTimeStr) == 0 {
- checkTimeStr = time.Now().Format("2006-01-02 15:04")
- }
- checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
-
- doubleCheck := models.DoubleCheck{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: id,
- DialysisItemCheck: dialysis_item_check,
- DialysisParameterCheck: dialysis_parameter_check,
- VascularAccessVerification: vascular_access_verification,
- PipelineConnectionCheck: pipeline_connection_check,
- DialysisItemDesc: dialysis_item_desc,
- DialysisParameterDesc: dialysis_parameter_desc,
- VascularAccessDesc: vascular_access_desc,
- PipelineConnectionDesc: pipeline_connection_desc,
- Collator: collator,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- CheckDate: recordDate.Unix(),
- }
-
- _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- if check.ID == 0 { //新增
- doubleCheck.FirstCheckTime = checkDate.Unix()
-
- doubleCheck.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleDoubleCheck(&doubleCheck)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": doubleCheck,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
-
- }
- } else { //修改
- if check.Modifier != 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
-
- } else {
- if adminUserInfo.AdminUser.Id == check.Creater {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
- return
- }
- doubleCheck.FirstCheckTime = check.FirstCheckTime
- doubleCheck.CheckTime = checkDate.Unix()
- doubleCheck.Creater = check.Creater
- doubleCheck.CreatedTime = check.CreatedTime
- doubleCheck.UpdatedTime = time.Now().Unix()
- doubleCheck.Modifier = adminUserInfo.AdminUser.Id
- doubleCheck.ID = check.ID
- err := service.UpdateDoubleCheck(&doubleCheck)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": doubleCheck,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
-
- }
-
- }
-
- }
- func (c *DialysisApiController) PostReceiveTreatmentAsses() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- way, _ := c.GetInt64("way", 0)
- consciousness, _ := c.GetInt64("consciousness", 0)
- appetite, _ := c.GetInt64("appetite", 0)
- condition, _ := c.GetInt64("condition", 0)
- posture, _ := c.GetInt64("posture")
- score := c.GetString("score")
-
- sick_condition, _ := c.GetInt64("sick_condition", 0)
- danger_level, _ := c.GetInt64("danger_level", 0)
- intake, _ := c.GetInt64("intake", 0)
- nutrition, _ := c.GetInt64("nutrition", 0)
- psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
- psychological_assessment_other := c.GetString("psychological_assessment_other")
- sick_condition_other := c.GetString("sick_condition_other")
-
- precaution, _ := c.GetInt64("precaution", 0)
- precaution_other := c.GetString("precaution_other")
- psychological_other := c.GetString("psychological_other")
- admission_number := c.GetString("admission_number")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- receiveTreatmentAsses := models.ReceiveTreatmentAsses{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- Way: way,
- Consciousness: consciousness,
- Appetite: appetite,
- Condition: condition,
- SickCondition: sick_condition,
- DangerLevel: danger_level,
- Intake: intake,
- Nutrition: nutrition,
- PsychologicalAssessment: psychological_assessment,
- PsychologicalAssessmentOther: psychological_assessment_other,
- SickConditionOther: sick_condition_other,
- Posture: posture,
- CreatedTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- Status: 1,
- Score: score,
- Precaution: precaution,
- PrecautionOther: precaution_other,
- PsychologicalOther: psychological_other,
- AdmissionNumber: admission_number,
- }
-
- if receiveTreatment.ID == 0 { //新增
- receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- } else {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
-
- }
-
- } else { //修改
- //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- receiveTreatmentAsses.Creater = receiveTreatment.Creater
- receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
- receiveTreatmentAsses.UpdateTime = time.Now().Unix()
- receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
- receiveTreatmentAsses.ID = receiveTreatment.ID
- err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- } else {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
-
- }
- }
-
- }
-
- func (c *DialysisApiController) PostAssessmentAfterDislysis() {
- patient, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- fmt.Println(recordDateStr)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
-
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // data := make(map[string]interface{}, 0)
- var data models.AssessmentAfterDislysis
- var err error
- err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
- fmt.Println(err)
- if err != nil {
- c.ErrorLog("数据解析错误:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
-
- assessment.DialysisOrderId = data.DialysisOrderId
- assessment.Evaluator = adminUserInfo.AdminUser.Id
- assessment.Status = 1
- assessment.WeightAfter = data.WeightAfter
- assessment.WeightLoss = data.WeightLoss
- assessment.Temperature = data.Temperature
- assessment.SystolicBloodPressure = data.SystolicBloodPressure
- assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
- assessment.PulseFrequency = data.PulseFrequency
- assessment.ActualUltrafiltration = data.ActualUltrafiltration
- assessment.ActualDisplacement = data.ActualDisplacement
- assessment.ActualTreatmentHour = data.ActualTreatmentHour
- assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
- assessment.Cruor = data.Cruor
- assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
- assessment.DialysisIntakes = data.DialysisIntakes
- assessment.InternalFistula = data.InternalFistula
- assessment.BloodAccessPartId = data.BloodAccessPartId
- assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
- assessment.Catheter = data.Catheter
- assessment.Complication = data.Complication
- assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
- assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
- assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
- assessment.PatientGose = data.PatientGose
- assessment.InpatientDepartment = data.InpatientDepartment
- assessment.ObservationContent = data.ObservationContent
- assessment.ObservationContentOther = data.ObservationContentOther
- assessment.Remark = data.Remark
- assessment.BreathingRate = data.BreathingRate
- assessment.DialysisProcess = data.DialysisProcess
- assessment.InAdvanceMinute = data.InAdvanceMinute
- assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
- assessment.InAdvanceReason = data.InAdvanceReason
- assessment.HemostasisOpera = data.HemostasisOpera
- assessment.HemostasisMinute = data.HemostasisMinute
- assessment.TremorNoise = data.TremorNoise
- assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
- assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
- assessment.ArterialTube = data.ArterialTube
- assessment.IntravenousTube = data.IntravenousTube
- assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
- assessment.Dialyzer = data.Dialyzer
- assessment.IsEat = data.IsEat
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
-
- if evaluation.ID > 0 {
- if evaluation.WeightBefore > 0 && assessment.WeightAfter > 0 {
- if (evaluation.WeightBefore-evaluation.AdditionalWeight)-(assessment.WeightAfter-assessment.AdditionalWeight) > 0 {
- assessment.WeightLoss = (evaluation.WeightBefore - evaluation.AdditionalWeight) - (assessment.WeightAfter - assessment.AdditionalWeight)
- } else {
- assessment.WeightLoss = 0
- }
- }
- }
-
- if assessment.ID > 0 {
- //if appRole.UserType == 3 {
- // if assessment.Creater != adminUserInfo.AdminUser.Id && assessment.Creater != 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessment.AssessmentTime = time.Now().Unix()
-
- }
- if assessment.Creater == 0 {
- assessment.Modifier = adminUserInfo.AdminUser.Id
- assessment.Creater = adminUserInfo.AdminUser.Id
-
- } else {
- assessment.Modifier = adminUserInfo.AdminUser.Id
- assessment.Creater = assessment.Creater
-
- }
-
- assessment.UpdatedTime = time.Now().Unix()
- err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
- } else {
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessment.AssessmentTime = time.Now().Unix()
-
- }
- assessment.Creater = adminUserInfo.AdminUser.Id
- assessment.CreatedTime = time.Now().Unix()
- assessment.UpdatedTime = time.Now().Unix()
- assessment.UserOrgId = adminUserInfo.CurrentOrgId
- assessment.PatientId = patient
- assessment.AssessmentDate = recordDate.Unix()
-
- err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "AssessmentAfterDislysis": &assessment,
- })
-
- }
-
- func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
- patient, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- weight_before, _ := c.GetFloat("weight_before", 0)
- dry_weight, _ := c.GetFloat("dry_weight", 0)
- additional_weight, _ := c.GetFloat("additional_weight", 0)
- temperature, _ := c.GetFloat("temperature", 0)
- pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
- systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
- diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
- last_post_dialysis := c.GetString("last_post_dialysis")
- dialysis_interphase := c.GetString("dialysis_interphase")
- symptom_before_dialysis := c.GetString("symptom_before_dialysis")
- bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
- bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
- internalFistula := c.GetString("internal_fistula")
- internal_fistula_skin := c.GetString("internal_fistula_skin")
- catheter := c.GetString("catheter")
- catheter_bend, _ := c.GetInt("catheter_bend")
- complication := c.GetString("complication")
- is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
- hemorrhage := c.GetString("hemorrhage")
- hemorrhage_other := c.GetString("hemorrhage_other")
- remark := c.GetString("remark")
- puncture_method := c.GetString("puncture_method")
-
- dialysis_count, _ := c.GetInt64("dialysis_count", 0)
- emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
- emergency_treatment_other := c.GetString("emergency_treatment_other")
- ductus_arantii := c.GetString("ductus_arantii")
- venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
- venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
- venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
- puncture_way, _ := c.GetInt64("puncture_way", 0)
- blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
- internal_fistula_other := c.GetString("internal_fistula_other")
- blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
-
- breathing_rate, _ := c.GetFloat("breathing_rate", 0)
-
- is_infect, _ := c.GetInt64("is_infect", 0)
- exposed, _ := c.GetFloat("exposed", 0)
- skin, _ := c.GetInt64("skin", 0)
- skin_other := c.GetString("skin_other")
- infect_other := c.GetString("infect_other")
- ductus_arantii_other := c.GetString("ductus_arantii_other")
- machine_type := c.GetString("machine_type")
- puncture_needle := c.GetString("puncture_needle")
-
- assessmentBeforeDislysis := models.PredialysisEvaluation{
- DialysisCount: dialysis_count,
- EmergencyTreatment: emergency_treatment,
- EmergencyTreatmentOther: emergency_treatment_other,
- DuctusArantii: ductus_arantii,
- VenousCatheterization: venous_catheterization,
- VenousCatheterizationPart: venous_catheterization_part,
- VenousCatheterizationPartOther: venous_catheterization_part_other,
- PunctureWay: puncture_way,
- BloodAccessInternalFistula: blood_access_internal_fistula,
- BloodAccessNoise: blood_access_noise,
- InternalFistulaOther: internal_fistula_other,
- Evaluator: adminUserInfo.AdminUser.Id,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: patient,
- AssessmentDate: recordDate.Unix(),
- Temperature: temperature,
- PulseFrequency: pulse_frequency,
- SystolicBloodPressure: systolic_blood_pressure,
- DiastolicBloodPressure: diastolic_blood_pressure,
- WeightBefore: weight_before,
- DryWeight: dry_weight,
- AdditionalWeight: additional_weight,
- DialysisInterphase: dialysis_interphase,
- LastPostDialysis: last_post_dialysis,
- SymptomBeforeDialysis: symptom_before_dialysis,
- InternalFistula: internalFistula,
- InternalFistulaSkin: internal_fistula_skin,
- Catheter: catheter,
- CatheterBend: catheter_bend,
- Complication: complication,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- Remark: remark,
- IsHemorrhage: is_hemorrhage,
- Hemorrhage: hemorrhage,
- HemorrhageOther: hemorrhage_other,
- BloodAccessPartId: bloodAccessPartId,
- BloodAccessPartOperaId: bloodAccessPartOperaId,
- PunctureMethod: puncture_method,
- BreathingRate: breathing_rate,
- IsInfect: is_infect,
- Exposed: exposed,
- Skin: skin,
- SkinOther: skin_other,
- InfectOther: infect_other,
- DuctusArantiiOther: ductus_arantii_other,
- MachineType: machine_type,
- PunctureNeedle: puncture_needle,
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- if evaluation.ID == 0 { //新增
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
- }
-
- assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
-
- err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentBeforeDislysis": &assessmentBeforeDislysis,
- })
- } else {
- //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
-
- }
- } else { //修改
- //if appRole.UserType == 3 {
- // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
- }
- if assessmentBeforeDislysis.Creater == 0 {
- assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
- assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
- } else {
- assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
- assessmentBeforeDislysis.Creater = evaluation.Creater
- }
-
- assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
- assessmentBeforeDislysis.ID = evaluation.ID
- assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
- //
-
- //新增逻辑
-
- var dewater_amount float64
- dewater_amount = 0
- if evaluation.DryWeight > 0 {
- dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
- if dewater_amount <= 0 {
- dewater_amount = 0
- }
- } else {
- dewater_amount = 0
- }
- // 计算透析处方的相关超滤量
- schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
- var lastDialysisPrescribe *models.DialysisPrescription
- var dialysisSolution *models.DialysisSolution
- var dialysisPrescribe *models.DialysisPrescription
- var mode_id int64
- if schedual != nil {
- dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
- lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
- // 获取透析模版
- dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
- mode_id = schedual.ModeId
- } else {
- //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
- // 获取透析模版
- dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
- dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
-
- if dialysisPrescribe == nil && dialysisSolution != nil {
- mode_id = dialysisSolution.ModeId
- }
-
- if dialysisPrescribe == nil && dialysisSolution == nil {
- mode_id = 0
- }
- }
-
- // 插入透析处方
- if dialysisPrescribe == nil && dialysisSolution != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = dialysisSolution.UserOrgId
- newprescribe.PatientId = dialysisSolution.PatientId
- newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
- newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
- newprescribe.ModeId = dialysisSolution.ModeId
- newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
- newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
- newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
- newprescribe.BloodFilter = dialysisSolution.BloodFilter
- newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
- newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
- newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
- newprescribe.Glucose = dialysisSolution.Glucose
- newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
- newprescribe.Kalium = dialysisSolution.Kalium
- newprescribe.Sodium = dialysisSolution.Sodium
- newprescribe.Calcium = dialysisSolution.Calcium
- newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
- newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
- newprescribe.Conductivity = dialysisSolution.Conductivity
- newprescribe.BodyFluid = dialysisSolution.BodyFluid
- newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
- newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
- newprescribe.BloodAccess = dialysisSolution.BloodAccess
- newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
- newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
- newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
- newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
- newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
- newprescribe.Dialyzer = dialysisSolution.Dialyzer
- newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
- newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
- newprescribe.TargetKtv = dialysisSolution.TargetKtv
-
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = recordDate.Unix()
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
-
- err := service.AddSigleRecord(&newprescribe)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
-
- if dialysisPrescribe == nil && dialysisSolution == nil {
- if lastDialysisPrescribe != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
- newprescribe.PatientId = lastDialysisPrescribe.PatientId
- newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
- newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
- newprescribe.ModeId = lastDialysisPrescribe.ModeId
- newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
- newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
- newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
- newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
- newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
- newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
- newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
- newprescribe.Glucose = lastDialysisPrescribe.Glucose
- newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
- newprescribe.Kalium = lastDialysisPrescribe.Kalium
- newprescribe.Sodium = lastDialysisPrescribe.Sodium
- newprescribe.Calcium = lastDialysisPrescribe.Calcium
- newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
- newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
- newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
- newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
- newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
- newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
- newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
- newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
- newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
- newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
- newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
- newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
- newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
- newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
- newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = recordDate.Unix()
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
- err := service.AddSigleRecord(&newprescribe)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- } else {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
- newprescribe.PatientId = patient
- newprescribe.ModeId = mode_id
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = recordDate.Unix()
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
-
- err := service.AddSigleRecord(&newprescribe)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
- }
-
- err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentBeforeDislysis": &assessmentBeforeDislysis,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
-
- }
-
- }
-
- }
- func (c *DialysisApiController) PostTreatmentSummary() {
- patient, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mission := c.GetString("mission")
- dialysis_summary := c.GetString("dialysis_summary")
- sj_nurse := adminUserInfo.AdminUser.Id
- zl_nurse := adminUserInfo.AdminUser.Id
- hd_nurse := adminUserInfo.AdminUser.Id
- xj_nurse := adminUserInfo.AdminUser.Id
- zl_doctor := adminUserInfo.AdminUser.Id
-
- treatmentSummary := models.TreatmentSummary{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: patient,
- AssessmentDate: recordDate.Unix(),
- Mission: mission,
- DialysisSummary: dialysis_summary,
- SjNurse: sj_nurse,
- ZlNurse: zl_nurse,
- HdNurse: hd_nurse,
- XjNurse: xj_nurse,
- ZlDoctor: zl_doctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- }
-
- _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
- if tempTreatmentSummary.ID == 0 { //新增
- treatmentSummary.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleSummaryRecord(&treatmentSummary)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "summary": treatmentSummary,
- })
- } else {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
-
- }
-
- } else { //修改
- //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- treatmentSummary.Creater = tempTreatmentSummary.Creater
- treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
- treatmentSummary.UpdatedTime = time.Now().Unix()
- treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
- treatmentSummary.ID = tempTreatmentSummary.ID
- err := service.UpdateSummeRecord(&treatmentSummary)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "summary": treatmentSummary,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
-
- }
-
- }
-
- func (c *DialysisApiController) GetDeviceList() {
- adminUserInfo := c.GetAdminUserInfo()
- device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "device": device,
- })
- }
-
- func (c *DialysisApiController) GetAllDeviceZone() {
- adminUserInfo := c.GetAdminUserInfo()
- err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "zone": zone,
- })
- }
-
- }
-
- func (c *DialysisApiController) GetDialysisWatch() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- schedulType, _ := c.GetInt64("schedul_type", 0)
- startTime, _ := c.GetInt64("schedul_time", 0)
- partitionType, _ := c.GetInt64("partition_type", 0)
- keywords := c.GetString("keywords")
-
- adminUserInfo := c.GetAdminUserInfo()
- if len(keywords) > 0 {
- dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": dialysisSchedule,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- }
-
- } else {
- dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": dialysisSchedule,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- }
- }
- }
-
- func (c *DialysisApiController) GetSchedualPatientsInfo() {
- patientId, _ := c.GetInt64("id", 0)
- record_date, _ := c.GetInt64("record_date", 0)
- adminUserInfo := c.GetAdminUserInfo()
- _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
- var dialysisStatus int64
- if dialysisOrder == nil { //没有透析记录
- dialysisStatus = 0 //未透析
- } else {
- dialysisStatus = dialysisOrder.Stage
- }
- //用户基本信息
- schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
-
- //接诊评估
- receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
- //透前评估
- PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
- //临时医嘱
- DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
- //双人核对
- DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
- //透析监测
- Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
-
- //透后评估
- AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
- //透析小结
- TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
-
- //透析处方
- dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
- if dialysisPrescription.ID == 0 {
- solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patientInfo": schedualPatientInfo,
- "dialysisPrescription": solution,
- "receiverTreatmentAccess": receiverTreatmentAccess,
- "predialysisEvaluation": PredialysisEvaluation,
- "doctorAdvice": DoctorAdvice,
- "doubleCheck": DoubleCheck,
- "assessmentAfterDislysis": AssessmentAfterDislysis,
- "treatmentSummary": TreatmentSummary,
- "monitorRecord": Record,
- "dialysisStatus": dialysisStatus,
- "dialysisOrder": dialysisOrder,
- "isSolution": 1,
- })
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "patientInfo": schedualPatientInfo,
- "dialysisPrescription": dialysisPrescription,
- "receiverTreatmentAccess": receiverTreatmentAccess,
- "predialysisEvaluation": PredialysisEvaluation,
- "doctorAdvice": DoctorAdvice,
- "doubleCheck": DoubleCheck,
- "assessmentAfterDislysis": AssessmentAfterDislysis,
- "treatmentSummary": TreatmentSummary,
- "monitorRecord": Record,
- "dialysisStatus": dialysisStatus,
- "dialysisOrder": dialysisOrder,
- "isSolution": 2,
- })
-
- }
-
- }
-
- func (c *DialysisApiController) CreateDoctorAdvice() {
- patient, _ := c.GetInt64("id", 0)
- dialysis_id, _ := c.GetInt64("dialysis_id", 0)
- record_date, _ := c.GetInt64("record_date", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var advice models.DoctorAdvice
- code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- if advice.ParentId > 0 {
- old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
- if old.ID == 0 || old.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
- return
- }
-
- if old.StopState == 1 || old.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- if old.ParentId > 0 {
- advice.ParentId = old.ParentId
- }
- advice.StartTime = old.StartTime
- advice.AdviceDoctor = old.AdviceDoctor
- advice.DeliveryWay = old.DeliveryWay
- advice.ExecutionFrequency = old.ExecutionFrequency
- }
- advice.RecordDate = record_date
- advice.DialysisOrderId = dialysis_id
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.AdviceType = 2
- advice.UserOrgId = adminUserInfo.CurrentOrgId
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- err := service.CreateDoctorAdvice(&advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- for _, subAdvice := range subAdivice {
- subAdvice.ParentId = advice.ID
- subAdvice.PatientId = patient
- subAdvice.RecordDate = record_date
- subAdvice.CreatedTime = time.Now().Unix()
- subAdvice.UpdatedTime = time.Now().Unix()
- subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
-
- }
- service.CreateSubDoctorAdvice(subAdivice)
- _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- "subAdvice": subAdivices,
- })
- return
-
- }
- func (c *DialysisApiController) EditDoctorAdvice() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- parent_id, _ := c.GetInt64("parent_id", 0)
- execution_time := c.GetString("execution_time")
- // execution_staff, _ := c.GetInt64("execution_staff", 0)
- // checker, _ := c.GetInt64("checker", 0)
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- if len(execution_time) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- execution_staff := adminUserInfo.AdminUser.Id
- checker := adminUserInfo.AdminUser.Id
-
- timeLayout2 := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- advices := models.DoctorAdvice{
- ExecutionStaff: execution_staff,
- ExecutionTime: theTime.Unix(),
- Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- if parent_id > 0 {
- err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
- } else {
- err = service.ExceDoctorAdviceById(&advices, id, patient)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
-
- }
- func (c *DialysisApiController) GetDoctorAdvice() {
- patient, _ := c.GetInt64("patient_id", 0)
- parent_id, _ := c.GetInt64("parent_id", 0)
- adviceId, _ := c.GetInt64("id", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- var subAdvice []*models.DoctorAdvice
- var advice models.DoctorAdvice
-
- if parent_id > 0 {
- _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
- return
- }
- subAdvice = service.FindSubAdivceById(patient, parent_id)
-
- } else {
- _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
- return
- }
- subAdvice = service.FindSubAdivceById(patient, adviceId)
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- "subAdvice": subAdvice,
- })
- }
- func (this *DialysisApiController) DelMonitor() {
- recordID, _ := this.GetInt64("record_id")
- patientID, _ := this.GetInt64("patient_id")
- if recordID <= 0 || patientID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := this.GetAdminUserInfo()
- patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
- if getMonitorErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- //if monitor != nil {
- // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
- if err != nil {
- this.ErrorLog("删除透析监测记录失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "record_id": monitor.ID,
- })
-
- }
- func (c *DialysisApiController) CreateMonitor() {
- patient, _ := c.GetInt64("id", 0)
- dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
- monitoring_date, _ := c.GetInt64("monitoring_date", 0)
- operate_time, _ := c.GetInt64("operate_time", 0)
- // monitoring_time := c.GetString("monitoring_time")
- pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
- breathing_rated, _ := c.GetFloat("breathing_rated", 0)
- systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
- diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
- blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- venous_pressure, _ := c.GetFloat("venous_pressure", 0)
- venous_pressure_unit := c.GetString("venous_pressure_unit")
- transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
- transmembrane_pressure_unit := c.GetString("transmembrane_pressure_unit")
- ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
- ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
- sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
- arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- temperature, _ := c.GetFloat("temperature", 0)
- replacement_rate, _ := c.GetFloat("replacement_rate", 0)
- displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
-
- displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
-
- ktv, _ := c.GetFloat("ktv", 0)
- symptom := c.GetString("symptom")
- dispose := c.GetString("dispose")
- result := c.GetString("results")
-
- monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
- monitoring_date = monitoring_date / 1000
- // operate_time = operate_time / 1000
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- monitorRecord := models.MonitoringRecord{
- PatientId: patient,
- MonitoringDate: monitoring_date,
- DialysisOrderId: dialysis_order_id,
- OperateTime: operate_time,
- // MonitoringTime: monitoring_time,
- PulseFrequency: pulse_frequency,
- BreathingRate: breathing_rated,
- SystolicBloodPressure: systolic_blood_pressure,
- DiastolicBloodPressure: diastolic_blood_pressure,
- BloodPressureType: blood_pressure_type,
- BloodFlowVolume: blood_flow_volume,
- VenousPressure: venous_pressure,
- VenousPressureUnit: venous_pressure_unit,
- TransmembranePressure: transmembrane_pressure,
- TransmembranePressureUnit: transmembrane_pressure_unit,
- UltrafiltrationRate: ultrafiltration_rate,
- UltrafiltrationVolume: ultrafiltration_volume,
- SodiumConcentration: sodium_concentration,
- ArterialPressure: arterial_pressure,
- DialysateTemperature: dialysate_temperature,
- Temperature: temperature,
- ReplacementRate: replacement_rate,
- DisplacementQuantity: displacement_quantity,
- Ktv: ktv,
- Symptom: symptom,
- Dispose: dispose,
- Result: result,
- MonitoringNurse: monitoring_nurse,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- UserOrgId: adminUserInfo.CurrentOrgId,
- Conductivity: conductivity,
- DisplacementFlowQuantity: displacement_flow_quantity,
- }
-
- err := service.CreateMonitor(&monitorRecord)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "monitor": monitorRecord,
- })
- return
-
- }
-
- // 已弃用
- // func (c *DialysisApiController) CreateRecordData() {
- // patient, _ := c.GetInt64("id", 0)
- // status, _ := c.GetInt64("status", 0)
-
- // now := time.Now()
- // year, month, day := now.Date()
- // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- // todayTimeStamp := today_time.Unix()
-
- // if patient <= 0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
-
- // adminUserInfo := c.GetAdminUserInfo()
- // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- // if patientInfo.ID == 0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- // return
- // }
-
- // record := &models.DialysisOrder{
- // DialysisDate: todayTimeStamp,
- // UserOrgId: adminUserInfo.CurrentOrgId,
- // PatientId: patient,
- // Stage: status,
- // Status: 1,
- // CreatedTime: time.Now().Unix(),
- // UpdatedTime: time.Now().Unix(),
- // }
-
- // if status == 1 {
- // //创建透析记录
- // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
- // if err == nil {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "dialysisOrder": record,
- // })
- // } else {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- // }
-
- // } else {
-
- // record_id, _ := c.GetInt64("record_id", 0)
- // //修改透析记录状态
- // errs := service.ModifyDialysisRecord(record_id)
- // //结束时候透析次数加1
- // service.UpdateSolutionByPatientId(patient)
-
- // if errs == nil {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "dialysisOrder": record,
- // })
-
- // } else {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
-
- // }
-
- // }
-
- // }
-
- func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- timeLayout := "2006-01-02 "
- timeLayout2 := "2006-01-02 15:04"
-
- loc, _ := time.LoadLocation("Local")
-
- if action == "create" {
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- code = enums.ErrorCodeParamWrong
- return
- }
-
- adviceType := int64(dataBody["advice_type"].(float64))
- if adviceType != 1 && adviceType != 2 {
- utils.ErrorLog("advice_type != 1&&2")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceType = adviceType
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceDate, _ := dataBody["advice_date"].(string)
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceDate = theTime.Unix()
-
- }
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- code = enums.ErrorCodeParamWrong
- return
- }
- startDate, _ := dataBody["start_time"].(string)
- if len(startDate) == 0 {
- utils.ErrorLog("len(startDate) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.StartTime = theTime.Unix()
-
- if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceName, _ := dataBody["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceName = adviceName
-
- if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
- utils.ErrorLog("delivery_way")
- code = enums.ErrorCodeParamWrong
- return
- }
- deliveryWay, _ := dataBody["delivery_way"].(string)
- if len(deliveryWay) == 0 {
- utils.ErrorLog("len(deliveryWay) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.DeliveryWay = deliveryWay
-
- if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
- utils.ErrorLog("execution_frequency")
- code = enums.ErrorCodeParamWrong
- return
- }
- execution_frequency, _ := dataBody["execution_frequency"].(string)
- if len(execution_frequency) == 0 {
- utils.ErrorLog("len(execution_frequency) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.ExecutionFrequency = execution_frequency
-
- if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
- adviceDsc, _ := dataBody["advice_desc"].(string)
- advice.AdviceDesc = adviceDsc
- }
-
- if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
-
- if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
-
- if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
- thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
- if len(thisContagions) > 0 {
- for _, item := range thisContagions {
- items := item.(map[string]interface{})
- advice_name, _ := items["advice_name"].(string)
- advice_desc, _ := items["advice_desc"].(string)
- drug_spec_unit, _ := items["drug_spec_unit"].(string)
-
- prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
- single_dose_unit, _ := items["single_dose_unit"].(string)
- prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
- single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
-
- advice := &models.DoctorAdvice{
- AdviceName: advice_name,
- AdviceDesc: advice_desc,
- SingleDose: single_dose,
- SingleDoseUnit: single_dose_unit,
- DrugSpecUnit: drug_spec_unit,
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- }
- subAdvice = append(subAdvice, advice)
-
- }
- }
- }
-
- return
-
- }
-
- func (c *DialysisApiController) GetDialysisOrder() {
- xtno := c.GetString("xtno")
- xtdate := c.GetString("xtdate")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- xttime := theTime.Unix()
-
- operatorIDs := make([]int64, 0)
-
- adminUserInfo := c.GetAdminUserInfo()
-
- adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
-
- patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
-
- //透析单
- dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- if dialysisOrder != nil {
- if dialysisOrder.FinishNurse > 0 {
- operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
- }
- if dialysisOrder.StartNurse > 0 {
- operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
- }
- }
-
- //透前评估
- PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
- //透后评估
- AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- if AssessmentAfterDislysis.Modifier > 0 {
- operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
- }
- //透析处方
- dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- if dialysisPrescription.PrescriptionDoctor > 0 {
- operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
- }
-
- //获取病人的透析模式
- schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
-
- order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
- //fmt.Print("nurse------------", err)
- startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
- FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
- //获取透析处方
- dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- //获取临时医嘱
- doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
-
- //获取医嘱内容
- doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
- DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
- //fmt.Print("err---------------------------------",err)
- DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- //获取上次的透后体重
- assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- //获取透析次数
- _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
-
- if len(DoctorAdvice) > 0 {
- for _, item := range DoctorAdvice {
- if item.AdviceDoctor > 0 {
- operatorIDs = append(operatorIDs, item.AdviceDoctor)
- }
- if item.ExecutionStaff > 0 {
- operatorIDs = append(operatorIDs, item.ExecutionStaff)
- }
- if item.Checker > 0 {
- operatorIDs = append(operatorIDs, item.Checker)
- }
- }
- }
-
- //透析监测
- Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- //透析检测
- monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
- //透析小结
- TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
-
- //接诊评估
- receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
-
- check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
-
- //相关操作对应的操作人
- operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
-
- templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "xtdate": xtdate,
- "users": adminUser,
- "patientInfo": patientInfo,
- "PredialysisEvaluation": PredialysisEvaluation,
- "AssessmentAfterDislysis": AssessmentAfterDislysis,
- "dialysisPrescription": dialysisPrescription,
- "advices": DoctorAdvice,
- "monitors": Record,
- "summary": TreatmentSummary,
- "receiverTreatmentAccess": receiverTreatmentAccess,
- "dialysisOrder": dialysisOrder,
- "operators": operators,
- "org_template_info": templateInfo,
- "check": check,
- "schedule": schedule,
- "dialysisway": dialysisway,
- "order": order,
- "doctorAdvice": doctorAdvice,
- "doctor": doctor,
- "nurse": nurse,
- "doctorAdevieInfo": doctorAdevieInfo,
- "total": total,
- "startNuse": startNuse,
- "DoctorName": DoctorName,
- "monitor": monitor,
- "assessmentAfterDislysis": assessmentAfterDislysis,
- "predialysName": predialysName,
- "FinishNuse": FinishNuse,
- })
-
- }
-
- //
- func (c *DialysisApiController) GetLongAdvice() {
- patient_id, _ := c.GetInt64("patient_id")
- adminUserInfo := c.GetAdminUserInfo()
- _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
-
- //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
- if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "1",
- })
- return
- } else { //开启推送提醒
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
- //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
- advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id)
- advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id)
-
- for _, advice := range advices {
- if advice.FrequencyType == 3 {
- t := time.Now()
- week := int(t.Weekday())
-
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") == -1 {
- advice_three = append(advice_three, advice)
- }
-
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") == -1 {
- advice_three = append(advice_three, advice)
- }
-
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") == -1 {
- advice_three = append(advice_three, advice)
- }
-
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") == -1 {
- advice_three = append(advice_three, advice)
- }
-
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- }
- }
-
- for _, advice := range advices_two {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
-
- for _, ad := range advices {
- advice_three = append(advice_three, ad)
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "2",
- "advices": advices,
- "advices_two": RemoveRepeatedElement(advice_three),
- "is_open_remind": config.IsOpenRemind,
- })
- }
- }
-
- }
-
- func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
- newArr = make([]*models.DoctorAdvice, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].ID == arr[j].ID {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *DialysisApiController) CreateRemindDoctorAdvice() {
-
- patient, _ := c.GetInt64("id", 0)
- groupNo, _ := c.GetInt64("groupno", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- timeLayout2 := "2006-01-02"
- loc2, _ := time.LoadLocation("Local")
-
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- return
- }
- adviceType := int64(2)
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- return
- }
- adviceDate, _ := dataBody["advice_date"].(string)
- theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
- AdviceDate := theTime.Unix()
- RecordDate := theTime.Unix()
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- return
- }
- theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- StartTime := theTime.Unix()
-
- Remark := ""
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- Remark = remark
- }
-
- var advices []*models.GroupAdvice
- if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
- utils.ErrorLog("advices")
- return
- }
- adviceNames := dataBody["advices"].([]interface{})
- for _, adviceNameMap := range adviceNames {
- adviceNameM := adviceNameMap.(map[string]interface{})
- var advice models.GroupAdvice
- advice.Remark = Remark
- advice.AdviceType = adviceType
- advice.StartTime = StartTime
- advice.AdviceDate = AdviceDate
-
- advice.RecordDate = RecordDate
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.CurrentOrgId
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceName, _ := adviceNameM["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.AdviceName = adviceName
-
- if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
- adviceDesc, _ := adviceNameM["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- }
-
- if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
- // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
- // advice.SingleDose = singleDose
- //}
-
- if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
- //single_dose := int64(adviceNameM["single_dose"].(float64))
- advice.SingleDose = adviceNameM["single_dose"].(float64)
- }
-
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
- // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
- // advice.PrescribingNumber = prescribingNumber
- //}
-
- if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
-
- advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
- }
-
- if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
- deliveryWay, _ := adviceNameM["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
- frequency_type := int64(adviceNameM["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
- day_count := int64(adviceNameM["day_count"].(float64))
- advice.DayCount = day_count
- }
-
- if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
- week_day, _ := adviceNameM["week_day"].(string)
- advice.WeekDay = week_day
- }
-
- if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
- template_id, _ := adviceNameM["template_id"].(string)
- advice.TemplateId = template_id
- }
-
- if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
- children := adviceNameM["child"].([]interface{})
- if len(children) > 0 {
- for _, childrenMap := range children {
- childMap := childrenMap.(map[string]interface{})
- var child models.GroupAdvice
- child.Remark = Remark
- child.AdviceType = adviceType
- child.StartTime = StartTime
- child.AdviceDate = AdviceDate
- child.RecordDate = RecordDate
- child.Status = 1
- child.CreatedTime = time.Now().Unix()
- child.UpdatedTime = time.Now().Unix()
- child.StopState = 2
- child.ExecutionState = 2
- child.UserOrgId = adminUserInfo.CurrentOrgId
- child.PatientId = patient
- child.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
- utils.ErrorLog("child advice_name")
- return
- }
- childAdviceName, _ := childMap["advice_name"].(string)
- if len(childAdviceName) == 0 {
- utils.ErrorLog("len(child advice_name) == 0")
- return
- }
- child.AdviceName = childAdviceName
-
- if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
- childAdviceDesc, _ := childMap["advice_desc"].(string)
- child.AdviceDesc = childAdviceDesc
- }
-
- if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
- childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
- child.DrugSpec = childDrugSpec
- }
-
- if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
- childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
- child.DrugSpecUnit = childDrugSpecUnit
- }
-
- if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
- childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
- child.SingleDose = childSingleDose
- }
-
- if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
- childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
- child.SingleDoseUnit = childSingleDoseUnit
- }
-
- if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
- childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
- child.PrescribingNumber = childPrescribingNumber
- }
-
- if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
- childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
- child.PrescribingNumberUnit = childPrescribingNumberUnit
- }
-
- child.DeliveryWay = advice.DeliveryWay
- child.ExecutionFrequency = advice.ExecutionFrequency
- advice.Children = append(advice.Children, &child)
- }
- }
- }
-
- advices = append(advices, &advice)
- }
-
- list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": list,
- })
-
- return
-
- }
-
- func (c *DialysisApiController) GetSolution() {
- patient_id, _ := c.GetInt64("patient_id")
- mode_id, _ := c.GetInt64("mode_id")
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
- prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
- system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, mode_id)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": solution,
- "prescription": prescription,
- "system_prescription": system_prescription,
- })
-
- }
-
- func (c *DialysisApiController) GetSchedule() {
- schedual_type, _ := c.GetInt64("schedual_type")
- adminUserInfo := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02 15:04:05"
-
- date := time.Now().Format("2006-01-02") + " 00:00:00"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
- scheduleTime := theStartTime.Unix()
-
- deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "number": deviceNumber,
- })
-
- }
-
- func (this *DialysisApiController) GetTodayMonitor() {
- thisTime := time.Now()
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theAssessmentDateTime := theStartTime.Unix()
-
- patientID, _ := this.GetInt64("patient_id")
- monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
- adminInfo := this.GetAdminUserInfo()
- record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
- fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
-
- template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
-
- var ultrafiltration_rate float64
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
- if prescription.ID > 0 {
- if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
-
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
- if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- }
- // 只针对方济医院
- if template.TemplateId == 1 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
- ultrafiltration_rate = value
- }
- }
- }
- record.UltrafiltrationRate = ultrafiltration_rate
- record.UltrafiltrationVolume = 0
- if template.TemplateId == 1 {
- if ultrafiltration_rate > 0 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
- record.UltrafiltrationVolume = value
- }
- }
-
- if template.TemplateId == 6 {
- if ultrafiltration_rate > 0 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
- record.UltrafiltrationVolume = ultrafiltration_volume
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "monitor": record,
- })
-
- }
-
- func (c *DialysisApiController) UploadDryWeight() {
- patient_id, _ := c.GetInt64("id")
- dry_weight, _ := c.GetFloat("dry_weight")
- doctor_id, _ := c.GetInt64("doctor_id")
- remark := c.GetString("remark")
- adminUserInfo := c.GetAdminUserInfo()
- weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
- fmt.Println(err)
- if err == gorm.ErrRecordNotFound {
- dryWeight := &models.SgjPatientDryweight{
- PatientId: patient_id,
- DryWeight: dry_weight,
- Remakes: remark,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: doctor_id,
- Status: 1,
- UserOrgId: adminUserInfo.CurrentOrgId,
- AdjustedValue: "/",
- UserId: adminUserInfo.AdminUser.Id,
- }
- createErr := service.CreatePatientWeightAdjust(dryWeight)
-
- if createErr == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "weight": dryWeight,
- })
- }
-
- } else {
- dryWeight := &models.SgjPatientDryweight{
- PatientId: patient_id,
- DryWeight: dry_weight,
- Remakes: remark,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: doctor_id,
- Status: 1,
- UserOrgId: adminUserInfo.CurrentOrgId,
- AdjustedValue: "/",
- UserId: adminUserInfo.AdminUser.Id,
- }
- var value float64
- value = dry_weight - weightAdjust.DryWeight
- fmt.Println(value)
-
- if value < 0 {
- dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
- } else if value == 0 {
- dryWeight.AdjustedValue = "/"
- } else if value > 0 {
- dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
- }
- fmt.Println(value)
-
- createErr := service.CreatePatientWeightAdjust(dryWeight)
- if createErr == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "weight": dryWeight,
- })
- }
- }
-
- }
|