patient_service.go 162KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "XT_New/models"
  9. "XT_New/utils"
  10. "github.com/jinzhu/gorm"
  11. )
  12. // GetPatientList 返回患者的列表
  13. 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) (patients []*models.Patients, total int64, err error) {
  14. db := readDb.Table("xt_patients as p").Where("p.status=1")
  15. if orgID > 0 {
  16. db = db.Where("p.user_org_id=?", orgID)
  17. }
  18. if len(keywords) > 0 {
  19. likeKey := "%" + keywords + "%"
  20. db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ? OR p.first_letter LIKE ?", likeKey, likeKey, likeKey)
  21. }
  22. if schedulType > 0 {
  23. db = db.Joins("JOIN xt_schedule as s ON s.patient_id=p.id")
  24. db = db.Where("s.status=1 and s.schedule_type=?", schedulType)
  25. }
  26. if contagion > 0 {
  27. db = db.Joins("JOIN xt_patients_infectious_diseases as xpid ON xpid.patient_id=p.id")
  28. db = db.Where("xpid.disease_id=? and xpid.status=1", contagion)
  29. }
  30. if isscheduling == 1 {
  31. db = db.Where("EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.status=1").QueryExpr())
  32. } else if isscheduling == 2 {
  33. db = db.Where("NOT EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.status=1").QueryExpr())
  34. }
  35. if isprescription == 1 {
  36. db = db.Where("EXISTS (?)", readDb.Table("xt_dialysis_prescription as xdp").Where("xdp.patient_id=p.id and xdp.status=1").QueryExpr())
  37. } else if isprescription == 2 {
  38. db = db.Where("NOT EXISTS (?)", readDb.Table("xt_dialysis_prescription as xdp").Where("xdp.patient_id=p.id and xdp.status=1").QueryExpr())
  39. }
  40. if bindingState > 0 {
  41. db = db.Where("p.binding_state=?", bindingState)
  42. }
  43. if lapseto > 0 {
  44. db = db.Where("p.lapseto=?", lapseto)
  45. }
  46. if source > 0 {
  47. db = db.Where("p.source=?", source)
  48. }
  49. if reimbursementWay > 0 {
  50. db = db.Where("p.reimbursement_way_id = ?", reimbursementWay)
  51. }
  52. if isStartTime {
  53. db = db.Where("p.created_time>=?", startTime)
  54. }
  55. if isEndTime {
  56. db = db.Where("p.created_time<=?", endTime)
  57. }
  58. if patientSoureType > 0 {
  59. db = db.Where("p.patient_source =?", patientSoureType)
  60. }
  61. if nurse > 0 {
  62. db = db.Where("p.head_nurse_id = ?", nurse)
  63. }
  64. offset := (page - 1) * limit
  65. if lapseto == 2 || lapseto == 3 {
  66. 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").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
  67. }
  68. if lapseto != 2 && lapseto != 3 {
  69. if orgID != 10579 && orgID != 10600 && orgID != 10587 {
  70. 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").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
  71. }
  72. if orgID == 10579 || orgID == 10600 {
  73. 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").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
  74. }
  75. if orgID == 10587 {
  76. 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").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
  77. }
  78. }
  79. return
  80. }
  81. // GetAllPatientList 返回全部患者的列表
  82. func GetAllPatientList(orgID int64) (patients []*models.Patients, total int64, err error) {
  83. db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1", orgID)
  84. 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
  85. return
  86. }
  87. func GetAllPatientListTwenty(orgID int64) (patients []*models.Patients, total int64, err error) {
  88. db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1 and p.lapseto = 1", orgID)
  89. 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
  90. return
  91. }
  92. func GetAllPatientListSix(orgID int64) (patients []*models.MSchedualPatientList, err error) {
  93. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1", orgID).Find(&patients).Error
  94. return patients, err
  95. }
  96. // GetAllPatientList 返回全部患者的列表
  97. func GetAllPatientListByList(orgID int64) (patients []*models.MSchedualPatientList, err error) {
  98. redis := RedisClient()
  99. defer redis.Close()
  100. key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
  101. patient_info_str, _ := redis.Get(key).Result()
  102. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  103. err = readDb.Model(&models.MSchedualPatientList{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
  104. if err != nil {
  105. if err == gorm.ErrRecordNotFound {
  106. if len(patients) <= 0 {
  107. redis.Set(key, "null", time.Second*60*60*18)
  108. }
  109. return nil, nil
  110. } else {
  111. return nil, err
  112. }
  113. } else {
  114. if len(patients) > 0 {
  115. //缓存数据
  116. patient_info_json, err := json.Marshal(&patients)
  117. if err == nil {
  118. redis.Set(key, patient_info_json, time.Second*60*60*18)
  119. }
  120. } else {
  121. redis.Set(key, "null", time.Second*60*60*18)
  122. }
  123. return patients, nil
  124. }
  125. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  126. if patient_info_str == "null" {
  127. return nil, nil
  128. } else {
  129. json.Unmarshal([]byte(patient_info_str), &patients)
  130. return patients, nil
  131. }
  132. }
  133. }
  134. func GetAllDevicetByListSix(orgID int64) (devices []*models.MDeviceNumberForList, err error) {
  135. err = readDb.Model(&models.MDeviceNumberForList{}).Preload("Zone", "status = 1 AND org_id = ?", orgID).Where("org_id=?", orgID).Find(&devices).Error
  136. return devices, err
  137. }
  138. func GetMonitorByListSix(orgID int64, monitor_date int64) (monitor []models.VMMonitoringRecord, err error) {
  139. err = readDb.Where("user_org_id = ? and monitor_date = ? and status =1", orgID, monitor_date).Find(&monitor).Error
  140. return monitor, err
  141. }
  142. func GetAllDevicetByList(orgID int64) (devices []*models.MDeviceNumberForList, err error) {
  143. redis := RedisClient()
  144. defer redis.Close()
  145. key := strconv.FormatInt(orgID, 10) + ":" + ":device_list_all"
  146. device_list_str, _ := redis.Get(key).Result()
  147. if len(device_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  148. err = readDb.Model(&models.MDeviceNumberForList{}).Preload("Zone", "status = 1 AND org_id = ?", orgID).Where("org_id=? and status=1 ", orgID).Find(&devices).Error
  149. if err != nil {
  150. if err == gorm.ErrRecordNotFound {
  151. if len(devices) <= 0 {
  152. redis.Set(key, "null", time.Second*60*60*18)
  153. }
  154. return nil, nil
  155. } else {
  156. return nil, err
  157. }
  158. } else {
  159. if len(devices) > 0 {
  160. //缓存数据
  161. device_list_str, err := json.Marshal(&devices)
  162. if err == nil {
  163. redis.Set(key, device_list_str, time.Second*60*60*18)
  164. }
  165. } else {
  166. redis.Set(key, "null", time.Second*60*60*18)
  167. }
  168. return devices, nil
  169. }
  170. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  171. if device_list_str == "null" {
  172. return nil, nil
  173. } else {
  174. json.Unmarshal([]byte(device_list_str), &devices)
  175. return devices, nil
  176. }
  177. }
  178. }
  179. func GetAllAdvicestByList(orgID int64, scheduleDate int64) (advices []models.VMDoctorAdviceForList, err error) {
  180. redis := RedisClient()
  181. defer redis.Close()
  182. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":advice_list_all"
  183. advice_list_str, _ := redis.Get(key).Result()
  184. if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  185. err = readDb.Model(&models.VMDoctorAdviceForList{}).Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).Find(&advices).Error
  186. if err != nil {
  187. if err == gorm.ErrRecordNotFound {
  188. if len(advices) <= 0 {
  189. redis.Set(key, "null", time.Second*60*60*18)
  190. }
  191. return nil, nil
  192. } else {
  193. return nil, err
  194. }
  195. } else {
  196. if len(advices) > 0 {
  197. //缓存数据
  198. advice_list_str, err := json.Marshal(&advices)
  199. if err == nil {
  200. redis.Set(key, advice_list_str, time.Second*60*60*18)
  201. }
  202. } else {
  203. redis.Set(key, "null", time.Second*60*60*18)
  204. }
  205. return advices, nil
  206. }
  207. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  208. if advice_list_str == "null" {
  209. return nil, nil
  210. } else {
  211. json.Unmarshal([]byte(advice_list_str), &advices)
  212. return advices, nil
  213. }
  214. }
  215. }
  216. func GetAllPrescriptionsByList(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionList, err error) {
  217. err = readDb.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
  218. return prescriptions, err
  219. }
  220. //func GetAllPrescriptionsByList(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionList, err error) {
  221. // redis := RedisClient()
  222. // defer redis.Close()
  223. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
  224. // prescriptions_list_all, _ := redis.Get(key).Result()
  225. // redis.Set(prescriptions_list_all, "", time.Second)
  226. // if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  227. // err = readDb.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
  228. // if err != nil {
  229. // if err == gorm.ErrRecordNotFound {
  230. // if len(prescriptions) <= 0 {
  231. // redis.Set(key, "null", time.Second*60*60*18)
  232. // }
  233. // return nil, nil
  234. // } else {
  235. // return nil, err
  236. // }
  237. // } else {
  238. // if len(prescriptions) > 0 {
  239. // //缓存数据
  240. // prescriptions_list_all, err := json.Marshal(&prescriptions)
  241. // if err == nil {
  242. // redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
  243. // }
  244. // } else {
  245. // redis.Set(key, "null", time.Second*60*60*18)
  246. // }
  247. // return prescriptions, nil
  248. // }
  249. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  250. // if prescriptions_list_all == "null" {
  251. // return nil, nil
  252. // } else {
  253. // json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
  254. // return prescriptions, nil
  255. // }
  256. //
  257. // }
  258. //}
  259. func GetAllAssessmentBeforesByList(orgID int64, scheduleDate int64) (assessmentBefores []*models.PredialysisEvaluationList, err error) {
  260. redis := RedisClient()
  261. defer redis.Close()
  262. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
  263. assessment_befores_list_all, _ := redis.Get(key).Result()
  264. if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  265. err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
  266. if err != nil {
  267. if err == gorm.ErrRecordNotFound {
  268. if len(assessmentBefores) <= 0 {
  269. redis.Set(key, "null", time.Second*60*60*18)
  270. }
  271. return nil, nil
  272. } else {
  273. return nil, err
  274. }
  275. } else {
  276. if len(assessmentBefores) > 0 {
  277. //缓存数据
  278. assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
  279. if err == nil {
  280. redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
  281. }
  282. } else {
  283. redis.Set(key, "null", time.Second*60*60*18)
  284. }
  285. return assessmentBefores, nil
  286. }
  287. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  288. if assessment_befores_list_all == "null" {
  289. return nil, nil
  290. } else {
  291. json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
  292. return assessmentBefores, nil
  293. }
  294. }
  295. }
  296. func GetAllDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*models.MDialysisOrderForList, err error) {
  297. 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
  298. return dialysisOrders, err
  299. }
  300. //func GetAllDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*models.MDialysisOrderForList, err error) {
  301. // redis := RedisClient()
  302. // defer redis.Close()
  303. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
  304. // dialysis_orders_list_all, _ := redis.Get(key).Result()
  305. // redis.Set(dialysis_orders_list_all, "", time.Second)
  306. // if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  307. // 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
  308. //
  309. // if err != nil {
  310. // if err == gorm.ErrRecordNotFound {
  311. // return nil, nil
  312. // } else {
  313. // return nil, err
  314. // }
  315. // } else {
  316. // if len(dialysisOrders) > 0 {
  317. // //缓存数据
  318. // dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
  319. // if err == nil {
  320. // redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
  321. // }
  322. // } else {
  323. // redis.Set(key, "null", time.Second*60*60*18)
  324. // }
  325. // return dialysisOrders, nil
  326. // }
  327. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  328. // if dialysis_orders_list_all == "null" {
  329. // return nil, nil
  330. // } else {
  331. // json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
  332. // return dialysisOrders, nil
  333. // }
  334. //
  335. // }
  336. //}
  337. func GetAllTreatmentSummarysByList(orgID int64, scheduleDate int64) (treatmentSummarys []*models.VMTreatmentSummaryForList, err error) {
  338. redis := RedisClient()
  339. defer redis.Close()
  340. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":treatment_summarys_list_all"
  341. treatment_summarys_all, _ := redis.Get(key).Result()
  342. if len(treatment_summarys_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  343. err = readDb.Model(&models.VMTreatmentSummaryForList{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&treatmentSummarys).Error
  344. if err != nil {
  345. if err == gorm.ErrRecordNotFound {
  346. if len(treatment_summarys_all) <= 0 {
  347. redis.Set(key, "null", time.Second*60*60*18)
  348. }
  349. return nil, nil
  350. } else {
  351. return nil, err
  352. }
  353. } else {
  354. if len(treatmentSummarys) > 0 {
  355. //缓存数据
  356. treatment_summarys_all, err := json.Marshal(&treatmentSummarys)
  357. if err == nil {
  358. redis.Set(key, treatment_summarys_all, time.Second*60*60*18)
  359. }
  360. } else {
  361. redis.Set(key, "null", time.Second*60*60*18)
  362. }
  363. return treatmentSummarys, nil
  364. }
  365. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  366. if treatment_summarys_all == "null" {
  367. return nil, nil
  368. } else {
  369. json.Unmarshal([]byte(treatment_summarys_all), &treatmentSummarys)
  370. return treatmentSummarys, nil
  371. }
  372. }
  373. }
  374. func GetAllAssessmentAfterDislysisByList(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
  375. redis := RedisClient()
  376. defer redis.Close()
  377. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
  378. assessment_after_dislysis__all, _ := redis.Get(key).Result()
  379. if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  380. err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
  381. if err != nil {
  382. if err == gorm.ErrRecordNotFound {
  383. if len(assessmentAfterDislysis) <= 0 {
  384. redis.Set(key, "null", time.Second*60*60*18)
  385. }
  386. return nil, nil
  387. } else {
  388. return nil, err
  389. }
  390. } else {
  391. if len(assessmentAfterDislysis) > 0 {
  392. //缓存数据
  393. assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
  394. if err == nil {
  395. redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
  396. }
  397. } else {
  398. redis.Set(key, "null", time.Second*60*60*18)
  399. }
  400. return assessmentAfterDislysis, nil
  401. }
  402. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  403. if assessment_after_dislysis__all == "null" {
  404. return nil, nil
  405. } else {
  406. json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
  407. return assessmentAfterDislysis, nil
  408. }
  409. }
  410. }
  411. func GetAllDobuleCheckList(orgID int64, scheduleDate int64) (dobulecheck []*models.DoubleCheck, err error) {
  412. err = XTReadDB().Where("check_date = ? and user_org_id = ? and status = 1", scheduleDate, orgID).Find(&dobulecheck).Error
  413. return dobulecheck, err
  414. }
  415. func GetAllHisAdvicesByList(orgID int64, scheduleDate int64) (hisAdvices []VMHisDoctorAdviceInfo, err error) {
  416. redis := RedisClient()
  417. defer redis.Close()
  418. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":his_advices_list_all"
  419. his_advices_all, _ := redis.Get(key).Result()
  420. if len(his_advices_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  421. err = readDb.Model(&VMHisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).Find(&hisAdvices).Error
  422. if err != nil {
  423. if err == gorm.ErrRecordNotFound {
  424. if len(hisAdvices) <= 0 {
  425. redis.Set(key, "null", time.Second*60*60*18)
  426. }
  427. return nil, nil
  428. } else {
  429. return nil, err
  430. }
  431. } else {
  432. if len(hisAdvices) > 0 {
  433. //缓存数据
  434. his_advices_all, err := json.Marshal(&hisAdvices)
  435. if err == nil {
  436. redis.Set(key, his_advices_all, time.Second*60*60*18)
  437. }
  438. } else {
  439. redis.Set(key, "null", time.Second*60*60*18)
  440. }
  441. return hisAdvices, nil
  442. }
  443. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  444. if his_advices_all == "null" {
  445. return nil, nil
  446. } else {
  447. json.Unmarshal([]byte(his_advices_all), &hisAdvices)
  448. return hisAdvices, nil
  449. }
  450. }
  451. }
  452. func GetPatientListByUpdateTime(orgID int64, syncTime int64) (patients []*models.PatientListForFaceList, total int64, err error) {
  453. 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)
  454. db = db.Where("updated_time >= ?", syncTime)
  455. err = db.Count(&total).Find(&patients).Error
  456. return
  457. }
  458. func GetPatientListBySchedules(orgID int64, syncTime int64) (patients []*models.SchedulePatients, total int64, err error) {
  459. 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)
  460. err = db.Count(&total).Find(&patients).Error
  461. return
  462. }
  463. func GetPatientListBySchedulesFind(orgID int64, syncTime int64, patient_name string) (patients []*models.SchedulePatients, total int64, err error) {
  464. 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+"%")
  465. err = db.Count(&total).Find(&patients).Error
  466. return
  467. }
  468. func GetPatientListById(orgID int64, patientId int64) (patients models.PatientListForFace, err error) {
  469. err = readDb.Model(&models.PatientListForFaceList{}).Where("user_org_id=? and id = ? and status=1", orgID, patientId).First(&patients).Error
  470. return
  471. }
  472. func GetPatientCount(orgID int64) (total int64) {
  473. readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Count(&total)
  474. return
  475. }
  476. func GetLapsetoPatientCount(orgID int64, lapseto int64) (total int64) {
  477. readDb.Model(&models.Patients{}).Where("user_org_id=? and lapseto=? and status=1", orgID, lapseto).Count(&total)
  478. return
  479. }
  480. func ChechLastDialysisNo(orgID int64) (dialysisNo int64) {
  481. var patient models.Patients
  482. if orgID == 10278 {
  483. err := readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=?", orgID).Order("id desc").First(&patient).Error
  484. if err != nil {
  485. return
  486. }
  487. } else {
  488. err := readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=?", orgID).Order("dialysis_no desc").First(&patient).Error
  489. if err != nil {
  490. return
  491. }
  492. }
  493. if patient.ID == 0 {
  494. return
  495. }
  496. dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
  497. return
  498. }
  499. func FindPatientByDialysisNo(orgID int64, dialysisNo string) (patient models.Patients, err error) {
  500. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=? and lapseto = 1", orgID, dialysisNo).First(&patient).Error
  501. return
  502. }
  503. func FindPatientByIdCardNo(orgID int64, idCardNo string) (patient models.Patients, err error) {
  504. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=?", orgID, idCardNo).First(&patient).Error
  505. return
  506. }
  507. func FindPatientByMobile(orgID int64, mobile string) (patient models.Patients, err error) {
  508. err = readDb.Model(&models.Patients{}).Where("phone=? and user_org_id=? and status=1", mobile, orgID).First(&patient).Error
  509. return
  510. }
  511. func FindPatientById(orgID int64, id int64) (patient models.Patients, err error) {
  512. err = readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
  513. return
  514. }
  515. func FindPatientByIdTwo(orgID int64, id int64) (patient models.XtPatientsNew, err error) {
  516. err = readDb.Model(&models.XtPatientsNew{}).Where("blood_id = ? and user_org_id = ? and status =1", id, orgID).First(&patient).Error
  517. return
  518. }
  519. // func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients, err error) {
  520. // 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
  521. // return
  522. // }
  523. func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients, err error) {
  524. redis := RedisClient()
  525. defer redis.Close()
  526. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
  527. patient_info_str, _ := redis.Get(key).Result()
  528. redis.Set(key, "", time.Second)
  529. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  530. 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
  531. if err != nil {
  532. if err == gorm.ErrRecordNotFound {
  533. return patient, nil
  534. } else {
  535. return patient, err
  536. }
  537. } else {
  538. if patient.ID > 0 {
  539. //缓存数据
  540. patient_info_json, err := json.Marshal(&patient)
  541. if err == nil {
  542. redis.Set(key, patient_info_json, time.Second*60*60*18)
  543. }
  544. } else {
  545. redis.Set(key, "null", time.Second*60*60*18)
  546. }
  547. return patient, nil
  548. }
  549. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  550. if patient_info_str == "null" {
  551. return patient, nil
  552. } else {
  553. json.Unmarshal([]byte(patient_info_str), &patient)
  554. return patient, nil
  555. }
  556. }
  557. }
  558. func FindPatientWithDeviceByNo(orgID int64, no string, time int64) (patient models.SchedualPatient2, err error) {
  559. err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
  560. return db.Preload("DeviceNumber", "org_id = ?", orgID).
  561. Preload("DeviceZone", "org_id = ?", orgID).
  562. Where("user_org_id = ? AND schedule_date = ? ", orgID, time)
  563. }).Preload("InfectiousDiseases", "status = 1").Where("user_org_id=? and dialysis_no = ? and status = 1 ", orgID, no).First(&patient).Error
  564. return
  565. }
  566. func FindPatientWithDeviceByPatientId(orgID int64, id int64, time int64) (patient models.SchedualPatient2, err error) {
  567. err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
  568. return db.Preload("DeviceNumber", "org_id = ?", orgID).
  569. Preload("DeviceZone", "org_id = ?", orgID).
  570. Where("user_org_id = ? AND schedule_date = ? ", orgID, time)
  571. }).Preload("InfectiousDiseases", "status = 1").Where("user_org_id=? and id = ? and status = 1 ", orgID, id).First(&patient).Error
  572. return
  573. }
  574. func CreatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
  575. user, _ := GetSgjUserByMobild(patient.Phone)
  576. customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
  577. utx := writeDb.Begin()
  578. btx := writeUserDb.Begin()
  579. if user.ID == 0 {
  580. user.Mobile = patient.Phone
  581. user.Avatar = patient.Avatar
  582. user.AvatarThumb = patient.Avatar
  583. user.Birthday = patient.Birthday
  584. user.Username = patient.Name
  585. user.Gender = patient.Gender
  586. user.Sources = 11
  587. user.Introduce = patient.Remark
  588. user.Status = 1
  589. user.UpdatedTime = patient.UpdatedTime
  590. user.CreatedTime = patient.CreatedTime
  591. err = btx.Create(&user).Error
  592. if err != nil {
  593. utx.Rollback()
  594. btx.Rollback()
  595. return
  596. }
  597. }
  598. patient.UserId = user.ID
  599. if customer == nil {
  600. err = btx.Create(&models.SgjCustomer{
  601. UserOrgId: patient.UserOrgId,
  602. UserId: user.ID,
  603. Mobile: patient.Phone,
  604. Name: patient.Name,
  605. Gender: patient.Gender,
  606. Birthday: patient.Birthday,
  607. Sources: 11,
  608. Status: 1,
  609. CreatedTime: patient.CreatedTime,
  610. UpdatedTime: patient.UpdatedTime,
  611. Avatar: patient.Avatar,
  612. Remark: patient.Remark,
  613. }).Error
  614. if err != nil {
  615. utx.Rollback()
  616. btx.Rollback()
  617. return
  618. }
  619. }
  620. err = utx.Create(patient).Error
  621. if err != nil {
  622. utx.Rollback()
  623. btx.Rollback()
  624. return
  625. }
  626. var lapseto models.PatientLapseto
  627. lapseto.PatientId = patient.ID
  628. lapseto.LapsetoType = patient.Lapseto
  629. lapseto.CreatedTime = patient.CreatedTime
  630. lapseto.UpdatedTime = patient.CreatedTime
  631. lapseto.Status = 1
  632. lapseto.LapsetoTime = patient.CreatedTime
  633. err = utx.Create(&lapseto).Error
  634. if err != nil {
  635. utx.Rollback()
  636. btx.Rollback()
  637. return
  638. }
  639. if len(contagions) > 0 {
  640. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  641. insertParams := make([]string, 0)
  642. insertData := make([]interface{}, 0)
  643. for _, contagion := range contagions {
  644. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  645. insertData = append(insertData, patient.ID)
  646. insertData = append(insertData, contagion)
  647. insertData = append(insertData, 1)
  648. insertData = append(insertData, patient.CreatedTime)
  649. insertData = append(insertData, patient.UpdatedTime)
  650. }
  651. thisSQL += strings.Join(insertParams, ", ")
  652. err = utx.Exec(thisSQL, insertData...).Error
  653. if err != nil {
  654. utx.Rollback()
  655. btx.Rollback()
  656. return
  657. }
  658. }
  659. if len(diseases) > 0 {
  660. thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  661. insertParams := make([]string, 0)
  662. insertData := make([]interface{}, 0)
  663. for _, disease := range diseases {
  664. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  665. insertData = append(insertData, patient.ID)
  666. insertData = append(insertData, disease)
  667. insertData = append(insertData, 1)
  668. insertData = append(insertData, patient.CreatedTime)
  669. insertData = append(insertData, patient.UpdatedTime)
  670. }
  671. thisSQL += strings.Join(insertParams, ", ")
  672. err = utx.Exec(thisSQL, insertData...).Error
  673. if err != nil {
  674. utx.Rollback()
  675. btx.Rollback()
  676. return
  677. }
  678. }
  679. utx.Commit()
  680. btx.Commit()
  681. return
  682. }
  683. func GetLastPatientData(orgid int64) (models.Patients, error) {
  684. patients := models.Patients{}
  685. err := XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1", orgid).Last(&patients).Error
  686. return patients, err
  687. }
  688. func CreatePatientsNew(patientsNew *models.XtPatientsNew) error {
  689. err := XTWriteDB().Model(&patientsNew).Create(&patientsNew).Error
  690. return err
  691. }
  692. func CreateAllergic(allergic models.XtPatientAllergic) error {
  693. err := XTWriteDB().Create(&allergic).Error
  694. return err
  695. }
  696. func EditPatientLapseto(patient *models.Patients, lapseto *models.PatientLapseto) (err error) {
  697. utx := writeDb.Begin()
  698. 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
  699. //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
  700. if err != nil {
  701. utx.Rollback()
  702. return
  703. }
  704. err = utx.Create(lapseto).Error
  705. if err != nil {
  706. utx.Rollback()
  707. return
  708. }
  709. // 删除排班和排班模板信息
  710. if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
  711. now := time.Now()
  712. deleteScheduleErr := utx.Model(&models.PatientSchedule{}).Where("patient_id = ? AND schedule_date >= ? AND status = 1", patient.ID, lapseto.LapsetoTime).Updates(map[string]interface{}{
  713. "status": 0,
  714. "updated_time": now.Unix(),
  715. }).Error
  716. if deleteScheduleErr != nil {
  717. utx.Rollback()
  718. err = deleteScheduleErr
  719. return
  720. }
  721. deleteSchTempItemErr := utx.Model(&models.PatientScheduleTemplateItem{}).Where("patient_id = ? AND status = 1", patient.ID).Updates(map[string]interface{}{
  722. "status": 0,
  723. "mtime": now.Unix(),
  724. }).Error
  725. if deleteSchTempItemErr != nil {
  726. utx.Rollback()
  727. err = deleteSchTempItemErr
  728. return
  729. }
  730. }
  731. utx.Commit()
  732. return
  733. }
  734. func UpdatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
  735. // if len(contagions) > 0 || len(diseases) > 0 {
  736. utx := writeDb.Begin()
  737. err = utx.Save(patient).Error
  738. if err != nil {
  739. utx.Rollback()
  740. return
  741. }
  742. err = utx.Model(&models.InfectiousDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
  743. fmt.Println("err", err)
  744. if err != nil {
  745. utx.Rollback()
  746. return
  747. }
  748. if len(contagions) > 0 && patient.IsInfectious == 2 {
  749. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  750. insertParams := make([]string, 0)
  751. insertData := make([]interface{}, 0)
  752. for _, contagion := range contagions {
  753. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  754. insertData = append(insertData, patient.ID)
  755. insertData = append(insertData, contagion)
  756. insertData = append(insertData, 1)
  757. insertData = append(insertData, time.Now().Unix())
  758. insertData = append(insertData, time.Now().Unix())
  759. }
  760. thisSQL += strings.Join(insertParams, ", ")
  761. err = utx.Exec(thisSQL, insertData...).Error
  762. if err != nil {
  763. utx.Rollback()
  764. return
  765. }
  766. }
  767. err = utx.Model(&models.ChronicDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
  768. if err != nil {
  769. utx.Rollback()
  770. return
  771. }
  772. if len(diseases) > 0 {
  773. thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  774. insertParams := make([]string, 0)
  775. insertData := make([]interface{}, 0)
  776. for _, disease := range diseases {
  777. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  778. insertData = append(insertData, patient.ID)
  779. insertData = append(insertData, disease)
  780. insertData = append(insertData, 1)
  781. insertData = append(insertData, time.Now().Unix())
  782. insertData = append(insertData, time.Now().Unix())
  783. }
  784. thisSQL += strings.Join(insertParams, ", ")
  785. err = utx.Exec(thisSQL, insertData...).Error
  786. if err != nil {
  787. utx.Rollback()
  788. return
  789. }
  790. }
  791. utx.Commit()
  792. // } else {
  793. // err = writeDb.Save(patient).Error
  794. // }
  795. return
  796. }
  797. func UpdatePatientLapseto(patientid int64, lapseto models.PatientLapseto) error {
  798. 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
  799. return err
  800. }
  801. func UpdatepatientTwo(patientsNew *models.XtPatientsNew, id int64) error {
  802. 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,
  803. "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}).Error
  804. return err
  805. }
  806. func GetLastInfectionRecord(id int64, org_id int64, project_id int64, date int64) (inspection models.Inspection, err error) {
  807. 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
  808. return
  809. }
  810. func GetAllInfectionRecord(date int64, org_id int64, patient_id int64, project_id int64) (inspection []*models.Inspection, err error) {
  811. 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
  812. return
  813. }
  814. func GetPatientDiseases(id int64) []int64 {
  815. var dis []models.ChronicDiseases
  816. ids := make([]int64, 0)
  817. err := readDb.Model(&models.ChronicDiseases{}).Where("patient_id=? and status=1", id).Find(&dis).Error
  818. if err != nil || len(dis) == 0 {
  819. return ids
  820. }
  821. for _, item := range dis {
  822. ids = append(ids, item.DiseaseId)
  823. }
  824. return ids
  825. }
  826. func GetPatientContagions(id int64) []int64 {
  827. var cis []models.InfectiousDiseases
  828. ids := make([]int64, 0)
  829. err := readDb.Model(&models.InfectiousDiseases{}).Where("patient_id=? and status=1", id).Find(&cis).Error
  830. if err != nil || len(cis) == 0 {
  831. return ids
  832. }
  833. for _, item := range cis {
  834. ids = append(ids, item.DiseaseId)
  835. }
  836. return ids
  837. }
  838. func FindPatientDialysisSolutionByMode(orgID int64, patientID, modeId int64) (solution models.DialysisSolution, err error) {
  839. 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
  840. return
  841. }
  842. func FindPatientDialysisSolution(orgID int64, id int64) (solution models.DialysisSolution, err error) {
  843. err = readDb.Model(&models.DialysisSolution{}).Where("id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
  844. return
  845. }
  846. func FindPatientDialysisSolutionChild(orgID int64, id int64) (solution models.DialysisSolution, err error) {
  847. err = readDb.Model(&models.DialysisSolution{}).Where("parent_id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
  848. return
  849. }
  850. func CreatePatientDialysisSolution(solution *models.DialysisSolution) (err error) {
  851. err = writeDb.Create(solution).Error
  852. return
  853. }
  854. func UpdatePatientDialysisSolution(solution *models.DialysisSolution) (err error) {
  855. err = writeDb.Save(solution).Error
  856. return
  857. }
  858. // GetPatientDialysisSolutionList 返回患者透析方案的列表
  859. func GetPatientDialysisSolutionList(orgID int64, patientID int64, page, limit int64) (solutions []*models.DialysisSolution, total int64, err error) {
  860. offset := (page - 1) * limit
  861. db := readDb.Table("xt_dialysis_solution as ds").Where("ds.status=1")
  862. if orgID > 0 {
  863. db = db.Where("ds.user_org_id=?", orgID)
  864. }
  865. if patientID > 0 {
  866. db = db.Where("ds.patient_id=?", patientID)
  867. }
  868. db = db.Count(&total).Offset(offset).Limit(limit)
  869. err = db.Order("id desc").Find(&solutions).Error
  870. if err != nil {
  871. return
  872. }
  873. if len(solutions) > 0 {
  874. nilNameIds := make([]int64, 0)
  875. for _, solution := range solutions {
  876. if len(solution.ModeName) == 0 {
  877. nilNameIds = append(nilNameIds, solution.ModeId)
  878. }
  879. }
  880. if len(nilNameIds) > 0 {
  881. var modes []*models.TreatmentMode
  882. err = readDb.Model(&models.TreatmentMode{}).Where("id IN (?)", nilNameIds).Find(&modes).Error
  883. if err != nil {
  884. return
  885. }
  886. modesMap := make(map[int64]models.TreatmentMode, 0)
  887. for _, mode := range modes {
  888. modesMap[mode.ID] = *mode
  889. }
  890. for index, solution := range solutions {
  891. if _, exixt := modesMap[solution.ModeId]; exixt && len(solution.ModeName) == 0 {
  892. solutions[index].ModeName = modesMap[solution.ModeId].Name
  893. }
  894. }
  895. }
  896. }
  897. return
  898. }
  899. // GetPatientDryWeightAdjustList 返回患者调整干体重的列表
  900. func GetPatientDryWeightAdjustList(orgID int64, patientID int64, page int64, limit int64) (weights []*models.DryWeightAdjust, total int64, err error) {
  901. db := readDb.Table("xt_dry_weight_adjust as dwa").Where("dwa.status=1")
  902. if orgID > 0 {
  903. db = db.Where("dwa.user_org_id=?", orgID)
  904. }
  905. if patientID > 0 {
  906. db = db.Where("dwa.patient_id=?", patientID)
  907. }
  908. 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")
  909. if page > 0 && limit > 0 {
  910. offset := (page - 1) * limit
  911. db = db.Offset(offset).Limit(limit)
  912. }
  913. err = db.Find(&weights).Error
  914. return
  915. }
  916. func CreateDryWeightAdjust(m *models.DryWeightAdjust) (err error) {
  917. err = writeDb.Create(m).Error
  918. return
  919. }
  920. func FindPatientLastDryWeightAdjust(orgID int64, id int64) (weight models.DryWeightAdjust, err error) {
  921. err = readDb.Model(&models.DryWeightAdjust{}).Where("user_org_id=? and patient_id=? and status=1", orgID, id).Order("id desc").First(&weight).Error
  922. return
  923. }
  924. func UpdateDoctorAdviceById(id int64, prescribing_number float64, single_dose float64) error {
  925. err := XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=? and status =1", id).Updates(map[string]interface{}{"prescribing_number": prescribing_number, "single_dose": single_dose}).Error
  926. return err
  927. }
  928. func CreateDoctorAdvice(m *models.DoctorAdvice) (err error) {
  929. return writeDb.Create(m).Error
  930. }
  931. func GetMaxAdviceGroupID(orgId int64) (group int64) {
  932. var advice models.DoctorAdvice
  933. err := readDb.Table("xt_doctor_advice").Where("user_org_id=?", orgId).Select("max(groupno) as groupno").First(&advice).Error
  934. if err != nil {
  935. fmt.Println(err)
  936. group = 0
  937. }
  938. group = advice.GroupNo
  939. return
  940. }
  941. func CreateGroupAdvice(orgId int64, group int64, advices []*models.GroupAdvice) (err error) {
  942. if group == 0 {
  943. group = GetMaxAdviceGroupID(orgId) + 1
  944. }
  945. tx := writeDb.Begin()
  946. defer func() {
  947. if r := recover(); r != nil {
  948. tx.Rollback()
  949. }
  950. }()
  951. for _, advice := range advices {
  952. advice.GroupNo = group
  953. if err = tx.Create(advice).Error; err != nil {
  954. tx.Rollback()
  955. return
  956. }
  957. }
  958. tx.Commit()
  959. return
  960. }
  961. func CreateMGroupAdvice(orgId int64, advices []*models.GroupAdvice, groupNo int64) (list []*models.GroupAdvice, err error) {
  962. if groupNo <= 0 {
  963. group := GetMaxAdviceGroupID(orgId)
  964. groupNo = group + 1
  965. }
  966. tx := writeDb.Begin()
  967. defer func() {
  968. if r := recover(); r != nil {
  969. tx.Rollback()
  970. }
  971. }()
  972. for _, advice := range advices {
  973. advice.GroupNo = groupNo
  974. if err = tx.Create(advice).Error; err != nil {
  975. tx.Rollback()
  976. return
  977. }
  978. list = append(list, advice)
  979. if len(advice.Children) > 0 {
  980. for _, child := range advice.Children {
  981. child.GroupNo = groupNo
  982. child.ParentId = advice.ID
  983. fmt.Println(child)
  984. if err = tx.Create(&child).Error; err != nil {
  985. tx.Rollback()
  986. return
  987. }
  988. list = append(list, child)
  989. }
  990. }
  991. }
  992. tx.Commit()
  993. return
  994. }
  995. func CreateMGroupAdviceOne(orgId int64, advices []*models.GroupAdvice, groupNo int64) (list []*models.GroupAdvice, err error) {
  996. if groupNo <= 0 {
  997. group := GetMaxAdviceGroupID(orgId)
  998. groupNo = group + 1
  999. }
  1000. tx := writeDb.Begin()
  1001. defer func() {
  1002. if r := recover(); r != nil {
  1003. tx.Rollback()
  1004. }
  1005. }()
  1006. for _, advice := range advices {
  1007. advice.GroupNo = advice.GroupNo
  1008. if err = tx.Create(advice).Error; err != nil {
  1009. tx.Rollback()
  1010. return
  1011. }
  1012. list = append(list, advice)
  1013. if len(advice.Children) > 0 {
  1014. for _, child := range advice.Children {
  1015. child.GroupNo = advice.GroupNo
  1016. child.ParentId = advice.ID
  1017. fmt.Println(child)
  1018. if err = tx.Create(&child).Error; err != nil {
  1019. tx.Rollback()
  1020. return
  1021. }
  1022. list = append(list, child)
  1023. }
  1024. }
  1025. }
  1026. tx.Commit()
  1027. return
  1028. }
  1029. func UpdateDoctorAdvice(m *models.DoctorAdvice) (err error) {
  1030. return writeDb.Save(m).Error
  1031. }
  1032. func StopGroupAdvice(orgId int64, groupNo int64, m *models.DoctorAdvice) (err error) {
  1033. 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
  1034. if err != nil {
  1035. return
  1036. }
  1037. return
  1038. }
  1039. func StopDoctorAdvice(m *models.DoctorAdvice) (err error) {
  1040. ut := writeDb.Begin()
  1041. err = ut.Save(m).Error
  1042. if err != nil {
  1043. ut.Rollback()
  1044. return
  1045. }
  1046. 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
  1047. if err != nil {
  1048. ut.Rollback()
  1049. return
  1050. }
  1051. ut.Commit()
  1052. return
  1053. }
  1054. func DeleteSolution(m *models.DialysisSolution) (err error) {
  1055. if m.ParentId > 0 {
  1056. return writeDb.Save(m).Error
  1057. } else {
  1058. ut := writeDb.Begin()
  1059. err = ut.Save(m).Error
  1060. if err != nil {
  1061. ut.Rollback()
  1062. return
  1063. }
  1064. err = ut.Model(&models.DialysisSolution{}).Where("parent_id=?", m.ID).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0}).Error
  1065. if err != nil {
  1066. ut.Rollback()
  1067. return
  1068. }
  1069. ut.Commit()
  1070. }
  1071. return
  1072. }
  1073. func DeleteDoctorAdvice(m *models.DoctorAdvice) (err error) {
  1074. if m.ParentId > 0 {
  1075. return writeDb.Save(m).Error
  1076. } else {
  1077. ut := writeDb.Begin()
  1078. err = ut.Save(m).Error
  1079. if err != nil {
  1080. ut.Rollback()
  1081. return
  1082. }
  1083. 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
  1084. if err != nil {
  1085. ut.Rollback()
  1086. return
  1087. }
  1088. ut.Commit()
  1089. }
  1090. return
  1091. }
  1092. func DeleteGroupAdvice(orgId int64, groupNo int64, admin_user_id int64) (err error) {
  1093. 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
  1094. if err != nil {
  1095. return
  1096. }
  1097. return
  1098. }
  1099. func DeleteGroupAdviceOne(orgId int64, groupNo int64, admin_user_id int64) (err error) {
  1100. 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
  1101. if err != nil {
  1102. return
  1103. }
  1104. return
  1105. }
  1106. func FindDoctorAdvice(orgID, id int64) (advice models.DoctorAdvice, err error) {
  1107. err = readDb.Model(&models.DoctorAdvice{}).Where("id = ? and user_org_id=? and status = 1", id, orgID).First(&advice).Error
  1108. return
  1109. }
  1110. func FindDoctorAdviceOne(orgID, patient_id int64) (advice models.DoctorAdvice, err error) {
  1111. err = readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id=? and status = 1", patient_id, orgID).First(&advice).Error
  1112. return
  1113. }
  1114. func FindDoctorAdviceTwo(ids []string, orgID int64) (advice []*models.DoctorAdvice, err error) {
  1115. err = readDb.Model(&models.DoctorAdvice{}).Where("id in(?) and user_org_id=? and status = 1", ids, orgID).First(&advice).Error
  1116. return
  1117. }
  1118. func FindHisDoctorAdvice(orgID, id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1119. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and user_org_id=? and status = 1", id, orgID).First(&advice).Error
  1120. return
  1121. }
  1122. func FindHisDoctorAdviceTwo(ids []string, orgID int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1123. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id in(?) and user_org_id=? and status = 1", ids, orgID).First(&advice).Error
  1124. return
  1125. }
  1126. func FindHisDoctorAdviceOne(orgID, patient_id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1127. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? and user_org_id=? and status = 1", patient_id, orgID).First(&advice).Error
  1128. return
  1129. }
  1130. func FindDoctorAdviceByGroupNo(orgID, groupNo int64) (advice models.DoctorAdvice, err error) {
  1131. err = readDb.Model(&models.DoctorAdvice{}).Where("groupno = ? and user_org_id=? and status = 1", groupNo, orgID).First(&advice).Error
  1132. return
  1133. }
  1134. func GetDoctorAdviceList(orgID, patientID, advice_type, stop, start, end int64, keywords string) (advices []*models.DoctorAdvices, total int64, err error) {
  1135. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  1136. table := UserReadDB().Table("sgj_user_admin_role as r")
  1137. fmt.Print("table", table)
  1138. if orgID > 0 {
  1139. db = db.Where("x.user_org_id=?", orgID)
  1140. }
  1141. if patientID > 0 {
  1142. db = db.Where("x.patient_id = ?", patientID)
  1143. }
  1144. if advice_type > 0 {
  1145. db = db.Where("x.advice_type = ?", advice_type)
  1146. } else if advice_type == 0 {
  1147. db = db.Where("x.advice_type in (?)", []int{1, 3})
  1148. }
  1149. if stop == 1 {
  1150. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  1151. } else if stop == 2 {
  1152. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  1153. }
  1154. if start != 0 {
  1155. db = db.Where("x.start_time>=?", start)
  1156. }
  1157. if end != 0 {
  1158. db = db.Where("start_time<=?", end)
  1159. }
  1160. if len(keywords) > 0 {
  1161. likeKey := "%" + keywords + "%"
  1162. db = db.Where("x.advice_name LIKE ?", likeKey)
  1163. }
  1164. 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
  1165. fmt.Print("err", err)
  1166. return
  1167. }
  1168. func GetLongDoctorAdviceList(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64) (advices []*models.DoctorAdvices, total int64, err error) {
  1169. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  1170. table := UserReadDB().Table("sgj_user_admin_role as r")
  1171. fmt.Print("table", table)
  1172. if orgID > 0 {
  1173. db = db.Where("x.user_org_id=?", orgID)
  1174. }
  1175. if patientID > 0 {
  1176. db = db.Where("x.patient_id = ?", patientID)
  1177. }
  1178. if advice_type == 1 && advice_type > 0 {
  1179. db = db.Where("x.advice_type = ?", advice_type)
  1180. }
  1181. if advice_type == 3 && advice_type > 0 {
  1182. db = db.Where("x.advice_type = 2 or x.advice_type = 3")
  1183. }
  1184. if advice_type == 4 && advice_type > 0 {
  1185. db = db.Where("x.advice_type = 4")
  1186. }
  1187. if stop == 1 {
  1188. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  1189. } else if stop == 2 {
  1190. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  1191. }
  1192. if start != 0 {
  1193. db = db.Where("x.start_time>=?", start)
  1194. }
  1195. if end != 0 {
  1196. db = db.Where("x.start_time<=?", end)
  1197. }
  1198. if len(keywords) > 0 {
  1199. likeKey := "%" + keywords + "%"
  1200. db = db.Where("x.advice_name LIKE ?", likeKey)
  1201. }
  1202. offset := (page - 1) * limit
  1203. 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
  1204. fmt.Print("err", err)
  1205. return
  1206. }
  1207. 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) {
  1208. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  1209. table := UserReadDB().Table("sgj_user_admin_role as r")
  1210. fmt.Print("table", table)
  1211. if len(delive_way_one) > 0 {
  1212. db = db.Where("delivery_way=?", delive_way_one)
  1213. }
  1214. if orgID > 0 {
  1215. db = db.Where("x.user_org_id=?", orgID)
  1216. }
  1217. if patientID > 0 {
  1218. db = db.Where("x.patient_id = ?", patientID)
  1219. }
  1220. if advice_type == 1 && advice_type > 0 {
  1221. db = db.Where("x.advice_type = ?", advice_type)
  1222. }
  1223. if advice_type == 2 && advice_type > 0 {
  1224. db = db.Where("x.advice_type = ?", advice_type)
  1225. }
  1226. if advice_type == 3 && advice_type > 0 {
  1227. db = db.Where("x.advice_type = 2 or x.advice_type = 3")
  1228. }
  1229. if advice_type == 4 && advice_type > 0 {
  1230. db = db.Where("x.advice_type = 4")
  1231. }
  1232. if stop == 1 {
  1233. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  1234. } else if stop == 2 {
  1235. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  1236. }
  1237. if start != 0 {
  1238. db = db.Where("x.start_time>=?", start)
  1239. }
  1240. if end != 0 {
  1241. db = db.Where("x.start_time<=?", end)
  1242. }
  1243. if len(keywords) > 0 {
  1244. likeKey := "%" + keywords + "%"
  1245. db = db.Where("x.advice_name LIKE ?", likeKey)
  1246. }
  1247. offset := (page - 1) * limit
  1248. 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
  1249. fmt.Print("err", err)
  1250. return
  1251. }
  1252. 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) {
  1253. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  1254. table := UserReadDB().Table("sgj_user_admin_role as r")
  1255. fmt.Println(table)
  1256. if len(delive_way_one) > 0 {
  1257. db = db.Where("delivery_way=?", delive_way_one)
  1258. }
  1259. if orgID > 0 {
  1260. db = db.Where("x.user_org_id=?", orgID)
  1261. }
  1262. if patientID > 0 {
  1263. db = db.Where("x.patient_id = ?", patientID)
  1264. }
  1265. if advice_type == 1 {
  1266. db = db.Where("x.advice_type = ?", advice_type)
  1267. }
  1268. if advice_type == 3 && advice_type > 0 {
  1269. db = db.Where("x.advice_type = 2 or x.advice_type = 3")
  1270. }
  1271. if advice_type == 4 && advice_type > 0 {
  1272. db = db.Where("x.advice_type = 4")
  1273. }
  1274. if stop == 1 {
  1275. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  1276. } else if stop == 2 {
  1277. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  1278. }
  1279. if start != 0 {
  1280. db = db.Where("x.start_time>=?", start)
  1281. }
  1282. if end != 0 {
  1283. db = db.Where("x.start_time<=?", end)
  1284. }
  1285. if len(keywords) > 0 {
  1286. likeKey := "%" + keywords + "%"
  1287. db = db.Where("x.advice_name LIKE ?", likeKey)
  1288. }
  1289. offset := (page - 1) * limit
  1290. 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
  1291. fmt.Print("错误是什么", err)
  1292. return
  1293. }
  1294. func GetDoctorAdvicePageList(orgID, patientID, advice_type, stop, start, end int64, keywords string, page, limit int64) (advices []*models.DoctorAdvice, total int64, err error) {
  1295. offset := (page - 1) * limit
  1296. db := readDb.Model(&models.DoctorAdvice{}).Where("status=1")
  1297. if orgID > 0 {
  1298. db = db.Where("user_org_id=?", orgID)
  1299. }
  1300. if patientID > 0 {
  1301. db = db.Where("patient_id = ?", patientID)
  1302. }
  1303. if advice_type > 0 {
  1304. db = db.Where("advice_type = ?", advice_type)
  1305. }
  1306. if stop == 1 {
  1307. db = db.Where("(stop_state=? or execution_state=?) and parent_id=0", stop, stop)
  1308. } else if stop == 2 {
  1309. db = db.Where("stop_state=? and execution_state=?", stop, stop)
  1310. }
  1311. if start != 0 {
  1312. db = db.Where("start_time>=?", start)
  1313. }
  1314. if end != 0 {
  1315. db = db.Where("start_time<=?", end)
  1316. }
  1317. if len(keywords) > 0 {
  1318. likeKey := "%" + keywords + "%"
  1319. db = db.Where("advice_name LIKE ?", likeKey)
  1320. }
  1321. 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
  1322. return
  1323. }
  1324. func CreateSubDoctorAdvice(advices []*models.DoctorAdvice) (err error) {
  1325. if len(advices) > 0 {
  1326. utx := writeDb.Begin()
  1327. if len(advices) > 0 {
  1328. 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 "
  1329. insertParams := make([]string, 0)
  1330. insertData := make([]interface{}, 0)
  1331. for _, advice := range advices {
  1332. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  1333. insertData = append(insertData, advice.SingleDoseUnit)
  1334. insertData = append(insertData, advice.PrescribingNumber)
  1335. insertData = append(insertData, advice.PrescribingNumberUnit)
  1336. insertData = append(insertData, advice.AdviceName)
  1337. insertData = append(insertData, advice.AdviceDesc)
  1338. insertData = append(insertData, advice.SingleDose)
  1339. insertData = append(insertData, advice.CreatedTime)
  1340. insertData = append(insertData, advice.UpdatedTime)
  1341. insertData = append(insertData, advice.PatientId)
  1342. insertData = append(insertData, advice.ParentId)
  1343. insertData = append(insertData, advice.UserOrgId)
  1344. insertData = append(insertData, advice.RecordDate)
  1345. insertData = append(insertData, 2)
  1346. insertData = append(insertData, advice.DrugSpecUnit)
  1347. }
  1348. thisSQL += strings.Join(insertParams, ", ")
  1349. err = utx.Exec(thisSQL, insertData...).Error
  1350. if err != nil {
  1351. utx.Rollback()
  1352. return
  1353. }
  1354. }
  1355. utx.Commit()
  1356. }
  1357. return
  1358. }
  1359. func GetPatientDialysisRecord(orgID, patientID int64, page, limit, start, end, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
  1360. offset := (page - 1) * limit
  1361. var total int64
  1362. var err error
  1363. var orders []*models.PatientDialysisRecord
  1364. // err = readDb.Table("xt_dialysis_order as do").
  1365. // Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  1366. // Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  1367. // Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  1368. // Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  1369. // 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).
  1370. // Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
  1371. // 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
  1372. db := readDb.Table("xt_dialysis_order as do").
  1373. Preload("DoctorAdvice", "patient_id =? and user_org_id = ? and status =1 and advice_type =2", patientID, orgID).
  1374. Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  1375. Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  1376. Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
  1377. return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
  1378. return readUserDb.Where("status = 1 and org_id=?", orgID)
  1379. })
  1380. }).
  1381. Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  1382. Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  1383. Preload("Device", "org_id=? and status=1", orgID).
  1384. Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
  1385. return readUserDb.Where("org_id=?", orgID)
  1386. }).
  1387. 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).
  1388. Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
  1389. Where("do.patient_id=? and do.user_org_id=? and do.status=1 and s.status=1", patientID, orgID).Group("s.schedule_date")
  1390. if start != 0 {
  1391. db = db.Where("do.dialysis_date>=?", start)
  1392. }
  1393. if end != 0 {
  1394. db = db.Where("do.dialysis_date<=?", end)
  1395. }
  1396. if mode_id > 0 {
  1397. 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")
  1398. db = db.Where("dp.mode_id=?", mode_id)
  1399. }
  1400. 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
  1401. if len(orders) > 0 {
  1402. ids := make([]int64, 0)
  1403. for _, order := range orders {
  1404. dialyzer := order.DialysisPrescription.Dialyzer
  1405. ids = append(ids, dialyzer)
  1406. }
  1407. if len(ids) > 0 {
  1408. var dialyzers []*models.DeviceNumber
  1409. err = readDb.Model(&models.DeviceNumber{}).Where("id IN (?) and org_id=? and status=1", ids, orgID).Find(&dialyzers).Error
  1410. if err != nil {
  1411. return nil, 0, err
  1412. }
  1413. dialyzerMap := make(map[int64]models.DeviceNumber, 0)
  1414. for _, item := range dialyzers {
  1415. dialyzerMap[item.ID] = *item
  1416. }
  1417. for orderIndex, order := range orders {
  1418. if _, exist := dialyzerMap[order.DialysisPrescription.Dialyzer]; exist {
  1419. orders[orderIndex].DeviceNumber = dialyzerMap[order.DialysisPrescription.Dialyzer].Number
  1420. }
  1421. }
  1422. }
  1423. }
  1424. return orders, total, err
  1425. }
  1426. func GetPatientTreatmentSummaryList(orgID, patientID, page, limit, start, end int64) (list []*models.TreatmentSummary, total int, err error) {
  1427. offset := (page - 1) * limit
  1428. fmt.Println(offset)
  1429. fmt.Println(limit)
  1430. db := readDb.Model(&models.TreatmentSummary{}).Where("user_org_id = ? and patient_id=?", orgID, patientID)
  1431. if start != 0 {
  1432. db = db.Where("assessment_date >= ?", start)
  1433. }
  1434. if end != 0 {
  1435. db = db.Where("assessment_date <= ?", end)
  1436. }
  1437. db = db.Where("status=1")
  1438. err = db.Count(&total).Offset(offset).Limit(limit).Order("assessment_date desc, id desc").Find(&list).Error
  1439. return
  1440. }
  1441. func GetPatientScheduleList(orgID int64, patientID int64, page int64, limit int64, start int64) (schedules []*models.PatientSchedule, err error) {
  1442. offset := (page - 1) * limit
  1443. err = readDb.Table("xt_schedule as s").
  1444. Preload("DeviceZone", "org_id=? and status=1", orgID).
  1445. Preload("DeviceNumber", "org_id=? and status=1", orgID).
  1446. Preload("TreatmentMode", "status=1").
  1447. Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.status=1", patientID, orgID, start).
  1448. Limit(limit).Offset(offset).Find(&schedules).Error
  1449. return
  1450. }
  1451. func GetMonitorRecord(orgID int64, date int64, partition int64, patientId int64) ([]*models.NewVMMonitorDialysisSchedule, error) {
  1452. var mds []*models.NewVMMonitorDialysisSchedule
  1453. db := readDb.Model(&models.NewVMMonitorDialysisSchedule{})
  1454. if date > 0 {
  1455. db = db.Where("schedule_date = ?", date)
  1456. }
  1457. if partition > 0 {
  1458. db = db.Where("partition_id = ?", partition)
  1459. }
  1460. if patientId > 0 {
  1461. db = db.Where("patient_id = ?", patientId)
  1462. }
  1463. err = db.Where("status = 1 and user_org_id = ?", orgID).Find(&mds).Error
  1464. return mds, err
  1465. }
  1466. func MobileGetMonitorsWithPatient(orgID int64, keyword string, page int) ([]*models.MonitorDialysisSchedule, error) {
  1467. var patients []*models.Patients
  1468. 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
  1469. if getPatientErr != nil {
  1470. return nil, getPatientErr
  1471. }
  1472. patientIDs := make([]int64, len(patients))
  1473. for index, patient := range patients {
  1474. patientIDs[index] = patient.ID
  1475. }
  1476. db := readDb.
  1477. Model(&models.MonitorDialysisSchedule{}).
  1478. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1479. Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  1480. Preload("TreatmentMode", "status = 1").
  1481. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  1482. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  1483. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  1484. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  1485. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  1486. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID).
  1487. Where("status = 1 AND user_org_id = ? AND patient_id in (?)", orgID, patientIDs)
  1488. var schedules []*models.MonitorDialysisSchedule
  1489. err := db.Offset(20 * (page - 1)).Limit(20).Order("schedule_date desc").Find(&schedules).Error
  1490. return schedules, err
  1491. }
  1492. func GetPatientByKeyWord(orgID int64, keywords string) (patient []*models.Patients, err error) {
  1493. db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID)
  1494. if len(keywords) > 0 {
  1495. likekey := "%" + keywords + "%"
  1496. err = db.Where("name LIKE ? OR dialysis_no LIKE ? OR first_letter LIKE ?", likekey, likekey, likekey).Find(&patient).Error
  1497. } else {
  1498. err = db.Find(&patient).Error
  1499. }
  1500. return
  1501. }
  1502. func FindDoctorAdviceByGoroupNo(orgID int64, groupno int64) (advice models.DoctorAdvice, err error) {
  1503. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1", orgID, groupno).First(&advice).Error
  1504. return
  1505. }
  1506. func FindOldDoctorAdvice(orgID int64, advice_id int64) (advice models.DoctorAdvice, err error) {
  1507. err = readDb.Model(&models.DoctorAdvice{}).Where("id = ? AND user_org_id=? AND status = 1", advice_id, orgID).First(&advice).Error
  1508. return
  1509. }
  1510. func UpdateAdviceGroupStartTime(orgID int64, groupNO int64, startTime int64, admin_user_id int64) error {
  1511. now := time.Now().Unix()
  1512. 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{}{
  1513. "start_time": startTime,
  1514. "updated_time": now,
  1515. "modifier": admin_user_id,
  1516. }).Error
  1517. return err
  1518. }
  1519. func QueryPatientById(id int64) *models.Patients {
  1520. var pat models.Patients
  1521. err := readDb.Model(&models.Patients{}).Where("id=?", id).First(&pat).Error
  1522. if err != nil {
  1523. }
  1524. return &pat
  1525. }
  1526. func FindAllDoctorAdviceByGoroupNo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
  1527. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1", orgID, groupno).Find(&advice).Error
  1528. return
  1529. }
  1530. func FindAllDoctorAdviceByGoroupNoOne(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
  1531. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 and execution_state =2", orgID, groupno).Find(&advice).Error
  1532. return
  1533. }
  1534. func UpdateDoctorAdviceByGoroupNo(id int64, drug_id int64) error {
  1535. 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
  1536. return err
  1537. }
  1538. func FindAllDoctorAdviceByGoroupNoTwety(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
  1539. 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
  1540. return
  1541. }
  1542. func FindDoctorAdviceByIds(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
  1543. err = readDb.Model(&models.DoctorAdvice{}).Where("id IN (?) AND user_org_id = ? AND status = 1", ids, orgID).Find(&advice).Error
  1544. return
  1545. }
  1546. func FindDoctorAdviceByIdsOne(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
  1547. err = readDb.Model(&models.DoctorAdvice{}).Where("id IN (?) AND user_org_id = ? AND status = 1 and execution_state =2", ids, orgID).Find(&advice).Error
  1548. return
  1549. }
  1550. func FindDoctorAdviceByIdsTwety(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
  1551. 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
  1552. return
  1553. }
  1554. func GetBatchDoctorAdviceList(ids []string, user_org_id int64) (advice []*models.DoctorAdvice, err error) {
  1555. err = XTReadDB().Where("id in(?) and user_org_id = ? and status =1", ids, user_org_id).Find(&advice).Error
  1556. return advice, err
  1557. }
  1558. func BatchDeleteDoctorAdvice(ids []string, user_id int64) (err error) {
  1559. ut := writeDb.Begin()
  1560. 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
  1561. if err != nil {
  1562. ut.Rollback()
  1563. return
  1564. }
  1565. 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
  1566. if err != nil {
  1567. ut.Rollback()
  1568. return
  1569. }
  1570. ut.Commit()
  1571. return err
  1572. }
  1573. func FindAdviceByGoroupNo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
  1574. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 AND parent_id = 0", orgID, groupno).Find(&advice).Error
  1575. return
  1576. }
  1577. func UpdateDoctorAdviceAndSubAdvice(m *models.DoctorAdvice) (err error) {
  1578. ut := writeDb.Begin()
  1579. err = ut.Save(m).Error
  1580. if err != nil {
  1581. ut.Rollback()
  1582. return
  1583. }
  1584. 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
  1585. if err != nil {
  1586. ut.Rollback()
  1587. return
  1588. }
  1589. ut.Commit()
  1590. return err
  1591. }
  1592. func GetAllWaitRemindPatient(org_id int64, page int64, limit int64) (total int64, patient []*models.Patients, err error) {
  1593. type Total struct {
  1594. Count int64
  1595. }
  1596. var totals Total
  1597. offset := (page - 1) * limit
  1598. 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
  1599. 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)
  1600. return totals.Count, patient, err
  1601. }
  1602. func UpdatePatientRemindStatus(patient_id int64, remind int64, org_id int64) (err error) {
  1603. 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
  1604. return
  1605. }
  1606. func CreatePatientWeightAdjust(m *models.SgjPatientDryweight) (err error) {
  1607. err = writeDb.Create(m).Error
  1608. return
  1609. }
  1610. func FindLastDryWeightAdjust(orgID int64, id int64) (weight models.SgjPatientDryweight, err error) {
  1611. err = readDb.Model(&models.SgjPatientDryweight{}).Where("user_org_id=? and patient_id=? and status=1", orgID, id).Order("id desc").First(&weight).Error
  1612. return
  1613. }
  1614. func GetSchedualPatientByKeyWord(orgID int64, keywords string, date int64) (patient []*models.Patients, err error) {
  1615. db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1 ", orgID)
  1616. if len(keywords) > 0 {
  1617. likekey := "%" + keywords + "%"
  1618. 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
  1619. } else {
  1620. err = db.Find(&patient).Error
  1621. }
  1622. return
  1623. }
  1624. func GetPatientScheduleOne(patientid int64, nowdate int64, orgid int64) (models.XtSchedule, error) {
  1625. schedule := models.XtSchedule{}
  1626. err := XTReadDB().Model(&schedule).Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status =1", patientid, nowdate, orgid).Find(&schedule).Error
  1627. return schedule, err
  1628. }
  1629. func CreateExportPatient(patient *models.Patients, contagions []int64, org_creator int64) (err error) {
  1630. user, _ := GetSgjUserByMobild(patient.Phone)
  1631. customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
  1632. utx := writeDb.Begin()
  1633. btx := writeUserDb.Begin()
  1634. if user.ID == 0 {
  1635. user.Mobile = patient.Phone
  1636. user.Avatar = patient.Avatar
  1637. user.AvatarThumb = patient.Avatar
  1638. user.Birthday = patient.Birthday
  1639. user.Username = patient.Name
  1640. user.Gender = patient.Gender
  1641. user.Sources = 11
  1642. user.Introduce = patient.Remark
  1643. user.Status = 1
  1644. user.UpdatedTime = patient.UpdatedTime
  1645. user.CreatedTime = patient.CreatedTime
  1646. err = btx.Create(&user).Error
  1647. if err != nil {
  1648. utx.Rollback()
  1649. btx.Rollback()
  1650. return
  1651. }
  1652. }
  1653. patient.UserId = user.ID
  1654. if customer == nil {
  1655. err = btx.Create(&models.SgjCustomer{
  1656. UserOrgId: patient.UserOrgId,
  1657. UserId: user.ID,
  1658. Mobile: patient.Phone,
  1659. Name: patient.Name,
  1660. Gender: patient.Gender,
  1661. Birthday: patient.Birthday,
  1662. Sources: 11,
  1663. Status: 1,
  1664. CreatedTime: patient.CreatedTime,
  1665. UpdatedTime: patient.UpdatedTime,
  1666. Avatar: patient.Avatar,
  1667. Remark: patient.Remark,
  1668. }).Error
  1669. if err != nil {
  1670. utx.Rollback()
  1671. btx.Rollback()
  1672. return
  1673. }
  1674. }
  1675. err = utx.Create(patient).Error
  1676. if err != nil {
  1677. utx.Rollback()
  1678. btx.Rollback()
  1679. return
  1680. }
  1681. if patient.DryWeight > 0 {
  1682. var dryWeight models.SgjPatientDryweight
  1683. dryWeight.PatientId = patient.ID
  1684. dryWeight.UserOrgId = patient.UserOrgId
  1685. dryWeight.Status = 1
  1686. dryWeight.AdjustedValue = "/"
  1687. dryWeight.Creator = org_creator
  1688. dryWeight.UserId = org_creator
  1689. dryWeight.Ctime = time.Now().Unix()
  1690. dryWeight.Mtime = time.Now().Unix()
  1691. dryWeight.DryWeight = patient.DryWeight
  1692. dryWeight.Remakes = ""
  1693. err = utx.Create(&dryWeight).Error
  1694. }
  1695. var lapseto models.PatientLapseto
  1696. lapseto.PatientId = patient.ID
  1697. lapseto.LapsetoType = patient.Lapseto
  1698. lapseto.CreatedTime = patient.CreatedTime
  1699. lapseto.UpdatedTime = patient.CreatedTime
  1700. lapseto.Status = 1
  1701. lapseto.LapsetoTime = patient.CreatedTime
  1702. err = utx.Create(&lapseto).Error
  1703. if err != nil {
  1704. utx.Rollback()
  1705. btx.Rollback()
  1706. return
  1707. }
  1708. if len(contagions) > 0 {
  1709. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  1710. insertParams := make([]string, 0)
  1711. insertData := make([]interface{}, 0)
  1712. for _, contagion := range contagions {
  1713. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  1714. insertData = append(insertData, patient.ID)
  1715. insertData = append(insertData, contagion)
  1716. insertData = append(insertData, 1)
  1717. insertData = append(insertData, patient.CreatedTime)
  1718. insertData = append(insertData, patient.UpdatedTime)
  1719. }
  1720. thisSQL += strings.Join(insertParams, ", ")
  1721. err = utx.Exec(thisSQL, insertData...).Error
  1722. if err != nil {
  1723. utx.Rollback()
  1724. btx.Rollback()
  1725. return
  1726. }
  1727. }
  1728. patientsNew := models.XtPatientsNew{
  1729. Name: patient.Name,
  1730. Gender: patient.Gender,
  1731. Phone: patient.Phone,
  1732. IdCardNo: patient.IdCardNo,
  1733. FirstDialysisDate: patient.FirstDialysisDate,
  1734. Source: patient.Source,
  1735. Lapseto: patient.Lapseto,
  1736. IsInfectious: patient.IsInfectious,
  1737. DialysisNo: patient.DialysisNo,
  1738. Height: patient.Height,
  1739. HomeAddress: patient.HomeAddress,
  1740. IsExcelExport: 1,
  1741. BloodPatients: 1,
  1742. Status: 1,
  1743. CreatedTime: time.Now().Unix(),
  1744. UserOrgId: patient.UserOrgId,
  1745. BloodId: patient.ID,
  1746. Avatar: "https://images.shengws.com/201809182128111.png",
  1747. }
  1748. err = utx.Create(&patientsNew).Error
  1749. record := models.XtPatientLaspseRecord{
  1750. PatientId: patient.ID,
  1751. RecordDate: time.Now().Unix(),
  1752. LapseDate: time.Now().Unix(),
  1753. LapseType: 1,
  1754. LapseClass: 0,
  1755. LapseReason: "",
  1756. AdminUserId: org_creator,
  1757. Remark: "",
  1758. UserOrgId: patient.UserOrgId,
  1759. Ctime: time.Now().Unix(),
  1760. Mtime: time.Now().Unix(),
  1761. Status: 1,
  1762. LapseTypeName: "转入",
  1763. HisType: 0,
  1764. HisZone: "",
  1765. HisBed: "",
  1766. }
  1767. err = utx.Create(&record).Error
  1768. if err != nil {
  1769. utx.Rollback()
  1770. btx.Rollback()
  1771. return
  1772. }
  1773. utx.Commit()
  1774. btx.Commit()
  1775. return
  1776. }
  1777. func FindPatientPhoneIsExist(phone string, org_id int64) (count int64) {
  1778. readDb.Model(&models.Patients{}).Where("user_org_id = ? AND phone = ? AND status = 1", org_id, phone).Count(&count)
  1779. return
  1780. }
  1781. func FindPatientIdCardNoIsExist(id_card_no string, org_id int64) (count int64) {
  1782. readDb.Model(&models.Patients{}).Where("user_org_id = ? AND id_card_no = ? AND status = 1", org_id, id_card_no).Count(&count)
  1783. return
  1784. }
  1785. func CreateExportErrLog(log *models.ExportErrLog) {
  1786. writeDb.Create(&log)
  1787. return
  1788. }
  1789. func FindPatientExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
  1790. err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 1", org_id, export_time).Find(&errLogs).Error
  1791. return
  1792. }
  1793. func FindPatientExportLogOne(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
  1794. err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 4", org_id, export_time).Find(&errLogs).Error
  1795. return
  1796. }
  1797. func FindPatientExportLogTwo(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
  1798. err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 5", org_id, export_time).Find(&errLogs).Error
  1799. return
  1800. }
  1801. func FindPatientExportLogThree(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
  1802. err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 6", org_id, export_time).Find(&errLogs).Error
  1803. return
  1804. }
  1805. func CreateExportLog(log *models.ExportLog) {
  1806. writeDb.Create(&log)
  1807. }
  1808. func UpdateDoctorEditAdvice(advice models.XtDoctorAdvice, orgid int64, groupno int64, date int64, patientid int64) error {
  1809. 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
  1810. return err
  1811. }
  1812. func GetPatientsByKey(orgID int64, keywords string) (patient []*models.Patients, err error) {
  1813. db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1 ", orgID)
  1814. if len(keywords) > 0 {
  1815. likekey := "%" + keywords + "%"
  1816. err = db.Where("(name LIKE ? OR dialysis_no LIKE ? OR first_letter LIKE ?)", likekey, likekey, likekey).Find(&patient).Error
  1817. } else {
  1818. err = db.Find(&patient).Error
  1819. }
  1820. return
  1821. }
  1822. func FindAllDoctorAdviceByGoroupNoTwo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
  1823. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 AND execution_state = 2", orgID, groupno).Find(&advice).Error
  1824. return
  1825. }
  1826. func FindDoctorAdviceByIdsTwo(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
  1827. 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
  1828. return
  1829. }
  1830. func CreateHisGroupAdvice(orgId int64, advices []*models.HisGroupAdvice, groupNo int64) (list []*models.HisGroupAdvice, err error) {
  1831. if groupNo <= 0 {
  1832. group := GetMaxAdviceGroupID(orgId)
  1833. groupNo = group + 1
  1834. }
  1835. tx := writeDb.Begin()
  1836. defer func() {
  1837. if r := recover(); r != nil {
  1838. tx.Rollback()
  1839. }
  1840. }()
  1841. for _, advice := range advices {
  1842. advice.Groupno = groupNo
  1843. if err = tx.Create(advice).Error; err != nil {
  1844. tx.Rollback()
  1845. return
  1846. }
  1847. list = append(list, advice)
  1848. if len(advice.Children) > 0 {
  1849. for _, child := range advice.Children {
  1850. child.Groupno = groupNo
  1851. child.ParentId = advice.ID
  1852. fmt.Println(child)
  1853. if err = tx.Create(&child).Error; err != nil {
  1854. tx.Rollback()
  1855. return
  1856. }
  1857. list = append(list, child)
  1858. }
  1859. }
  1860. }
  1861. tx.Commit()
  1862. return
  1863. }
  1864. func GetDialysisCount(orgid int64, partitionid int64) (order []*models.BloodDialysisOrderCount, err error) {
  1865. db := XTReadDB().Table("xt_dialysis_order as o")
  1866. if partitionid == 0 {
  1867. 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)
  1868. }
  1869. if partitionid > 0 {
  1870. 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)
  1871. }
  1872. return order, err
  1873. }
  1874. func UpdatePatientDialysisSolutionOne(patientid int64, orgid int64, prescription *models.DialysisPrescription, timenow int64) error {
  1875. 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
  1876. return err
  1877. }
  1878. //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) {
  1879. // 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
  1880. // return
  1881. //}
  1882. 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) {
  1883. 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
  1884. return
  1885. }
  1886. func UpdateScheduleByDeathTime(patientid int64, shcheduledate int64) error {
  1887. err := XTWriteDB().Model(models.XtSchedule{}).Where("patient_id = ? and schedule_date > ? and status=1", patientid, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
  1888. return err
  1889. }
  1890. func UpdatePatientLapsetoByPatientId(patient_id int64, record_date int64, lapse_reason string) error {
  1891. 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
  1892. 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
  1893. return err
  1894. }
  1895. func UpdatePatientLapsetoByPatientIdOne(patient_id int64, record_date int64, lapse_reason string) error {
  1896. 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
  1897. 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
  1898. return err
  1899. }
  1900. func UpdatePatientLapsetoByPatientIdTwo(patient_id int64, record_date int64) error {
  1901. err := XTWriteDB().Model(&models.Patients{}).Where("id = ? and status= 1", patient_id).Updates(map[string]interface{}{"death_time": record_date, "lapseto": 1}).Error
  1902. err = XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status=1", patient_id).Updates(map[string]interface{}{"death_time": record_date, "lapseto": 1}).Error
  1903. return err
  1904. }
  1905. func UpdateScheduleItemByPatientId(id int64) error {
  1906. err := XTWriteDB().Model(models.PatientScheduleTemplateItem{}).Where("patient_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1907. return err
  1908. }
  1909. 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) {
  1910. db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
  1911. table := UserReadDB().Table("sgj_user_admin_role as r")
  1912. fmt.Print("table", table)
  1913. if len(delivery_way_one) > 0 {
  1914. db = db.Where("delivery_way = ?", delivery_way_one)
  1915. }
  1916. if orgID > 0 {
  1917. db = db.Where("x.user_org_id=?", orgID)
  1918. }
  1919. if patientID > 0 {
  1920. db = db.Where("x.patient_id = ?", patientID)
  1921. }
  1922. if advice_type == 1 && advice_type > 0 {
  1923. db = db.Where("x.advice_type = ?", advice_type)
  1924. }
  1925. if advice_type == 2 && advice_type > 0 {
  1926. db = db.Where("x.advice_type = ?", advice_type)
  1927. }
  1928. if advice_type == 3 && advice_type > 0 {
  1929. db = db.Where("x.advice_type = 2 or x.advice_type = 3")
  1930. }
  1931. if advice_type == 4 && advice_type > 0 {
  1932. db = db.Where("x.advice_type = 4")
  1933. }
  1934. if stop == 1 {
  1935. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  1936. } else if stop == 2 {
  1937. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  1938. }
  1939. if start != 0 {
  1940. db = db.Where("x.start_time>=?", start)
  1941. }
  1942. if end != 0 {
  1943. db = db.Where("x.start_time<=?", end)
  1944. }
  1945. if len(keywords) > 0 {
  1946. likeKey := "%" + keywords + "%"
  1947. db = db.Where("x.advice_name LIKE ?", likeKey)
  1948. }
  1949. offset := (page - 1) * limit
  1950. 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
  1951. fmt.Print("err", err)
  1952. return
  1953. }
  1954. 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) {
  1955. db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
  1956. table := UserReadDB().Table("sgj_user_admin_role as r")
  1957. fmt.Println(table)
  1958. if len(delive_way_one) > 0 {
  1959. db = db.Where("delivery_way = ?", delive_way_one)
  1960. }
  1961. if orgID > 0 {
  1962. db = db.Where("x.user_org_id=?", orgID)
  1963. }
  1964. if patientID > 0 {
  1965. db = db.Where("x.patient_id = ?", patientID)
  1966. }
  1967. if advice_type == 1 {
  1968. db = db.Where("x.advice_type = ?", advice_type)
  1969. }
  1970. if advice_type == 3 && advice_type > 0 {
  1971. db = db.Where("x.advice_type = 2 or x.advice_type = 3")
  1972. }
  1973. if advice_type == 4 && advice_type > 0 {
  1974. db = db.Where("x.advice_type = 4")
  1975. }
  1976. if stop == 1 {
  1977. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  1978. } else if stop == 2 {
  1979. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  1980. }
  1981. if start != 0 {
  1982. db = db.Where("x.start_time>=?", start)
  1983. }
  1984. if end != 0 {
  1985. db = db.Where("x.start_time<=?", end)
  1986. }
  1987. if len(keywords) > 0 {
  1988. likeKey := "%" + keywords + "%"
  1989. db = db.Where("x.advice_name LIKE ?", likeKey)
  1990. }
  1991. offset := (page - 1) * limit
  1992. 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
  1993. fmt.Print("错误是什么", err)
  1994. return
  1995. }
  1996. func GetAllDeviceNumberByListSix(orgID int64) (number []*models.DeviceNumber, err error) {
  1997. err = readDb.Model(&models.DeviceNumber{}).Where("org_id=? and status=1", orgID).Find(&number).Error
  1998. return number, err
  1999. }
  2000. func GetAllDeviceNumberByList(orgID int64) (number []*models.DeviceNumber, err error) {
  2001. redis := RedisClient()
  2002. defer redis.Close()
  2003. key := strconv.FormatInt(orgID, 10) + ":" + ":device_number_all"
  2004. number_info_str, _ := redis.Get(key).Result()
  2005. if len(number_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2006. err = readDb.Model(&models.DeviceNumber{}).Where("org_id=? and status=1", orgID).Find(&number).Error
  2007. if err != nil {
  2008. if err == gorm.ErrRecordNotFound {
  2009. return nil, nil
  2010. } else {
  2011. return nil, err
  2012. }
  2013. } else {
  2014. if len(number) > 0 {
  2015. //缓存数据
  2016. device_number_json, err := json.Marshal(&number)
  2017. if err == nil {
  2018. redis.Set(key, device_number_json, time.Second*60*60*18)
  2019. }
  2020. }
  2021. return number, nil
  2022. }
  2023. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2024. json.Unmarshal([]byte(number_info_str), &number)
  2025. return number, nil
  2026. }
  2027. }
  2028. func GetAllPrescriptionByListTwo(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescription, err error) {
  2029. redis := RedisClient()
  2030. defer redis.Close()
  2031. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
  2032. prescriptions_list_all, _ := redis.Get(key).Result()
  2033. if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2034. if scheduleDate > 0 {
  2035. err = readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
  2036. } else {
  2037. err = readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&prescriptions).Error
  2038. }
  2039. if err != nil {
  2040. if err == gorm.ErrRecordNotFound {
  2041. return nil, nil
  2042. } else {
  2043. return nil, err
  2044. }
  2045. } else {
  2046. if len(prescriptions) > 0 {
  2047. //缓存数据
  2048. prescriptions_list_all, err := json.Marshal(&prescriptions)
  2049. if err == nil {
  2050. redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
  2051. }
  2052. }
  2053. return prescriptions, nil
  2054. }
  2055. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2056. json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
  2057. return prescriptions, nil
  2058. }
  2059. }
  2060. func GetAllAssessmentBeforesByListThree(orgID int64, scheduleDate int64) (assessmentBefores []*models.PredialysisEvaluation, err error) {
  2061. redis := RedisClient()
  2062. defer redis.Close()
  2063. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
  2064. assessment_befores_list_all, _ := redis.Get(key).Result()
  2065. if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2066. if scheduleDate > 0 {
  2067. err = readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
  2068. } else {
  2069. err = readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&assessmentBefores).Error
  2070. }
  2071. if err != nil {
  2072. if err == gorm.ErrRecordNotFound {
  2073. return nil, nil
  2074. } else {
  2075. return nil, err
  2076. }
  2077. } else {
  2078. if len(assessmentBefores) > 0 {
  2079. //缓存数据
  2080. assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
  2081. if err == nil {
  2082. redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
  2083. }
  2084. }
  2085. return assessmentBefores, nil
  2086. }
  2087. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2088. json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
  2089. return assessmentBefores, nil
  2090. }
  2091. }
  2092. func GetAllDialysisOrdersByListThree(orgID int64, scheduleDate int64) (dialysisOrders []*models.MonitorDialysisOrder, err error) {
  2093. redis := RedisClient()
  2094. defer redis.Close()
  2095. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
  2096. dialysis_orders_list_all, _ := redis.Get(key).Result()
  2097. if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2098. if scheduleDate > 0 {
  2099. 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
  2100. } else {
  2101. err = readDb.Model(&models.MonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ?", orgID).Find(&dialysisOrders).Error
  2102. }
  2103. if err != nil {
  2104. if err == gorm.ErrRecordNotFound {
  2105. return nil, nil
  2106. } else {
  2107. return nil, err
  2108. }
  2109. } else {
  2110. if len(dialysisOrders) > 0 {
  2111. //缓存数据
  2112. dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
  2113. if err == nil {
  2114. redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
  2115. }
  2116. }
  2117. return dialysisOrders, nil
  2118. }
  2119. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2120. json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
  2121. return dialysisOrders, nil
  2122. }
  2123. }
  2124. func GetAllAssessmentAfterDislysisByListThree(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.AssessmentAfterDislysis, err error) {
  2125. redis := RedisClient()
  2126. defer redis.Close()
  2127. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
  2128. assessment_after_dislysis__all, _ := redis.Get(key).Result()
  2129. if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2130. if scheduleDate > 0 {
  2131. err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
  2132. } else {
  2133. err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&assessmentAfterDislysis).Error
  2134. }
  2135. if err != nil {
  2136. if err == gorm.ErrRecordNotFound {
  2137. return nil, nil
  2138. } else {
  2139. return nil, err
  2140. }
  2141. } else {
  2142. if len(assessmentAfterDislysis) > 0 {
  2143. //缓存数据
  2144. assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
  2145. if err == nil {
  2146. redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
  2147. }
  2148. }
  2149. return assessmentAfterDislysis, nil
  2150. }
  2151. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2152. json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
  2153. return assessmentAfterDislysis, nil
  2154. }
  2155. }
  2156. func GetAllMonitorListThree(orgID int64, scheduleDate int64) (monitor []*models.MonitoringRecord, err error) {
  2157. redis := RedisClient()
  2158. defer redis.Close()
  2159. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_record_list_all"
  2160. monitor_record_list_all, _ := redis.Get(key).Result()
  2161. if len(monitor_record_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2162. if scheduleDate > 0 {
  2163. err = readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ?", orgID, scheduleDate).Find(&monitor).Error
  2164. } else {
  2165. err = readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&monitor).Error
  2166. }
  2167. if err != nil {
  2168. if err == gorm.ErrRecordNotFound {
  2169. return nil, nil
  2170. } else {
  2171. return nil, err
  2172. }
  2173. } else {
  2174. if len(monitor) > 0 {
  2175. //缓存数据
  2176. assessment_after_dislysis__all, err := json.Marshal(&monitor)
  2177. if err == nil {
  2178. redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
  2179. }
  2180. }
  2181. return monitor, nil
  2182. }
  2183. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2184. json.Unmarshal([]byte(monitor_record_list_all), &monitor)
  2185. return monitor, nil
  2186. }
  2187. }
  2188. func GetAllPatientListByListThree(orgID int64) (patients []*models.MonitorPatients, err error) {
  2189. redis := RedisClient()
  2190. defer redis.Close()
  2191. key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
  2192. patient_info_str, _ := redis.Get(key).Result()
  2193. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2194. err = readDb.Model(&models.MonitorPatients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
  2195. if err != nil {
  2196. if err == gorm.ErrRecordNotFound {
  2197. return nil, nil
  2198. } else {
  2199. return nil, err
  2200. }
  2201. } else {
  2202. if len(patients) > 0 {
  2203. //缓存数据
  2204. patient_info_json, err := json.Marshal(&patients)
  2205. if err == nil {
  2206. redis.Set(key, patient_info_json, time.Second*60*60*18)
  2207. }
  2208. }
  2209. return patients, nil
  2210. }
  2211. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2212. json.Unmarshal([]byte(patient_info_str), &patients)
  2213. return patients, nil
  2214. }
  2215. }
  2216. func GetAllPatientListByListSix(orgID int64, keywords string) (patients []*models.MonitorPatients, err error) {
  2217. db := readDb.Model(&models.MonitorPatients{}).Where("status = 1 and lapseto = 1")
  2218. likeKey := "%" + keywords + "%"
  2219. if orgID > 0 {
  2220. db = db.Where("user_org_id = ?", orgID)
  2221. }
  2222. if len(keywords) > 0 {
  2223. db = db.Where("name like ?", likeKey)
  2224. }
  2225. err = db.Find(&patients).Error
  2226. return patients, err
  2227. }
  2228. func GetAllDialysisOrdersByListTwo(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVM, err error) {
  2229. redis := RedisClient()
  2230. defer redis.Close()
  2231. key := strconv.FormatInt(orgID, 10) + ":" + ":dialysis_orders_list_all"
  2232. dialysis_orders_list_all, _ := redis.Get(key).Result()
  2233. if scheduleDate < 1669132800 {
  2234. fmt.Println("key233232232332323232", key)
  2235. redis.Set(key, "", time.Second)
  2236. }
  2237. fmt.Println("dialysis_orders_list_all", dialysis_orders_list_all)
  2238. if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2239. 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
  2240. if err != nil {
  2241. if err == gorm.ErrRecordNotFound {
  2242. return nil, nil
  2243. } else {
  2244. return nil, err
  2245. }
  2246. } else {
  2247. if len(dialysisOrders) > 0 {
  2248. //缓存数据
  2249. dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
  2250. if err == nil {
  2251. redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
  2252. }
  2253. }
  2254. return dialysisOrders, nil
  2255. }
  2256. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2257. json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
  2258. return dialysisOrders, nil
  2259. }
  2260. }
  2261. func GetAllZoneByList(orgID int64) (zone []*models.DeviceZone, err error) {
  2262. redis := RedisClient()
  2263. defer redis.Close()
  2264. key := strconv.FormatInt(orgID, 10) + ":" + ":device_zone_all"
  2265. zone_info_str, _ := redis.Get(key).Result()
  2266. if len(zone_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2267. err = readDb.Model(&models.DeviceZone{}).Where("org_id=? and status=1", orgID).Find(&zone).Error
  2268. if err != nil {
  2269. if err == gorm.ErrRecordNotFound {
  2270. return nil, nil
  2271. } else {
  2272. return nil, err
  2273. }
  2274. } else {
  2275. if len(zone) > 0 {
  2276. //缓存数据
  2277. zone_number_json, err := json.Marshal(&zone)
  2278. if err == nil {
  2279. redis.Set(key, zone_number_json, time.Second*60*60*18)
  2280. }
  2281. }
  2282. return zone, nil
  2283. }
  2284. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2285. json.Unmarshal([]byte(zone_info_str), &zone)
  2286. return zone, nil
  2287. }
  2288. }
  2289. func GetAllDialysisOrdersByListNight(orgID int64, scheduleDate int64, pay_tyep int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
  2290. if pay_tyep == 0 {
  2291. 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
  2292. }
  2293. //待下机
  2294. if pay_tyep == 3 {
  2295. 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
  2296. }
  2297. fmt.Println("pay_typeowowowoowwo", pay_tyep)
  2298. if pay_tyep == 7 {
  2299. 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
  2300. }
  2301. return dialysisOrders, err
  2302. }
  2303. func GetAllPrescriptionByListSix(orgID int64, scheduleDate int64) (prescriptions []*models.VMDialysisPrescription, err error) {
  2304. err = readDb.Model(&models.VMDialysisPrescription{}).Where("status= 1 and user_org_id = ? and record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
  2305. return prescriptions, err
  2306. //redis := RedisClient()
  2307. //defer redis.Close()
  2308. //key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
  2309. //redis.Set(key, "", time.Second)
  2310. //prescriptions_list_all, _ := redis.Get(key).Result()
  2311. //
  2312. //if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2313. // err = readDb.Model(&models.VMDialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
  2314. // if err != nil {
  2315. // if err == gorm.ErrRecordNotFound {
  2316. // return nil, nil
  2317. // } else {
  2318. // return nil, err
  2319. // }
  2320. // } else {
  2321. // if len(prescriptions) > 0 {
  2322. // //缓存数据
  2323. // prescriptions_list_all, err := json.Marshal(&prescriptions)
  2324. // if err == nil {
  2325. // redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
  2326. // }
  2327. // }
  2328. // return prescriptions, nil
  2329. // }
  2330. //} else { //缓存数据了数据,将redis缓存的json字符串转为map
  2331. // json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
  2332. // return prescriptions, nil
  2333. //}
  2334. }
  2335. func GetAllPrescriptionByList(orgID int64, scheduleDate int64) (prescriptions []*models.VMDialysisPrescription, err error) {
  2336. redis := RedisClient()
  2337. defer redis.Close()
  2338. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
  2339. redis.Set(key, "", time.Second)
  2340. prescriptions_list_all, _ := redis.Get(key).Result()
  2341. if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2342. err = readDb.Model(&models.VMDialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
  2343. if err != nil {
  2344. if err == gorm.ErrRecordNotFound {
  2345. return nil, nil
  2346. } else {
  2347. return nil, err
  2348. }
  2349. } else {
  2350. if len(prescriptions) > 0 {
  2351. //缓存数据
  2352. prescriptions_list_all, err := json.Marshal(&prescriptions)
  2353. if err == nil {
  2354. redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
  2355. }
  2356. }
  2357. return prescriptions, nil
  2358. }
  2359. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2360. json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
  2361. return prescriptions, nil
  2362. }
  2363. }
  2364. func GetAllAssessmentBeforesByListOne(orgID int64, scheduleDate int64) (assessmentBefores []*models.VMPredialysisEvaluation, err error) {
  2365. redis := RedisClient()
  2366. defer redis.Close()
  2367. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
  2368. assessment_befores_list_all, _ := redis.Get(key).Result()
  2369. if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2370. err = readDb.Model(&models.VMPredialysisEvaluation{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
  2371. if err != nil {
  2372. if err == gorm.ErrRecordNotFound {
  2373. return nil, nil
  2374. } else {
  2375. return nil, err
  2376. }
  2377. } else {
  2378. if len(assessmentBefores) > 0 {
  2379. //缓存数据
  2380. assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
  2381. if err == nil {
  2382. redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
  2383. }
  2384. }
  2385. return assessmentBefores, nil
  2386. }
  2387. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2388. json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
  2389. return assessmentBefores, nil
  2390. }
  2391. }
  2392. func GetAllDialysisOrdersByListSix(orgID int64, scheduleDate int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
  2393. 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
  2394. return dialysisOrders, err
  2395. }
  2396. func GetAllDialysisOrdersByListSeven(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVM, err error) {
  2397. 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
  2398. return dialysisOrders, err
  2399. }
  2400. func GetAllDialysisOrdersByListOne(orgID int64, scheduleDate int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
  2401. redis := RedisClient()
  2402. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
  2403. fmt.Println("key22332323232323223", key)
  2404. dialysis_orders_list_all, _ := redis.Get(key).Result()
  2405. defer redis.Close()
  2406. if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2407. 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
  2408. if err != nil {
  2409. if err == gorm.ErrRecordNotFound {
  2410. return nil, nil
  2411. } else {
  2412. return nil, err
  2413. }
  2414. } else {
  2415. if len(dialysisOrders) > 0 {
  2416. //缓存数据
  2417. dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
  2418. if err == nil {
  2419. redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
  2420. }
  2421. }
  2422. return dialysisOrders, nil
  2423. }
  2424. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2425. json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
  2426. return dialysisOrders, nil
  2427. }
  2428. }
  2429. func GetAllAssessmentAfterDislysisByListSix(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
  2430. err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status=1 and user_org_id = ? and assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
  2431. return assessmentAfterDislysis, err
  2432. //redis := RedisClient()
  2433. //defer redis.Close()
  2434. //key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
  2435. //redis.Set(key, "", time.Second)
  2436. //assessment_after_dislysis__all, _ := redis.Get(key).Result()
  2437. //
  2438. //if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2439. // err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
  2440. // if err != nil {
  2441. // if err == gorm.ErrRecordNotFound {
  2442. // return nil, nil
  2443. // } else {
  2444. // return nil, err
  2445. // }
  2446. // } else {
  2447. // if len(assessmentAfterDislysis) > 0 {
  2448. // //缓存数据
  2449. // assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
  2450. // if err == nil {
  2451. // redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
  2452. // }
  2453. // }
  2454. // return assessmentAfterDislysis, nil
  2455. // }
  2456. //} else { //缓存数据了数据,将redis缓存的json字符串转为map
  2457. // json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
  2458. // return assessmentAfterDislysis, nil
  2459. //}
  2460. }
  2461. func GetAllAssessmentAfterDislysisByListOne(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
  2462. redis := RedisClient()
  2463. defer redis.Close()
  2464. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
  2465. redis.Set(key, "", time.Second)
  2466. assessment_after_dislysis__all, _ := redis.Get(key).Result()
  2467. if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2468. err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
  2469. if err != nil {
  2470. if err == gorm.ErrRecordNotFound {
  2471. return nil, nil
  2472. } else {
  2473. return nil, err
  2474. }
  2475. } else {
  2476. if len(assessmentAfterDislysis) > 0 {
  2477. //缓存数据
  2478. assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
  2479. if err == nil {
  2480. redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
  2481. }
  2482. }
  2483. return assessmentAfterDislysis, nil
  2484. }
  2485. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2486. json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
  2487. return assessmentAfterDislysis, nil
  2488. }
  2489. }
  2490. func GetAllMonitorList(orgID int64, scheduleDate int64) (monitor []*models.VMMonitoringRecord, err error) {
  2491. redis := RedisClient()
  2492. defer redis.Close()
  2493. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_record_list_all"
  2494. monitor_record_list_all, _ := redis.Get(key).Result()
  2495. redis.Set(key, "", time.Second)
  2496. if len(monitor_record_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2497. err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ?", orgID, scheduleDate).Order("monitoring_date asc").Find(&monitor).Error
  2498. if err != nil {
  2499. if err == gorm.ErrRecordNotFound {
  2500. return nil, nil
  2501. } else {
  2502. return nil, err
  2503. }
  2504. } else {
  2505. if len(monitor) > 0 {
  2506. //缓存数据
  2507. assessment_after_dislysis__all, err := json.Marshal(&monitor)
  2508. if err == nil {
  2509. redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
  2510. }
  2511. }
  2512. return monitor, nil
  2513. }
  2514. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2515. json.Unmarshal([]byte(monitor_record_list_all), &monitor)
  2516. return monitor, nil
  2517. }
  2518. }
  2519. func GetAllPatientListByListOne(orgID int64) (patients []*models.VMMonitorPatients, err error) {
  2520. redis := RedisClient()
  2521. defer redis.Close()
  2522. key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
  2523. patient_info_str, _ := redis.Get(key).Result()
  2524. redis.Set(key, "", time.Second)
  2525. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2526. err = readDb.Model(&models.VMMonitorPatients{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
  2527. if err != nil {
  2528. if err == gorm.ErrRecordNotFound {
  2529. return nil, nil
  2530. } else {
  2531. return nil, err
  2532. }
  2533. } else {
  2534. if len(patients) > 0 {
  2535. //缓存数据
  2536. patient_info_json, err := json.Marshal(&patients)
  2537. if err == nil {
  2538. redis.Set(key, patient_info_json, time.Second*60*60*18)
  2539. }
  2540. }
  2541. return patients, nil
  2542. }
  2543. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2544. json.Unmarshal([]byte(patient_info_str), &patients)
  2545. return patients, nil
  2546. }
  2547. }
  2548. func GetAllTreatModeByList(orgID int64) (treatement []*models.TreatmentMode, err error) {
  2549. redis := RedisClient()
  2550. defer redis.Close()
  2551. key := strconv.FormatInt(orgID, 10) + ":" + ":treatement_mode_all"
  2552. treatment_info_str, _ := redis.Get(key).Result()
  2553. if len(treatment_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2554. err = readDb.Model(&models.TreatmentMode{}).Where("status=1").Find(&treatement).Error
  2555. if err != nil {
  2556. if err == gorm.ErrRecordNotFound {
  2557. return nil, nil
  2558. } else {
  2559. return nil, err
  2560. }
  2561. } else {
  2562. if len(treatement) > 0 {
  2563. //缓存数据
  2564. patient_info_json, err := json.Marshal(&treatement)
  2565. if err == nil {
  2566. redis.Set(key, patient_info_json, time.Second*60*60*18)
  2567. }
  2568. }
  2569. return treatement, nil
  2570. }
  2571. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2572. json.Unmarshal([]byte(treatment_info_str), &treatement)
  2573. return treatement, nil
  2574. }
  2575. }
  2576. func GetAllPatientListByListSeven(orgID int64) (patients []*MSchedualPatientVM, err error) {
  2577. err = readDb.Model(&MSchedualPatientVM{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
  2578. return patients, nil
  2579. }
  2580. func GetAllPatientListByListTwo(orgID int64) (patients []*MSchedualPatientVM, err error) {
  2581. redis := RedisClient()
  2582. defer redis.Close()
  2583. key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
  2584. patient_info_str, _ := redis.Get(key).Result()
  2585. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2586. err = readDb.Model(&MSchedualPatientVM{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
  2587. if err != nil {
  2588. if err == gorm.ErrRecordNotFound {
  2589. return nil, nil
  2590. } else {
  2591. return nil, err
  2592. }
  2593. } else {
  2594. if len(patients) > 0 {
  2595. //缓存数据
  2596. patient_info_json, err := json.Marshal(&patients)
  2597. if err == nil {
  2598. redis.Set(key, patient_info_json, time.Second*60*60*18)
  2599. }
  2600. }
  2601. return patients, nil
  2602. }
  2603. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2604. json.Unmarshal([]byte(patient_info_str), &patients)
  2605. return patients, nil
  2606. }
  2607. }
  2608. func GetAllDeviceNumberByListOne(orgID int64) (number []*MDeviceNumberVM, err error) {
  2609. redis := RedisClient()
  2610. defer redis.Close()
  2611. key := strconv.FormatInt(orgID, 10) + ":" + ":device_number_all"
  2612. number_info_str, _ := redis.Get(key).Result()
  2613. if len(number_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2614. err = readDb.Model(&MDeviceNumberVM{}).Where("org_id=? and status=1", orgID).Find(&number).Error
  2615. if err != nil {
  2616. if err == gorm.ErrRecordNotFound {
  2617. return nil, nil
  2618. } else {
  2619. return nil, err
  2620. }
  2621. } else {
  2622. if len(number) > 0 {
  2623. //缓存数据
  2624. device_number_json, err := json.Marshal(&number)
  2625. if err == nil {
  2626. redis.Set(key, device_number_json, time.Second*60*60*18)
  2627. }
  2628. }
  2629. return number, nil
  2630. }
  2631. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2632. json.Unmarshal([]byte(number_info_str), &number)
  2633. return number, nil
  2634. }
  2635. }
  2636. func GetAllPrescriptionByListOne(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionTwenty, err error) {
  2637. redis := RedisClient()
  2638. defer redis.Close()
  2639. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
  2640. prescriptions_list_all, _ := redis.Get(key).Result()
  2641. if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2642. err = readDb.Model(&models.DialysisPrescriptionTwenty{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
  2643. if err != nil {
  2644. if err == gorm.ErrRecordNotFound {
  2645. return nil, nil
  2646. } else {
  2647. return nil, err
  2648. }
  2649. } else {
  2650. if len(prescriptions) > 0 {
  2651. //缓存数据
  2652. prescriptions_list_all, err := json.Marshal(&prescriptions)
  2653. if err == nil {
  2654. redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
  2655. }
  2656. }
  2657. return prescriptions, nil
  2658. }
  2659. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2660. json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
  2661. return prescriptions, nil
  2662. }
  2663. }
  2664. func GetAllHisProjectPrescription(orgid int64, recorddate int64) (project []*models.HisPrescriptionProjectTwo, err error) {
  2665. err = XTReadDB().Where("user_org_id = ? and record_date = ? and status = 1", orgid, recorddate).Find(&project).Error
  2666. return project, err
  2667. }
  2668. func GetZoneCountList(orgid int64, schedule_date int64) (list []*models.XtScheduleSeven, err error) {
  2669. db := XTReadDB().Model(&list).Where("status = 1")
  2670. if orgid > 0 {
  2671. db = db.Where("user_org_id = ?", orgid)
  2672. }
  2673. if schedule_date > 0 {
  2674. db = db.Where("schedule_date =?", schedule_date)
  2675. }
  2676. err = db.Select("partition_id,count(id) as count").Group("partition_id").Scan(&list).Error
  2677. return list, err
  2678. }
  2679. func GetPatientDialysisLongSolution(patient_id int64, page int64, limit int64, orgid int64) (solution []*models.DialysisSolution, total int64, err error) {
  2680. db := XTReadDB().Model(&solution).Where("status = 1 and solution_status = 1")
  2681. if patient_id > 0 {
  2682. db = db.Where("patient_id = ?", patient_id)
  2683. }
  2684. if orgid > 0 {
  2685. db = db.Where("user_org_id = ?", orgid)
  2686. }
  2687. offset := (page - 1) * limit
  2688. err = db.Group("mode_id").Count(&total).Offset(offset).Limit(limit).Order("created_time desc").Find(&solution).Error
  2689. return solution, total, err
  2690. }
  2691. func GetDialysisSolutionDetailList(orgid int64, patient_id int64, mode_id int64, page int64, limit int64) (solution []*models.DialysisSolution, total int64, err error) {
  2692. offset := (page - 1) * limit
  2693. db := XTReadDB().Model(&solution).Where("status = 1")
  2694. if orgid > 0 {
  2695. db = db.Where("user_org_id = ?", orgid)
  2696. }
  2697. if patient_id > 0 {
  2698. db = db.Where("patient_id = ?", patient_id)
  2699. }
  2700. if mode_id > 0 {
  2701. db = db.Where("mode_id = ?", mode_id)
  2702. }
  2703. err = db.Count(&total).Offset(offset).Limit(limit).Find(&solution).Order("created_time desc").Error
  2704. return solution, total, err
  2705. }
  2706. func UpdateDialysisBefor(dislysis models.XtAssessmentBeforeDislysis, id int64) error {
  2707. 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
  2708. return err
  2709. }
  2710. func GetAllSchedulesByPatientInfo(org_id int64, patient_id int64, mode_id int64) ([]Schedule, error) {
  2711. var record []Schedule
  2712. if org_id == 10579 {
  2713. timeNowStr := time.Now().Format("2006-01-02")
  2714. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2715. 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
  2716. if err != nil {
  2717. if err == gorm.ErrRecordNotFound {
  2718. return nil, nil
  2719. } else {
  2720. return nil, err
  2721. }
  2722. }
  2723. } else {
  2724. timeNowStr := time.Now().Format("2006-01-02")
  2725. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2726. 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
  2727. if err != nil {
  2728. if err == gorm.ErrRecordNotFound {
  2729. return nil, nil
  2730. } else {
  2731. return nil, err
  2732. }
  2733. }
  2734. }
  2735. return record, nil
  2736. }
  2737. func UpdateScheduleByExport(org_id int64, shcheduledate int64) error {
  2738. err := XTWriteDB().Model(models.XtSchedule{}).Where("user_org_id = ? and schedule_date > ?", org_id, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
  2739. return err
  2740. }
  2741. func GetContextScheduleListGroupPatientId(limit int64, page int64, startTime int64, endTime int64, org_id int64) (schedule []*models.ConScheduleList, total int64, err error) {
  2742. db := XTReadDB().Model(&schedule).Where("status=1")
  2743. offset := (page - 1) * limit
  2744. if startTime > 0 {
  2745. db = db.Where("schedule_date >=?", startTime)
  2746. }
  2747. if endTime > 0 {
  2748. db = db.Where("schedule_date<=?", endTime)
  2749. }
  2750. if org_id > 0 {
  2751. db = db.Where("user_org_id = ?", org_id)
  2752. }
  2753. err = db.Count(&total).Offset(offset).Limit(limit).Group("patient_id").Find(&schedule).Error
  2754. return schedule, total, err
  2755. }
  2756. func GetContextScheduleListPatientId(startTime int64, endTime int64, org_id int64) (schedule []*models.ConScheduleList, total int64, err error) {
  2757. db := XTReadDB().Model(&schedule).Where("status=1")
  2758. if startTime > 0 {
  2759. db = db.Where("schedule_date >=?", startTime)
  2760. }
  2761. if endTime > 0 {
  2762. db = db.Where("schedule_date<=?", endTime)
  2763. }
  2764. if org_id > 0 {
  2765. db = db.Where("user_org_id = ?", org_id)
  2766. }
  2767. err = db.Find(&schedule).Error
  2768. return schedule, total, err
  2769. }
  2770. func GetPatientAllagicList(patient_id int64, user_org_id int64) (list []*models.XtPatientAllergic, err error) {
  2771. err = XTReadDB().Where("patient_id = ? and user_org_id =? and status= 1", patient_id, user_org_id).Find(&list).Error
  2772. return list, err
  2773. }
  2774. func GetPatientAllagicListOne(user_org_id int64) (list []*models.XtPatientAllergic, err error) {
  2775. err = XTReadDB().Where("user_org_id =? and status= 1", user_org_id).Find(&list).Error
  2776. return list, err
  2777. }
  2778. func GetNewMonitorRecord(orgID int64, date int64, partition int64, patientId int64) ([]*models.NewMonitorDialysisScheduleList, error) {
  2779. var mds []*models.NewMonitorDialysisScheduleList
  2780. db := readDb.Model(&models.NewMonitorDialysisScheduleList{})
  2781. if date > 0 {
  2782. db = db.Where("schedule_date = ?", date)
  2783. }
  2784. if partition > 0 {
  2785. db = db.Where("partition_id = ?", partition)
  2786. }
  2787. if patientId > 0 {
  2788. db = db.Where("patient_id = ?", patientId)
  2789. }
  2790. err = db.Where("status = 1 and user_org_id = ?", orgID).Find(&mds).Error
  2791. return mds, err
  2792. }
  2793. func GetAdviceList(user_org_id int64, advice_date int64, pat_type int64) (advice []*models.VMDoctorAdviceForList, err error) {
  2794. if pat_type == 0 {
  2795. err = XTReadDB().Where("user_org_id = ? and advice_date = ? and status =7 and check_time = 0", user_org_id, advice_date).Find(&advice).Error
  2796. }
  2797. //待医嘱核对
  2798. if pat_type == 1 {
  2799. err = XTReadDB().Where("user_org_id = ? and advice_date = ? and status =1 and check_time = 0", user_org_id, advice_date).Find(&advice).Error
  2800. }
  2801. //待医嘱执行
  2802. if pat_type == 6 {
  2803. err = XTReadDB().Where("user_org_id = ? and advice_date = ? and status =1 and execution_state = 2", user_org_id, advice_date).Find(&advice).Error
  2804. }
  2805. return advice, err
  2806. }
  2807. func GetDobuleCheck(user_org_id int64, advice_date int64) (check []*models.VmDoubleCheck, err error) {
  2808. err = XTReadDB().Where("user_org_id = ? and check_date = ? and status = 1", user_org_id, advice_date).Find(&check).Error
  2809. return check, err
  2810. }
  2811. func GetTreatmentSummaryForList(user_org_id int64, advice_date int64) (summary []*models.VMTreatmentSummaryForList, err error) {
  2812. err = XTReadDB().Where("user_org_id =? and assessment_date = ? and status =1", user_org_id, advice_date).Find(&summary).Error
  2813. return summary, err
  2814. }
  2815. func GetDialysisInformationList(user_org_id int64, advice_date int64) (information []*models.NewDeviceInformation, err error) {
  2816. err = UserReadDB().Where("user_org_id =? and date = ? and status =1", user_org_id, advice_date).Find(&information).Error
  2817. return information, err
  2818. }
  2819. func GetNewAllMonitorList(orgID int64, scheduleDate int64, pat_type int64) (monitor []*models.VMMonitoringRecord, err error) {
  2820. if pat_type == 0 || pat_type == 9 {
  2821. err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ?", orgID, scheduleDate).Order("monitoring_date asc").Find(&monitor).Error
  2822. }
  2823. if pat_type == 10 {
  2824. 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
  2825. }
  2826. if pat_type == 11 {
  2827. 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
  2828. }
  2829. if pat_type == 12 {
  2830. 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
  2831. }
  2832. return monitor, err
  2833. }
  2834. func GetBaseDrugByName(drug_name string, org_id int64) (models.BaseDrugLibSeven, error) {
  2835. libSeven := models.BaseDrugLibSeven{}
  2836. err := XTReadDB().Where("drug_name= ? and org_id = ? and status=1", drug_name, org_id).First(&libSeven).Error
  2837. return libSeven, err
  2838. }
  2839. func CreateDeviceValsualMap(valsualMap models.XtDeviceValsualMap) error {
  2840. err := XTWriteDB().Save(&valsualMap).Error
  2841. return err
  2842. }
  2843. func GetPatientSitemap(patient_id int64, user_org_id int64) (models.XtDeviceValsualMap, error) {
  2844. valsualMap := models.XtDeviceValsualMap{}
  2845. 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
  2846. return valsualMap, err
  2847. }
  2848. func UpdateSiteMap(valsualMap models.XtDeviceValsualMap) error {
  2849. err := XTWriteDB().Save(&valsualMap).Error
  2850. return err
  2851. }
  2852. func CreateValsualAleft(left models.XtDeviceValsualALeft) error {
  2853. err := XTWriteDB().Create(&left).Error
  2854. return err
  2855. }
  2856. func UpdateValsualAleft(patient_id int64, user_org_id int64) error {
  2857. 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
  2858. return err
  2859. }
  2860. func CreateValsualMapFangxiangA(a models.XtDeviceValsualMapFangxiangA) error {
  2861. err := XTWriteDB().Create(&a).Error
  2862. return err
  2863. }
  2864. func UpdateValsualMapFangxiangA(patient_id int64, user_org_id int64) error {
  2865. 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
  2866. return err
  2867. }
  2868. func CreateValsualMapFangxiangV(v models.XtDeviceValsualMapFangxiangV) error {
  2869. err := XTWriteDB().Create(&v).Error
  2870. return err
  2871. }
  2872. func UpdateValsualMapFangxiangV(patient_id int64, user_org_id int64) error {
  2873. 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
  2874. return err
  2875. }
  2876. func ValsualMapFangxiangA(patient_id int64, user_org_id int64) error {
  2877. 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
  2878. return err
  2879. }
  2880. func CreateValSualFuzhA(a models.XtDeviceValsualFuzhuA) error {
  2881. err := XTReadDB().Create(&a).Error
  2882. return err
  2883. }
  2884. func UpdateValSualFuzhA(patient_id int64, user_org_id int64) error {
  2885. 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
  2886. return err
  2887. }
  2888. func CreateVasuaLfuzhuV(v models.XtDeviceValsualFuzhuV) error {
  2889. err := XTReadDB().Create(&v).Error
  2890. return err
  2891. }
  2892. func UpdateVasuaLfuzhuV(patient_id int64, user_org_id int64) error {
  2893. 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
  2894. return err
  2895. }
  2896. func CreateTextArr(arr models.XtDeviceValsualTextArr) error {
  2897. err := XTReadDB().Create(&arr).Error
  2898. return err
  2899. }
  2900. func UpdateTextArr(patient_id int64, user_org_id int64) error {
  2901. 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
  2902. return err
  2903. }
  2904. func CreateValsualVleft(left models.XtDeviceValsualVLeft) error {
  2905. err = XTReadDB().Create(&left).Error
  2906. return err
  2907. }
  2908. func UpdateValsualVleft(patient_id int64, user_org_id int64) error {
  2909. 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
  2910. return err
  2911. }
  2912. func UpdateValusalMapArr(patient_id int64, user_org_id int64) error {
  2913. 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
  2914. return err
  2915. }
  2916. func CreateDeviceValusalMapArr(vrr models.XtDeviceValusalMapArr) error {
  2917. err := XTWriteDB().Create(&vrr).Error
  2918. return err
  2919. }
  2920. func UpdateDeviceValusalMapVrr(patient_id int64, user_org_id int64) error {
  2921. 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
  2922. return err
  2923. }
  2924. func CreateDeviceValusalMapVrr(vrr models.XtDeviceValusalMapVrr) error {
  2925. err := XTWriteDB().Create(&vrr).Error
  2926. return err
  2927. }
  2928. func GetDialysisOrderNoExecution(start_nurse int64, user_org_id int64, timenow int64) (order []*models.XtDialysisOrder, err error) {
  2929. err = XTReadDB().Where("start_nurse = ? and user_org_id =? and status =1 and dialysis_date =?", start_nurse, user_org_id, timenow).Find(&order).Error
  2930. return order, err
  2931. }
  2932. func GetAdviceListNoExecution(advice_date int64, user_org_id int64, patientIds []int64) (advice []*models.NoDoctorAdvice, err error) {
  2933. db := XTReadDB().Model(advice).Where("status=1 and execution_state = 2 and advice_type = 2")
  2934. if len(patientIds) > 0 {
  2935. if advice_date > 0 {
  2936. db = db.Where("advice_date= ?", advice_date)
  2937. }
  2938. if user_org_id > 0 {
  2939. db = db.Where("user_org_id =?", user_org_id)
  2940. }
  2941. if len(patientIds) > 0 {
  2942. db = db.Where("patient_id in(?)", patientIds)
  2943. }
  2944. err = db.Select("patient_id,Count(id) as count,advice_date").Group("patient_id").Find(&advice).Error
  2945. return advice, err
  2946. } else {
  2947. return advice, err
  2948. }
  2949. }
  2950. func GetHisAdviceListNoExecution(advice_date int64, user_org_id int64, patientIds []int64) (advice []*models.HisNoDoctorAdvice, err error) {
  2951. db := XTReadDB().Model(advice).Where("status=1 and execution_state = 2")
  2952. if advice_date > 0 {
  2953. db = db.Where("advice_date= ?", advice_date)
  2954. }
  2955. if user_org_id > 0 {
  2956. db = db.Where("user_org_id =?", user_org_id)
  2957. }
  2958. if len(patientIds) > 0 {
  2959. db = db.Where("patient_id in(?)", patientIds)
  2960. }
  2961. err = db.Select("advice_date,patient_id,Count(id) as count").Group("patient_id").Find(&advice).Error
  2962. return advice, err
  2963. }
  2964. func GetProjectListNoExecution(record_date int64, user_org_id int64, patientIds []int64) (project []*models.NoHisPrescriptionProject, err error) {
  2965. db := XTReadDB().Model(&project).Where("status=1 and execution_state =0")
  2966. if record_date > 0 {
  2967. db = db.Where("record_date= ?", record_date)
  2968. }
  2969. if user_org_id > 0 {
  2970. db = db.Where("user_org_id =?", user_org_id)
  2971. }
  2972. if len(patientIds) > 0 {
  2973. db = db.Where("patient_id in(?)", patientIds)
  2974. }
  2975. err = db.Select("patient_id,Count(id) as count,record_date as advice_date").Group("patient_id").Find(&project).Error
  2976. return project, err
  2977. }
  2978. func GetPatientNoExecutionList(org_id int64, patientsIds []int64) (patient []*models.XtPatients, err error) {
  2979. err = XTReadDB().Where("user_org_id = ? and id in(?)", org_id, patientsIds).Find(&patient).Error
  2980. return patient, err
  2981. }
  2982. func FindHisConfig(org_id int64) (err error, config models.XtHisConfig) {
  2983. err = readDb.Model(&models.XtHisConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  2984. return
  2985. }
  2986. func GetPatientDetailInformedConsent(patient_id int64, org_id int64) (models.XtPatients, error) {
  2987. patients := models.XtPatients{}
  2988. err := XTReadDB().Where("id = ? and status=1 and user_org_id =?", patient_id, org_id).Find(&patients).Error
  2989. return patients, err
  2990. }
  2991. func GetAllPrescriptionList(org_id int64) (prescription []*models.DialysisPrescription, err error) {
  2992. err = XTReadDB().Where("user_org_id = ? and status =1", org_id).Find(&prescription).Error
  2993. return prescription, err
  2994. }
  2995. func GetPatientScheudleListTwenty(org_id int64, scheduel_type int64, startime int64, endtime int64, schedule_date int64) (schedule []*models.ScheduleTen, err error) {
  2996. db := XTReadDB().Model(&schedule).Where("status= 1")
  2997. if org_id > 0 {
  2998. db = db.Where("user_org_id = ?", org_id)
  2999. }
  3000. if scheduel_type > 0 {
  3001. db = db.Where("schedule_type =?", scheduel_type)
  3002. }
  3003. if startime > 0 {
  3004. db = db.Where("schedule_date >=?", startime)
  3005. }
  3006. if endtime > 0 {
  3007. db = db.Where("schedule_date <=?", endtime)
  3008. }
  3009. if startime == 0 && endtime == 0 {
  3010. db = db.Where("schedule_date = ?", schedule_date)
  3011. }
  3012. err = db.Find(&schedule).Error
  3013. fmt.Println("err2330230320202023", err)
  3014. return schedule, err
  3015. }
  3016. func GetDialysisOrderCountTwentyEight(orgID int64, patient_id int64, recordDate int64) (models.VmDialysisOrder, error) {
  3017. order := models.VmDialysisOrder{}
  3018. 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
  3019. return order, err
  3020. }
  3021. func GetDialysisOrderCountTenEight(patient_id int64, recordDate int64) (models.VmDialysisOrder, error) {
  3022. order := models.VmDialysisOrder{}
  3023. err := XTReadDB().Where("patient_id = ? and dialysis_date = ? and status = 1", patient_id, recordDate).Last(&order).Error
  3024. return order, err
  3025. }
  3026. func GetLastAcceptRecrods(patient_id int64) (models.ReceiveTreatmentAsses, error) {
  3027. treatmentAsses := models.ReceiveTreatmentAsses{}
  3028. err := XTReadDB().Where("patient_id = ? and status= 1 and admission_number!=''", patient_id).Last(&treatmentAsses).Error
  3029. return treatmentAsses, err
  3030. }
  3031. func GetOutPrintList(user_org_id int64) (models.XtFallOutPrint, error) {
  3032. outPrint := models.XtFallOutPrint{}
  3033. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&outPrint).Error
  3034. return outPrint, err
  3035. }
  3036. func CreateFallOutBedPrint(outPrint models.XtFallOutPrint) error {
  3037. err := XTWriteDB().Create(&outPrint).Error
  3038. return err
  3039. }
  3040. func UpdateFallOutBedPrint(id int64, content string) error {
  3041. err := XTWriteDB().Model(&models.XtFallOutPrint{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
  3042. return err
  3043. }
  3044. func GetFallOutBedPrintList(user_org_id int64) (models.XtFallOutPrint, error) {
  3045. outPrint := models.XtFallOutPrint{}
  3046. err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&outPrint).Error
  3047. return outPrint, err
  3048. }
  3049. func GetFilterInformed(user_org_id int64) (models.XtFilterInformed, error) {
  3050. informed := models.XtFilterInformed{}
  3051. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&informed).Error
  3052. return informed, err
  3053. }
  3054. func CreateFilterInformed(informed models.XtFilterInformed) error {
  3055. err := XTWriteDB().Create(&informed).Error
  3056. return err
  3057. }
  3058. func UpdateFilterInformed(id int64, content string) error {
  3059. err := XTWriteDB().Model(&models.XtFilterInformed{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
  3060. return err
  3061. }
  3062. func GetProfundaInformed(user_org_id int64) (models.XtProfundaInformed, error) {
  3063. informed := models.XtProfundaInformed{}
  3064. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&informed).Error
  3065. return informed, err
  3066. }
  3067. func CreateProfundaInformed(informed models.XtProfundaInformed) error {
  3068. err := XTWriteDB().Create(&informed).Error
  3069. return err
  3070. }
  3071. func UpdateProfundaInformed(id int64, content string) error {
  3072. profundaInformed := models.XtProfundaInformed{}
  3073. err := XTWriteDB().Model(&profundaInformed).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
  3074. return err
  3075. }
  3076. func GetArterOvenousList(user_org_id int64) (models.XtArterOvenous, error) {
  3077. ovenous := models.XtArterOvenous{}
  3078. err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&ovenous).Error
  3079. return ovenous, err
  3080. }
  3081. func CreateArterOvernous(ovenous models.XtArterOvenous) error {
  3082. err := XTWriteDB().Create(&ovenous).Error
  3083. return err
  3084. }
  3085. func UpdateArterOvernous(id int64, content string) error {
  3086. err := XTWriteDB().Model(&models.XtArterOvenous{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
  3087. return err
  3088. }
  3089. func GetHightRikInformed(user_org_id int64) (models.XtHightRisk, error) {
  3090. risk := models.XtHightRisk{}
  3091. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&risk).Error
  3092. return risk, err
  3093. }
  3094. func CreateHighRik(risk models.XtHightRisk) error {
  3095. err := XTWriteDB().Create(&risk).Error
  3096. return err
  3097. }
  3098. func UpdateHighRik(id int64, content string) error {
  3099. err := XTWriteDB().Model(&models.XtHightRisk{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
  3100. return err
  3101. }
  3102. func GetAnticoagulation(user_org_id int64) (models.XtAuticoagutionPrint, error) {
  3103. auticoagutionPrint := models.XtAuticoagutionPrint{}
  3104. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&auticoagutionPrint).Error
  3105. return auticoagutionPrint, err
  3106. }
  3107. func CreateAnticoagulation(auticoagutionPrint models.XtAuticoagutionPrint) error {
  3108. err := XTWriteDB().Create(&auticoagutionPrint).Error
  3109. return err
  3110. }
  3111. func UpdateAnticoagulation(id int64, content string) error {
  3112. err := XTWriteDB().Model(&models.XtAuticoagutionPrint{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
  3113. return err
  3114. }
  3115. func GetCriticalInfomed(org_id int64) (models.XtCriticalinfomedPrint, error) {
  3116. criticalinfomedPrint := models.XtCriticalinfomedPrint{}
  3117. err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&criticalinfomedPrint).Error
  3118. return criticalinfomedPrint, err
  3119. }
  3120. func CreatedCriticalInfomed(criticalinfomedPrint models.XtCriticalinfomedPrint) error {
  3121. err := XTWriteDB().Create(&criticalinfomedPrint).Error
  3122. return err
  3123. }
  3124. func UpdateCriticalInfomed(id int64, content string) error {
  3125. err := XTWriteDB().Model(&models.XtCriticalinfomedPrint{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
  3126. return err
  3127. }
  3128. func GetHemoperfusionInformed(user_org_id int64) (models.XtHemoperfusionmedPrint, error) {
  3129. hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{}
  3130. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&hemoperfusionmedPrint).Error
  3131. return hemoperfusionmedPrint, err
  3132. }
  3133. func CreateHemoperfusionInformed(hemoperfusionmedPrint models.XtHemoperfusionmedPrint) error {
  3134. err := XTWriteDB().Create(&hemoperfusionmedPrint).Error
  3135. return err
  3136. }
  3137. func UpdateHemoperfusionInformed(id int64, content string) error {
  3138. err := XTWriteDB().Model(&models.XtHemoperfusionmedPrint{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
  3139. return err
  3140. }
  3141. func GetBringInformed(org_id int64) (models.XtBringinformedPrint, error) {
  3142. bringinformedPrint := models.XtBringinformedPrint{}
  3143. err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&bringinformedPrint).Error
  3144. return bringinformedPrint, err
  3145. }
  3146. func CreateBringInformed(bringinformedPrint models.XtBringinformedPrint) error {
  3147. err := XTWriteDB().Create(&bringinformedPrint).Error
  3148. return err
  3149. }
  3150. func UpdateBringInformed(id int64, content string) error {
  3151. err := XTWriteDB().Model(&models.XtBringinformedPrint{}).Where("id =? and status= 1", id).Updates(map[string]interface{}{"content": content}).Error
  3152. return err
  3153. }
  3154. func GetCatheterization(user_org_id int64) (models.XtCathetercationPrint, error) {
  3155. cathetercationPrint := models.XtCathetercationPrint{}
  3156. err := XTReadDB().Where("user_org_id = ? and status= 1", user_org_id).Find(&cathetercationPrint).Error
  3157. return cathetercationPrint, err
  3158. }
  3159. func CreateCatheteriztion(cathetercationPrint models.XtCathetercationPrint) error {
  3160. err := XTWriteDB().Create(&cathetercationPrint).Error
  3161. return err
  3162. }
  3163. func UpdateCatheterization(id int64, content string) error {
  3164. err := XTWriteDB().Model(models.XtCathetercationPrint{}).Where("id=? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
  3165. return err
  3166. }
  3167. func GetDialyzerInformed(org_id int64) (models.XtDialyszerinformedPrint, error) {
  3168. dialyszerinformedPrint := models.XtDialyszerinformedPrint{}
  3169. err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&dialyszerinformedPrint).Error
  3170. return dialyszerinformedPrint, err
  3171. }
  3172. func CreateDialyzerInformed(dialyszerinformedPrint models.XtDialyszerinformedPrint) error {
  3173. err := XTWriteDB().Create(&dialyszerinformedPrint).Error
  3174. return err
  3175. }
  3176. func UpdateDialyszerInformed(id int64, content string) error {
  3177. err := XTWriteDB().Model(&models.XtDialyszerinformedPrint{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
  3178. return err
  3179. }
  3180. func GetTheapyInformed(org_id int64) (models.XtTheapyinformedPrint, error) {
  3181. theapyinformedPrint := models.XtTheapyinformedPrint{}
  3182. err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Find(&theapyinformedPrint).Error
  3183. return theapyinformedPrint, err
  3184. }
  3185. func CreateTheapyInformed(theapyinformedPrint models.XtTheapyinformedPrint) error {
  3186. err := XTWriteDB().Create(&theapyinformedPrint).Error
  3187. return err
  3188. }
  3189. func UpdateTheaphInformed(id int64, content string) error {
  3190. err := XTWriteDB().Model(&models.XtTheapyinformedPrint{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
  3191. return err
  3192. }
  3193. func GetPatientMedicalHistory(patient_id int64, user_org_id int64) (models.XtMedicalHistory, error) {
  3194. history := models.XtMedicalHistory{}
  3195. err := XTReadDB().Model(&history).Where("patient_id = ? and user_org_id = ? and status=1", patient_id, user_org_id).Find(&history).Error
  3196. return history, err
  3197. }
  3198. func UpdatePatientMedicalHistory(id int64, content string) error {
  3199. history := models.XtMedicalHistory{}
  3200. err := XTWriteDB().Model(&history).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
  3201. return err
  3202. }
  3203. func CreatePatientMedicalHistory(history models.XtMedicalHistory) error {
  3204. err := XTWriteDB().Create(&history).Error
  3205. return err
  3206. }
  3207. func GetPatientMedicalList(patient_id int64, user_org_id int64) (models.XtMedicalHistory, error) {
  3208. history := models.XtMedicalHistory{}
  3209. err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status=1", patient_id, user_org_id).Find(&history).Error
  3210. return history, err
  3211. }
  3212. func CreatePatientFallassessment(tx *gorm.DB, patientFallassessment models.XtPatientFallassessment) (err error) {
  3213. err = tx.Create(&patientFallassessment).Error
  3214. if err == gorm.ErrRecordNotFound {
  3215. tx.Rollback()
  3216. return
  3217. }
  3218. return
  3219. }
  3220. func SavePatientFallassessment(tx *gorm.DB, patientFallassessment models.XtPatientFallassessment) (err error) {
  3221. err = tx.Save(&patientFallassessment).Error
  3222. if err == gorm.ErrRecordNotFound {
  3223. tx.Rollback()
  3224. return
  3225. }
  3226. return
  3227. }
  3228. func GetPatientFallsessMentList(patient_id int64, user_org_id int64, limit int64, page int64) (list []*models.XtPatientFallassessment, total int64, err error) {
  3229. offset := (page - 1) * limit
  3230. db := XTReadDB().Model(&list).Where("status =1")
  3231. if patient_id > 0 {
  3232. db = db.Where("patient_id = ?", patient_id)
  3233. }
  3234. if user_org_id > 0 {
  3235. db = db.Where("user_org_id = ?", user_org_id)
  3236. }
  3237. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  3238. return list, total, err
  3239. }
  3240. func GetPatientFallsessMentListOne(ids []string, user_org_id int64) (list []*models.XtPatientFallassessment, err error) {
  3241. db := XTReadDB().Model(&list).Where("status =1")
  3242. if len(ids) > 0 {
  3243. db = db.Where("id in(?)", ids)
  3244. }
  3245. if user_org_id > 0 {
  3246. db = db.Where("user_org_id = ?", user_org_id)
  3247. }
  3248. err = db.Find(&list).Error
  3249. return list, err
  3250. }
  3251. func GetPatientFallsessmentById(id int64, user_org_id int64) (models.XtPatientFallassessment, error) {
  3252. fallassessment := models.XtPatientFallassessment{}
  3253. err := XTReadDB().Where("id = ? and user_org_id = ?", id, user_org_id).Find(&fallassessment).Error
  3254. return fallassessment, err
  3255. }
  3256. func DeletePatientFallsessment(id int64, user_org_id int64) (models.XtPatientFallassessment, error) {
  3257. fallassessment := models.XtPatientFallassessment{}
  3258. err := XTWriteDB().Model(&fallassessment).Where("id =? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3259. return fallassessment, err
  3260. }
  3261. func CreatePadFallssessment(fallssessment models.XtPatientPedFallssessment) error {
  3262. err := XTWriteDB().Create(&fallssessment).Error
  3263. return err
  3264. }
  3265. func UpdatePedFallssessment(fallssessment models.XtPatientPedFallssessment) error {
  3266. err := XTWriteDB().Save(&fallssessment).Error
  3267. return err
  3268. }
  3269. func GetBedDiatricFallassessmentList(patient_id int64, is_type int64, user_org_id int64, limit int64, page int64) (list []*models.XtPatientPedFallssessment, total int64, err error) {
  3270. offset := (page - 1) * limit
  3271. db := XTReadDB().Model(&list).Where("status =1")
  3272. if patient_id > 0 {
  3273. db = db.Where("patient_id = ?", patient_id)
  3274. }
  3275. if user_org_id > 0 {
  3276. db = db.Where("user_org_id = ?", user_org_id)
  3277. }
  3278. if is_type > 0 {
  3279. db = db.Where("type = ?", is_type)
  3280. }
  3281. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  3282. return list, total, err
  3283. }
  3284. func GetPedPatientFallassessmentById(id int64) (models.XtPatientPedFallssessment, error) {
  3285. fallassessment := models.XtPatientPedFallssessment{}
  3286. err := XTReadDB().Where("id = ? and status=1", id).Find(&fallassessment).Error
  3287. return fallassessment, err
  3288. }
  3289. func DeletePadPatientFallassment(id int64) (err error) {
  3290. err = XTWriteDB().Model(&models.XtPatientPedFallssessment{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3291. return err
  3292. }
  3293. func GetPatientCritaicalInformed(user_org_id int64) (models.XtPatientCritical, error) {
  3294. patientCritical := models.XtPatientCritical{}
  3295. err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&patientCritical).Error
  3296. return patientCritical, err
  3297. }
  3298. func CreatePatientCritaicalinformed(critical models.XtPatientCritical) error {
  3299. err = XTWriteDB().Create(&critical).Error
  3300. return err
  3301. }
  3302. func UpdatePatientCritaicalInformed(id int64, content string) error {
  3303. err := XTWriteDB().Model(&models.XtPatientCritical{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"content": content}).Error
  3304. return err
  3305. }
  3306. func GetPatientCriticalByUserOrgId(user_org_id int64) (models.XtPatientCriticalOne, error) {
  3307. criticalOne := models.XtPatientCriticalOne{}
  3308. err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&criticalOne).Error
  3309. return criticalOne, err
  3310. }
  3311. func CreatePatientCritical(patient models.XtPatientCriticalOne) error {
  3312. err := XTWriteDB().Create(&patient).Error
  3313. return err
  3314. }
  3315. func UpdatePatientCriticalOne(user_org_id int64, content string) error {
  3316. err := XTWriteDB().Model(&models.XtPatientCriticalOne{}).Where("user_org_id = ? and status=1", user_org_id).Updates(map[string]interface{}{"content": content}).Error
  3317. return err
  3318. }
  3319. func GetPatientCriticalOneList(user_org_id int64) (models.XtPatientCriticalOne, error) {
  3320. criticalOne := models.XtPatientCriticalOne{}
  3321. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&criticalOne).Error
  3322. return criticalOne, err
  3323. }
  3324. func CreatePatientPedList(fallssessment models.XtPatientPedFallssessment) error {
  3325. err := XTWriteDB().Create(&fallssessment).Error
  3326. return err
  3327. }
  3328. func UpdatePatientPedList(fallssessment models.XtPatientPedFallssessment) error {
  3329. err := XTWriteDB().Save(&fallssessment).Error
  3330. return err
  3331. }
  3332. func GetPatientFallsessMentListTwo(ids []string, user_org_id int64) (list []*models.XtPatientFallassessment, err error) {
  3333. db := XTReadDB().Model(&list).Where("status =1")
  3334. if len(ids) > 0 {
  3335. db = db.Where("id in(?)", ids)
  3336. }
  3337. if user_org_id > 0 {
  3338. db = db.Where("user_org_id = ?", user_org_id)
  3339. }
  3340. err = db.Find(&list).Error
  3341. return list, err
  3342. }
  3343. func CeatePatientSign(braden models.XtPatientBraden) error {
  3344. err := XTWriteDB().Create(&braden).Error
  3345. return err
  3346. }
  3347. func GetPatientBradenList(patient_id int64, limit int64, page int64, user_org_id int64) (list []*models.XtPatientBraden, total int64, err error) {
  3348. offset := (page - 1) * limit
  3349. db := XTReadDB().Model(&list).Where("status =1")
  3350. if patient_id > 0 {
  3351. db = db.Where("patient_id = ?", patient_id)
  3352. }
  3353. if user_org_id > 0 {
  3354. db = db.Where("user_org_id = ?", user_org_id)
  3355. }
  3356. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  3357. return list, total, err
  3358. }
  3359. func GetPatientBradenById(id int64) (models.XtPatientBraden, error) {
  3360. patientBraden := models.XtPatientBraden{}
  3361. err := XTReadDB().Where("id = ? and status=1", id).Find(&patientBraden).Error
  3362. return patientBraden, err
  3363. }
  3364. func SavePatientBraden(braden models.XtPatientBraden) error {
  3365. err := XTWriteDB().Save(&braden).Error
  3366. return err
  3367. }
  3368. func DeletePatientBraden(id int64) error {
  3369. patientBraden := models.XtPatientBraden{}
  3370. err := XTWriteDB().Model(&patientBraden).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3371. return err
  3372. }
  3373. func GetBatchPatientBraden(ids []string, user_org_id int64) (list []*models.XtPatientBraden, err error) {
  3374. db := XTReadDB().Model(&list).Where("status=1")
  3375. if len(ids) > 0 {
  3376. db = db.Where("id in(?)", ids)
  3377. }
  3378. if user_org_id > 0 {
  3379. db = db.Where("user_org_id =?", user_org_id)
  3380. }
  3381. err = db.Find(&list).Error
  3382. return list, err
  3383. }
  3384. func GetAllPatientListMap(user_org_id int64) (list []*models.XtAgePatients, err error) {
  3385. err = XTReadDB().Where("user_org_id =? and status=1 and lapseto = 1", user_org_id).Find(&list).Error
  3386. return list, err
  3387. }
  3388. func GetLastBefor(patient_id int64) (models.XtAssessmentBeforeDislysis, error) {
  3389. beforeDislysis := models.XtAssessmentBeforeDislysis{}
  3390. 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
  3391. return beforeDislysis, err
  3392. }
  3393. func GetLastRecordAfter(patient_id int64) (models.XtAssessmentAfterDislysis, error) {
  3394. afterDislysis := models.XtAssessmentAfterDislysis{}
  3395. 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
  3396. return afterDislysis, err
  3397. }
  3398. func GetInspectionByPatientId(patient_id int64, item_id int64) (models.XtInspection, error) {
  3399. inspection := models.XtInspection{}
  3400. 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
  3401. return inspection, err
  3402. }
  3403. func DeleteSolutionById(id int64) (models.DialysisSolution, error) {
  3404. solution := models.DialysisSolution{}
  3405. err := XTWriteDB().Model(&solution).Where("id=? and status=1", id).Updates(map[string]interface{}{"status": 12}).Error
  3406. return solution, err
  3407. }
  3408. func GetPatientBeforRecordList(patient_id int64, user_org_id int64) (befor []*models.XtAssessmentBeforeDislysis, err error) {
  3409. 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
  3410. return befor, err
  3411. }
  3412. func GetPatientAfterRecordList(patient_id int64, user_org_id int64) (after []*models.XtAssessmentAfterDislysis, err error) {
  3413. 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
  3414. return after, err
  3415. }
  3416. func GetMonitorRecordByGroup(patient_id int64, user_org_id int64) (monitor []*models.MonitoringRecordOne, err error) {
  3417. 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
  3418. return monitor, err
  3419. }
  3420. func GetMonitorRecordList(patient_id int64, monitor_date int64, user_org_id int64) (monitor []*models.MonitoringRecord, err error) {
  3421. 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
  3422. return monitor, err
  3423. }
  3424. func GetDialysisTotalCountByTime(user_org_id int64, start_time int64, end_time int64, patient_id int64) (order []*models.XtDialysisOrder, err error) {
  3425. db := XTReadDB().Table("xt_dialysis_order").Where("status =1")
  3426. if user_org_id > 0 {
  3427. db = db.Where("user_org_id =?", user_org_id)
  3428. }
  3429. if start_time > 0 {
  3430. db = db.Where("dialysis_date >=?", start_time)
  3431. }
  3432. if end_time > 0 {
  3433. db = db.Where("dialysis_date <=?", end_time)
  3434. }
  3435. if patient_id > 0 {
  3436. db = db.Where("patient_id = ?", patient_id)
  3437. }
  3438. err = db.Find(&order).Error
  3439. return order, err
  3440. }
  3441. func GetTreamentPland(user_org_id int64) (models.XtTreatmentPlan, error) {
  3442. treatmentPlan := models.XtTreatmentPlan{}
  3443. err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&treatmentPlan).Error
  3444. return treatmentPlan, err
  3445. }
  3446. func CreateTreatqmentPland(plan models.XtTreatmentPlan) error {
  3447. err := XTWriteDB().Create(&plan).Error
  3448. return err
  3449. }
  3450. func UpdateTheatmentPland(id int64, content string) error {
  3451. err := XTWriteDB().Model(&models.XtTreatmentPlan{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"content": content}).Error
  3452. return err
  3453. }
  3454. func GetEditAdviceActionList(id int64, org_id int64) (models.XtDoctorAdviceOne, error) {
  3455. doctorAdviceOne := models.XtDoctorAdviceOne{}
  3456. err := XTReadDB().Where("id = ? and status=1 and user_org_id = ?", id, org_id).Find(&doctorAdviceOne).Error
  3457. return doctorAdviceOne, err
  3458. }
  3459. func CreatePatientRecord(record models.XtPatientLaspseRecord) error {
  3460. err := XTWriteDB().Create(&record).Error
  3461. return err
  3462. }
  3463. func GetPatientLapseRecord(patient_id int64, limit int64, page int64, user_org_id int64) (record []*models.XtPatientLaspseRecord, total int64, err error) {
  3464. db := XTReadDB().Model(&record).Where("status=1")
  3465. offset := (page - 1) * limit
  3466. if patient_id > 0 {
  3467. db = db.Where("patient_id = ?", patient_id)
  3468. }
  3469. if user_org_id > 0 {
  3470. db = db.Where("user_org_id = ?", user_org_id)
  3471. }
  3472. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&record).Error
  3473. return record, total, err
  3474. }
  3475. func GetPatientLapsorecord(id int64) (models.XtPatientLaspseRecord, error) {
  3476. laspseRecord := models.XtPatientLaspseRecord{}
  3477. err := XTReadDB().Where("id = ? and status= 1", id).Find(&laspseRecord).Error
  3478. return laspseRecord, err
  3479. }
  3480. func SavePatientLapseRecord(record models.XtPatientLaspseRecord) error {
  3481. err := XTWriteDB().Save(&record).Error
  3482. return err
  3483. }
  3484. func DeletePatientLapseRecord(id int64) error {
  3485. record := models.XtPatientLaspseRecord{}
  3486. err := XTWriteDB().Model(&record).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3487. return err
  3488. }
  3489. func GetPatientLapsorecordListOne() (lapseto []*models.PatientLapseto, err error) {
  3490. err = XTReadDB().Where("status=1 and (lapseto_type=2 or lapseto_type =3)").Find(&lapseto).Error
  3491. return lapseto, err
  3492. }