dialysis_api_controller.go 224KB

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