12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691 |
- package service
-
- import (
- "encoding/json"
- "fmt"
- "strconv"
- "strings"
- "time"
-
- "XT_New/models"
- "XT_New/utils"
-
- "github.com/jinzhu/gorm"
- )
-
- // GetPatientList 返回患者的列表
- func GetPatientList(orgID int64, keywords string, page, limit, schedulType, bindingState, lapseto, source, startTime, endTime, contagion, reimbursementWay, isscheduling, isprescription int64, isStartTime, isEndTime bool, patientSoureType int64, nurse int64, patient_type int64) (patients []*models.Patients, total int64, err error) {
-
- db := readDb.Table("xt_patients as p").Where("p.status=1")
- if orgID > 0 {
- db = db.Where("p.user_org_id=?", orgID)
- }
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ? OR p.first_letter LIKE ?", likeKey, likeKey, likeKey)
- }
-
- if schedulType > 0 {
- db = db.Joins("JOIN xt_schedule as s ON s.patient_id=p.id")
- db = db.Where("s.status=1 and s.schedule_type=?", schedulType)
- }
-
- if contagion > 0 {
- db = db.Joins("JOIN xt_patients_infectious_diseases as xpid ON xpid.patient_id=p.id")
- db = db.Where("xpid.disease_id=? and xpid.status=1", contagion)
- }
-
- if isscheduling == 1 {
- db = db.Where("EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.status=1").QueryExpr())
- } else if isscheduling == 2 {
- db = db.Where("NOT EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.status=1").QueryExpr())
- }
- if isprescription == 1 {
- db = db.Where("EXISTS (?)", readDb.Table("xt_dialysis_prescription as xdp").Where("xdp.patient_id=p.id and xdp.status=1").QueryExpr())
- } else if isprescription == 2 {
- db = db.Where("NOT EXISTS (?)", readDb.Table("xt_dialysis_prescription as xdp").Where("xdp.patient_id=p.id and xdp.status=1").QueryExpr())
- }
-
- if bindingState > 0 {
- db = db.Where("p.binding_state=?", bindingState)
- }
- if lapseto > 0 {
- db = db.Where("p.lapseto=?", lapseto)
- }
- if source > 0 {
- db = db.Where("p.source=?", source)
- }
- if reimbursementWay > 0 {
- db = db.Where("p.reimbursement_way_id = ?", reimbursementWay)
- }
-
- if isStartTime {
- db = db.Where("p.created_time>=?", startTime)
- }
- if isEndTime {
- db = db.Where("p.created_time<=?", endTime)
- }
-
- if patientSoureType > 0 {
- db = db.Where("p.patient_source =?", patientSoureType)
- }
- if nurse > 0 {
- db = db.Where("p.head_nurse_id = ?", nurse)
- }
- if patient_type > 0 {
- db = db.Where("p.patient_type = ?", patient_type)
- }
-
- offset := (page - 1) * limit
- if lapseto == 2 || lapseto == 3 {
- err = db.Order("p.death_time desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time,p.is_infectious,p.patient_type").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
-
- }
- if lapseto != 2 && lapseto != 3 {
- if orgID != 10579 && orgID != 10600 && orgID != 10587 {
- err = db.Order("p.id desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time,p.is_infectious,p.patient_type").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
- }
-
- if orgID == 10579 || orgID == 10600 {
- err = db.Order("p.dialysis_no asc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time,p.is_infectious,p.patient_type").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
- }
-
- if orgID == 10587 {
- err = db.Order("p.created_time desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time,p.is_infectious,p.patient_type").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
- }
-
- }
-
- return
-
- }
-
- // GetAllPatientList 返回全部患者的列表
- func GetAllPatientList(orgID int64) (patients []*models.Patients, total int64, err error) {
-
- db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1", orgID)
-
- err = db.Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.age,p.id_card_no").Count(&total).Find(&patients).Error
- return
- }
-
- func GetAllPatientListOne(orgID int64) (patients []*models.Patients, total int64, err error) {
-
- db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1 and p.lapseto =1", orgID)
-
- err = db.Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.age,p.id_card_no").Count(&total).Find(&patients).Error
- return
- }
-
- func GetAllPatientListTwenty(orgID int64) (patients []*models.Patients, total int64, err error) {
-
- db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1 and p.lapseto = 1", orgID)
-
- err = db.Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time").Count(&total).Find(&patients).Error
- return
- }
-
- func GetAllPatientListSix(orgID int64) (patients []*models.MSchedualPatientList, err error) {
-
- err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1", orgID).Find(&patients).Error
-
- return patients, err
- }
-
- // GetAllPatientList 返回全部患者的列表
- func GetAllPatientListByList(orgID int64) (patients []*models.MSchedualPatientList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
- patient_info_str, _ := redis.Get(key).Result()
-
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.MSchedualPatientList{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(patients) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(patients) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patients)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return patients, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if patient_info_str == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(patient_info_str), &patients)
- return patients, nil
- }
- }
- }
-
- func GetAllDevicetByListSix(orgID int64) (devices []*models.MDeviceNumberForList, err error) {
-
- err = readDb.Model(&models.MDeviceNumberForList{}).Preload("Zone", "status = 1 AND org_id = ?", orgID).Where("org_id=?", orgID).Find(&devices).Error
- return devices, err
- }
-
- func GetMonitorByListSix(orgID int64, monitor_date int64) (monitor []models.VMMonitoringRecord, err error) {
-
- err = readDb.Where("user_org_id = ? and monitor_date = ? and status =1", orgID, monitor_date).Find(&monitor).Error
- return monitor, err
- }
-
- func GetAllDevicetByList(orgID int64) (devices []*models.MDeviceNumberForList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":device_list_all"
- device_list_str, _ := redis.Get(key).Result()
-
- if len(device_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.MDeviceNumberForList{}).Preload("Zone", "status = 1 AND org_id = ?", orgID).Where("org_id=? and status=1 ", orgID).Find(&devices).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(devices) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(devices) > 0 {
- //缓存数据
- device_list_str, err := json.Marshal(&devices)
- if err == nil {
- redis.Set(key, device_list_str, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return devices, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if device_list_str == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(device_list_str), &devices)
- return devices, nil
- }
- }
- }
-
- func GetAllAdvicestByList(orgID int64, scheduleDate int64) (advices []models.VMDoctorAdviceForList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":advice_list_all"
- advice_list_str, _ := redis.Get(key).Result()
-
- if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMDoctorAdviceForList{}).Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).Find(&advices).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(advices) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(advices) > 0 {
- //缓存数据
- advice_list_str, err := json.Marshal(&advices)
- if err == nil {
- redis.Set(key, advice_list_str, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return advices, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if advice_list_str == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(advice_list_str), &advices)
- return advices, nil
- }
-
- }
- }
-
- func GetAllPrescriptionsByList(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionList, err error) {
-
- err = readDb.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- return prescriptions, err
- }
-
- //func GetAllPrescriptionsByList(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionList, err error) {
- // redis := RedisClient()
- // defer redis.Close()
- // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
- // prescriptions_list_all, _ := redis.Get(key).Result()
- // redis.Set(prescriptions_list_all, "", time.Second)
- // if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- // err = readDb.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- // if err != nil {
- // if err == gorm.ErrRecordNotFound {
- // if len(prescriptions) <= 0 {
- // redis.Set(key, "null", time.Second*60*60*18)
- // }
- // return nil, nil
- // } else {
- // return nil, err
- // }
- // } else {
- // if len(prescriptions) > 0 {
- // //缓存数据
- // prescriptions_list_all, err := json.Marshal(&prescriptions)
- // if err == nil {
- // redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- // }
- // } else {
- // redis.Set(key, "null", time.Second*60*60*18)
- // }
- // return prescriptions, nil
- // }
- // } else { //缓存数据了数据,将redis缓存的json字符串转为map
- // if prescriptions_list_all == "null" {
- // return nil, nil
- // } else {
- // json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- // return prescriptions, nil
- // }
- //
- // }
- //}
-
- func GetAllAssessmentBeforesByList(orgID int64, scheduleDate int64) (assessmentBefores []*models.PredialysisEvaluationList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
- assessment_befores_list_all, _ := redis.Get(key).Result()
-
- if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(assessmentBefores) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentBefores) > 0 {
- //缓存数据
- assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
- if err == nil {
- redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return assessmentBefores, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if assessment_befores_list_all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
- return assessmentBefores, nil
- }
- }
- }
-
- func GetAllDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*models.MDialysisOrderForList, err error) {
-
- err = readDb.Model(&models.MDialysisOrderForList{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- return dialysisOrders, err
- }
-
- //func GetAllDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*models.MDialysisOrderForList, err error) {
- // redis := RedisClient()
- // defer redis.Close()
- // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
- // dialysis_orders_list_all, _ := redis.Get(key).Result()
- // redis.Set(dialysis_orders_list_all, "", time.Second)
- // if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- // err = readDb.Model(&models.MDialysisOrderForList{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- //
- // if err != nil {
- // if err == gorm.ErrRecordNotFound {
- // return nil, nil
- // } else {
- // return nil, err
- // }
- // } else {
- // if len(dialysisOrders) > 0 {
- // //缓存数据
- // dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
- // if err == nil {
- // redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
- // }
- // } else {
- // redis.Set(key, "null", time.Second*60*60*18)
- // }
- // return dialysisOrders, nil
- // }
- // } else { //缓存数据了数据,将redis缓存的json字符串转为map
- // if dialysis_orders_list_all == "null" {
- // return nil, nil
- // } else {
- // json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
- // return dialysisOrders, nil
- // }
- //
- // }
- //}
-
- func GetAllTreatmentSummarysByList(orgID int64, scheduleDate int64) (treatmentSummarys []*models.VMTreatmentSummaryForList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":treatment_summarys_list_all"
- treatment_summarys_all, _ := redis.Get(key).Result()
-
- if len(treatment_summarys_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMTreatmentSummaryForList{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&treatmentSummarys).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(treatment_summarys_all) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(treatmentSummarys) > 0 {
- //缓存数据
- treatment_summarys_all, err := json.Marshal(&treatmentSummarys)
- if err == nil {
- redis.Set(key, treatment_summarys_all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return treatmentSummarys, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if treatment_summarys_all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(treatment_summarys_all), &treatmentSummarys)
- return treatmentSummarys, nil
- }
- }
- }
-
- func GetAllAssessmentAfterDislysisByList(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
- assessment_after_dislysis__all, _ := redis.Get(key).Result()
-
- if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(assessmentAfterDislysis) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentAfterDislysis) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return assessmentAfterDislysis, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if assessment_after_dislysis__all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
- return assessmentAfterDislysis, nil
- }
-
- }
- }
-
- func GetAllDobuleCheckList(orgID int64, scheduleDate int64) (dobulecheck []*models.DoubleCheck, err error) {
-
- err = XTReadDB().Where("check_date = ? and user_org_id = ? and status = 1", scheduleDate, orgID).Find(&dobulecheck).Error
- return dobulecheck, err
- }
-
- func GetAllHisAdvicesByList(orgID int64, scheduleDate int64) (hisAdvices []VMHisDoctorAdviceInfo, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":his_advices_list_all"
- his_advices_all, _ := redis.Get(key).Result()
- redis.Set(key, "", time.Second)
- if orgID != 10721 {
- if len(his_advices_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&VMHisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).Find(&hisAdvices).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(hisAdvices) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(hisAdvices) > 0 {
- //缓存数据
- his_advices_all, err := json.Marshal(&hisAdvices)
- if err == nil {
- redis.Set(key, his_advices_all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return hisAdvices, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if his_advices_all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(his_advices_all), &hisAdvices)
- return hisAdvices, nil
- }
-
- }
- }
-
- if orgID == 10721 {
-
- var keyword = "胰岛素"
-
- keyword = "%" + keyword + "%"
-
- if len(his_advices_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&VMHisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency !='上机前' and delivery_way!='口服' and advice_name not like ? ", orgID, scheduleDate, keyword).Find(&hisAdvices).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(hisAdvices) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(hisAdvices) > 0 {
- //缓存数据
- his_advices_all, err := json.Marshal(&hisAdvices)
- if err == nil {
- redis.Set(key, his_advices_all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return hisAdvices, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if his_advices_all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(his_advices_all), &hisAdvices)
- return hisAdvices, nil
- }
-
- }
- }
-
- return hisAdvices, nil
- }
-
- func GetPatientListByUpdateTime(orgID int64, syncTime int64) (patients []*models.PatientListForFaceList, total int64, err error) {
- db := readDb.Model(&models.PatientListForFaceList{}).Where("user_org_id=? AND status=1 AND avatar <> 'https://images.shengws.com/201809182128222.png' AND avatar <> 'https://images.shengws.com/201809182128111.png' AND avatar <> ''", orgID)
-
- db = db.Where("updated_time >= ?", syncTime)
-
- err = db.Count(&total).Find(&patients).Error
- return
- }
-
- func GetPatientListBySchedules(orgID int64, syncTime int64) (patients []*models.SchedulePatients, total int64, err error) {
- db := readDb.Model(&models.SchedulePatients{}).Where("user_org_id=? AND status=1 AND schedule_date = ?", orgID, syncTime).Preload("Patient", "status = 1 AND user_org_id = ? ", orgID)
- err = db.Count(&total).Find(&patients).Error
- return
- }
-
- func GetPatientListBySchedulesFind(orgID int64, syncTime int64, patient_name string) (patients []*models.SchedulePatients, total int64, err error) {
- db := readDb.Model(&models.SchedulePatients{}).Where("user_org_id=? AND status=1 AND schedule_date = ?", orgID, syncTime).Preload("Patient", "status = 1 AND user_org_id = ? and name like ? ", orgID, "%"+patient_name+"%")
- err = db.Count(&total).Find(&patients).Error
- return
- }
-
- func GetPatientListById(orgID int64, patientId int64) (patients models.PatientListForFace, err error) {
- err = readDb.Model(&models.PatientListForFaceList{}).Where("user_org_id=? and id = ? and status=1", orgID, patientId).First(&patients).Error
- return
- }
-
- func GetPatientCount(orgID int64) (total int64) {
- readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Count(&total)
- return
- }
- func GetLapsetoPatientCount(orgID int64, lapseto int64) (total int64) {
- readDb.Model(&models.Patients{}).Where("user_org_id=? and lapseto=? and status=1", orgID, lapseto).Count(&total)
- return
- }
-
- func ChechLastDialysisNo(orgID int64) (dialysisNo int64) {
- var patient models.Patients
- if orgID == 10278 {
- err := readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=?", orgID).Order("id desc").First(&patient).Error
- if err != nil {
- return
- }
- } else {
- err := readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=?", orgID).Order("dialysis_no desc").First(&patient).Error
- if err != nil {
- return
- }
- }
-
- if patient.ID == 0 {
- return
- }
- dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
- return
- }
-
- func FindPatientByDialysisNo(orgID int64, dialysisNo string) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=? and lapseto = 1", orgID, dialysisNo).First(&patient).Error
- return
- }
-
- func FindPatientByIdCardNo(orgID int64, idCardNo string) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=?", orgID, idCardNo).First(&patient).Error
- return
- }
- func FindPatientByMobile(orgID int64, mobile string) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("phone=? and user_org_id=? and status=1", mobile, orgID).First(&patient).Error
- return
- }
-
- func FindPatientById(orgID int64, id int64) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
- return
- }
-
- func FindPatientByIdTwo(orgID int64, id int64) (patient models.XtPatientsNew, err error) {
-
- err = readDb.Model(&models.XtPatientsNew{}).Where("blood_id = ? and user_org_id = ? and status =1", id, orgID).First(&patient).Error
- return
- }
-
- // func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients, err error) {
- // err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
- // return
- // }
- func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
- patient_info_str, _ := redis.Get(key).Result()
- redis.Set(key, "", time.Second)
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return patient, nil
- } else {
- return patient, err
- }
- } else {
- if patient.ID > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patient)
-
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return patient, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
-
- if patient_info_str == "null" {
- return patient, nil
- } else {
- json.Unmarshal([]byte(patient_info_str), &patient)
- return patient, nil
- }
-
- }
- }
-
- func FindPatientWithDeviceByNo(orgID int64, no string, time int64) (patient models.SchedualPatient2, err error) {
- err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
- return db.Preload("DeviceNumber", "org_id = ?", orgID).
- Preload("DeviceZone", "org_id = ?", orgID).
- Where("user_org_id = ? AND schedule_date = ? ", orgID, time)
- }).Preload("InfectiousDiseases", "status = 1").Where("user_org_id=? and dialysis_no = ? and status = 1 ", orgID, no).First(&patient).Error
- return
- }
-
- func FindPatientWithDeviceByPatientId(orgID int64, id int64, time int64) (patient models.SchedualPatient2, err error) {
- err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
- return db.Preload("DeviceNumber", "org_id = ?", orgID).
- Preload("DeviceZone", "org_id = ?", orgID).
- Where("user_org_id = ? AND schedule_date = ? ", orgID, time)
- }).Preload("InfectiousDiseases", "status = 1").Where("user_org_id=? and id = ? and status = 1 ", orgID, id).First(&patient).Error
- return
- }
-
- func CreatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
-
- user, _ := GetSgjUserByMobild(patient.Phone)
- customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
-
- utx := writeDb.Begin()
- btx := writeUserDb.Begin()
-
- if user.ID == 0 {
-
- user.Mobile = patient.Phone
- user.Avatar = patient.Avatar
- user.AvatarThumb = patient.Avatar
- user.Birthday = patient.Birthday
- user.Username = patient.Name
- user.Gender = patient.Gender
- user.Sources = 11
- user.Introduce = patient.Remark
- user.Status = 1
- user.UpdatedTime = patient.UpdatedTime
- user.CreatedTime = patient.CreatedTime
- err = btx.Create(&user).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- patient.UserId = user.ID
-
- if customer == nil {
- err = btx.Create(&models.SgjCustomer{
- UserOrgId: patient.UserOrgId,
- UserId: user.ID,
- Mobile: patient.Phone,
- Name: patient.Name,
- Gender: patient.Gender,
- Birthday: patient.Birthday,
- Sources: 11,
- Status: 1,
- CreatedTime: patient.CreatedTime,
- UpdatedTime: patient.UpdatedTime,
- Avatar: patient.Avatar,
- Remark: patient.Remark,
- }).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
-
- err = utx.Create(patient).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
-
- var lapseto models.PatientLapseto
- lapseto.PatientId = patient.ID
- lapseto.LapsetoType = patient.Lapseto
- lapseto.CreatedTime = patient.CreatedTime
- lapseto.UpdatedTime = patient.CreatedTime
- lapseto.Status = 1
- lapseto.LapsetoTime = patient.CreatedTime
-
- err = utx.Create(&lapseto).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
-
- if len(contagions) > 0 {
- thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, contagion := range contagions {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, patient.CreatedTime)
- insertData = append(insertData, patient.UpdatedTime)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- if len(diseases) > 0 {
- thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, disease := range diseases {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, disease)
- insertData = append(insertData, 1)
- insertData = append(insertData, patient.CreatedTime)
- insertData = append(insertData, patient.UpdatedTime)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- utx.Commit()
- btx.Commit()
-
- return
- }
-
- func GetLastPatientData(orgid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1", orgid).Last(&patients).Error
- return patients, err
- }
-
- func CreatePatientsNew(patientsNew *models.XtPatientsNew) error {
-
- err := XTWriteDB().Model(&patientsNew).Create(&patientsNew).Error
- return err
- }
-
- func CreateAllergic(allergic models.XtPatientAllergic) error {
-
- err := XTWriteDB().Create(&allergic).Error
-
- return err
- }
-
- func EditPatientLapseto(patient *models.Patients, lapseto *models.PatientLapseto) (err error) {
- utx := writeDb.Begin()
- err = utx.Model(&models.Patients{}).Where("id=?", patient.ID).Update(map[string]interface{}{"lapseto": patient.Lapseto, "out_reason": patient.OutReason, "death_time": patient.DeathTime, "patient_start_time": patient.PatientStartTime, "patient_end_time": patient.PatientEndTime, "patient_address": patient.PatientAddress}).Error
- //err = utx.Model(&models.PatientLapseto{}).Where("id=?", patient.ID).Update(map[string]interface{}{"lapseto_type": patient.Lapseto, "lapseto_time": time.Now().Unix(), "updated_time": time.Now().Unix()}).Error
- if err != nil {
- utx.Rollback()
- return
- }
- err = utx.Create(lapseto).Error
- if err != nil {
- utx.Rollback()
- return
- }
- // 删除排班和排班模板信息
- if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
- now := time.Now()
- deleteScheduleErr := utx.Model(&models.PatientSchedule{}).Where("patient_id = ? AND schedule_date >= ? AND status = 1", patient.ID, lapseto.LapsetoTime).Updates(map[string]interface{}{
- "status": 0,
- "updated_time": now.Unix(),
- }).Error
- if deleteScheduleErr != nil {
- utx.Rollback()
- err = deleteScheduleErr
- return
- }
-
- deleteSchTempItemErr := utx.Model(&models.PatientScheduleTemplateItem{}).Where("patient_id = ? AND status = 1", patient.ID).Updates(map[string]interface{}{
- "status": 0,
- "mtime": now.Unix(),
- }).Error
- if deleteSchTempItemErr != nil {
- utx.Rollback()
- err = deleteSchTempItemErr
- return
- }
- }
- utx.Commit()
- return
- }
-
- func UpdatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
- // if len(contagions) > 0 || len(diseases) > 0 {
- utx := writeDb.Begin()
- err = utx.Save(patient).Error
- if err != nil {
- utx.Rollback()
- return
- }
- err = utx.Model(&models.InfectiousDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
- fmt.Println("err", err)
- if err != nil {
- utx.Rollback()
- return
- }
- if len(contagions) > 0 && patient.IsInfectious == 2 {
- thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, contagion := range contagions {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, time.Now().Unix())
- insertData = append(insertData, time.Now().Unix())
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
-
- err = utx.Model(&models.ChronicDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
- if err != nil {
- utx.Rollback()
- return
- }
- if len(diseases) > 0 {
- thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, disease := range diseases {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, disease)
- insertData = append(insertData, 1)
- insertData = append(insertData, time.Now().Unix())
- insertData = append(insertData, time.Now().Unix())
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
-
- // } else {
- // err = writeDb.Save(patient).Error
- // }
- return
- }
-
- func UpdatePatientLapseto(patientid int64, lapseto models.PatientLapseto) error {
- err := XTWriteDB().Model(&lapseto).Where("patient_id = ?", patientid).Updates(map[string]interface{}{"lapseto_type": lapseto.LapsetoType, "lapseto_time": time.Now().Unix(), "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func UpdatepatientTwo(patientsNew *models.XtPatientsNew, id int64) error {
-
- err := XTWriteDB().Model(&patientsNew).Where("blood_id = ?", id).Update(map[string]interface{}{"user_org_id": patientsNew.UserOrgId, "user_id": patientsNew.UserId, "avatar": patientsNew.Avatar, "patient_type": patientsNew.Avatar, "dialysis_no": patientsNew.DialysisNo, "admission_number": patientsNew.AdmissionNumber, "source": patientsNew.Source, "lapseto": patientsNew.Lapseto, "partition_id": patientsNew.PartitionId, "bed_id": patientsNew.BedId, "name": patientsNew.Name, "alias": patientsNew.Alias, "gender": patientsNew.Gender, "marital_status": patientsNew.MaritalStatus, "id_card_no": patientsNew.IdCardNo, "birthday": patientsNew.Birthday, "reimbursement_way_id": patientsNew.ReimbursementWayId, "health_care_type": patientsNew.HealthCareType, "health_care_no": patientsNew.HealthCareType, "health_care_due_date": patientsNew.HealthCareType, "height": patientsNew.Height, "blood_type": patientsNew.BloodType, "rh": patientsNew.Rh, "health_care_due_alert_date": patientsNew.HealthCareDueAlertDate, "education_level": patientsNew.EducationLevel, "profession": patientsNew.Profession, "phone": patientsNew.Phone, "home_telephone": patientsNew.HomeTelephone, "relative_phone": patientsNew.RelativePhone, "relative_relations": patientsNew.RelativeRelations, "home_address": patientsNew.HomeAddress, "work_unit": patientsNew.WorkUnit, "unit_address": patientsNew.UnitAddress, "children": patientsNew.Children, "receiving_date": patientsNew.ReceivingDate, "is_hospital_first_dialysis": patientsNew.IsHospitalFirstDialysis, "first_dialysis_date": patientsNew.FirstDialysisDate, "first_dialysis_hospital": patientsNew.FirstDialysisHospital, "predialysis_condition": patientsNew.PredialysisCondition, "pre_hospital_dialysis_frequency": patientsNew.PreHospitalDialysisFrequency, "pre_hospital_dialysis_times": patientsNew.PreHospitalDialysisFrequency, "hospital_first_dialysis_date": patientsNew.HospitalFirstDialysisDate, "induction_period": patientsNew.InductionPeriod, "initial_dialysis": patientsNew.InitialDialysis, "total_dialysis": patientsNew.TotalDialysis, "attending_doctor_id": patientsNew.AttendingDoctorId, "head_nurse_id": patientsNew.HeadNurseId, "evaluate": patientsNew.Evaluate, "diagnose": patientsNew.Diagnose, "remark": patientsNew.Remark, "registrars_id": patientsNew.RegistrarsId, "registrars": patientsNew.Registrars, "qr_code": patientsNew.QrCode, "binding_state": patientsNew.BindingState, "patient_complains": patientsNew.PatientComplains, "present_history": patientsNew.PresentHistory, "past_history": patientsNew.PastHistory, "temperature": patientsNew.Temperature,
- "pulse": patientsNew.Pulse, "respiratory": patientsNew.Respiratory, "sbp": patientsNew.Sbp, "dbp": patientsNew.Dbp, "nation": patientsNew.Nation, "native_place": patientsNew.NativePlace, "age": patientsNew.Age, "infectious_next_record_time": patientsNew.InfectiousNextRecordTime, "is_infectious": patientsNew.IsInfectious, "remind_cycle": patientsNew.RemindCycle, "response_result": patientsNew.ResponseResult, "is_open_remind": patientsNew.IsOpenRemind, "first_treatment_date": patientsNew.FirstTreatmentDate, "dialysis_age": patientsNew.DialysisAge, "expense_kind": patientsNew.ExpenseKind, "tell_phone": patientsNew.ExpenseKind, "contact_name": patientsNew.ContactName, "blood_patients": patientsNew.BloodPatients, "slow_patients": patientsNew.SlowPatients, "member_patients": patientsNew.MemberPatients, "ecommer_patients": patientsNew.EcommerPatients, "troble_shoot": patientsNew.TrobleShoot, "sch_remark": patientsNew.SchRemark, "treatment_plan": patientsNew.TreatmentPlan, "record_number": patientsNew.RecordNumber, "patient_start_time": patientsNew.PatientStartTime, "patient_end_time": patientsNew.PatientEndTime, "infectious_remark": patientsNew.InfectiousRemark, "allergic_history": patientsNew.AllergicHistory, "patient_address": patientsNew.PatientAddress, "print_date": patientsNew.PrintDate, "patient_type:": patientsNew.PatientType}).Error
- return err
- }
-
- func GetLastInfectionRecord(id int64, org_id int64, project_id int64, date int64) (inspection models.Inspection, err error) {
- err = readDb.Model(&models.Inspection{}).Where("patient_id=? and status=1 and org_id = ? and project_id = ? AND inspect_date = ? ", id, org_id, project_id, date).Last(&inspection).Error
- return
- }
-
- func GetAllInfectionRecord(date int64, org_id int64, patient_id int64, project_id int64) (inspection []*models.Inspection, err error) {
- err = readDb.Model(&models.Inspection{}).Where("patient_id=? and status=1 and org_id = ? and project_id = ? and inspect_date = ?", patient_id, org_id, project_id, date).Find(&inspection).Error
- return
- }
-
- func GetPatientDiseases(id int64) []int64 {
- var dis []models.ChronicDiseases
- ids := make([]int64, 0)
- err := readDb.Model(&models.ChronicDiseases{}).Where("patient_id=? and status=1", id).Find(&dis).Error
- if err != nil || len(dis) == 0 {
- return ids
- }
- for _, item := range dis {
- ids = append(ids, item.DiseaseId)
- }
- return ids
- }
- func GetPatientContagions(id int64) []int64 {
- var cis []models.InfectiousDiseases
- ids := make([]int64, 0)
- err := readDb.Model(&models.InfectiousDiseases{}).Where("patient_id=? and status=1", id).Find(&cis).Error
- if err != nil || len(cis) == 0 {
- return ids
- }
- for _, item := range cis {
- ids = append(ids, item.DiseaseId)
- }
- return ids
- }
-
- func FindPatientDialysisSolutionByMode(orgID int64, patientID, modeId int64) (solution models.DialysisSolution, err error) {
- err = readDb.Model(&models.DialysisSolution{}).Where("user_org_id=? and patient_id=? and mode_id=? and parent_id=0 and status=1", orgID, patientID, modeId).First(&solution).Error
- return
- }
-
- func FindPatientDialysisSolution(orgID int64, id int64) (solution models.DialysisSolution, err error) {
- err = readDb.Model(&models.DialysisSolution{}).Where("id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
- return
- }
-
- func FindPatientDialysisSolutionChild(orgID int64, id int64) (solution models.DialysisSolution, err error) {
- err = readDb.Model(&models.DialysisSolution{}).Where("parent_id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
- return
- }
-
- func CreatePatientDialysisSolution(solution *models.DialysisSolution) (err error) {
- err = writeDb.Create(solution).Error
- return
- }
-
- func UpdatePatientDialysisSolution(solution *models.DialysisSolution) (err error) {
- err = writeDb.Save(solution).Error
- return
- }
-
- // GetPatientDialysisSolutionList 返回患者透析方案的列表
- func GetPatientDialysisSolutionList(orgID int64, patientID int64, page, limit int64) (solutions []*models.DialysisSolution, total int64, err error) {
-
- offset := (page - 1) * limit
- db := readDb.Table("xt_dialysis_solution as ds").Where("ds.status=1")
- if orgID > 0 {
- db = db.Where("ds.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("ds.patient_id=?", patientID)
- }
- db = db.Count(&total).Offset(offset).Limit(limit)
-
- err = db.Order("id desc").Find(&solutions).Error
- if err != nil {
- return
- }
- if len(solutions) > 0 {
- nilNameIds := make([]int64, 0)
- for _, solution := range solutions {
- if len(solution.ModeName) == 0 {
- nilNameIds = append(nilNameIds, solution.ModeId)
- }
- }
- if len(nilNameIds) > 0 {
- var modes []*models.TreatmentMode
- err = readDb.Model(&models.TreatmentMode{}).Where("id IN (?)", nilNameIds).Find(&modes).Error
- if err != nil {
- return
- }
-
- modesMap := make(map[int64]models.TreatmentMode, 0)
- for _, mode := range modes {
- modesMap[mode.ID] = *mode
- }
- for index, solution := range solutions {
- if _, exixt := modesMap[solution.ModeId]; exixt && len(solution.ModeName) == 0 {
- solutions[index].ModeName = modesMap[solution.ModeId].Name
- }
- }
- }
- }
- return
- }
-
- // GetPatientDryWeightAdjustList 返回患者调整干体重的列表
- func GetPatientDryWeightAdjustList(orgID int64, patientID int64, page int64, limit int64) (weights []*models.DryWeightAdjust, total int64, err error) {
- db := readDb.Table("xt_dry_weight_adjust as dwa").Where("dwa.status=1")
- if orgID > 0 {
- db = db.Where("dwa.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("dwa.patient_id=?", patientID)
- }
-
- db = db.Select("dwa.id, dwa.user_org_id, dwa.patient_id, dwa.weight, dwa.adjusted_value, dwa.doctor, dwa.registrars_id, dwa.remark, dwa.status, dwa.created_time, dwa.updated_time").Count(&total).Order("id desc")
-
- if page > 0 && limit > 0 {
- offset := (page - 1) * limit
- db = db.Offset(offset).Limit(limit)
- }
- err = db.Find(&weights).Error
- return
- }
-
- func CreateDryWeightAdjust(m *models.DryWeightAdjust) (err error) {
- err = writeDb.Create(m).Error
- return
- }
-
- func FindPatientLastDryWeightAdjust(orgID int64, id int64) (weight models.DryWeightAdjust, err error) {
- err = readDb.Model(&models.DryWeightAdjust{}).Where("user_org_id=? and patient_id=? and status=1", orgID, id).Order("id desc").First(&weight).Error
- return
- }
-
- func UpdateDoctorAdviceById(id int64, prescribing_number float64, single_dose float64) error {
-
- err := XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=? and status =1", id).Updates(map[string]interface{}{"prescribing_number": prescribing_number, "single_dose": single_dose}).Error
- return err
- }
-
- func CreateDoctorAdvice(m *models.DoctorAdvice) (err error) {
- return writeDb.Create(m).Error
- }
- func GetMaxAdviceGroupID(orgId int64) (group int64) {
- var advice models.DoctorAdvice
- err := readDb.Table("xt_doctor_advice").Where("user_org_id=?", orgId).Select("max(groupno) as groupno").First(&advice).Error
- if err != nil {
- fmt.Println(err)
- group = 0
- }
- group = advice.GroupNo
- return
- }
-
- func CreateGroupAdvice(orgId int64, group int64, advices []*models.GroupAdvice) (err error) {
- if group == 0 {
- group = GetMaxAdviceGroupID(orgId) + 1
- }
-
- tx := writeDb.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- for _, advice := range advices {
- advice.GroupNo = group
- if err = tx.Create(advice).Error; err != nil {
- tx.Rollback()
- return
- }
- }
- tx.Commit()
- return
- }
-
- func CreateMGroupAdvice(orgId int64, advices []*models.GroupAdvice, groupNo int64) (list []*models.GroupAdvice, err error) {
- if groupNo <= 0 {
- group := GetMaxAdviceGroupID(orgId)
- groupNo = group + 1
- }
- tx := writeDb.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- for _, advice := range advices {
- advice.GroupNo = groupNo
- if err = tx.Create(advice).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, advice)
- if len(advice.Children) > 0 {
- for _, child := range advice.Children {
- child.GroupNo = groupNo
- child.ParentId = advice.ID
- fmt.Println(child)
- if err = tx.Create(&child).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, child)
- }
- }
-
- }
- tx.Commit()
- return
- }
-
- func CreateMGroupAdviceOne(orgId int64, advices []*models.GroupAdvice, groupNo int64) (list []*models.GroupAdvice, err error) {
- if groupNo <= 0 {
- group := GetMaxAdviceGroupID(orgId)
- groupNo = group + 1
- }
- tx := writeDb.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- for _, advice := range advices {
- advice.GroupNo = advice.GroupNo
- if err = tx.Create(advice).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, advice)
- if len(advice.Children) > 0 {
- for _, child := range advice.Children {
-
- child.GroupNo = advice.GroupNo
- child.ParentId = advice.ID
- fmt.Println(child)
- if err = tx.Create(&child).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, child)
- }
- }
-
- }
- tx.Commit()
- return
- }
-
- func UpdateDoctorAdvice(m *models.DoctorAdvice) (err error) {
- return writeDb.Save(m).Error
- }
-
- func StopGroupAdvice(orgId int64, groupNo int64, m *models.DoctorAdvice) (err error) {
- err = writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? and groupno=?", orgId, groupNo).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "StopState": 1, "StopReason": m.StopReason, "StopDoctor": m.StopDoctor, "StopTime": m.StopTime}).Error
- if err != nil {
- return
- }
- return
- }
-
- func StopDoctorAdvice(m *models.DoctorAdvice) (err error) {
-
- ut := writeDb.Begin()
- err = ut.Save(m).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DoctorAdvice{}).Where("parent_id=?", m.ID).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "StopState": 1, "StopReason": m.StopReason, "StopDoctor": m.StopDoctor, "StopTime": m.StopTime, "Modifier": m.Modifier}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func DeleteSolution(m *models.DialysisSolution) (err error) {
-
- if m.ParentId > 0 {
- return writeDb.Save(m).Error
- } else {
- ut := writeDb.Begin()
- err = ut.Save(m).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DialysisSolution{}).Where("parent_id=?", m.ID).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- }
-
- return
- }
-
- func DeleteDoctorAdvice(m *models.DoctorAdvice) (err error) {
-
- if m.ParentId > 0 {
- return writeDb.Save(m).Error
- } else {
- ut := writeDb.Begin()
- err = ut.Save(m).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DoctorAdvice{}).Where("parent_id=? AND user_org_id = ?", m.ID, m.UserOrgId).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0, "Modifier": m.Modifier}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- }
-
- return
- }
- func DeleteGroupAdvice(orgId int64, groupNo int64, admin_user_id int64) (err error) {
- err = writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ?", orgId, groupNo).Update(map[string]interface{}{"UpdatedTime": time.Now().Unix(), "Status": 0, "Modifier": admin_user_id}).Error
- if err != nil {
- return
- }
- return
- }
-
- func DeleteGroupAdviceOne(orgId int64, groupNo int64, admin_user_id int64) (err error) {
- err = writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ? and status =1 and advice_type=1", orgId, groupNo).Update(map[string]interface{}{"UpdatedTime": time.Now().Unix(), "Status": 0, "Modifier": admin_user_id}).Error
- if err != nil {
- return
- }
- return
- }
-
- func FindDoctorAdvice(orgID, id int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id = ? and user_org_id=? and status = 1", id, orgID).First(&advice).Error
- return
- }
-
- func FindDoctorAdviceOne(orgID, patient_id int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id=? and status = 1", patient_id, orgID).First(&advice).Error
- return
- }
-
- func FindDoctorAdviceTwo(ids []string, orgID int64) (advice []*models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id in(?) and user_org_id=? and status = 1", ids, orgID).First(&advice).Error
- return
- }
-
- func FindHisDoctorAdvice(orgID, id int64) (advice models.HisDoctorAdviceInfo, err error) {
- err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and user_org_id=? and status = 1", id, orgID).First(&advice).Error
- return
- }
-
- func FindHisDoctorAdviceTwo(ids []string, orgID int64) (advice []*models.HisDoctorAdviceInfo, err error) {
- err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id in(?) and user_org_id=? and status = 1", ids, orgID).First(&advice).Error
- return
- }
-
- func FindHisDoctorAdviceOne(orgID, patient_id int64) (advice models.HisDoctorAdviceInfo, err error) {
- err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? and user_org_id=? and status = 1", patient_id, orgID).First(&advice).Error
- return
- }
-
- func FindDoctorAdviceByGroupNo(orgID, groupNo int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("groupno = ? and user_org_id=? and status = 1", groupNo, orgID).First(&advice).Error
- return
- }
- func GetDoctorAdviceList(orgID, patientID, advice_type, stop, start, end int64, keywords string) (advices []*models.DoctorAdvices, total int64, err error) {
-
- db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Print("table", table)
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- } else if advice_type == 0 {
- db = db.Where("x.advice_type in (?)", []int{1, 3})
- }
-
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- err = db.Group("x.id").Count(&total).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
- fmt.Print("err", err)
- return
- }
-
- func GetLongDoctorAdviceList(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64) (advices []*models.DoctorAdvices, total int64, err error) {
-
- db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Print("table", table)
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 && advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,x.push_start_time,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
- fmt.Print("err", err)
- return
- }
-
- func GetDoctorAdviceListOne(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64, delive_way_one string) (advices []*models.DoctorAdvices, total int64, err error) {
-
- db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Print("table", table)
-
- if len(delive_way_one) > 0 {
- db = db.Where("delivery_way=?", delive_way_one)
- }
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 && advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 2 && advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,x.push_start_time,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
- fmt.Print("err", err)
- return
- }
-
- func GetDoctorAdviceListTwo(orgID int64, patientID int64, advice_type int64, stop int64, start int64, end int64, keywords string, limit int64, page int64, delive_way_one string) (advices []*models.DoctorAdvices, total int64, err error) {
-
- db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println(table)
-
- if len(delive_way_one) > 0 {
- db = db.Where("delivery_way=?", delive_way_one)
- }
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
-
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,x.push_start_time,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&advices).Error
- fmt.Print("错误是什么", err)
- return
-
- }
-
- func GetDoctorAdvicePageList(orgID, patientID, advice_type, stop, start, end int64, keywords string, page, limit int64) (advices []*models.DoctorAdvice, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := readDb.Model(&models.DoctorAdvice{}).Where("status=1")
- if orgID > 0 {
- db = db.Where("user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("patient_id = ?", patientID)
- }
- if advice_type > 0 {
- db = db.Where("advice_type = ?", advice_type)
- }
- if stop == 1 {
- db = db.Where("(stop_state=? or execution_state=?) and parent_id=0", stop, stop)
- } else if stop == 2 {
- db = db.Where("stop_state=? and execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("advice_name LIKE ?", likeKey)
- }
- err = db.Count(&total).Select("id,user_org_id,patient_id,advice_type,advice_date,start_time,advice_name,advice_desc,reminder_date,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker IF(parent_id>0, parent_id, id) as advice_order").Order("advice_order desc, id").Offset(offset).Limit(limit).Scan(&advices).Error
- return
- }
- func CreateSubDoctorAdvice(advices []*models.DoctorAdvice) (err error) {
- if len(advices) > 0 {
- utx := writeDb.Begin()
- if len(advices) > 0 {
- thisSQL := "INSERT INTO xt_doctor_advice (single_dose_unit, prescribing_number, prescribing_number_unit, advice_name, advice_desc,single_dose,created_time,updated_time,patient_id,parent_id,user_org_id,record_date,advice_type,drug_spec_unit) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, advice := range advices {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, advice.SingleDoseUnit)
- insertData = append(insertData, advice.PrescribingNumber)
- insertData = append(insertData, advice.PrescribingNumberUnit)
- insertData = append(insertData, advice.AdviceName)
- insertData = append(insertData, advice.AdviceDesc)
- insertData = append(insertData, advice.SingleDose)
- insertData = append(insertData, advice.CreatedTime)
- insertData = append(insertData, advice.UpdatedTime)
- insertData = append(insertData, advice.PatientId)
- insertData = append(insertData, advice.ParentId)
- insertData = append(insertData, advice.UserOrgId)
- insertData = append(insertData, advice.RecordDate)
- insertData = append(insertData, 2)
- insertData = append(insertData, advice.DrugSpecUnit)
-
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func GetPatientDialysisRecord(orgID, patientID int64, page, limit, start, end, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
-
- offset := (page - 1) * limit
- var total int64
- var err error
- var orders []*models.PatientDialysisRecord
-
- // err = readDb.Table("xt_dialysis_order as do").
- // Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- // Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- // Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- // Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- // Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
- // Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
- // Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Count(&total).Offset(offset).Limit(limit).Order("do.dialysis_date desc").Select(" do.id, do.dialysis_date, do.user_org_id, do.patient_id, do.prescription_id, do.stage, do.remark, do.status, do.created_time, do.updated_time, s.schedule_type, s.partition_id, dz.name as partition_name").Find(&orders).Error
-
- db := readDb.Table("xt_dialysis_order as do").
- Preload("DoctorAdvice", "patient_id =? and user_org_id = ? and status =1 and advice_type =2", patientID, orgID).
- Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
- return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
- return readUserDb.Where("status = 1 and org_id=?", orgID)
- })
- }).
- Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("Device", "org_id=? and status=1", orgID).
- Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
- return readUserDb.Where("org_id=?", orgID)
- }).
- Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
- Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
- Where("do.patient_id=? and do.user_org_id=? and do.status=1 and s.status=1", patientID, orgID).Group("s.schedule_date")
-
- if start != 0 {
- db = db.Where("do.dialysis_date>=?", start)
- }
- if end != 0 {
- db = db.Where("do.dialysis_date<=?", end)
- }
- if mode_id > 0 {
- db = db.Joins("JOIN xt_dialysis_prescription as dp ON dp.patient_id=do.patient_id and dp.user_org_id = do.user_org_id and dp.record_date = do.dialysis_date")
- db = db.Where("dp.mode_id=?", mode_id)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("do.dialysis_date desc").Select("do.bed_id, do.id, do.dialysis_date, do.user_org_id, do.patient_id, do.prescription_id, do.stage, do.remark, do.status, do.created_time, do.updated_time,do.start_nurse,do.finish_nurse ,do.start_time,do.end_time,do.url,s.schedule_type, s.partition_id, dz.name as partition_name").Find(&orders).Error
-
- if len(orders) > 0 {
- ids := make([]int64, 0)
- for _, order := range orders {
- dialyzer := order.DialysisPrescription.Dialyzer
- ids = append(ids, dialyzer)
- }
- if len(ids) > 0 {
- var dialyzers []*models.DeviceNumber
- err = readDb.Model(&models.DeviceNumber{}).Where("id IN (?) and org_id=? and status=1", ids, orgID).Find(&dialyzers).Error
- if err != nil {
- return nil, 0, err
- }
-
- dialyzerMap := make(map[int64]models.DeviceNumber, 0)
- for _, item := range dialyzers {
- dialyzerMap[item.ID] = *item
- }
- for orderIndex, order := range orders {
- if _, exist := dialyzerMap[order.DialysisPrescription.Dialyzer]; exist {
- orders[orderIndex].DeviceNumber = dialyzerMap[order.DialysisPrescription.Dialyzer].Number
- }
- }
- }
- }
-
- return orders, total, err
- }
-
- func GetPatientTreatmentSummaryList(orgID, patientID, page, limit, start, end int64) (list []*models.TreatmentSummary, total int, err error) {
-
- offset := (page - 1) * limit
- fmt.Println(offset)
- fmt.Println(limit)
- db := readDb.Model(&models.TreatmentSummary{}).Where("user_org_id = ? and patient_id=?", orgID, patientID)
- if start != 0 {
- db = db.Where("assessment_date >= ?", start)
- }
- if end != 0 {
- db = db.Where("assessment_date <= ?", end)
- }
- db = db.Where("status=1")
- err = db.Count(&total).Offset(offset).Limit(limit).Order("assessment_date desc, id desc").Find(&list).Error
- return
-
- }
-
- func GetPatientScheduleList(orgID int64, patientID int64, page int64, limit int64, start int64) (schedules []*models.PatientSchedule, err error) {
- offset := (page - 1) * limit
- err = readDb.Table("xt_schedule as s").
- Preload("DeviceZone", "org_id=? and status=1", orgID).
- Preload("DeviceNumber", "org_id=? and status=1", orgID).
- Preload("TreatmentMode", "status=1").
- Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.status=1", patientID, orgID, start).
- Limit(limit).Offset(offset).Find(&schedules).Error
- return
- }
-
- func GetMonitorRecord(orgID int64, date int64, partition int64, patientId int64) ([]*models.NewVMMonitorDialysisSchedule, error) {
- var mds []*models.NewVMMonitorDialysisSchedule
-
- db := readDb.Model(&models.NewVMMonitorDialysisSchedule{})
- if date > 0 {
- db = db.Where("schedule_date = ?", date)
- }
- if partition > 0 {
- db = db.Where("partition_id = ?", partition)
- }
- if patientId > 0 {
-
- db = db.Where("patient_id = ?", patientId)
- }
-
- err = db.Where("status = 1 and user_org_id = ?", orgID).Find(&mds).Error
-
- return mds, err
- }
-
- func MobileGetMonitorsWithPatient(orgID int64, keyword string, page int) ([]*models.MonitorDialysisSchedule, error) {
- var patients []*models.Patients
- getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
- if getPatientErr != nil {
- return nil, getPatientErr
- }
- patientIDs := make([]int64, len(patients))
- for index, patient := range patients {
- patientIDs[index] = patient.ID
- }
-
- db := readDb.
- Model(&models.MonitorDialysisSchedule{}).
- Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
- Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
- Preload("TreatmentMode", "status = 1").
- Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
- Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
- Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
- Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
- Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
- Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID).
- Where("status = 1 AND user_org_id = ? AND patient_id in (?)", orgID, patientIDs)
-
- var schedules []*models.MonitorDialysisSchedule
- err := db.Offset(20 * (page - 1)).Limit(20).Order("schedule_date desc").Find(&schedules).Error
- return schedules, err
- }
-
- func GetPatientByKeyWord(orgID int64, keywords string) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID)
-
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("name LIKE ? OR dialysis_no LIKE ? OR first_letter LIKE ?", likekey, likekey, likekey).Find(&patient).Error
- } else {
- err = db.Find(&patient).Error
- }
- return
- }
-
- func FindDoctorAdviceByGoroupNo(orgID int64, groupno int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1", orgID, groupno).First(&advice).Error
- return
- }
-
- func FindOldDoctorAdvice(orgID int64, advice_id int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id = ? AND user_org_id=? AND status = 1", advice_id, orgID).First(&advice).Error
- return
- }
-
- func UpdateAdviceGroupStartTime(orgID int64, groupNO int64, startTime int64, admin_user_id int64) error {
- now := time.Now().Unix()
- err := writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND status = 1 AND execution_state <> 1 AND check_state <> 1 AND groupno = ? AND admin_user_id = ?", orgID, groupNO, admin_user_id).Updates(map[string]interface{}{
- "start_time": startTime,
- "updated_time": now,
- "modifier": admin_user_id,
- }).Error
- return err
- }
-
- func QueryPatientById(id int64) *models.Patients {
- var pat models.Patients
- err := readDb.Model(&models.Patients{}).Where("id=?", id).First(&pat).Error
- if err != nil {
-
- }
- return &pat
- }
-
- func FindAllDoctorAdviceByGoroupNo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1", orgID, groupno).Find(&advice).Error
- return
- }
-
- func FindAllDoctorAdviceByGoroupNoOne(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 and execution_state =2", orgID, groupno).Find(&advice).Error
- return
- }
-
- func FindAllDoctorAdviceByGoroupNoThree(orgID int64, groupno int64, patient_id int64, advice_date int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 and patient_id =? and advice_date =?", orgID, groupno, patient_id, advice_date).Find(&advice).Error
- return
- }
-
- func UpdateDoctorAdviceByGoroupNo(id int64, drug_id int64) error {
-
- err := XTWriteDB().Model(&models.DoctorAdvice{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"drug_id": drug_id, "drug_name_id": drug_id, "way": 1}).Error
- return err
- }
-
- func FindAllDoctorAdviceByGoroupNoTwety(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 and (drug_id >0 or drug_name_id >0)", orgID, groupno).Find(&advice).Error
- return
- }
-
- func FindDoctorAdviceByIds(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id IN (?) AND user_org_id = ? AND status = 1", ids, orgID).Find(&advice).Error
- return
- }
-
- func FindDoctorAdviceByIdsOne(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id IN (?) AND user_org_id = ? AND status = 1 and execution_state =2", ids, orgID).Find(&advice).Error
- return
- }
-
- func FindDoctorAdviceByIdsTwety(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id IN (?) AND user_org_id = ? AND status = 1 and (drug_id >0 or drug_name_id >0)", ids, orgID).Find(&advice).Error
- return
- }
-
- func GetBatchDoctorAdviceList(ids []string, user_org_id int64) (advice []*models.DoctorAdvice, err error) {
-
- err = XTReadDB().Where("id in(?) and user_org_id = ? and status =1", ids, user_org_id).Find(&advice).Error
-
- return advice, err
- }
-
- func BatchDeleteDoctorAdvice(ids []string, user_id int64) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix(), "modifier": user_id}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix(), "modifier": user_id}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return err
-
- }
-
- func FindAdviceByGoroupNo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 AND parent_id = 0", orgID, groupno).Find(&advice).Error
- return
- }
-
- func UpdateDoctorAdviceAndSubAdvice(m *models.DoctorAdvice) (err error) {
- ut := writeDb.Begin()
- err = ut.Save(m).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?)", m.ID).Updates(map[string]interface{}{"start_time": m.StartTime, "groupno": m.GroupNo, "updated_time": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return err
-
- }
-
- func GetAllWaitRemindPatient(org_id int64, page int64, limit int64) (total int64, patient []*models.Patients, err error) {
- type Total struct {
- Count int64
- }
- var totals Total
-
- offset := (page - 1) * limit
- err = readDb.Raw("select * from xt_patients where user_org_id = ? AND lapseto = 1 AND infectious_next_record_time > 0 AND status = 1 AND date_sub(DATE_FORMAT(date(from_unixtime(`xt_patients`.`infectious_next_record_time`)),'%Y-%m-%d'), interval 7 day) <= now() Order by infectious_next_record_time", org_id).Offset(offset).Limit(limit).Scan(&patient).Error
- readDb.Raw("select Count(id) as count from xt_patients where user_org_id = ? AND lapseto = 1 AND infectious_next_record_time > 0 AND status = 1 AND date_sub(DATE_FORMAT(date(from_unixtime(`xt_patients`.`infectious_next_record_time`)),'%Y-%m-%d'), interval 7 day) <= now() Order by infectious_next_record_time", org_id).Scan(&totals)
-
- return totals.Count, patient, err
- }
-
- func UpdatePatientRemindStatus(patient_id int64, remind int64, org_id int64) (err error) {
- err = writeDb.Model(&models.Patients{}).Where("status = 1 AND id = ? AND user_org_id = ?", patient_id, org_id).Updates(map[string]interface{}{"is_open_remind": remind}).Error
- return
- }
-
- func CreatePatientWeightAdjust(m *models.SgjPatientDryweight) (err error) {
- err = writeDb.Create(m).Error
- return
- }
-
- func GetPatientAssesmentBefor(patient_id int64, assessment_date int64, org_id int64) (models.XtAssessmentBeforeDislysis, error) {
-
- beforeDislysis := models.XtAssessmentBeforeDislysis{}
-
- err := XTReadDB().Where("patient_id = ? and assessment_date = ? and user_org_id = ? and status=1", patient_id, assessment_date, org_id).Find(&beforeDislysis).Error
-
- return beforeDislysis, err
- }
-
- func GetPatientDialysisPrescription(patient_id int64, record_date int64, org_id int64) (models.XtDialysisPrescription, error) {
-
- prescription := models.XtDialysisPrescription{}
-
- err := XTReadDB().Where("patient_id = ? and record_date = ? and user_org_id = ? and status=1", patient_id, record_date, org_id).Find(&prescription).Error
-
- return prescription, err
- }
-
- func UpdatePatientAssesmentBefor(id int64, dry_weight float64) (models.XtAssessmentBeforeDislysis, error) {
-
- beforeDislysis := models.XtAssessmentBeforeDislysis{}
- err := XTWriteDB().Model(&beforeDislysis).Where("id = ? and status=1", id).Update(map[string]interface{}{"dry_weight": dry_weight}).Error
-
- return beforeDislysis, err
- }
-
- func UpdatePatientDialysisPrscription(id int64, dewater_amount float64) (models.XtDialysisPrescription, error) {
-
- prescription := models.XtDialysisPrescription{}
-
- err := XTWriteDB().Model(&prescription).Where("id = ? and status =1", id).Update(map[string]interface{}{"target_ultrafiltration": dewater_amount, "prescription_water": dewater_amount}).Error
-
- return prescription, err
- }
-
- func FindLastDryWeightAdjust(orgID int64, id int64) (weight models.SgjPatientDryweight, err error) {
- err = readDb.Model(&models.SgjPatientDryweight{}).Where("user_org_id=? and patient_id=? and status=1", orgID, id).Order("id desc").First(&weight).Error
- return
- }
-
- func GetSchedualPatientByKeyWord(orgID int64, keywords string, date int64) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1 ", orgID)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(name LIKE ? OR dialysis_no LIKE ?) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = xt_patients.id AND d.user_org_id = xt_patients.user_org_id)", likekey, likekey, date).Find(&patient).Error
- } else {
- err = db.Find(&patient).Error
- }
- return
- }
-
- func GetPatientScheduleOne(patientid int64, nowdate int64, orgid int64) (models.XtSchedule, error) {
- schedule := models.XtSchedule{}
- err := XTReadDB().Model(&schedule).Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status =1", patientid, nowdate, orgid).Find(&schedule).Error
- return schedule, err
- }
-
- func CreateExportPatient(patient *models.Patients, contagions []int64, org_creator int64) (err error) {
- user, _ := GetSgjUserByMobild(patient.Phone)
- customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
- utx := writeDb.Begin()
- btx := writeUserDb.Begin()
- if user.ID == 0 {
- user.Mobile = patient.Phone
- user.Avatar = patient.Avatar
- user.AvatarThumb = patient.Avatar
- user.Birthday = patient.Birthday
- user.Username = patient.Name
- user.Gender = patient.Gender
- user.Sources = 11
- user.Introduce = patient.Remark
- user.Status = 1
- user.UpdatedTime = patient.UpdatedTime
- user.CreatedTime = patient.CreatedTime
- err = btx.Create(&user).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- patient.UserId = user.ID
-
- if customer == nil {
- err = btx.Create(&models.SgjCustomer{
- UserOrgId: patient.UserOrgId,
- UserId: user.ID,
- Mobile: patient.Phone,
- Name: patient.Name,
- Gender: patient.Gender,
- Birthday: patient.Birthday,
- Sources: 11,
- Status: 1,
- CreatedTime: patient.CreatedTime,
- UpdatedTime: patient.UpdatedTime,
- Avatar: patient.Avatar,
- Remark: patient.Remark,
- }).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
-
- err = utx.Create(patient).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
-
- if patient.DryWeight > 0 {
- var dryWeight models.SgjPatientDryweight
- dryWeight.PatientId = patient.ID
- dryWeight.UserOrgId = patient.UserOrgId
- dryWeight.Status = 1
- dryWeight.AdjustedValue = "/"
- dryWeight.Creator = org_creator
- dryWeight.UserId = org_creator
- dryWeight.Ctime = time.Now().Unix()
- dryWeight.Mtime = time.Now().Unix()
- dryWeight.DryWeight = patient.DryWeight
- dryWeight.Remakes = ""
- err = utx.Create(&dryWeight).Error
- }
-
- var lapseto models.PatientLapseto
- lapseto.PatientId = patient.ID
- lapseto.LapsetoType = patient.Lapseto
- lapseto.CreatedTime = patient.CreatedTime
- lapseto.UpdatedTime = patient.CreatedTime
- lapseto.Status = 1
- lapseto.LapsetoTime = patient.CreatedTime
-
- err = utx.Create(&lapseto).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
-
- if len(contagions) > 0 {
- thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, contagion := range contagions {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, patient.CreatedTime)
- insertData = append(insertData, patient.UpdatedTime)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- patientsNew := models.XtPatientsNew{
- Name: patient.Name,
- Gender: patient.Gender,
- Phone: patient.Phone,
- IdCardNo: patient.IdCardNo,
- FirstDialysisDate: patient.FirstDialysisDate,
- Source: patient.Source,
- Lapseto: patient.Lapseto,
- IsInfectious: patient.IsInfectious,
- DialysisNo: patient.DialysisNo,
- Height: patient.Height,
- HomeAddress: patient.HomeAddress,
- IsExcelExport: 1,
- BloodPatients: 1,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UserOrgId: patient.UserOrgId,
- BloodId: patient.ID,
- Avatar: "https://images.shengws.com/201809182128111.png",
- }
-
- err = utx.Create(&patientsNew).Error
-
- record := models.XtPatientLaspseRecord{
- PatientId: patient.ID,
- RecordDate: time.Now().Unix(),
- LapseDate: time.Now().Unix(),
- LapseType: 1,
- LapseClass: 0,
- LapseReason: "",
- AdminUserId: org_creator,
- Remark: "",
- UserOrgId: patient.UserOrgId,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: "转入",
- HisType: 0,
- HisZone: "",
- HisBed: "",
- }
- err = utx.Create(&record).Error
-
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- utx.Commit()
- btx.Commit()
-
- return
- }
-
- func FindPatientPhoneIsExist(phone string, org_id int64) (count int64) {
- readDb.Model(&models.Patients{}).Where("user_org_id = ? AND phone = ? AND status = 1", org_id, phone).Count(&count)
- return
- }
-
- func FindPatientIdCardNoIsExist(id_card_no string, org_id int64) (count int64) {
- readDb.Model(&models.Patients{}).Where("user_org_id = ? AND id_card_no = ? AND status = 1", org_id, id_card_no).Count(&count)
- return
- }
-
- func CreateExportErrLog(log *models.ExportErrLog) {
- writeDb.Create(&log)
- return
- }
-
- func FindPatientExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 1", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func FindPatientExportLogOne(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 4", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func FindPatientExportLogTwo(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 5", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func FindPatientExportLogThree(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 6", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func CreateExportLog(log *models.ExportLog) {
- writeDb.Create(&log)
- }
-
- func UpdateDoctorEditAdvice(advice models.XtDoctorAdvice, orgid int64, groupno int64, date int64, patientid int64) error {
-
- err := XTWriteDB().Model(&advice).Where("user_org_id = ? and groupno = ? and advice_date = ? and patient_id = ?", orgid, groupno, date, patientid).Update(map[string]interface{}{"start_time": advice.StartTime, "updated_time": advice.UpdatedTime}).Error
- return err
- }
-
- func GetPatientsByKey(orgID int64, keywords string) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1 ", orgID)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(name LIKE ? OR dialysis_no LIKE ? OR first_letter LIKE ?)", likekey, likekey, likekey).Find(&patient).Error
- } else {
- err = db.Find(&patient).Error
- }
- return
- }
-
- func FindAllDoctorAdviceByGoroupNoTwo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 AND execution_state = 2", orgID, groupno).Find(&advice).Error
- return
- }
-
- func FindDoctorAdviceByIdsTwo(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND status = 1 AND execution_state = 2 AND (id IN (?) OR parent_id IN (?))", orgID, ids, ids).Find(&advice).Error
- return
- }
-
- func CreateHisGroupAdvice(orgId int64, advices []*models.HisGroupAdvice, groupNo int64) (list []*models.HisGroupAdvice, err error) {
- if groupNo <= 0 {
- group := GetMaxAdviceGroupID(orgId)
- groupNo = group + 1
- }
- tx := writeDb.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- for _, advice := range advices {
- advice.Groupno = groupNo
- if err = tx.Create(advice).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, advice)
- if len(advice.Children) > 0 {
- for _, child := range advice.Children {
- child.Groupno = groupNo
- child.ParentId = advice.ID
- fmt.Println(child)
- if err = tx.Create(&child).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, child)
- }
- }
-
- }
- tx.Commit()
- return
- }
-
- func GetDialysisCount(orgid int64, partitionid int64) (order []*models.BloodDialysisOrderCount, err error) {
-
- db := XTReadDB().Table("xt_dialysis_order as o")
- if partitionid == 0 {
- db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1", orgid).Group("o.patient_id").Scan(&order)
- }
-
- if partitionid > 0 {
- db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and x.partition_id = ? and x.schedule_date = o.dialysis_date and x.status = 1", orgid, partitionid).Group("o.patient_id").Scan(&order)
- }
- return order, err
- }
-
- func UpdatePatientDialysisSolutionOne(patientid int64, orgid int64, prescription *models.DialysisPrescription, timenow int64) error {
-
- err = XTWriteDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and record_date = ? ", patientid, orgid, timenow).Updates(map[string]interface{}{"dialyzer": prescription.Dialyzer, "anticoagulant": prescription.Anticoagulant, "mode_id": prescription.ModeId, "dialysis_duration_hour": prescription.DialysisDurationHour, "anticoagulant_shouji": prescription.AnticoagulantShouji, "anticoagulant_weichi": prescription.AnticoagulantWeichi, "anticoagulant_zongliang": prescription.AnticoagulantZongliang, "kalium": prescription.Kalium, "sodium": prescription.Sodium, "calcium": prescription.Calcium, "dialyzer_perfusion_apparatus": prescription.DialyzerPerfusionApparatus, "blood_access": prescription.BloodAccess, "dialysate_flow": prescription.DialysateFlow, "dialysate_temperature": prescription.DialysateTemperature, "dialysis_dialyszers": prescription.DialysisDialyszers, "dialysis_irrigation": prescription.DialysisIrrigation, "plasma_separator": prescription.PlasmaSeparator, "bilirubin_adsorption_column": prescription.BilirubinAdsorptionColumn, "oxygen_uptake": prescription.OxygenUptake, "oxygen_flow": prescription.OxygenFlow, "oxygen_time": prescription.OxygenTime, "dialysis_strainer": prescription.DialysisStrainer, "chaptalization": prescription.Chaptalization, "blood_access_part_id": prescription.BloodAccessPartId}).Error
- return err
- }
-
- //func FindRemindAdvice(user_org_id int64, advice_name string, advice_desc string, template_id string, fre_type int64, patient_id int64, record_date int64) (advice models.DoctorAdvice, err error) {
- // err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and record_date = ? and advice_name = ? and advice_desc = ? and template_id = ? and frequency_type = ? ", patient_id, user_org_id, record_date, advice_name, advice_desc, template_id, fre_type).First(&advice).Error
- // return
- //}
-
- func FindRemindAdvice(user_org_id int64, advice_name string, advice_desc string, template_id string, fre_type int64, patient_id int64, record_date int64) (advice models.DoctorAdvice, err error) {
- err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and record_date = ? and advice_name = ? and advice_desc = ? and template_id = ? and frequency_type = ? AND advice_type = 2 ", patient_id, user_org_id, record_date, advice_name, advice_desc, template_id, fre_type).First(&advice).Error
- return
- }
-
- func UpdateScheduleByDeathTime(patientid int64, shcheduledate int64) error {
- var err error
- if shcheduledate > 0 {
- err = XTWriteDB().Model(models.XtSchedule{}).Where("patient_id = ? and schedule_date > ? and status=1", patientid, shcheduledate).Updates(map[string]interface{}{"status": 0, "remark": "转出删除排班"}).Error
- }
-
- return err
-
- }
-
- func UpdatePatientLapsetoByPatientId(patient_id int64, record_date int64, lapse_reason string) error {
-
- err := XTWriteDB().Model(&models.Patients{}).Where("id = ? and status= 1", patient_id).Updates(map[string]interface{}{"death_time": record_date, "lapseto": 2, "out_reason": lapse_reason}).Error
-
- err = XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status=1", patient_id).Updates(map[string]interface{}{"death_time": record_date, "lapseto": 2, "out_reason": lapse_reason}).Error
-
- return err
- }
-
- func UpdatePatientLapsetoByPatientIdOne(patient_id int64, record_date int64, lapse_reason string) error {
-
- err := XTWriteDB().Model(&models.Patients{}).Where("id = ? and status= 1", patient_id).Updates(map[string]interface{}{"death_time": record_date, "lapseto": 3, "out_reason": lapse_reason}).Error
-
- err = XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status=1", patient_id).Updates(map[string]interface{}{"death_time": record_date, "lapseto": 3, "out_reason": lapse_reason}).Error
-
- return err
- }
-
- func UpdatePatientLasetoType(patient_id int64, lapse_type int64) error {
-
- err := XTWriteDB().Model(&models.Patients{}).Where("id = ? and status=1", patient_id).Updates(map[string]interface{}{"lapseto": 11}).Error
- err = XTWriteDB().Model(&models.XtPatientsNew{}).Where("id = ? and status=1", patient_id).Updates(map[string]interface{}{"lapseto": 11}).Error
- return err
- }
-
- func UpdatePatientLapsetoByPatientIdTwo(patient_id int64, record_date int64) error {
-
- err := XTWriteDB().Model(&models.Patients{}).Where("id = ? and status= 1", patient_id).Updates(map[string]interface{}{"death_time": record_date, "lapseto": 1}).Error
-
- err = XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status=1", patient_id).Updates(map[string]interface{}{"death_time": record_date, "lapseto": 1}).Error
-
- return err
- }
-
- func UpdateScheduleItemByPatientId(id int64) error {
-
- err := XTWriteDB().Model(models.PatientScheduleTemplateItem{}).Where("patient_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetDoctorAdviceListThree(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64, delivery_way_one string) (advices []*models.HisDoctorAdvice, total int64, err error) {
-
- db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Print("table", table)
-
- if len(delivery_way_one) > 0 {
- db = db.Where("delivery_way = ?", delivery_way_one)
- }
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 && advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 2 && advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
- fmt.Print("err", err)
- return
- }
-
- func GetDoctorAdviceListFour(orgID int64, patientID int64, advice_type int64, stop int64, start int64, end int64, keywords string, limit int64, page int64, delive_way_one string) (advices []*models.HisDoctorAdvice, total int64, err error) {
-
- db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println(table)
- if len(delive_way_one) > 0 {
- db = db.Where("delivery_way = ?", delive_way_one)
- }
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
-
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&advices).Error
- fmt.Print("错误是什么", err)
- return
-
- }
-
- func GetAllDeviceNumberByListSix(orgID int64) (number []*models.DeviceNumber, err error) {
-
- err = readDb.Model(&models.DeviceNumber{}).Where("org_id=? and status=1", orgID).Find(&number).Error
-
- return number, err
- }
-
- func GetAllDeviceNumberByList(orgID int64) (number []*models.DeviceNumber, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":device_number_all"
- number_info_str, _ := redis.Get(key).Result()
- if len(number_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.DeviceNumber{}).Where("org_id=? and status=1", orgID).Find(&number).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(number) > 0 {
- //缓存数据
- device_number_json, err := json.Marshal(&number)
- if err == nil {
- redis.Set(key, device_number_json, time.Second*60*60*18)
- }
- }
- return number, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(number_info_str), &number)
- return number, nil
- }
- }
-
- func GetAllPrescriptionByListTwo(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescription, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
- prescriptions_list_all, _ := redis.Get(key).Result()
-
- if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- } else {
- err = readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&prescriptions).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(prescriptions) > 0 {
- //缓存数据
- prescriptions_list_all, err := json.Marshal(&prescriptions)
- if err == nil {
- redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- }
- }
- return prescriptions, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- return prescriptions, nil
- }
- }
-
- func GetAllAssessmentBeforesByListThree(orgID int64, scheduleDate int64) (assessmentBefores []*models.PredialysisEvaluation, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
- assessment_befores_list_all, _ := redis.Get(key).Result()
-
- if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
- } else {
- err = readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&assessmentBefores).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentBefores) > 0 {
- //缓存数据
- assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
- if err == nil {
- redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
- }
- }
- return assessmentBefores, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
- return assessmentBefores, nil
- }
- }
-
- func GetAllDialysisOrdersByListThree(orgID int64, scheduleDate int64) (dialysisOrders []*models.MonitorDialysisOrder, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
- dialysis_orders_list_all, _ := redis.Get(key).Result()
-
- if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.MonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- } else {
- err = readDb.Model(&models.MonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ?", orgID).Find(&dialysisOrders).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(dialysisOrders) > 0 {
- //缓存数据
- dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
- if err == nil {
- redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
- }
- }
- return dialysisOrders, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
- return dialysisOrders, nil
- }
- }
-
- func GetAllAssessmentAfterDislysisByListThree(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.AssessmentAfterDislysis, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
- assessment_after_dislysis__all, _ := redis.Get(key).Result()
-
- if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
- } else {
- err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&assessmentAfterDislysis).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentAfterDislysis) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- }
- return assessmentAfterDislysis, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
- return assessmentAfterDislysis, nil
- }
- }
-
- func GetAllMonitorListThree(orgID int64, scheduleDate int64) (monitor []*models.MonitoringRecord, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_record_list_all"
- monitor_record_list_all, _ := redis.Get(key).Result()
-
- if len(monitor_record_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ?", orgID, scheduleDate).Find(&monitor).Error
- } else {
- err = readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&monitor).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(monitor) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&monitor)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- }
- return monitor, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(monitor_record_list_all), &monitor)
- return monitor, nil
- }
- }
-
- func GetAllPatientListByListThree(orgID int64) (patients []*models.MonitorPatients, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
- patient_info_str, _ := redis.Get(key).Result()
-
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.MonitorPatients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(patients) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patients)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- }
- return patients, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(patient_info_str), &patients)
- return patients, nil
- }
- }
-
- func GetAllPatientListByListSix(orgID int64, keywords string) (patients []*models.MonitorPatients, err error) {
-
- db := readDb.Model(&models.MonitorPatients{}).Where("status = 1 and lapseto = 1")
- likeKey := "%" + keywords + "%"
- if orgID > 0 {
- db = db.Where("user_org_id = ?", orgID)
- }
- if len(keywords) > 0 {
-
- db = db.Where("name like ?", likeKey)
- }
- err = db.Find(&patients).Error
-
- return patients, err
- }
-
- func GetAllDialysisOrdersByListTwo(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVM, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":dialysis_orders_list_all"
- dialysis_orders_list_all, _ := redis.Get(key).Result()
-
- if scheduleDate < 1669132800 {
- fmt.Println("key233232232332323232", key)
- redis.Set(key, "", time.Second)
- }
- fmt.Println("dialysis_orders_list_all", dialysis_orders_list_all)
- if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&MDialysisOrderVM{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(dialysisOrders) > 0 {
- //缓存数据
- dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
- if err == nil {
- redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
- }
- }
- return dialysisOrders, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
- return dialysisOrders, nil
- }
- }
-
- func GetAllZoneByList(orgID int64) (zone []*models.DeviceZone, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":device_zone_all"
- zone_info_str, _ := redis.Get(key).Result()
- if len(zone_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.DeviceZone{}).Where("org_id=? and status=1", orgID).Find(&zone).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(zone) > 0 {
- //缓存数据
- zone_number_json, err := json.Marshal(&zone)
- if err == nil {
- redis.Set(key, zone_number_json, time.Second*60*60*18)
- }
- }
- return zone, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(zone_info_str), &zone)
- return zone, nil
- }
- }
-
- func GetAllDialysisOrdersByListNight(orgID int64, scheduleDate int64, pay_tyep int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
-
- if pay_tyep == 0 {
- err = readDb.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- }
- //待下机
- if pay_tyep == 3 {
- err = readDb.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ? and end_time = 0", orgID, scheduleDate).Find(&dialysisOrders).Error
- }
-
- fmt.Println("pay_typeowowowoowwo", pay_tyep)
- if pay_tyep == 7 {
- err = readDb.Preload("DeviceNumber", "status = 1 AND org_id = ?'", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ? and url = ''", orgID, scheduleDate).Find(&dialysisOrders).Error
- }
-
- return dialysisOrders, err
- }
-
- func GetAllPrescriptionByListSix(orgID int64, scheduleDate int64) (prescriptions []*models.VMDialysisPrescription, err error) {
-
- err = readDb.Model(&models.VMDialysisPrescription{}).Where("status= 1 and user_org_id = ? and record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- return prescriptions, err
- //redis := RedisClient()
- //defer redis.Close()
- //key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
- //redis.Set(key, "", time.Second)
- //prescriptions_list_all, _ := redis.Get(key).Result()
- //
- //if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- // err = readDb.Model(&models.VMDialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- // if err != nil {
- // if err == gorm.ErrRecordNotFound {
- // return nil, nil
- // } else {
- // return nil, err
- // }
- // } else {
- // if len(prescriptions) > 0 {
- // //缓存数据
- // prescriptions_list_all, err := json.Marshal(&prescriptions)
- // if err == nil {
- // redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- // }
- // }
- // return prescriptions, nil
- // }
- //} else { //缓存数据了数据,将redis缓存的json字符串转为map
- // json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- // return prescriptions, nil
- //}
- }
-
- func GetAllPrescriptionByList(orgID int64, scheduleDate int64) (prescriptions []*models.VMDialysisPrescription, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
- redis.Set(key, "", time.Second)
- prescriptions_list_all, _ := redis.Get(key).Result()
-
- if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMDialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(prescriptions) > 0 {
- //缓存数据
- prescriptions_list_all, err := json.Marshal(&prescriptions)
- if err == nil {
- redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- }
- }
- return prescriptions, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- return prescriptions, nil
- }
- }
-
- func GetAllAssessmentBeforesByListOne(orgID int64, scheduleDate int64) (assessmentBefores []*models.VMPredialysisEvaluation, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
- assessment_befores_list_all, _ := redis.Get(key).Result()
-
- if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMPredialysisEvaluation{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentBefores) > 0 {
- //缓存数据
- assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
- if err == nil {
- redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
- }
- }
- return assessmentBefores, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
- return assessmentBefores, nil
- }
- }
-
- func GetAllDialysisOrdersByListSix(orgID int64, scheduleDate int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
-
- err = readDb.Model(&models.VMMonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
-
- return dialysisOrders, err
- }
-
- func GetAllDialysisOrdersByListSeven(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVM, err error) {
-
- err = readDb.Model(&MDialysisOrderVM{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
-
- return dialysisOrders, err
- }
-
- func GetAllDialysisOrdersByListOne(orgID int64, scheduleDate int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
- redis := RedisClient()
-
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
- fmt.Println("key22332323232323223", key)
- dialysis_orders_list_all, _ := redis.Get(key).Result()
- defer redis.Close()
- if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMMonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(dialysisOrders) > 0 {
- //缓存数据
- dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
- if err == nil {
- redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
- }
- }
- return dialysisOrders, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
- return dialysisOrders, nil
- }
- }
-
- func GetAllAssessmentAfterDislysisByListSix(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
-
- err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status=1 and user_org_id = ? and assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
- return assessmentAfterDislysis, err
- //redis := RedisClient()
- //defer redis.Close()
- //key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
- //redis.Set(key, "", time.Second)
- //assessment_after_dislysis__all, _ := redis.Get(key).Result()
- //
- //if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- // err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
- // if err != nil {
- // if err == gorm.ErrRecordNotFound {
- // return nil, nil
- // } else {
- // return nil, err
- // }
- // } else {
- // if len(assessmentAfterDislysis) > 0 {
- // //缓存数据
- // assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
- // if err == nil {
- // redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- // }
- // }
- // return assessmentAfterDislysis, nil
- // }
- //} else { //缓存数据了数据,将redis缓存的json字符串转为map
- // json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
- // return assessmentAfterDislysis, nil
- //}
- }
-
- func GetAllAssessmentAfterDislysisByListOne(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(key, "", time.Second)
- assessment_after_dislysis__all, _ := redis.Get(key).Result()
-
- if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentAfterDislysis) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- }
- return assessmentAfterDislysis, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
- return assessmentAfterDislysis, nil
- }
- }
-
- func GetAllMonitorList(orgID int64, scheduleDate int64) (monitor []*models.VMMonitoringRecord, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_record_list_all"
- monitor_record_list_all, _ := redis.Get(key).Result()
-
- redis.Set(key, "", time.Second)
- if len(monitor_record_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ?", orgID, scheduleDate).Order("monitoring_date asc").Find(&monitor).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(monitor) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&monitor)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- }
- return monitor, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(monitor_record_list_all), &monitor)
- return monitor, nil
- }
- }
-
- func GetAllPatientListByListOne(orgID int64) (patients []*models.VMMonitorPatients, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
- patient_info_str, _ := redis.Get(key).Result()
- redis.Set(key, "", time.Second)
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMMonitorPatients{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(patients) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patients)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- }
- return patients, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(patient_info_str), &patients)
- return patients, nil
- }
- }
-
- func GetAllTreatModeByList(orgID int64) (treatement []*models.TreatmentMode, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":treatement_mode_all"
- treatment_info_str, _ := redis.Get(key).Result()
-
- if len(treatment_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
-
- err = readDb.Model(&models.TreatmentMode{}).Where("status=1").Find(&treatement).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(treatement) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&treatement)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- }
- return treatement, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(treatment_info_str), &treatement)
- return treatement, nil
- }
- }
-
- func GetAllPatientListByListSeven(orgID int64) (patients []*MSchedualPatientVM, err error) {
-
- err = readDb.Model(&MSchedualPatientVM{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
- return patients, nil
- }
-
- func GetAllPatientListByListTwo(orgID int64) (patients []*MSchedualPatientVM, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
- patient_info_str, _ := redis.Get(key).Result()
-
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&MSchedualPatientVM{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(patients) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patients)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- }
- return patients, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(patient_info_str), &patients)
- return patients, nil
- }
- }
-
- func GetAllDeviceNumberByListOne(orgID int64) (number []*MDeviceNumberVM, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":device_number_all"
- number_info_str, _ := redis.Get(key).Result()
- if len(number_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&MDeviceNumberVM{}).Where("org_id=? and status=1", orgID).Find(&number).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(number) > 0 {
- //缓存数据
- device_number_json, err := json.Marshal(&number)
- if err == nil {
- redis.Set(key, device_number_json, time.Second*60*60*18)
- }
- }
- return number, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(number_info_str), &number)
- return number, nil
- }
- }
-
- func GetAllPrescriptionByListOne(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionTwenty, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
-
- prescriptions_list_all, _ := redis.Get(key).Result()
-
- if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.DialysisPrescriptionTwenty{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(prescriptions) > 0 {
- //缓存数据
- prescriptions_list_all, err := json.Marshal(&prescriptions)
- if err == nil {
- redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- }
- }
- return prescriptions, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- return prescriptions, nil
- }
- }
-
- func GetAllHisProjectPrescription(orgid int64, recorddate int64) (project []*models.HisPrescriptionProjectTwo, err error) {
- err = XTReadDB().Where("user_org_id = ? and record_date = ? and status = 1", orgid, recorddate).Find(&project).Error
- return project, err
- }
-
- func GetZoneCountList(orgid int64, schedule_date int64) (list []*models.XtScheduleSeven, err error) {
-
- db := XTReadDB().Model(&list).Where("status = 1")
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if schedule_date > 0 {
- db = db.Where("schedule_date =?", schedule_date)
- }
- err = db.Select("partition_id,count(id) as count").Group("partition_id").Scan(&list).Error
- return list, err
- }
-
- func GetPatientDialysisLongSolution(patient_id int64, page int64, limit int64, orgid int64) (solution []*models.DialysisSolution, total int64, err error) {
-
- db := XTReadDB().Model(&solution).Where("status = 1 and solution_status = 1")
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- offset := (page - 1) * limit
-
- err = db.Group("mode_id").Count(&total).Offset(offset).Limit(limit).Order("created_time desc").Find(&solution).Error
- return solution, total, err
- }
-
- func GetDialysisSolutionDetailList(orgid int64, patient_id int64, mode_id int64, page int64, limit int64) (solution []*models.DialysisSolution, total int64, err error) {
- offset := (page - 1) * limit
- db := XTReadDB().Model(&solution).Where("status = 1")
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if mode_id > 0 {
- db = db.Where("mode_id = ?", mode_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&solution).Order("created_time desc").Error
- return solution, total, err
- }
-
- func UpdateDialysisBefor(dislysis models.XtAssessmentBeforeDislysis, id int64) error {
-
- err := XTWriteDB().Model(&models.XtAssessmentBeforeDislysis{}).Where("id = ? and status= 1", id).Update(map[string]interface{}{"systolic_blood_pressure": dislysis.SystolicBloodPressure, "diastolic_blood_pressure": dislysis.DiastolicBloodPressure}).Error
- return err
- }
-
- func GetAllSchedulesByPatientInfo(org_id int64, patient_id int64, mode_id int64) ([]Schedule, error) {
- var record []Schedule
- if org_id == 10579 {
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
- err := readDb.Model(&Schedule{}).Where("status = 1 AND schedule_date >? AND patient_id = ? AND user_org_id = ? AND mode_id= ?", timeNewDate.Unix(), patient_id, org_id, mode_id).Find(&record).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- }
- } else {
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
- err := readDb.Model(&Schedule{}).Where("status = 1 AND schedule_date >= ? AND patient_id = ? AND user_org_id = ? AND mode_id= ?", timeNewDate.Unix(), patient_id, org_id, mode_id).Find(&record).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- }
- }
-
- return record, nil
- }
-
- func UpdateScheduleByExport(org_id int64, shcheduledate int64) error {
- err := XTWriteDB().Model(models.XtSchedule{}).Where("user_org_id = ? and schedule_date > ?", org_id, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetContextScheduleListGroupPatientId(limit int64, page int64, startTime int64, endTime int64, org_id int64) (schedule []*models.ConScheduleList, total int64, err error) {
-
- db := XTReadDB().Model(&schedule).Where("status=1")
-
- offset := (page - 1) * limit
-
- if startTime > 0 {
- db = db.Where("schedule_date >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("schedule_date<=?", endTime)
- }
-
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Group("patient_id").Find(&schedule).Error
-
- return schedule, total, err
- }
-
- func GetContextScheduleListPatientId(startTime int64, endTime int64, org_id int64) (schedule []*models.ConScheduleList, total int64, err error) {
-
- db := XTReadDB().Model(&schedule).Where("status=1")
-
- if startTime > 0 {
- db = db.Where("schedule_date >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("schedule_date<=?", endTime)
- }
-
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- err = db.Find(&schedule).Error
-
- return schedule, total, err
- }
-
- func GetPatientAllagicList(patient_id int64, user_org_id int64) (list []*models.XtPatientAllergic, err error) {
-
- err = XTReadDB().Where("patient_id = ? and user_org_id =? and status= 1", patient_id, user_org_id).Find(&list).Error
-
- return list, err
- }
-
- func GetPatientAllagicListOne(user_org_id int64) (list []*models.XtPatientAllergic, err error) {
-
- err = XTReadDB().Where("user_org_id =? and status= 1", user_org_id).Find(&list).Error
-
- return list, err
- }
-
- func GetNewMonitorRecord(orgID int64, date int64, partition int64, patientId int64) ([]*models.NewMonitorDialysisScheduleList, error) {
- var mds []*models.NewMonitorDialysisScheduleList
-
- db := readDb.Model(&models.NewMonitorDialysisScheduleList{})
- if date > 0 {
- db = db.Where("schedule_date = ?", date)
- }
- if partition > 0 {
- db = db.Where("partition_id = ?", partition)
- }
- if patientId > 0 {
-
- db = db.Where("patient_id = ?", patientId)
- }
-
- err = db.Where("status = 1 and user_org_id = ?", orgID).Find(&mds).Error
-
- return mds, err
- }
-
- func GetAdviceList(user_org_id int64, advice_date int64, pat_type int64) (advice []*models.VMDoctorAdviceForList, err error) {
-
- if pat_type == 0 {
- err = XTReadDB().Where("user_org_id = ? and advice_date = ? and status =7 and check_time = 0", user_org_id, advice_date).Find(&advice).Error
- }
- //待医嘱核对
- if pat_type == 1 {
- err = XTReadDB().Where("user_org_id = ? and advice_date = ? and status =1 and check_time = 0", user_org_id, advice_date).Find(&advice).Error
- }
- //待医嘱执行
- if pat_type == 6 {
- err = XTReadDB().Where("user_org_id = ? and advice_date = ? and status =1 and execution_state = 2", user_org_id, advice_date).Find(&advice).Error
-
- }
- return advice, err
- }
-
- func GetDobuleCheck(user_org_id int64, advice_date int64) (check []*models.VmDoubleCheck, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and check_date = ? and status = 1", user_org_id, advice_date).Find(&check).Error
- return check, err
- }
-
- func GetDobuleCheckOne(user_org_id int64, advice_date int64, patient_id int64) (check models.VmDoubleCheck, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and check_date = ? and status = 1 and patient_id = ?", user_org_id, advice_date, patient_id).Find(&check).Error
- return check, err
- }
-
- func GetTreatmentSummaryForList(user_org_id int64, advice_date int64) (summary []*models.VMTreatmentSummaryForList, err error) {
-
- err = XTReadDB().Where("user_org_id =? and assessment_date = ? and status =1", user_org_id, advice_date).Find(&summary).Error
-
- return summary, err
- }
-
- func GetDialysisInformationList(user_org_id int64, advice_date int64) (information []*models.NewDeviceInformation, err error) {
-
- err = UserReadDB().Where("user_org_id =? and date = ? and status =1", user_org_id, advice_date).Find(&information).Error
- return information, err
- }
-
- func GetNewAllMonitorList(orgID int64, scheduleDate int64, pat_type int64) (monitor []*models.VMMonitoringRecord, err error) {
- if pat_type == 0 || pat_type == 9 {
- err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ?", orgID, scheduleDate).Order("monitoring_date asc").Find(&monitor).Error
- }
-
- if pat_type == 10 {
- err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ? AND accumulated_blood_volume = 0", orgID, scheduleDate).Order("monitoring_date asc").Find(&monitor).Error
- }
-
- if pat_type == 11 {
- err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ? AND symptom <> ''", orgID, scheduleDate).Order("monitoring_date asc").Find(&monitor).Error
- }
-
- if pat_type == 12 {
- err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ? AND dispose <> ''", orgID, scheduleDate).Order("monitoring_date asc").Find(&monitor).Error
- }
- return monitor, err
- }
-
- func GetBaseDrugByName(drug_name string, org_id int64) (models.BaseDrugLibSeven, error) {
-
- libSeven := models.BaseDrugLibSeven{}
-
- err := XTReadDB().Where("drug_name= ? and org_id = ? and status=1", drug_name, org_id).First(&libSeven).Error
-
- return libSeven, err
- }
-
- func CreateDeviceValsualMap(valsualMap models.XtDeviceValsualMap) error {
-
- err := XTWriteDB().Save(&valsualMap).Error
-
- return err
- }
-
- func GetPatientSitemap(patient_id int64, user_org_id int64) (models.XtDeviceValsualMap, error) {
-
- valsualMap := models.XtDeviceValsualMap{}
- err := XTReadDB().Where("patient_id = ? and status =1 and user_org_id = ?", patient_id, user_org_id).Preload("XtDeviceValsualALeft", "status=1 and user_org_id =?", user_org_id).Preload("XtDeviceValsualVLeft", "status=1 and user_org_id =?", user_org_id).Preload("XtDeviceValsualMapFangxiangA", "status=1 and user_org_id =?", user_org_id).Preload("XtDeviceValsualMapFangxiangV", "status=1 and user_org_id =?", user_org_id).Preload("XtDeviceValsualFuzhuA", "status=1 and user_org_id =?", user_org_id).Preload("XtDeviceValsualFuzhuV", "status=1 and user_org_id =?", user_org_id).Preload("XtDeviceValsualTextArr", "status=1 and user_org_id =?", user_org_id).Preload("DeviceValusalMapArr", "status=1 and user_org_id =?", user_org_id).Preload("XtDeviceValusalMapVrr", "status=1 and user_org_id =?", user_org_id).Find(&valsualMap).Error
- return valsualMap, err
- }
-
- func UpdateSiteMap(valsualMap models.XtDeviceValsualMap) error {
-
- err := XTWriteDB().Save(&valsualMap).Error
- return err
- }
-
- func CreateValsualAleft(left models.XtDeviceValsualALeft) error {
-
- err := XTWriteDB().Create(&left).Error
- return err
- }
-
- func UpdateValsualAleft(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValsualALeft{}).Where("patient_id = ? and user_org_id = ? and status =1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateValsualMapFangxiangA(a models.XtDeviceValsualMapFangxiangA) error {
-
- err := XTWriteDB().Create(&a).Error
- return err
- }
-
- func UpdateValsualMapFangxiangA(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValsualMapFangxiangA{}).Where("patient_id = ? and user_org_id = ? and status =1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateValsualMapFangxiangV(v models.XtDeviceValsualMapFangxiangV) error {
-
- err := XTWriteDB().Create(&v).Error
- return err
- }
-
- func UpdateValsualMapFangxiangV(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValsualMapFangxiangV{}).Where("patient_id = ? and user_org_id = ? and status=1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func ValsualMapFangxiangA(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(models.XtDeviceValsualMapFangxiangA{}).Where("patient_id = ? and user_org_id = ? and status=1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateValSualFuzhA(a models.XtDeviceValsualFuzhuA) error {
-
- err := XTReadDB().Create(&a).Error
- return err
- }
-
- func UpdateValSualFuzhA(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValsualFuzhuA{}).Where("patient_id =? and user_org_id = ? and status=1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateVasuaLfuzhuV(v models.XtDeviceValsualFuzhuV) error {
-
- err := XTReadDB().Create(&v).Error
- return err
- }
-
- func UpdateVasuaLfuzhuV(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValsualFuzhuV{}).Where("patient_id = ? and user_org_id =? and status=1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateTextArr(arr models.XtDeviceValsualTextArr) error {
-
- err := XTReadDB().Create(&arr).Error
- return err
- }
-
- func UpdateTextArr(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValsualTextArr{}).Where("patient_id = ? and user_org_id = ? and status=1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateValsualVleft(left models.XtDeviceValsualVLeft) error {
-
- err = XTReadDB().Create(&left).Error
- return err
- }
-
- func UpdateValsualVleft(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValsualVLeft{}).Where("patient_id = ? and user_org_id =? and status=1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func UpdateValusalMapArr(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValusalMapArr{}).Where("patient_id =? and user_org_id =? and status=1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateDeviceValusalMapArr(vrr models.XtDeviceValusalMapArr) error {
-
- err := XTWriteDB().Create(&vrr).Error
- return err
- }
-
- func UpdateDeviceValusalMapVrr(patient_id int64, user_org_id int64) error {
-
- err := XTWriteDB().Model(&models.XtDeviceValusalMapVrr{}).Where("patient_id = ? and user_org_id =? and status=1", patient_id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateDeviceValusalMapVrr(vrr models.XtDeviceValusalMapVrr) error {
-
- err := XTWriteDB().Create(&vrr).Error
- return err
- }
-
- func GetDialysisOrderNoExecution(start_nurse int64, user_org_id int64, timenow int64) (order []*models.XtDialysisOrder, err error) {
-
- err = XTReadDB().Where("start_nurse = ? and user_org_id =? and status =1 and dialysis_date =?", start_nurse, user_org_id, timenow).Find(&order).Error
- return order, err
- }
-
- func GetAdviceListNoExecution(advice_date int64, user_org_id int64, patientIds []int64) (advice []*models.NoDoctorAdvice, err error) {
-
- db := XTReadDB().Model(advice).Where("status=1 and execution_state = 2 and advice_type = 2")
- if len(patientIds) > 0 {
- if advice_date > 0 {
- db = db.Where("advice_date= ?", advice_date)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id =?", user_org_id)
- }
- if len(patientIds) > 0 {
- db = db.Where("patient_id in(?)", patientIds)
- }
- err = db.Select("patient_id,Count(id) as count,advice_date").Group("patient_id").Find(&advice).Error
- return advice, err
- } else {
- return advice, err
- }
-
- }
-
- func GetHisAdviceListNoExecution(advice_date int64, user_org_id int64, patientIds []int64) (advice []*models.HisNoDoctorAdvice, err error) {
-
- db := XTReadDB().Model(advice).Where("status=1 and execution_state = 2")
-
- if advice_date > 0 {
- db = db.Where("advice_date= ?", advice_date)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id =?", user_org_id)
- }
- if len(patientIds) > 0 {
- db = db.Where("patient_id in(?)", patientIds)
- }
-
- err = db.Select("advice_date,patient_id,Count(id) as count").Group("patient_id").Find(&advice).Error
-
- return advice, err
- }
-
- func GetProjectListNoExecution(record_date int64, user_org_id int64, patientIds []int64) (project []*models.NoHisPrescriptionProject, err error) {
-
- db := XTReadDB().Model(&project).Where("status=1 and execution_state =0")
- if record_date > 0 {
- db = db.Where("record_date= ?", record_date)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id =?", user_org_id)
- }
- if len(patientIds) > 0 {
- db = db.Where("patient_id in(?)", patientIds)
- }
-
- err = db.Select("patient_id,Count(id) as count,record_date as advice_date").Group("patient_id").Find(&project).Error
- return project, err
- }
-
- func GetPatientNoExecutionList(org_id int64, patientsIds []int64) (patient []*models.XtPatients, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and id in(?)", org_id, patientsIds).Find(&patient).Error
- return patient, err
- }
- func FindHisConfig(org_id int64) (err error, config models.XtHisConfig) {
- err = readDb.Model(&models.XtHisConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
- return
- }
-
- func GetPatientDetailInformedConsent(patient_id int64, org_id int64) (models.XtPatients, error) {
-
- patients := models.XtPatients{}
- err := XTReadDB().Where("id = ? and status=1 and user_org_id =?", patient_id, org_id).Find(&patients).Error
- return patients, err
- }
-
- func GetAllPrescriptionList(org_id int64) (prescription []*models.DialysisPrescription, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status =1", org_id).Find(&prescription).Error
-
- return prescription, err
- }
-
- func GetPatientScheudleListTwenty(org_id int64, scheduel_type int64, startime int64, endtime int64, schedule_date int64) (schedule []*models.ScheduleTen, err error) {
-
- db := XTReadDB().Model(&schedule).Where("status= 1")
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- if scheduel_type > 0 {
- db = db.Where("schedule_type =?", scheduel_type)
- }
- if startime > 0 {
- db = db.Where("schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("schedule_date <=?", endtime)
- }
-
- if startime == 0 && endtime == 0 {
- db = db.Where("schedule_date = ?", schedule_date)
- }
-
- err = db.Find(&schedule).Error
- fmt.Println("err2330230320202023", err)
- return schedule, err
- }
-
- func GetDialysisOrderCountTwentyEight(orgID int64, patient_id int64, recordDate int64) (models.VmDialysisOrder, error) {
- order := models.VmDialysisOrder{}
- err := XTReadDB().Raw("SELECT Count(id) as count,Max(dialysis_date) as dialysis_date from xt_dialysis_order where dialysis_date>=1672502400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND patient_id = ? and user_org_id = ?", recordDate, patient_id, orgID).Scan(&order).Error
- return order, err
- }
-
- func GetDialysisOrderCountTenEight(patient_id int64, recordDate int64) (models.VmDialysisOrder, error) {
- order := models.VmDialysisOrder{}
- err := XTReadDB().Where("patient_id = ? and dialysis_date = ? and status = 1", patient_id, recordDate).Last(&order).Error
- return order, err
- }
-
- func GetLastAcceptRecrods(patient_id int64) (models.ReceiveTreatmentAsses, error) {
-
- treatmentAsses := models.ReceiveTreatmentAsses{}
- err := XTReadDB().Where("patient_id = ? and status= 1 and admission_number!=''", patient_id).Last(&treatmentAsses).Error
- return treatmentAsses, err
- }
-
- func GetOutPrintList(user_org_id int64) (models.XtFallOutPrint, error) {
-
- outPrint := models.XtFallOutPrint{}
-
- err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&outPrint).Error
-
- return outPrint, err
- }
-
- func CreateFallOutBedPrint(outPrint models.XtFallOutPrint) error {
-
- err := XTWriteDB().Create(&outPrint).Error
-
- return err
- }
-
- func UpdateFallOutBedPrint(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtFallOutPrint{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetFallOutBedPrintList(user_org_id int64) (models.XtFallOutPrint, error) {
-
- outPrint := models.XtFallOutPrint{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&outPrint).Error
-
- return outPrint, err
- }
-
- func GetFilterInformed(user_org_id int64) (models.XtFilterInformed, error) {
-
- informed := models.XtFilterInformed{}
-
- err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&informed).Error
-
- return informed, err
- }
-
- func CreateFilterInformed(informed models.XtFilterInformed) error {
-
- err := XTWriteDB().Create(&informed).Error
-
- return err
- }
-
- func UpdateFilterInformed(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtFilterInformed{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetProfundaInformed(user_org_id int64) (models.XtProfundaInformed, error) {
-
- informed := models.XtProfundaInformed{}
-
- err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&informed).Error
-
- return informed, err
- }
-
- func CreateProfundaInformed(informed models.XtProfundaInformed) error {
-
- err := XTWriteDB().Create(&informed).Error
-
- return err
- }
-
- func UpdateProfundaInformed(id int64, content string) error {
-
- profundaInformed := models.XtProfundaInformed{}
-
- err := XTWriteDB().Model(&profundaInformed).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
- return err
- }
-
- func GetArterOvenousList(user_org_id int64) (models.XtArterOvenous, error) {
-
- ovenous := models.XtArterOvenous{}
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&ovenous).Error
- return ovenous, err
- }
-
- func CreateArterOvernous(ovenous models.XtArterOvenous) error {
-
- err := XTWriteDB().Create(&ovenous).Error
-
- return err
- }
-
- func UpdateArterOvernous(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtArterOvenous{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetHightRikInformed(user_org_id int64) (models.XtHightRisk, error) {
-
- risk := models.XtHightRisk{}
-
- err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&risk).Error
-
- return risk, err
- }
-
- func CreateHighRik(risk models.XtHightRisk) error {
-
- err := XTWriteDB().Create(&risk).Error
-
- return err
- }
-
- func UpdateHighRik(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtHightRisk{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetAnticoagulation(user_org_id int64) (models.XtAuticoagutionPrint, error) {
-
- auticoagutionPrint := models.XtAuticoagutionPrint{}
-
- err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&auticoagutionPrint).Error
-
- return auticoagutionPrint, err
- }
-
- func CreateAnticoagulation(auticoagutionPrint models.XtAuticoagutionPrint) error {
-
- err := XTWriteDB().Create(&auticoagutionPrint).Error
-
- return err
- }
-
- func UpdateAnticoagulation(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtAuticoagutionPrint{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetCriticalInfomed(org_id int64) (models.XtCriticalinfomedPrint, error) {
-
- criticalinfomedPrint := models.XtCriticalinfomedPrint{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&criticalinfomedPrint).Error
-
- return criticalinfomedPrint, err
- }
-
- func CreatedCriticalInfomed(criticalinfomedPrint models.XtCriticalinfomedPrint) error {
-
- err := XTWriteDB().Create(&criticalinfomedPrint).Error
-
- return err
- }
-
- func UpdateCriticalInfomed(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtCriticalinfomedPrint{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetHemoperfusionInformed(user_org_id int64) (models.XtHemoperfusionmedPrint, error) {
-
- hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{}
-
- err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&hemoperfusionmedPrint).Error
-
- return hemoperfusionmedPrint, err
- }
-
- func CreateHemoperfusionInformed(hemoperfusionmedPrint models.XtHemoperfusionmedPrint) error {
-
- err := XTWriteDB().Create(&hemoperfusionmedPrint).Error
-
- return err
- }
-
- func UpdateHemoperfusionInformed(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtHemoperfusionmedPrint{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetBringInformed(org_id int64) (models.XtBringinformedPrint, error) {
-
- bringinformedPrint := models.XtBringinformedPrint{}
- err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&bringinformedPrint).Error
-
- return bringinformedPrint, err
- }
-
- func CreateBringInformed(bringinformedPrint models.XtBringinformedPrint) error {
-
- err := XTWriteDB().Create(&bringinformedPrint).Error
-
- return err
- }
-
- func UpdateBringInformed(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtBringinformedPrint{}).Where("id =? and status= 1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetCatheterization(user_org_id int64) (models.XtCathetercationPrint, error) {
-
- cathetercationPrint := models.XtCathetercationPrint{}
-
- err := XTReadDB().Where("user_org_id = ? and status= 1", user_org_id).Find(&cathetercationPrint).Error
- return cathetercationPrint, err
- }
-
- func CreateCatheteriztion(cathetercationPrint models.XtCathetercationPrint) error {
-
- err := XTWriteDB().Create(&cathetercationPrint).Error
- return err
- }
-
- func UpdateCatheterization(id int64, content string) error {
-
- err := XTWriteDB().Model(models.XtCathetercationPrint{}).Where("id=? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetDialyzerInformed(org_id int64) (models.XtDialyszerinformedPrint, error) {
-
- dialyszerinformedPrint := models.XtDialyszerinformedPrint{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&dialyszerinformedPrint).Error
-
- return dialyszerinformedPrint, err
- }
-
- func CreateDialyzerInformed(dialyszerinformedPrint models.XtDialyszerinformedPrint) error {
-
- err := XTWriteDB().Create(&dialyszerinformedPrint).Error
-
- return err
- }
-
- func UpdateDialyszerInformed(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtDialyszerinformedPrint{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
- return err
- }
-
- func GetTheapyInformed(org_id int64) (models.XtTheapyinformedPrint, error) {
-
- theapyinformedPrint := models.XtTheapyinformedPrint{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&theapyinformedPrint).Error
-
- return theapyinformedPrint, err
- }
-
- func CreateTheapyInformed(theapyinformedPrint models.XtTheapyinformedPrint) error {
-
- err := XTWriteDB().Create(&theapyinformedPrint).Error
- return err
- }
-
- func UpdateTheaphInformed(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtTheapyinformedPrint{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
- return err
- }
-
- func GetPatientMedicalHistory(patient_id int64, user_org_id int64) (models.XtMedicalHistory, error) {
-
- history := models.XtMedicalHistory{}
-
- err := XTReadDB().Model(&history).Where("patient_id = ? and user_org_id = ? and status=1", patient_id, user_org_id).Find(&history).Error
-
- return history, err
- }
-
- func UpdatePatientMedicalHistory(id int64, content string) error {
-
- history := models.XtMedicalHistory{}
-
- err := XTWriteDB().Model(&history).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
- return err
- }
-
- func CreatePatientMedicalHistory(history models.XtMedicalHistory) error {
-
- err := XTWriteDB().Create(&history).Error
-
- return err
- }
-
- func GetPatientMedicalList(patient_id int64, user_org_id int64) (models.XtMedicalHistory, error) {
-
- history := models.XtMedicalHistory{}
- err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status=1", patient_id, user_org_id).Find(&history).Error
- return history, err
- }
-
- func CreatePatientFallassessment(tx *gorm.DB, patientFallassessment models.XtPatientFallassessment) (err error) {
-
- err = tx.Create(&patientFallassessment).Error
- if err == gorm.ErrRecordNotFound {
- tx.Rollback()
- return
- }
-
- return
- }
-
- func SavePatientFallassessment(tx *gorm.DB, patientFallassessment models.XtPatientFallassessment) (err error) {
-
- err = tx.Save(&patientFallassessment).Error
- if err == gorm.ErrRecordNotFound {
- tx.Rollback()
- return
- }
-
- return
- }
-
- func GetPatientFallsessMentList(patient_id int64, user_org_id int64, limit int64, page int64) (list []*models.XtPatientFallassessment, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&list).Where("status =1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
-
- return list, total, err
- }
-
- func GetPatientFallsessMentListOne(ids []string, user_org_id int64) (list []*models.XtPatientFallassessment, err error) {
-
- db := XTReadDB().Model(&list).Where("status =1")
-
- if len(ids) > 0 {
- db = db.Where("id in(?)", ids)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Find(&list).Error
-
- return list, err
- }
-
- func GetPatientFallsessmentById(id int64, user_org_id int64) (models.XtPatientFallassessment, error) {
-
- fallassessment := models.XtPatientFallassessment{}
-
- err := XTReadDB().Where("id = ? and user_org_id = ?", id, user_org_id).Find(&fallassessment).Error
-
- return fallassessment, err
- }
-
- func DeletePatientFallsessment(id int64, user_org_id int64) (models.XtPatientFallassessment, error) {
-
- fallassessment := models.XtPatientFallassessment{}
- err := XTWriteDB().Model(&fallassessment).Where("id =? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
- return fallassessment, err
- }
-
- func CreatePadFallssessment(fallssessment models.XtPatientPedFallssessment) error {
-
- err := XTWriteDB().Create(&fallssessment).Error
-
- return err
- }
-
- func UpdatePedFallssessment(fallssessment models.XtPatientPedFallssessment) error {
-
- err := XTWriteDB().Save(&fallssessment).Error
-
- return err
- }
-
- func GetBedDiatricFallassessmentList(patient_id int64, is_type int64, user_org_id int64, limit int64, page int64) (list []*models.XtPatientPedFallssessment, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&list).Where("status =1")
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- if is_type > 0 {
- db = db.Where("type = ?", is_type)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
-
- return list, total, err
- }
-
- func GetPedPatientFallassessmentById(id int64) (models.XtPatientPedFallssessment, error) {
-
- fallassessment := models.XtPatientPedFallssessment{}
-
- err := XTReadDB().Where("id = ? and status=1", id).Find(&fallassessment).Error
-
- return fallassessment, err
- }
-
- func DeletePadPatientFallassment(id int64) (err error) {
-
- err = XTWriteDB().Model(&models.XtPatientPedFallssessment{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
-
- }
-
- func GetPatientCritaicalInformed(user_org_id int64) (models.XtPatientCritical, error) {
-
- patientCritical := models.XtPatientCritical{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&patientCritical).Error
-
- return patientCritical, err
- }
-
- func CreatePatientCritaicalinformed(critical models.XtPatientCritical) error {
-
- err = XTWriteDB().Create(&critical).Error
-
- return err
- }
-
- func UpdatePatientCritaicalInformed(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtPatientCritical{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
- return err
- }
-
- func GetPatientCriticalByUserOrgId(user_org_id int64) (models.XtPatientCriticalOne, error) {
-
- criticalOne := models.XtPatientCriticalOne{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&criticalOne).Error
-
- return criticalOne, err
- }
-
- func CreatePatientCritical(patient models.XtPatientCriticalOne) error {
-
- err := XTWriteDB().Create(&patient).Error
-
- return err
- }
-
- func UpdatePatientCriticalOne(user_org_id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtPatientCriticalOne{}).Where("user_org_id = ? and status=1", user_org_id).Updates(map[string]interface{}{"content": content}).Error
- return err
- }
-
- func GetPatientCriticalOneList(user_org_id int64) (models.XtPatientCriticalOne, error) {
-
- criticalOne := models.XtPatientCriticalOne{}
-
- err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&criticalOne).Error
-
- return criticalOne, err
- }
-
- func CreatePatientPedList(fallssessment models.XtPatientPedFallssessment) error {
-
- err := XTWriteDB().Create(&fallssessment).Error
- return err
- }
-
- func UpdatePatientPedList(fallssessment models.XtPatientPedFallssessment) error {
-
- err := XTWriteDB().Save(&fallssessment).Error
-
- return err
- }
-
- func GetPatientFallsessMentListTwo(ids []string, user_org_id int64) (list []*models.XtPatientFallassessment, err error) {
-
- db := XTReadDB().Model(&list).Where("status =1")
-
- if len(ids) > 0 {
- db = db.Where("id in(?)", ids)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Find(&list).Error
- return list, err
- }
-
- func CeatePatientSign(braden models.XtPatientBraden) error {
-
- err := XTWriteDB().Create(&braden).Error
-
- return err
- }
-
- func GetPatientBradenList(patient_id int64, limit int64, page int64, user_org_id int64) (list []*models.XtPatientBraden, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&list).Where("status =1")
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
-
- return list, total, err
- }
-
- func GetPatientBradenById(id int64) (models.XtPatientBraden, error) {
-
- patientBraden := models.XtPatientBraden{}
-
- err := XTReadDB().Where("id = ? and status=1", id).Find(&patientBraden).Error
-
- return patientBraden, err
- }
-
- func SavePatientBraden(braden models.XtPatientBraden) error {
-
- err := XTWriteDB().Save(&braden).Error
-
- return err
- }
-
- func DeletePatientBraden(id int64) error {
-
- patientBraden := models.XtPatientBraden{}
- err := XTWriteDB().Model(&patientBraden).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetBatchPatientBraden(ids []string, user_org_id int64) (list []*models.XtPatientBraden, err error) {
-
- db := XTReadDB().Model(&list).Where("status=1")
-
- if len(ids) > 0 {
- db = db.Where("id in(?)", ids)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id =?", user_org_id)
- }
- err = db.Find(&list).Error
- return list, err
- }
-
- func GetAllPatientListMap(user_org_id int64) (list []*models.XtAgePatients, err error) {
-
- err = XTReadDB().Where("user_org_id =? and status=1 and lapseto = 1", user_org_id).Find(&list).Error
-
- return list, err
- }
-
- func GetLastBefor(patient_id int64) (models.XtAssessmentBeforeDislysis, error) {
-
- beforeDislysis := models.XtAssessmentBeforeDislysis{}
-
- err := XTReadDB().Where("patient_id = ? and status=1 AND assessment_date>=1704038400 AND assessment_date<=1711814400", patient_id).Order("id asc").Last(&beforeDislysis).Limit(1).Error
- return beforeDislysis, err
- }
-
- func GetLastRecordAfter(patient_id int64) (models.XtAssessmentAfterDislysis, error) {
-
- afterDislysis := models.XtAssessmentAfterDislysis{}
- err := XTReadDB().Where("patient_id = ? and status=1 AND assessment_date>=1704038400 AND assessment_date<=1711814400", patient_id).Order("id asc").Last(&afterDislysis).Limit(1).Error
- return afterDislysis, err
- }
-
- func GetInspectionByPatientId(patient_id int64, item_id int64) (models.XtInspection, error) {
-
- inspection := models.XtInspection{}
-
- err := XTReadDB().Where("patient_id =? and status =1 and inspect_date>=1704038400 and inspect_date<=1711814400 and item_id =?", patient_id, item_id).Order("id asc").Last(&inspection).Limit(1).Error
- return inspection, err
- }
-
- func DeleteSolutionById(id int64) (models.DialysisSolution, error) {
-
- solution := models.DialysisSolution{}
-
- err := XTWriteDB().Model(&solution).Where("id=? and status=1", id).Updates(map[string]interface{}{"status": 12}).Error
-
- return solution, err
- }
-
- func GetPatientBeforRecordList(patient_id int64, user_org_id int64) (befor []*models.XtAssessmentBeforeDislysis, err error) {
-
- err = XTReadDB().Where("patient_id = ? and user_org_id =? and status=1", patient_id, user_org_id).Order("id desc").Limit(5).Find(&befor).Error
-
- return befor, err
- }
-
- func GetPatientAfterRecordList(patient_id int64, user_org_id int64) (after []*models.XtAssessmentAfterDislysis, err error) {
-
- err = XTReadDB().Where("patient_id = ? and user_org_id =? and status=1", patient_id, user_org_id).Order("id desc").Limit(5).Find(&after).Error
-
- return after, err
- }
-
- func GetMonitorRecordByGroup(patient_id int64, user_org_id int64) (monitor []*models.MonitoringRecordOne, err error) {
-
- err = XTReadDB().Where("patient_id = ? and user_org_id =? and status=1 and monitoring_date>=1711900800", patient_id, user_org_id).Order("id desc").Preload("MonitoringRecord", "status=1 and user_org_id =? and monitoring_date>=1711900800", user_org_id).Group("monitoring_date").Limit(5).Find(&monitor).Error
-
- return monitor, err
- }
-
- func GetMonitorRecordList(patient_id int64, monitor_date int64, user_org_id int64) (monitor []*models.MonitoringRecord, err error) {
-
- err = XTReadDB().Where("patient_id = ? and user_org_id =? and monitoring_date = ? and status =1", patient_id, user_org_id, monitor_date).Find(&monitor).Error
- return monitor, err
- }
-
- func GetDialysisTotalCountByTime(user_org_id int64, start_time int64, end_time int64, patient_id int64) (order []*models.XtDialysisOrder, err error) {
-
- db := XTReadDB().Table("xt_dialysis_order").Where("status =1")
- if user_org_id > 0 {
- db = db.Where("user_org_id =?", user_org_id)
- }
- if start_time > 0 {
- db = db.Where("dialysis_date >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("dialysis_date <=?", end_time)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- err = db.Find(&order).Error
-
- return order, err
- }
-
- func GetTreamentPland(user_org_id int64) (models.XtTreatmentPlan, error) {
-
- treatmentPlan := models.XtTreatmentPlan{}
-
- err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&treatmentPlan).Error
-
- return treatmentPlan, err
- }
-
- func CreateTreatqmentPland(plan models.XtTreatmentPlan) error {
-
- err := XTWriteDB().Create(&plan).Error
-
- return err
- }
-
- func UpdateTheatmentPland(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtTreatmentPlan{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetEditAdviceActionList(id int64, org_id int64) (models.XtDoctorAdviceOne, error) {
-
- doctorAdviceOne := models.XtDoctorAdviceOne{}
- err := XTReadDB().Where("id = ? and status=1 and user_org_id = ?", id, org_id).Find(&doctorAdviceOne).Error
-
- return doctorAdviceOne, err
- }
-
- func CreatePatientRecord(record models.XtPatientLaspseRecord) error {
-
- err := XTWriteDB().Create(&record).Error
-
- return err
- }
-
- func GetPatientLapseRecord(patient_id int64, limit int64, page int64, user_org_id int64) (record []*models.XtPatientLaspseRecord, total int64, err error) {
-
- db := XTReadDB().Model(&record).Where("status=1")
- offset := (page - 1) * limit
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&record).Error
-
- return record, total, err
- }
-
- func GetPatientLapsorecord(id int64) (models.XtPatientLaspseRecord, error) {
-
- laspseRecord := models.XtPatientLaspseRecord{}
-
- err := XTReadDB().Where("id = ? and status= 1", id).Find(&laspseRecord).Error
-
- return laspseRecord, err
- }
-
- func SavePatientLapseRecord(record models.XtPatientLaspseRecord) error {
-
- err := XTWriteDB().Save(&record).Error
-
- return err
- }
-
- func DeletePatientLapseRecord(id int64) error {
-
- record := models.XtPatientLaspseRecord{}
-
- err := XTWriteDB().Model(&record).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func GetPatientLapsorecordListOne() (lapseto []*models.PatientLapseto, err error) {
-
- err = XTReadDB().Where("status=1 and (lapseto_type=2 or lapseto_type =3)").Find(&lapseto).Error
-
- return lapseto, err
- }
-
- func GetPatientBefor(patient_id int64, record_date int64, user_org_id int64) (models.XtAssessmentBeforeDislysis, error) {
-
- beforeDislysis := models.XtAssessmentBeforeDislysis{}
-
- err := XTReadDB().Where("patient_id = ? and assessment_date= ? and user_org_id = ? and status=1", patient_id, record_date, user_org_id).Find(&beforeDislysis).Error
-
- return beforeDislysis, err
- }
-
- func GetDialysisPrescribeOneList(patient_id int64, record_date int64, user_org_id int64) (models.DialysisPrescription, error) {
-
- prescription := models.DialysisPrescription{}
-
- err := XTReadDB().Where("patient_id = ? and record_date= ? and user_org_id = ? and status=1", patient_id, record_date, user_org_id).Find(&prescription).Error
-
- return prescription, err
- }
-
- func CreateDeathSummary(summary models.XtDeathSummary) error {
-
- err := XTWriteDB().Save(&summary).Error
-
- return err
- }
-
- func GetPatientDeathSummary(patient_id int64, user_org_id int64) (models.XtDeathSummary, error) {
-
- deathSummary := models.XtDeathSummary{}
-
- err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status=1", patient_id, user_org_id).Find(&deathSummary).Error
-
- return deathSummary, err
- }
-
- func DeletePatientDeathSummary(id int64) error {
-
- summary := models.XtDeathSummary{}
-
- err := XTWriteDB().Model(&summary).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func CreateNewSickHistoryRecord(history models.XtPatientSickHistory) error {
-
- err := XTWriteDB().Save(&history).Error
-
- return err
- }
-
- func GetNewSickHistory(patient_id int64, org_id int64) (sick []*models.XtPatientSickHistory, err error) {
-
- err = XTReadDB().Where("patient_id = ? and org_id = ? and status =1", patient_id, org_id).Order("record_time desc").Find(&sick).Error
-
- return sick, err
- }
-
- func DeleteNewSickHistory(id int64) error {
-
- err := XTWriteDB().Model(&models.XtPatientSickHistory{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func CreateSickHistoryTemplate(template models.XtSickHistoryTemplate) error {
-
- err := XTWriteDB().Create(&template).Error
-
- return err
- }
-
- func GetSickHistoryTemplate(user_org_id int64) (template []*models.XtSickHistoryTemplate, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&template).Error
-
- return template, err
- }
-
- func ModifySickHistoryTemplate(id int64, content string) error {
-
- err := XTReadDB().Model(&models.XtSickHistoryTemplate{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
- return err
- }
-
- func DeleteSickHistoryTemplate(id int64) error {
-
- err := XTWriteDB().Model(&models.XtSickHistoryTemplate{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func CreateNewCourseOfDiaseaseRecord(course models.PatientDiseaseCourse) error {
-
- err := XTWriteDB().Save(&course).Error
-
- return err
- }
-
- func GetPatientCoureseOfDiseasesList(patient_id int64, org_id int64) (list []*models.PatientDiseaseCourse, err error) {
-
- err = XTReadDB().Where("patient_id = ? and org_id = ? and status=1", patient_id, org_id).Find(&list).Error
-
- return list, err
-
- }
-
- func DeleteNewCourseOfDisease(id int64) error {
-
- patientCourse := models.PatientDiseaseCourse{}
- err := XTWriteDB().Model(&patientCourse).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateCourseTemplate(course models.XtPatientCourseTemplate) error {
-
- err := XTWriteDB().Create(&course).Error
-
- return err
- }
-
- func GetPatientDeathRecordList(org_id int64) (models.XtDeathRecord, error) {
-
- deathRecord := models.XtDeathRecord{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&deathRecord).Error
-
- return deathRecord, err
- }
-
- func CreatePatientDeathRecord(record models.XtDeathRecord) error {
-
- err := XTWriteDB().Create(&record).Error
-
- return err
- }
-
- func UpdatePatientDeathRecord(id int64, content string) error {
-
- err := XTWriteDB().Model(&models.XtDeathRecord{}).Where("id =? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return err
- }
-
- func GetPatientDeathRecord(user_org_id int64) (models.XtDeathRecord, error) {
-
- record := models.XtDeathRecord{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&record).Error
-
- return record, err
- }
-
- func SaveCoureseTemplateTitle(courseTemplate models.XtPatientCourseTemplate) error {
-
- err := XTWriteDB().Create(&courseTemplate).Error
-
- return err
-
- }
-
- func GetPatientCourseOfTemplate(user_org_id int64) (list []*models.XtPatientCourseTemplate, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&list).Error
-
- return list, err
- }
-
- func SaveCourseOfNewTemplate(id int64, content string) (models.XtPatientCourseTemplate, error) {
-
- template := models.XtPatientCourseTemplate{}
-
- err := XTWriteDB().Model(&template).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return template, err
- }
-
- func DeleteCouseTemplate(id int64) error {
-
- err := XTWriteDB().Model(&models.XtPatientCourseTemplate{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func GetAutoDialysisPrescription(patient_id int64, start_time int64, end_time int64, org_id int64) (prescription []*models.XtAutoDialysisPrescription, err error) {
-
- db := XTReadDB().Model(&prescription).Where("status=1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if start_time > 0 {
- db = db.Where("record_date>=?", start_time)
- }
-
- if end_time > 0 {
- db = db.Where("record_date<=?", end_time)
- }
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- err = db.Find(&prescription).Error
- return prescription, err
- }
-
- func GetAutoAssessmentBefor(patient_id int64, start_time int64, end_time int64, org_id int64) (berfor []*models.XtAssessmentBeforeDislysis, err error) {
-
- db := XTReadDB().Model(&berfor).Where("status=1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if start_time > 0 {
- db = db.Where("assessment_date>=?", start_time)
- }
-
- if end_time > 0 {
- db = db.Where("assessment_date<=?", end_time)
- }
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- err = db.Find(&berfor).Error
- return berfor, err
- }
-
- func GetAutoMonitorList(patient_id int64, start_time int64, end_time int64, org_id int64) (monitor []*models.XTMonitoringRecord, err error) {
-
- db := XTReadDB().Model(&monitor).Where("status=1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if start_time > 0 {
- db = db.Where("monitoring_date>=?", start_time)
- }
-
- if end_time > 0 {
- db = db.Where("monitoring_date<=?", end_time)
- }
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- err = db.Find(&monitor).Error
- return monitor, err
- }
-
- func GetAutoPatientDryWeight(patient_id int64, start_time int64, end_time int64, org_id int64) (dryweight []*models.SgjPatientDryweight, err error) {
-
- db := XTReadDB().Model(&dryweight).Where("status=1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- err = db.Order("id asc").Find(&dryweight).Error
- return dryweight, err
- }
-
- func GetAutoInspectionList(patient_id int64, start_time int64, end_time int64, org_id int64) (inpection []*models.XtInspection, err error) {
-
- db := XTReadDB().Model(&inpection).Where("status=1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if start_time > 0 {
- db = db.Where("inspect_date>=?", start_time)
- }
-
- if end_time > 0 {
- db = db.Where("inspect_date<=?", end_time)
- }
- if org_id > 0 {
- db = db.Where("org_id = ?", org_id)
- }
- err = db.Find(&inpection).Error
- return inpection, err
- }
-
- func GetPatientDialysisOrder(org_id int64) (order []*models.XtDialysisOrder, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status=1 and dialysis_date<1733155200", org_id).Find(&order).Error
-
- return order, err
- }
-
- func UpdateAssesmentAfeter(patient_id int64, dialysis_date int64, end_time int64) (models.XtAssessmentAfterDislysis, error) {
-
- dialysisOrder := models.XtAssessmentAfterDislysis{}
-
- err := XTWriteDB().Model(&dialysisOrder).Where("patient_id = ? and assessment_date =? and status=1", patient_id, dialysis_date).Updates(map[string]interface{}{"record_time": end_time}).Error
-
- return dialysisOrder, err
- }
-
- func GetPatientRescueRecord(id int64) (models.XtPatientRescueRecord, error) {
-
- rescueRecords := models.XtPatientRescueRecord{}
-
- err := XTReadDB().Where("id = ? and status=1", id).Find(&rescueRecords).Error
-
- return rescueRecords, err
- }
-
- func ModifyCoursePrint(id int64, content string) (models.XtPatientRescueRecord, error) {
-
- rescueRecord := models.XtPatientRescueRecord{}
-
- err := XTWriteDB().Model(&rescueRecord).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
-
- return rescueRecord, err
- }
-
- func GetPatientRescureRecordList(id int64) (rescueRecord []*models.XtPatientRescueRecord, err error) {
-
- err = XTWriteDB().Model(&rescueRecord).Where("id = ? and status=1", id).Find(&rescueRecord).Error
-
- return rescueRecord, err
- }
-
- func GetAutoDialysisOrder(patient_id int64, start_time int64, end_time int64, user_org_id int64) (order []*models.XtDialysisOrder, err error) {
-
- err = XTReadDB().Where("patient_id = ? and dialysis_date>=? and dialysis_date<=? and user_org_id = ? and status=1", patient_id, start_time, end_time, user_org_id).Find(&order).Error
-
- return order, err
- }
|