1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746 |
- package service
-
- import (
- "XT_New/models"
- "encoding/json"
- "fmt"
- "strconv"
- "strings"
- "time"
-
- "github.com/jinzhu/gorm"
- )
-
- //GetPatientList 返回患者的列表
- func GetPatientList(orgID int64, keywords string, page, limit, schedulType, bindingState, lapseto, source, startTime, endTime, contagion, reimbursementWay, isscheduling, isprescription int64, isStartTime, isEndTime bool) (patients []*models.Patients, total int64, err error) {
-
- db := readDb.Table("xt_patients as p").Where("p.status=1")
- if orgID > 0 {
- db = db.Where("p.user_org_id=?", orgID)
- }
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
- }
-
- if schedulType > 0 {
- db = db.Joins("JOIN xt_schedule as s ON s.patient_id=p.id")
- db = db.Where("s.status=1 and s.schedule_type=?", schedulType)
- }
-
- if contagion > 0 {
- db = db.Joins("JOIN xt_patients_infectious_diseases as xpid ON xpid.patient_id=p.id")
- db = db.Where("xpid.disease_id=? and xpid.status=1", contagion)
- }
-
- if isscheduling == 1 {
- db = db.Where("EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.status=1").QueryExpr())
- } else if isscheduling == 2 {
- db = db.Where("NOT EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.status=1").QueryExpr())
- }
- if isprescription == 1 {
- db = db.Where("EXISTS (?)", readDb.Table("xt_dialysis_prescription as xdp").Where("xdp.patient_id=p.id and xdp.status=1").QueryExpr())
- } else if isprescription == 2 {
- db = db.Where("NOT EXISTS (?)", readDb.Table("xt_dialysis_prescription as xdp").Where("xdp.patient_id=p.id and xdp.status=1").QueryExpr())
- }
-
- if bindingState > 0 {
- db = db.Where("p.binding_state=?", bindingState)
- }
- if lapseto > 0 {
- db = db.Where("p.lapseto=?", lapseto)
- }
- if source > 0 {
- db = db.Where("p.source=?", source)
- }
- if reimbursementWay > 0 {
- db = db.Where("p.reimbursement_way_id = ?", reimbursementWay)
- }
-
- if isStartTime {
- db = db.Where("p.created_time>=?", startTime)
- }
- if isEndTime {
- db = db.Where("p.created_time<=?", endTime)
- }
-
- offset := (page - 1) * limit
-
- 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
- return
- }
-
- //GetAllPatientList 返回全部患者的列表
- func GetAllPatientList(orgID int64) (patients []*models.Patients, total int64, err error) {
-
- db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1", orgID)
-
- err = db.Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time").Count(&total).Find(&patients).Error
- return
- }
-
- func GetAllPatientListTwenty(orgID int64) (patients []*models.Patients, total int64, err error) {
-
- db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1 and p.lapseto = 1", orgID)
-
- err = db.Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time").Count(&total).Find(&patients).Error
- return
- }
-
- func GetAllPatientListSix(orgID int64) (patients []*models.MSchedualPatientList, err error) {
-
- err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1", orgID).Find(&patients).Error
-
- return patients, err
- }
-
- //GetAllPatientList 返回全部患者的列表
- func GetAllPatientListByList(orgID int64) (patients []*models.MSchedualPatientList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
- patient_info_str, _ := redis.Get(key).Result()
-
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.MSchedualPatientList{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(patients) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(patients) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patients)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return patients, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if patient_info_str == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(patient_info_str), &patients)
- return patients, nil
- }
- }
- }
-
- func GetAllDevicetByListSix(orgID int64) (devices []*models.MDeviceNumberForList, err error) {
-
- err = readDb.Model(&models.MDeviceNumberForList{}).Preload("Zone", "status = 1 AND org_id = ?", orgID).Where("org_id=?", orgID).Find(&devices).Error
- return devices, err
- }
-
- func GetAllDevicetByList(orgID int64) (devices []*models.MDeviceNumberForList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":device_list_all"
- device_list_str, _ := redis.Get(key).Result()
-
- if len(device_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.MDeviceNumberForList{}).Preload("Zone", "status = 1 AND org_id = ?", orgID).Where("org_id=? and status=1 ", orgID).Find(&devices).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(devices) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(devices) > 0 {
- //缓存数据
- device_list_str, err := json.Marshal(&devices)
- if err == nil {
- redis.Set(key, device_list_str, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return devices, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if device_list_str == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(device_list_str), &devices)
- return devices, nil
- }
- }
- }
-
- func GetAllAdvicestByList(orgID int64, scheduleDate int64) (advices []models.VMDoctorAdviceForList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":advice_list_all"
- advice_list_str, _ := redis.Get(key).Result()
-
- if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMDoctorAdviceForList{}).Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).Find(&advices).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(advices) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(advices) > 0 {
- //缓存数据
- advice_list_str, err := json.Marshal(&advices)
- if err == nil {
- redis.Set(key, advice_list_str, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return advices, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if advice_list_str == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(advice_list_str), &advices)
- return advices, nil
- }
-
- }
- }
-
- func GetAllPrescriptionsByList(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionList, err error) {
-
- err = readDb.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- return prescriptions, err
- }
-
- //func GetAllPrescriptionsByList(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionList, err error) {
- // redis := RedisClient()
- // defer redis.Close()
- // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
- // prescriptions_list_all, _ := redis.Get(key).Result()
- // redis.Set(prescriptions_list_all, "", time.Second)
- // if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- // err = readDb.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- // if err != nil {
- // if err == gorm.ErrRecordNotFound {
- // if len(prescriptions) <= 0 {
- // redis.Set(key, "null", time.Second*60*60*18)
- // }
- // return nil, nil
- // } else {
- // return nil, err
- // }
- // } else {
- // if len(prescriptions) > 0 {
- // //缓存数据
- // prescriptions_list_all, err := json.Marshal(&prescriptions)
- // if err == nil {
- // redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- // }
- // } else {
- // redis.Set(key, "null", time.Second*60*60*18)
- // }
- // return prescriptions, nil
- // }
- // } else { //缓存数据了数据,将redis缓存的json字符串转为map
- // if prescriptions_list_all == "null" {
- // return nil, nil
- // } else {
- // json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- // return prescriptions, nil
- // }
- //
- // }
- //}
-
- func GetAllAssessmentBeforesByList(orgID int64, scheduleDate int64) (assessmentBefores []*models.PredialysisEvaluationList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
- assessment_befores_list_all, _ := redis.Get(key).Result()
-
- if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(assessmentBefores) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentBefores) > 0 {
- //缓存数据
- assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
- if err == nil {
- redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return assessmentBefores, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if assessment_befores_list_all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
- return assessmentBefores, nil
- }
- }
- }
-
- func GetAllDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*models.MDialysisOrderForList, err error) {
-
- err = readDb.Model(&models.MDialysisOrderForList{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- return dialysisOrders, err
- }
-
- //func GetAllDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*models.MDialysisOrderForList, err error) {
- // redis := RedisClient()
- // defer redis.Close()
- // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
- // dialysis_orders_list_all, _ := redis.Get(key).Result()
- // redis.Set(dialysis_orders_list_all, "", time.Second)
- // if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- // err = readDb.Model(&models.MDialysisOrderForList{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- //
- // if err != nil {
- // if err == gorm.ErrRecordNotFound {
- // return nil, nil
- // } else {
- // return nil, err
- // }
- // } else {
- // if len(dialysisOrders) > 0 {
- // //缓存数据
- // dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
- // if err == nil {
- // redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
- // }
- // } else {
- // redis.Set(key, "null", time.Second*60*60*18)
- // }
- // return dialysisOrders, nil
- // }
- // } else { //缓存数据了数据,将redis缓存的json字符串转为map
- // if dialysis_orders_list_all == "null" {
- // return nil, nil
- // } else {
- // json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
- // return dialysisOrders, nil
- // }
- //
- // }
- //}
-
- func GetAllTreatmentSummarysByList(orgID int64, scheduleDate int64) (treatmentSummarys []*models.VMTreatmentSummaryForList, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":treatment_summarys_list_all"
- treatment_summarys_all, _ := redis.Get(key).Result()
-
- if len(treatment_summarys_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMTreatmentSummaryForList{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&treatmentSummarys).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(treatment_summarys_all) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(treatmentSummarys) > 0 {
- //缓存数据
- treatment_summarys_all, err := json.Marshal(&treatmentSummarys)
- if err == nil {
- redis.Set(key, treatment_summarys_all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return treatmentSummarys, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if treatment_summarys_all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(treatment_summarys_all), &treatmentSummarys)
- return treatmentSummarys, nil
- }
- }
- }
-
- func GetAllAssessmentAfterDislysisByList(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
- assessment_after_dislysis__all, _ := redis.Get(key).Result()
-
- if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(assessmentAfterDislysis) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentAfterDislysis) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return assessmentAfterDislysis, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if assessment_after_dislysis__all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
- return assessmentAfterDislysis, nil
- }
-
- }
- }
-
- func GetAllDobuleCheckList(orgID int64, scheduleDate int64) (dobulecheck []*models.DoubleCheck, err error) {
-
- err = XTReadDB().Where("check_date = ? and user_org_id = ? and status = 1", scheduleDate, orgID).Find(&dobulecheck).Error
- return dobulecheck, err
- }
-
- func GetAllHisAdvicesByList(orgID int64, scheduleDate int64) (hisAdvices []VMHisDoctorAdviceInfo, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":his_advices_list_all"
- his_advices_all, _ := redis.Get(key).Result()
-
- if len(his_advices_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&VMHisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).Find(&hisAdvices).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if len(hisAdvices) <= 0 {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(hisAdvices) > 0 {
- //缓存数据
- his_advices_all, err := json.Marshal(&hisAdvices)
- if err == nil {
- redis.Set(key, his_advices_all, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return hisAdvices, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if his_advices_all == "null" {
- return nil, nil
- } else {
- json.Unmarshal([]byte(his_advices_all), &hisAdvices)
- return hisAdvices, nil
- }
-
- }
- }
-
- func GetPatientListByUpdateTime(orgID int64, syncTime int64) (patients []*models.PatientListForFaceList, total int64, err error) {
- db := readDb.Model(&models.PatientListForFaceList{}).Where("user_org_id=? AND status=1 AND avatar <> 'https://images.shengws.com/201809182128222.png' AND avatar <> 'https://images.shengws.com/201809182128111.png' AND avatar <> ''", orgID)
-
- db = db.Where("updated_time >= ?", syncTime)
-
- err = db.Count(&total).Find(&patients).Error
- return
- }
-
- func GetPatientListBySchedules(orgID int64, syncTime int64) (patients []*models.SchedulePatients, total int64, err error) {
- db := readDb.Model(&models.SchedulePatients{}).Where("user_org_id=? AND status=1 AND schedule_date = ?", orgID, syncTime).Preload("Patient", "status = 1 AND user_org_id = ? ", orgID)
- err = db.Count(&total).Find(&patients).Error
- return
- }
-
- func GetPatientListBySchedulesFind(orgID int64, syncTime int64, patient_name string) (patients []*models.SchedulePatients, total int64, err error) {
- db := readDb.Model(&models.SchedulePatients{}).Where("user_org_id=? AND status=1 AND schedule_date = ?", orgID, syncTime).Preload("Patient", "status = 1 AND user_org_id = ? and name like ? ", orgID, "%"+patient_name+"%")
- err = db.Count(&total).Find(&patients).Error
- return
- }
-
- func GetPatientListById(orgID int64, patientId int64) (patients models.PatientListForFace, err error) {
- err = readDb.Model(&models.PatientListForFaceList{}).Where("user_org_id=? and id = ? and status=1", orgID, patientId).First(&patients).Error
- return
- }
-
- func GetPatientCount(orgID int64) (total int64) {
- readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1", orgID).Count(&total)
- return
- }
-
- func GetLapsetoPatientCount(orgID int64, lapseto int64) (total int64) {
- readDb.Model(&models.Patients{}).Where("user_org_id=? and lapseto=? and status=1", orgID, lapseto).Count(&total)
- return
- }
-
- func ChechLastDialysisNo(orgID int64) (dialysisNo int64) {
- var patient models.Patients
- err := readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=?", orgID).Order("dialysis_no desc").First(&patient).Error
- if err != nil {
- return
- }
-
- if patient.ID == 0 {
- return
- }
- dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
- return
- }
-
- func FindPatientByDialysisNo(orgID int64, dialysisNo string) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=?", orgID, dialysisNo).First(&patient).Error
- return
- }
-
- func FindPatientByIdCardNo(orgID int64, idCardNo string) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=?", orgID, idCardNo).First(&patient).Error
- return
- }
- func FindPatientByMobile(orgID int64, mobile string) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("phone=? and user_org_id=? and status=1", mobile, orgID).First(&patient).Error
- return
- }
-
- func FindPatientById(orgID int64, id int64) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
- return
- }
-
- func FindPatientByIdTwo(orgID int64, id int64) (patient models.XtPatientsNew, err error) {
-
- err = readDb.Model(&models.XtPatientsNew{}).Where("blood_id = ? and user_org_id = ? and status =1", id, orgID).First(&patient).Error
- return
- }
-
- //func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients, err error) {
- // err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
- // return
- //}
- func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
- patient_info_str, _ := redis.Get(key).Result()
-
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return patient, nil
- } else {
- return patient, err
- }
- } else {
- if patient.ID > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patient)
-
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- } else {
- redis.Set(key, "null", time.Second*60*60*18)
- }
- return patient, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
-
- if patient_info_str == "null" {
- return patient, nil
- } else {
- json.Unmarshal([]byte(patient_info_str), &patient)
- return patient, nil
- }
-
- }
- }
-
- func FindPatientWithDeviceByNo(orgID int64, no string, time int64) (patient models.SchedualPatient2, err error) {
- err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
- return db.Preload("DeviceNumber", "org_id = ?", orgID).
- Preload("DeviceZone", "org_id = ?", orgID).
- Where("user_org_id = ? AND schedule_date = ? ", orgID, time)
- }).Preload("InfectiousDiseases", "status = 1").Where("user_org_id=? and dialysis_no = ? and status = 1", orgID, no).First(&patient).Error
- return
- }
-
- func CreatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
-
- user, _ := GetSgjUserByMobild(patient.Phone)
- customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
-
- utx := writeDb.Begin()
- btx := writeUserDb.Begin()
-
- if user.ID == 0 {
-
- user.Mobile = patient.Phone
- user.Avatar = patient.Avatar
- user.AvatarThumb = patient.Avatar
- user.Birthday = patient.Birthday
- user.Username = patient.Name
- user.Gender = patient.Gender
- user.Sources = 11
- user.Introduce = patient.Remark
- user.Status = 1
- user.UpdatedTime = patient.UpdatedTime
- user.CreatedTime = patient.CreatedTime
- err = btx.Create(&user).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- patient.UserId = user.ID
-
- if customer == nil {
- err = btx.Create(&models.SgjCustomer{
- UserOrgId: patient.UserOrgId,
- UserId: user.ID,
- Mobile: patient.Phone,
- Name: patient.Name,
- Gender: patient.Gender,
- Birthday: patient.Birthday,
- Sources: 11,
- Status: 1,
- CreatedTime: patient.CreatedTime,
- UpdatedTime: patient.UpdatedTime,
- Avatar: patient.Avatar,
- Remark: patient.Remark,
- }).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
-
- err = utx.Create(patient).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
-
- var lapseto models.PatientLapseto
- lapseto.PatientId = patient.ID
- lapseto.LapsetoType = patient.Lapseto
- lapseto.CreatedTime = patient.CreatedTime
- lapseto.UpdatedTime = patient.CreatedTime
- lapseto.Status = 1
- lapseto.LapsetoTime = patient.CreatedTime
-
- err = utx.Create(&lapseto).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
-
- if len(contagions) > 0 {
- thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, contagion := range contagions {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, patient.CreatedTime)
- insertData = append(insertData, patient.UpdatedTime)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- if len(diseases) > 0 {
- thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, disease := range diseases {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, disease)
- insertData = append(insertData, 1)
- insertData = append(insertData, patient.CreatedTime)
- insertData = append(insertData, patient.UpdatedTime)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- utx.Commit()
- btx.Commit()
-
- return
- }
-
- func GetLastPatientData(orgid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1", orgid).Last(&patients).Error
- return patients, err
- }
-
- func CreatePatientsNew(patientsNew *models.XtPatientsNew) error {
-
- err := XTWriteDB().Model(&patientsNew).Create(&patientsNew).Error
- return err
- }
-
- func EditPatientLapseto(patient *models.Patients, lapseto *models.PatientLapseto) (err error) {
- utx := writeDb.Begin()
- err = utx.Model(&models.Patients{}).Where("id=?", patient.ID).Update(map[string]interface{}{"lapseto": patient.Lapseto, "out_reason": patient.OutReason, "death_time": patient.DeathTime}).Error
- //err = utx.Model(&models.PatientLapseto{}).Where("id=?", patient.ID).Update(map[string]interface{}{"lapseto_type": patient.Lapseto, "lapseto_time": time.Now().Unix(), "updated_time": time.Now().Unix()}).Error
- if err != nil {
- utx.Rollback()
- return
- }
- err = utx.Create(lapseto).Error
- if err != nil {
- utx.Rollback()
- return
- }
- // 删除排班和排班模板信息
- if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
- now := time.Now()
- deleteScheduleErr := utx.Model(&models.PatientSchedule{}).Where("patient_id = ? AND schedule_date >= ? AND status = 1", patient.ID, lapseto.LapsetoTime).Updates(map[string]interface{}{
- "status": 0,
- "updated_time": now.Unix(),
- }).Error
- if deleteScheduleErr != nil {
- utx.Rollback()
- err = deleteScheduleErr
- return
- }
-
- deleteSchTempItemErr := utx.Model(&models.PatientScheduleTemplateItem{}).Where("patient_id = ? AND status = 1", patient.ID).Updates(map[string]interface{}{
- "status": 0,
- "mtime": now.Unix(),
- }).Error
- if deleteSchTempItemErr != nil {
- utx.Rollback()
- err = deleteSchTempItemErr
- return
- }
- }
- utx.Commit()
- return
- }
-
- func UpdatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
- // if len(contagions) > 0 || len(diseases) > 0 {
- utx := writeDb.Begin()
- err = utx.Save(patient).Error
- if err != nil {
- utx.Rollback()
- return
- }
- err = utx.Model(&models.InfectiousDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
- fmt.Println("err", err)
- if err != nil {
- utx.Rollback()
- return
- }
- if len(contagions) > 0 && patient.IsInfectious == 2 {
- thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, contagion := range contagions {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, time.Now().Unix())
- insertData = append(insertData, time.Now().Unix())
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
-
- err = utx.Model(&models.ChronicDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
- if err != nil {
- utx.Rollback()
- return
- }
- if len(diseases) > 0 {
- thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, disease := range diseases {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, disease)
- insertData = append(insertData, 1)
- insertData = append(insertData, time.Now().Unix())
- insertData = append(insertData, time.Now().Unix())
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
-
- // } else {
- // err = writeDb.Save(patient).Error
- // }
- return
- }
-
- func UpdatePatientLapseto(patientid int64, lapseto models.PatientLapseto) error {
- err := XTWriteDB().Model(&lapseto).Where("patient_id = ?", patientid).Updates(map[string]interface{}{"lapseto_type": lapseto.LapsetoType, "lapseto_time": time.Now().Unix(), "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func UpdatepatientTwo(patientsNew *models.XtPatientsNew, id int64) error {
-
- err := XTWriteDB().Model(&patientsNew).Where("blood_id = ?", id).Update(map[string]interface{}{"user_org_id": patientsNew.UserOrgId, "user_id": patientsNew.UserId, "avatar": patientsNew.Avatar, "patient_type": patientsNew.Avatar, "dialysis_no": patientsNew.DialysisNo, "admission_number": patientsNew.AdmissionNumber, "source": patientsNew.Source, "lapseto": patientsNew.Lapseto, "partition_id": patientsNew.PartitionId, "bed_id": patientsNew.BedId, "name": patientsNew.Name, "alias": patientsNew.Alias, "gender": patientsNew.Gender, "marital_status": patientsNew.MaritalStatus, "id_card_no": patientsNew.IdCardNo, "birthday": patientsNew.Birthday, "reimbursement_way_id": patientsNew.ReimbursementWayId, "health_care_type": patientsNew.HealthCareType, "health_care_no": patientsNew.HealthCareType, "health_care_due_date": patientsNew.HealthCareType, "height": patientsNew.Height, "blood_type": patientsNew.BloodType, "rh": patientsNew.Rh, "health_care_due_alert_date": patientsNew.HealthCareDueAlertDate, "education_level": patientsNew.EducationLevel, "profession": patientsNew.Profession, "phone": patientsNew.Phone, "home_telephone": patientsNew.HomeTelephone, "relative_phone": patientsNew.RelativePhone, "relative_relations": patientsNew.RelativeRelations, "home_address": patientsNew.HomeAddress, "work_unit": patientsNew.WorkUnit, "unit_address": patientsNew.UnitAddress, "children": patientsNew.Children, "receiving_date": patientsNew.ReceivingDate, "is_hospital_first_dialysis": patientsNew.IsHospitalFirstDialysis, "first_dialysis_date": patientsNew.FirstDialysisDate, "first_dialysis_hospital": patientsNew.FirstDialysisHospital, "predialysis_condition": patientsNew.PredialysisCondition, "pre_hospital_dialysis_frequency": patientsNew.PreHospitalDialysisFrequency, "pre_hospital_dialysis_times": patientsNew.PreHospitalDialysisFrequency, "hospital_first_dialysis_date": patientsNew.HospitalFirstDialysisDate, "induction_period": patientsNew.InductionPeriod, "initial_dialysis": patientsNew.InitialDialysis, "total_dialysis": patientsNew.TotalDialysis, "attending_doctor_id": patientsNew.AttendingDoctorId, "head_nurse_id": patientsNew.HeadNurseId, "evaluate": patientsNew.Evaluate, "diagnose": patientsNew.Diagnose, "remark": patientsNew.Remark, "registrars_id": patientsNew.RegistrarsId, "registrars": patientsNew.Registrars, "qr_code": patientsNew.QrCode, "binding_state": patientsNew.BindingState, "patient_complains": patientsNew.PatientComplains, "present_history": patientsNew.PresentHistory, "past_history": patientsNew.PastHistory, "temperature": patientsNew.Temperature,
- "pulse": patientsNew.Pulse, "respiratory": patientsNew.Respiratory, "sbp": patientsNew.Sbp, "dbp": patientsNew.Dbp, "nation": patientsNew.Nation, "native_place": patientsNew.NativePlace, "age": patientsNew.Age, "infectious_next_record_time": patientsNew.InfectiousNextRecordTime, "is_infectious": patientsNew.IsInfectious, "remind_cycle": patientsNew.RemindCycle, "response_result": patientsNew.ResponseResult, "is_open_remind": patientsNew.IsOpenRemind, "first_treatment_date": patientsNew.FirstTreatmentDate, "dialysis_age": patientsNew.DialysisAge, "expense_kind": patientsNew.ExpenseKind, "tell_phone": patientsNew.ExpenseKind, "contact_name": patientsNew.ContactName, "blood_patients": patientsNew.BloodPatients, "slow_patients": patientsNew.SlowPatients, "member_patients": patientsNew.MemberPatients, "ecommer_patients": patientsNew.EcommerPatients, "troble_shoot": patientsNew.TrobleShoot, "sch_remark": patientsNew.SchRemark, "treatment_plan": patientsNew.TreatmentPlan}).Error
- return err
- }
-
- func GetLastInfectionRecord(id int64, org_id int64, project_id int64, date int64) (inspection models.Inspection, err error) {
- err = readDb.Model(&models.Inspection{}).Where("patient_id=? and status=1 and org_id = ? and project_id = ? AND inspect_date = ? ", id, org_id, project_id, date).Last(&inspection).Error
- return
- }
-
- func GetAllInfectionRecord(date int64, org_id int64, patient_id int64, project_id int64) (inspection []*models.Inspection, err error) {
- err = readDb.Model(&models.Inspection{}).Where("patient_id=? and status=1 and org_id = ? and project_id = ? and inspect_date = ?", patient_id, org_id, project_id, date).Find(&inspection).Error
- return
- }
-
- func GetPatientDiseases(id int64) []int64 {
- var dis []models.ChronicDiseases
- ids := make([]int64, 0)
- err := readDb.Model(&models.ChronicDiseases{}).Where("patient_id=? and status=1", id).Find(&dis).Error
- if err != nil || len(dis) == 0 {
- return ids
- }
- for _, item := range dis {
- ids = append(ids, item.DiseaseId)
- }
- return ids
- }
- func GetPatientContagions(id int64) []int64 {
- var cis []models.InfectiousDiseases
- ids := make([]int64, 0)
- err := readDb.Model(&models.InfectiousDiseases{}).Where("patient_id=? and status=1", id).Find(&cis).Error
- if err != nil || len(cis) == 0 {
- return ids
- }
- for _, item := range cis {
- ids = append(ids, item.DiseaseId)
- }
- return ids
- }
-
- func FindPatientDialysisSolutionByMode(orgID int64, patientID, modeId int64) (solution models.DialysisSolution, err error) {
- err = readDb.Model(&models.DialysisSolution{}).Where("user_org_id=? and patient_id=? and mode_id=? and parent_id=0 and status=1", orgID, patientID, modeId).First(&solution).Error
- return
- }
-
- func FindPatientDialysisSolution(orgID int64, id int64) (solution models.DialysisSolution, err error) {
- err = readDb.Model(&models.DialysisSolution{}).Where("id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
- return
- }
-
- func FindPatientDialysisSolutionChild(orgID int64, id int64) (solution models.DialysisSolution, err error) {
- err = readDb.Model(&models.DialysisSolution{}).Where("parent_id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
- return
- }
-
- func CreatePatientDialysisSolution(solution *models.DialysisSolution) (err error) {
- err = writeDb.Create(solution).Error
- return
- }
-
- func UpdatePatientDialysisSolution(solution *models.DialysisSolution) (err error) {
- err = writeDb.Save(solution).Error
- return
- }
-
- //GetPatientDialysisSolutionList 返回患者透析方案的列表
- func GetPatientDialysisSolutionList(orgID int64, patientID int64, page, limit int64) (solutions []*models.DialysisSolution, total int64, err error) {
-
- offset := (page - 1) * limit
- db := readDb.Table("xt_dialysis_solution as ds").Where("ds.status=1")
- if orgID > 0 {
- db = db.Where("ds.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("ds.patient_id=?", patientID)
- }
- db = db.Count(&total).Offset(offset).Limit(limit)
-
- err = db.Order("id desc").Find(&solutions).Error
- if err != nil {
- return
- }
- if len(solutions) > 0 {
- nilNameIds := make([]int64, 0)
- for _, solution := range solutions {
- if len(solution.ModeName) == 0 {
- nilNameIds = append(nilNameIds, solution.ModeId)
- }
- }
- if len(nilNameIds) > 0 {
- var modes []*models.TreatmentMode
- err = readDb.Model(&models.TreatmentMode{}).Where("id IN (?)", nilNameIds).Find(&modes).Error
- if err != nil {
- return
- }
-
- modesMap := make(map[int64]models.TreatmentMode, 0)
- for _, mode := range modes {
- modesMap[mode.ID] = *mode
- }
- for index, solution := range solutions {
- if _, exixt := modesMap[solution.ModeId]; exixt && len(solution.ModeName) == 0 {
- solutions[index].ModeName = modesMap[solution.ModeId].Name
- }
- }
- }
- }
- return
- }
-
- //GetPatientDryWeightAdjustList 返回患者调整干体重的列表
- func GetPatientDryWeightAdjustList(orgID int64, patientID int64, page int64, limit int64) (weights []*models.DryWeightAdjust, total int64, err error) {
- db := readDb.Table("xt_dry_weight_adjust as dwa").Where("dwa.status=1")
- if orgID > 0 {
- db = db.Where("dwa.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("dwa.patient_id=?", patientID)
- }
-
- db = db.Select("dwa.id, dwa.user_org_id, dwa.patient_id, dwa.weight, dwa.adjusted_value, dwa.doctor, dwa.registrars_id, dwa.remark, dwa.status, dwa.created_time, dwa.updated_time").Count(&total).Order("id desc")
-
- if page > 0 && limit > 0 {
- offset := (page - 1) * limit
- db = db.Offset(offset).Limit(limit)
- }
- err = db.Find(&weights).Error
- return
- }
-
- func CreateDryWeightAdjust(m *models.DryWeightAdjust) (err error) {
- err = writeDb.Create(m).Error
- return
- }
-
- func FindPatientLastDryWeightAdjust(orgID int64, id int64) (weight models.DryWeightAdjust, err error) {
- err = readDb.Model(&models.DryWeightAdjust{}).Where("user_org_id=? and patient_id=? and status=1", orgID, id).Order("id desc").First(&weight).Error
- return
- }
-
- func CreateDoctorAdvice(m *models.DoctorAdvice) (err error) {
- return writeDb.Create(m).Error
- }
- func GetMaxAdviceGroupID(orgId int64) (group int64) {
- var advice models.DoctorAdvice
- err := readDb.Table("xt_doctor_advice").Where("user_org_id=?", orgId).Select("max(groupno) as groupno").First(&advice).Error
- if err != nil {
- fmt.Println(err)
- group = 0
- }
- group = advice.GroupNo
- return
- }
-
- func CreateGroupAdvice(orgId int64, group int64, advices []*models.GroupAdvice) (err error) {
- if group == 0 {
- group = GetMaxAdviceGroupID(orgId) + 1
- }
-
- tx := writeDb.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- for _, advice := range advices {
- advice.GroupNo = group
- if err = tx.Create(advice).Error; err != nil {
- tx.Rollback()
- return
- }
- }
- tx.Commit()
- return
- }
-
- func CreateMGroupAdvice(orgId int64, advices []*models.GroupAdvice, groupNo int64) (list []*models.GroupAdvice, err error) {
- if groupNo <= 0 {
- group := GetMaxAdviceGroupID(orgId)
- groupNo = group + 1
- }
- tx := writeDb.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- for _, advice := range advices {
- advice.GroupNo = groupNo
- if err = tx.Create(advice).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, advice)
- if len(advice.Children) > 0 {
- for _, child := range advice.Children {
- child.GroupNo = groupNo
- child.ParentId = advice.ID
- fmt.Println(child)
- if err = tx.Create(&child).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, child)
- }
- }
-
- }
- tx.Commit()
- return
- }
-
- func UpdateDoctorAdvice(m *models.DoctorAdvice) (err error) {
- return writeDb.Save(m).Error
- }
-
- func StopGroupAdvice(orgId int64, groupNo int64, m *models.DoctorAdvice) (err error) {
- err = writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? and groupno=?", orgId, groupNo).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "StopState": 1, "StopReason": m.StopReason, "StopDoctor": m.StopDoctor, "StopTime": m.StopTime}).Error
- if err != nil {
- return
- }
- return
- }
-
- func StopDoctorAdvice(m *models.DoctorAdvice) (err error) {
-
- ut := writeDb.Begin()
- err = ut.Save(m).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DoctorAdvice{}).Where("parent_id=?", m.ID).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "StopState": 1, "StopReason": m.StopReason, "StopDoctor": m.StopDoctor, "StopTime": m.StopTime, "Modifier": m.Modifier}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func DeleteSolution(m *models.DialysisSolution) (err error) {
-
- if m.ParentId > 0 {
- return writeDb.Save(m).Error
- } else {
- ut := writeDb.Begin()
- err = ut.Save(m).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DialysisSolution{}).Where("parent_id=?", m.ID).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- }
-
- return
- }
-
- func DeleteDoctorAdvice(m *models.DoctorAdvice) (err error) {
-
- if m.ParentId > 0 {
- return writeDb.Save(m).Error
- } else {
- ut := writeDb.Begin()
- err = ut.Save(m).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DoctorAdvice{}).Where("parent_id=? AND user_org_id = ?", m.ID, m.UserOrgId).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0, "Modifier": m.Modifier}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- }
-
- return
- }
- func DeleteGroupAdvice(orgId int64, groupNo int64, admin_user_id int64) (err error) {
- err = writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ?", orgId, groupNo).Update(map[string]interface{}{"UpdatedTime": time.Now().Unix(), "Status": 0, "Modifier": admin_user_id}).Error
- if err != nil {
- return
- }
- return
- }
-
- func FindDoctorAdvice(orgID, id int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id = ? and user_org_id=? and status = 1", id, orgID).First(&advice).Error
- return
- }
-
- func FindDoctorAdviceOne(orgID, patient_id int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id=? and status = 1", patient_id, orgID).First(&advice).Error
- return
- }
-
- func FindDoctorAdviceTwo(ids []string, orgID int64) (advice []*models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id in(?) and user_org_id=? and status = 1", ids, orgID).First(&advice).Error
- return
- }
-
- func FindHisDoctorAdvice(orgID, id int64) (advice models.HisDoctorAdviceInfo, err error) {
- err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and user_org_id=? and status = 1", id, orgID).First(&advice).Error
- return
- }
-
- func FindHisDoctorAdviceTwo(ids []string, orgID int64) (advice []*models.HisDoctorAdviceInfo, err error) {
- err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id in(?) and user_org_id=? and status = 1", ids, orgID).First(&advice).Error
- return
- }
-
- func FindHisDoctorAdviceOne(orgID, patient_id int64) (advice models.HisDoctorAdviceInfo, err error) {
- err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? and user_org_id=? and status = 1", patient_id, orgID).First(&advice).Error
- return
- }
-
- func FindDoctorAdviceByGroupNo(orgID, groupNo int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("groupno = ? and user_org_id=? and status = 1", groupNo, orgID).First(&advice).Error
- return
- }
- func GetDoctorAdviceList(orgID, patientID, advice_type, stop, start, end int64, keywords string) (advices []*models.DoctorAdvices, total int64, err error) {
-
- db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Print("table", table)
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- } else if advice_type == 0 {
- db = db.Where("x.advice_type in (?)", []int{1, 3})
- }
-
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- err = db.Group("x.id").Count(&total).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
- fmt.Print("err", err)
- return
- }
-
- func GetDoctorAdviceListOne(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64) (advices []*models.DoctorAdvices, total int64, err error) {
-
- db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Print("table", table)
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 && advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,x.push_start_time,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
- fmt.Print("err", err)
- return
- }
-
- func GetDoctorAdviceListTwo(orgID int64, patientID int64, advice_type int64, stop int64, start int64, end int64, keywords string, limit int64, page int64) (advices []*models.DoctorAdvices, total int64, err error) {
-
- db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println(table)
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
-
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,x.push_start_time,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&advices).Error
- fmt.Print("错误是什么", err)
- return
-
- }
-
- func GetDoctorAdvicePageList(orgID, patientID, advice_type, stop, start, end int64, keywords string, page, limit int64) (advices []*models.DoctorAdvice, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := readDb.Model(&models.DoctorAdvice{}).Where("status=1")
- if orgID > 0 {
- db = db.Where("user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("patient_id = ?", patientID)
- }
- if advice_type > 0 {
- db = db.Where("advice_type = ?", advice_type)
- }
- if stop == 1 {
- db = db.Where("(stop_state=? or execution_state=?) and parent_id=0", stop, stop)
- } else if stop == 2 {
- db = db.Where("stop_state=? and execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("advice_name LIKE ?", likeKey)
- }
- err = db.Count(&total).Select("id,user_org_id,patient_id,advice_type,advice_date,start_time,advice_name,advice_desc,reminder_date,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker IF(parent_id>0, parent_id, id) as advice_order").Order("advice_order desc, id").Offset(offset).Limit(limit).Scan(&advices).Error
- return
- }
- func CreateSubDoctorAdvice(advices []*models.DoctorAdvice) (err error) {
- if len(advices) > 0 {
- utx := writeDb.Begin()
- if len(advices) > 0 {
- thisSQL := "INSERT INTO xt_doctor_advice (single_dose_unit, prescribing_number, prescribing_number_unit, advice_name, advice_desc,single_dose,created_time,updated_time,patient_id,parent_id,user_org_id,record_date,advice_type,drug_spec_unit) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, advice := range advices {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, advice.SingleDoseUnit)
- insertData = append(insertData, advice.PrescribingNumber)
- insertData = append(insertData, advice.PrescribingNumberUnit)
- insertData = append(insertData, advice.AdviceName)
- insertData = append(insertData, advice.AdviceDesc)
- insertData = append(insertData, advice.SingleDose)
- insertData = append(insertData, advice.CreatedTime)
- insertData = append(insertData, advice.UpdatedTime)
- insertData = append(insertData, advice.PatientId)
- insertData = append(insertData, advice.ParentId)
- insertData = append(insertData, advice.UserOrgId)
- insertData = append(insertData, advice.RecordDate)
- insertData = append(insertData, 2)
- insertData = append(insertData, advice.DrugSpecUnit)
-
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func GetPatientDialysisRecord(orgID, patientID int64, page, limit, start, end, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
-
- offset := (page - 1) * limit
- var total int64
- var err error
- var orders []*models.PatientDialysisRecord
-
- // err = readDb.Table("xt_dialysis_order as do").
- // Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- // Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- // Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- // Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- // Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
- // Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
- // Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Count(&total).Offset(offset).Limit(limit).Order("do.dialysis_date desc").Select(" do.id, do.dialysis_date, do.user_org_id, do.patient_id, do.prescription_id, do.stage, do.remark, do.status, do.created_time, do.updated_time, s.schedule_type, s.partition_id, dz.name as partition_name").Find(&orders).Error
-
- db := readDb.Table("xt_dialysis_order as do").
- Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
- return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
- return readUserDb.Where("status = 1")
- })
- }).
- Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("Device", "org_id=? and status=1", orgID).
- Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
- return readUserDb.Where("org_id=?", orgID)
- }).
- Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
- Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
- Where("do.patient_id=? and do.user_org_id=? and do.status=1", patientID, orgID).Group("s.schedule_date")
-
- if start != 0 {
- db = db.Where("do.dialysis_date>=?", start)
- }
- if end != 0 {
- db = db.Where("do.dialysis_date<=?", end)
- }
- if mode_id > 0 {
- db = db.Joins("JOIN xt_dialysis_prescription as dp ON dp.patient_id=do.patient_id and dp.user_org_id = do.user_org_id and dp.record_date = do.dialysis_date")
- db = db.Where("dp.mode_id=?", mode_id)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("do.dialysis_date desc").Select("do.bed_id, do.id, do.dialysis_date, do.user_org_id, do.patient_id, do.prescription_id, do.stage, do.remark, do.status, do.created_time, do.updated_time,do.start_nurse,do.finish_nurse ,s.schedule_type, s.partition_id, dz.name as partition_name").Find(&orders).Error
-
- if len(orders) > 0 {
- ids := make([]int64, 0)
- for _, order := range orders {
- dialyzer := order.DialysisPrescription.Dialyzer
- ids = append(ids, dialyzer)
- }
- if len(ids) > 0 {
- var dialyzers []*models.DeviceNumber
- err = readDb.Model(&models.DeviceNumber{}).Where("id IN (?) and org_id=? and status=1", ids, orgID).Find(&dialyzers).Error
- if err != nil {
- return nil, 0, err
- }
-
- dialyzerMap := make(map[int64]models.DeviceNumber, 0)
- for _, item := range dialyzers {
- dialyzerMap[item.ID] = *item
- }
- for orderIndex, order := range orders {
- if _, exist := dialyzerMap[order.DialysisPrescription.Dialyzer]; exist {
- orders[orderIndex].DeviceNumber = dialyzerMap[order.DialysisPrescription.Dialyzer].Number
- }
- }
- }
- }
-
- return orders, total, err
- }
-
- func GetPatientTreatmentSummaryList(orgID, patientID, page, limit, start, end int64) (list []*models.TreatmentSummary, total int, err error) {
-
- offset := (page - 1) * limit
- fmt.Println(offset)
- fmt.Println(limit)
- db := readDb.Model(&models.TreatmentSummary{}).Where("user_org_id = ? and patient_id=?", orgID, patientID)
- if start != 0 {
- db = db.Where("assessment_date >= ?", start)
- }
- if end != 0 {
- db = db.Where("assessment_date <= ?", end)
- }
- db = db.Where("status=1")
- err = db.Count(&total).Offset(offset).Limit(limit).Order("assessment_date desc, id desc").Find(&list).Error
- return
-
- }
-
- func GetPatientScheduleList(orgID int64, patientID int64, page int64, limit int64, start int64) (schedules []*models.PatientSchedule, err error) {
- offset := (page - 1) * limit
- err = readDb.Table("xt_schedule as s").
- Preload("DeviceZone", "org_id=? and status=1", orgID).
- Preload("DeviceNumber", "org_id=? and status=1", orgID).
- Preload("TreatmentMode", "status=1").
- Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.status=1", patientID, orgID, start).
- Limit(limit).Offset(offset).Find(&schedules).Error
- return
- }
-
- func GetMonitorRecord(orgID int64, date int64, partition int64, patientId int64) ([]*models.NewVMMonitorDialysisSchedule, error) {
- var mds []*models.NewVMMonitorDialysisSchedule
-
- db := readDb.Model(&models.NewVMMonitorDialysisSchedule{})
- if date > 0 {
- db = db.Where("schedule_date = ?", date)
- }
- if partition > 0 {
- db = db.Where("partition_id = ?", partition)
- }
- if patientId > 0 {
-
- db = db.Where("patient_id = ?", patientId)
- }
-
- err = db.Where("status = 1 and user_org_id = ?", orgID).Find(&mds).Error
-
- return mds, err
- }
-
- func MobileGetMonitorsWithPatient(orgID int64, keyword string, page int) ([]*models.MonitorDialysisSchedule, error) {
- var patients []*models.Patients
- getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
- if getPatientErr != nil {
- return nil, getPatientErr
- }
- patientIDs := make([]int64, len(patients))
- for index, patient := range patients {
- patientIDs[index] = patient.ID
- }
-
- db := readDb.
- Model(&models.MonitorDialysisSchedule{}).
- Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
- Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
- Preload("TreatmentMode", "status = 1").
- Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
- Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
- Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
- Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
- Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
- Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID).
- Where("status = 1 AND user_org_id = ? AND patient_id in (?)", orgID, patientIDs)
-
- var schedules []*models.MonitorDialysisSchedule
- err := db.Offset(20 * (page - 1)).Limit(20).Order("schedule_date desc").Find(&schedules).Error
- return schedules, err
- }
-
- func GetPatientByKeyWord(orgID int64, keywords string) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1", orgID)
- fmt.Println("keywords22222223322332322332322323323", keywords)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("name LIKE ? OR dialysis_no LIKE ? ", likekey, likekey).Find(&patient).Error
- } else {
- err = db.Find(&patient).Error
- }
- return
- }
-
- func FindDoctorAdviceByGoroupNo(orgID int64, groupno int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1", orgID, groupno).First(&advice).Error
- return
- }
-
- func FindOldDoctorAdvice(orgID int64, advice_id int64) (advice models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id = ? AND user_org_id=? AND status = 1", advice_id, orgID).First(&advice).Error
- return
- }
-
- func UpdateAdviceGroupStartTime(orgID int64, groupNO int64, startTime int64, admin_user_id int64) error {
- now := time.Now().Unix()
- err := writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND status = 1 AND execution_state <> 1 AND check_state <> 1 AND groupno = ? AND admin_user_id = ?", orgID, groupNO, admin_user_id).Updates(map[string]interface{}{
- "start_time": startTime,
- "updated_time": now,
- "modifier": admin_user_id,
- }).Error
- return err
- }
-
- func QueryPatientById(id int64) *models.Patients {
- var pat models.Patients
- err := readDb.Model(&models.Patients{}).Where("id=?", id).First(&pat).Error
- if err != nil {
-
- }
- return &pat
- }
-
- func FindAllDoctorAdviceByGoroupNo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1", orgID, groupno).Find(&advice).Error
- return
- }
-
- func FindDoctorAdviceByIds(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("id IN (?) AND user_org_id = ? AND status = 1", ids, orgID).Find(&advice).Error
- return
- }
-
- func BatchDeleteDoctorAdvice(ids []string, user_id int64) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix(), "modifier": user_id}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix(), "modifier": user_id}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return err
-
- }
-
- func FindAdviceByGoroupNo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 AND parent_id = 0", orgID, groupno).Find(&advice).Error
- return
- }
-
- func UpdateDoctorAdviceAndSubAdvice(m *models.DoctorAdvice) (err error) {
- ut := writeDb.Begin()
- err = ut.Save(m).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?)", m.ID).Updates(map[string]interface{}{"start_time": m.StartTime, "groupno": m.GroupNo, "updated_time": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return err
-
- }
-
- func GetAllWaitRemindPatient(org_id int64, page int64, limit int64) (total int64, patient []*models.Patients, err error) {
- type Total struct {
- Count int64
- }
- var totals Total
-
- offset := (page - 1) * limit
- err = readDb.Raw("select * from xt_patients where user_org_id = ? AND lapseto = 1 AND infectious_next_record_time > 0 AND status = 1 AND date_sub(DATE_FORMAT(date(from_unixtime(`xt_patients`.`infectious_next_record_time`)),'%Y-%m-%d'), interval 7 day) <= now() Order by infectious_next_record_time", org_id).Offset(offset).Limit(limit).Scan(&patient).Error
- readDb.Raw("select Count(id) as count from xt_patients where user_org_id = ? AND lapseto = 1 AND infectious_next_record_time > 0 AND status = 1 AND date_sub(DATE_FORMAT(date(from_unixtime(`xt_patients`.`infectious_next_record_time`)),'%Y-%m-%d'), interval 7 day) <= now() Order by infectious_next_record_time", org_id).Scan(&totals)
-
- return totals.Count, patient, err
- }
-
- func UpdatePatientRemindStatus(patient_id int64, remind int64, org_id int64) (err error) {
- err = writeDb.Model(&models.Patients{}).Where("status = 1 AND id = ? AND user_org_id = ?", patient_id, org_id).Updates(map[string]interface{}{"is_open_remind": remind}).Error
- return
- }
-
- func CreatePatientWeightAdjust(m *models.SgjPatientDryweight) (err error) {
- err = writeDb.Create(m).Error
- return
- }
-
- func FindLastDryWeightAdjust(orgID int64, id int64) (weight models.SgjPatientDryweight, err error) {
- err = readDb.Model(&models.SgjPatientDryweight{}).Where("user_org_id=? and patient_id=? and status=1", orgID, id).Order("id desc").First(&weight).Error
- return
- }
-
- func GetSchedualPatientByKeyWord(orgID int64, keywords string, date int64) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1 ", orgID)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(name LIKE ? OR dialysis_no LIKE ?) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = xt_patients.id AND d.user_org_id = xt_patients.user_org_id)", likekey, likekey, date).Find(&patient).Error
- } else {
- err = db.Find(&patient).Error
- }
- return
- }
-
- func GetPatientScheduleOne(patientid int64, nowdate int64, orgid int64) (models.XtSchedule, error) {
- schedule := models.XtSchedule{}
- err := XTReadDB().Model(&schedule).Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status =1", patientid, nowdate, orgid).Find(&schedule).Error
- return schedule, err
- }
-
- func CreateExportPatient(patient *models.Patients, contagions []int64, org_creator int64) (err error) {
- user, _ := GetSgjUserByMobild(patient.Phone)
- customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
- utx := writeDb.Begin()
- btx := writeUserDb.Begin()
- if user.ID == 0 {
- user.Mobile = patient.Phone
- user.Avatar = patient.Avatar
- user.AvatarThumb = patient.Avatar
- user.Birthday = patient.Birthday
- user.Username = patient.Name
- user.Gender = patient.Gender
- user.Sources = 11
- user.Introduce = patient.Remark
- user.Status = 1
- user.UpdatedTime = patient.UpdatedTime
- user.CreatedTime = patient.CreatedTime
- err = btx.Create(&user).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- patient.UserId = user.ID
-
- if customer == nil {
- err = btx.Create(&models.SgjCustomer{
- UserOrgId: patient.UserOrgId,
- UserId: user.ID,
- Mobile: patient.Phone,
- Name: patient.Name,
- Gender: patient.Gender,
- Birthday: patient.Birthday,
- Sources: 11,
- Status: 1,
- CreatedTime: patient.CreatedTime,
- UpdatedTime: patient.UpdatedTime,
- Avatar: patient.Avatar,
- Remark: patient.Remark,
- }).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
-
- err = utx.Create(patient).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
-
- if patient.DryWeight > 0 {
- var dryWeight models.SgjPatientDryweight
- dryWeight.PatientId = patient.ID
- dryWeight.UserOrgId = patient.UserOrgId
- dryWeight.Status = 1
- dryWeight.AdjustedValue = "/"
- dryWeight.Creator = org_creator
- dryWeight.UserId = org_creator
- dryWeight.Ctime = time.Now().Unix()
- dryWeight.Mtime = time.Now().Unix()
- dryWeight.DryWeight = patient.DryWeight
- dryWeight.Remakes = ""
- err = utx.Create(&dryWeight).Error
- }
-
- var lapseto models.PatientLapseto
- lapseto.PatientId = patient.ID
- lapseto.LapsetoType = patient.Lapseto
- lapseto.CreatedTime = patient.CreatedTime
- lapseto.UpdatedTime = patient.CreatedTime
- lapseto.Status = 1
- lapseto.LapsetoTime = patient.CreatedTime
-
- err = utx.Create(&lapseto).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
-
- if len(contagions) > 0 {
- thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, contagion := range contagions {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patient.ID)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, patient.CreatedTime)
- insertData = append(insertData, patient.UpdatedTime)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- }
- patientsNew := models.XtPatientsNew{
- Name: patient.Name,
- Gender: patient.Gender,
- Phone: patient.Phone,
- IdCardNo: patient.IdCardNo,
- FirstDialysisDate: patient.FirstDialysisDate,
- Source: patient.Source,
- Lapseto: patient.Lapseto,
- IsInfectious: patient.IsInfectious,
- DialysisNo: patient.DialysisNo,
- Height: patient.Height,
- HomeAddress: patient.HomeAddress,
- IsExcelExport: 1,
- BloodPatients: 1,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UserOrgId: patient.UserOrgId,
- BloodId: patient.ID,
- Avatar: "https://images.shengws.com/201809182128111.png",
- }
- err = utx.Create(&patientsNew).Error
- if err != nil {
- utx.Rollback()
- btx.Rollback()
- return
- }
- utx.Commit()
- btx.Commit()
-
- return
- }
-
- func FindPatientPhoneIsExist(phone string, org_id int64) (count int64) {
- readDb.Model(&models.Patients{}).Where("user_org_id = ? AND phone = ? AND status = 1", org_id, phone).Count(&count)
- return
- }
-
- func FindPatientIdCardNoIsExist(id_card_no string, org_id int64) (count int64) {
- readDb.Model(&models.Patients{}).Where("user_org_id = ? AND id_card_no = ? AND status = 1", org_id, id_card_no).Count(&count)
- return
- }
-
- func CreateExportErrLog(log *models.ExportErrLog) {
- writeDb.Create(&log)
- return
- }
-
- func FindPatientExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 1", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func FindPatientExportLogOne(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 4", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func FindPatientExportLogTwo(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 5", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func FindPatientExportLogThree(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 6", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func CreateExportLog(log *models.ExportLog) {
- writeDb.Create(&log)
- }
-
- func UpdateDoctorEditAdvice(advice models.XtDoctorAdvice, orgid int64, groupno int64, date int64, patientid int64) error {
-
- err := XTWriteDB().Model(&advice).Where("user_org_id = ? and groupno = ? and advice_date = ? and patient_id = ?", orgid, groupno, date, patientid).Update(map[string]interface{}{"start_time": advice.StartTime, "updated_time": advice.UpdatedTime}).Error
- return err
- }
-
- func GetPatientsByKey(orgID int64, keywords string) (patient []*models.Patients, err error) {
- db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1 ", orgID)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(name LIKE ? OR dialysis_no LIKE ?)", likekey, likekey).Find(&patient).Error
- } else {
- err = db.Find(&patient).Error
- }
- return
- }
-
- func FindAllDoctorAdviceByGoroupNoTwo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 AND execution_state = 2", orgID, groupno).Find(&advice).Error
- return
- }
-
- func FindDoctorAdviceByIdsTwo(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND status = 1 AND execution_state = 2 AND (id IN (?) OR parent_id IN (?))", orgID, ids, ids).Find(&advice).Error
- return
- }
-
- func CreateHisGroupAdvice(orgId int64, advices []*models.HisGroupAdvice, groupNo int64) (list []*models.HisGroupAdvice, err error) {
- if groupNo <= 0 {
- group := GetMaxAdviceGroupID(orgId)
- groupNo = group + 1
- }
- tx := writeDb.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- for _, advice := range advices {
- advice.Groupno = groupNo
- if err = tx.Create(advice).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, advice)
- if len(advice.Children) > 0 {
- for _, child := range advice.Children {
- child.Groupno = groupNo
- child.ParentId = advice.ID
- fmt.Println(child)
- if err = tx.Create(&child).Error; err != nil {
- tx.Rollback()
- return
- }
- list = append(list, child)
- }
- }
-
- }
- tx.Commit()
- return
- }
-
- func GetDialysisCount(orgid int64, partitionid int64) (order []*models.BloodDialysisOrderCount, err error) {
-
- db := XTReadDB().Table("xt_dialysis_order as o")
- if partitionid == 0 {
- db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1", orgid).Group("o.patient_id").Scan(&order)
- }
-
- if partitionid > 0 {
- db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and x.partition_id = ? and x.schedule_date = o.dialysis_date and x.status = 1", orgid, partitionid).Group("o.patient_id").Scan(&order)
- }
- return order, err
- }
-
- func UpdatePatientDialysisSolutionOne(patientid int64, orgid int64, prescription *models.DialysisPrescription, timenow int64) error {
-
- err = XTWriteDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and record_date = ? ", patientid, orgid, timenow).Updates(map[string]interface{}{"dialyzer": prescription.Dialyzer, "anticoagulant": prescription.Anticoagulant, "mode_id": prescription.ModeId, "dialysis_duration_hour": prescription.DialysisDurationHour, "anticoagulant_shouji": prescription.AnticoagulantShouji, "anticoagulant_weichi": prescription.AnticoagulantWeichi, "anticoagulant_zongliang": prescription.AnticoagulantZongliang, "kalium": prescription.Kalium, "sodium": prescription.Sodium, "calcium": prescription.Calcium, "dialyzer_perfusion_apparatus": prescription.DialyzerPerfusionApparatus, "blood_access": prescription.BloodAccess, "dialysate_flow": prescription.DialysateFlow, "dialysate_temperature": prescription.DialysateTemperature, "dialysis_dialyszers": prescription.DialysisDialyszers, "dialysis_irrigation": prescription.DialysisIrrigation, "plasma_separator": prescription.PlasmaSeparator, "bilirubin_adsorption_column": prescription.BilirubinAdsorptionColumn, "oxygen_uptake": prescription.OxygenUptake, "oxygen_flow": prescription.OxygenFlow, "oxygen_time": prescription.OxygenTime}).Error
- return err
- }
-
- //func FindRemindAdvice(user_org_id int64, advice_name string, advice_desc string, template_id string, fre_type int64, patient_id int64, record_date int64) (advice models.DoctorAdvice, err error) {
- // err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and record_date = ? and advice_name = ? and advice_desc = ? and template_id = ? and frequency_type = ? ", patient_id, user_org_id, record_date, advice_name, advice_desc, template_id, fre_type).First(&advice).Error
- // return
- //}
-
- func FindRemindAdvice(user_org_id int64, advice_name string, advice_desc string, template_id string, fre_type int64, patient_id int64, record_date int64) (advice models.DoctorAdvice, err error) {
- err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and record_date = ? and advice_name = ? and advice_desc = ? and template_id = ? and frequency_type = ? AND advice_type = 2 ", patient_id, user_org_id, record_date, advice_name, advice_desc, template_id, fre_type).First(&advice).Error
- return
- }
-
- func UpdateScheduleByDeathTime(patientid int64, shcheduledate int64) error {
- err := XTWriteDB().Model(models.XtSchedule{}).Where("patient_id = ? and schedule_date > ?", patientid, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func UpdateScheduleItemByPatientId(id int64) error {
-
- err := XTWriteDB().Model(models.PatientScheduleTemplateItem{}).Where("patient_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetDoctorAdviceListThree(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64) (advices []*models.HisDoctorAdvice, total int64, err error) {
-
- db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Print("table", table)
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 && advice_type > 0 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
- fmt.Print("err", err)
- return
- }
-
- func GetDoctorAdviceListFour(orgID int64, patientID int64, advice_type int64, stop int64, start int64, end int64, keywords string, limit int64, page int64) (advices []*models.HisDoctorAdvice, total int64, err error) {
-
- db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println(table)
- if orgID > 0 {
- db = db.Where("x.user_org_id=?", orgID)
- }
- if patientID > 0 {
- db = db.Where("x.patient_id = ?", patientID)
- }
- if advice_type == 1 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if advice_type == 3 && advice_type > 0 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 && advice_type > 0 {
- db = db.Where("x.advice_type = 4")
- }
-
- if stop == 1 {
- db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
- } else if stop == 2 {
- db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
- }
-
- if start != 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end != 0 {
- db = db.Where("x.start_time<=?", end)
- }
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("x.advice_name LIKE ?", likeKey)
- }
- offset := (page - 1) * limit
- err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&advices).Error
- fmt.Print("错误是什么", err)
- return
-
- }
-
- func GetAllDeviceNumberByListSix(orgID int64) (number []*models.DeviceNumber, err error) {
-
- err = readDb.Model(&models.DeviceNumber{}).Where("org_id=? and status=1", orgID).Find(&number).Error
-
- return number, err
- }
-
- func GetAllDeviceNumberByList(orgID int64) (number []*models.DeviceNumber, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":device_number_all"
- number_info_str, _ := redis.Get(key).Result()
- if len(number_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.DeviceNumber{}).Where("org_id=? and status=1", orgID).Find(&number).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(number) > 0 {
- //缓存数据
- device_number_json, err := json.Marshal(&number)
- if err == nil {
- redis.Set(key, device_number_json, time.Second*60*60*18)
- }
- }
- return number, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(number_info_str), &number)
- return number, nil
- }
- }
-
- func GetAllPrescriptionByListTwo(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescription, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
- prescriptions_list_all, _ := redis.Get(key).Result()
-
- if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- } else {
- err = readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&prescriptions).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(prescriptions) > 0 {
- //缓存数据
- prescriptions_list_all, err := json.Marshal(&prescriptions)
- if err == nil {
- redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- }
- }
- return prescriptions, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- return prescriptions, nil
- }
- }
-
- func GetAllAssessmentBeforesByListThree(orgID int64, scheduleDate int64) (assessmentBefores []*models.PredialysisEvaluation, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
- assessment_befores_list_all, _ := redis.Get(key).Result()
-
- if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
- } else {
- err = readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&assessmentBefores).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentBefores) > 0 {
- //缓存数据
- assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
- if err == nil {
- redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
- }
- }
- return assessmentBefores, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
- return assessmentBefores, nil
- }
- }
-
- func GetAllDialysisOrdersByListThree(orgID int64, scheduleDate int64) (dialysisOrders []*models.MonitorDialysisOrder, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
- dialysis_orders_list_all, _ := redis.Get(key).Result()
-
- if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.MonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- } else {
- err = readDb.Model(&models.MonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ?", orgID).Find(&dialysisOrders).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(dialysisOrders) > 0 {
- //缓存数据
- dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
- if err == nil {
- redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
- }
- }
- return dialysisOrders, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
- return dialysisOrders, nil
- }
- }
-
- func GetAllAssessmentAfterDislysisByListThree(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.AssessmentAfterDislysis, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
- assessment_after_dislysis__all, _ := redis.Get(key).Result()
-
- if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
- } else {
- err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&assessmentAfterDislysis).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentAfterDislysis) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- }
- return assessmentAfterDislysis, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
- return assessmentAfterDislysis, nil
- }
- }
-
- func GetAllMonitorListThree(orgID int64, scheduleDate int64) (monitor []*models.MonitoringRecord, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_record_list_all"
- monitor_record_list_all, _ := redis.Get(key).Result()
-
- if len(monitor_record_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- if scheduleDate > 0 {
- err = readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ?", orgID, scheduleDate).Find(&monitor).Error
- } else {
- err = readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", orgID).Find(&monitor).Error
- }
-
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(monitor) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&monitor)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- }
- return monitor, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(monitor_record_list_all), &monitor)
- return monitor, nil
- }
- }
-
- func GetAllPatientListByListThree(orgID int64) (patients []*models.MonitorPatients, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
- patient_info_str, _ := redis.Get(key).Result()
-
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.MonitorPatients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(patients) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patients)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- }
- return patients, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(patient_info_str), &patients)
- return patients, nil
- }
- }
-
- func GetAllPatientListByListSix(orgID int64, keywords string) (patients []*models.MonitorPatients, err error) {
-
- db := readDb.Model(&models.MonitorPatients{}).Where("status = 1 and lapseto = 1")
- likeKey := "%" + keywords + "%"
- if orgID > 0 {
- db = db.Where("user_org_id = ?", orgID)
- }
- if len(keywords) > 0 {
-
- db = db.Where("name like ?", likeKey)
- }
- err = db.Find(&patients).Error
-
- return patients, err
- }
-
- func GetAllDialysisOrdersByListTwo(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVM, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":dialysis_orders_list_all"
- dialysis_orders_list_all, _ := redis.Get(key).Result()
-
- if scheduleDate < 1669132800 {
- fmt.Println("key233232232332323232", key)
- redis.Set(key, "", time.Second)
- }
- fmt.Println("dialysis_orders_list_all", dialysis_orders_list_all)
- if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&MDialysisOrderVM{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(dialysisOrders) > 0 {
- //缓存数据
- dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
- if err == nil {
- redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
- }
- }
- return dialysisOrders, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
- return dialysisOrders, nil
- }
- }
-
- func GetAllZoneByList(orgID int64) (zone []*models.DeviceZone, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":device_zone_all"
- zone_info_str, _ := redis.Get(key).Result()
- if len(zone_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.DeviceZone{}).Where("org_id=? and status=1", orgID).Find(&zone).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(zone) > 0 {
- //缓存数据
- zone_number_json, err := json.Marshal(&zone)
- if err == nil {
- redis.Set(key, zone_number_json, time.Second*60*60*18)
- }
- }
- return zone, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(zone_info_str), &zone)
- return zone, nil
- }
- }
-
- func GetAllDialysisOrdersByListSeven(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVM, err error) {
-
- err = readDb.Model(&MDialysisOrderVM{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- return dialysisOrders, err
- }
-
- func GetAllPrescriptionByList(orgID int64, scheduleDate int64) (prescriptions []*models.VMDialysisPrescription, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
- prescriptions_list_all, _ := redis.Get(key).Result()
-
- if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMDialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(prescriptions) > 0 {
- //缓存数据
- prescriptions_list_all, err := json.Marshal(&prescriptions)
- if err == nil {
- redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- }
- }
- return prescriptions, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- return prescriptions, nil
- }
- }
-
- func GetAllAssessmentBeforesByListOne(orgID int64, scheduleDate int64) (assessmentBefores []*models.VMPredialysisEvaluation, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_befores_list_all"
- assessment_befores_list_all, _ := redis.Get(key).Result()
-
- if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMPredialysisEvaluation{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentBefores) > 0 {
- //缓存数据
- assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
- if err == nil {
- redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
- }
- }
- return assessmentBefores, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
- return assessmentBefores, nil
- }
- }
-
- func GetAllDialysisOrdersByListSix(orgID int64, scheduleDate int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
-
- err = readDb.Model(&models.VMMonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
-
- return dialysisOrders, err
- }
-
- func GetAllDialysisOrdersByListOne(orgID int64, scheduleDate int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
- redis := RedisClient()
-
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all"
- fmt.Println("key22332323232323223", key)
- dialysis_orders_list_all, _ := redis.Get(key).Result()
- defer redis.Close()
- if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMMonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(dialysisOrders) > 0 {
- //缓存数据
- dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
- if err == nil {
- redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
- }
- }
- return dialysisOrders, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
- return dialysisOrders, nil
- }
- }
-
- func GetAllAssessmentAfterDislysisByListOne(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all"
- assessment_after_dislysis__all, _ := redis.Get(key).Result()
-
- if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(assessmentAfterDislysis) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- }
- return assessmentAfterDislysis, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
- return assessmentAfterDislysis, nil
- }
- }
-
- func GetAllMonitorList(orgID int64, scheduleDate int64) (monitor []*models.VMMonitoringRecord, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_record_list_all"
- monitor_record_list_all, _ := redis.Get(key).Result()
- fmt.Println("monitor_recorde_list", len(monitor_record_list_all))
- if len(monitor_record_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1 AND user_org_id = ? AND monitoring_date= ?", orgID, scheduleDate).Order("monitoring_date asc").Find(&monitor).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(monitor) > 0 {
- //缓存数据
- assessment_after_dislysis__all, err := json.Marshal(&monitor)
- if err == nil {
- redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
- }
- }
- return monitor, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(monitor_record_list_all), &monitor)
- return monitor, nil
- }
- }
-
- func GetAllPatientListByListOne(orgID int64) (patients []*models.VMMonitorPatients, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
- patient_info_str, _ := redis.Get(key).Result()
-
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.VMMonitorPatients{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(patients) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patients)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- }
- return patients, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(patient_info_str), &patients)
- return patients, nil
- }
- }
-
- func GetAllTreatModeByList(orgID int64) (treatement []*models.TreatmentMode, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":treatement_mode_all"
- treatment_info_str, _ := redis.Get(key).Result()
-
- if len(treatment_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
-
- err = readDb.Model(&models.TreatmentMode{}).Where("status=1").Find(&treatement).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(treatement) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&treatement)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- }
- return treatement, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(treatment_info_str), &treatement)
- return treatement, nil
- }
- }
-
- func GetAllPatientListByListSeven(orgID int64) (patients []*MSchedualPatientVM, err error) {
-
- err = readDb.Model(&MSchedualPatientVM{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
- return patients, nil
- }
-
- func GetAllPatientListByListTwo(orgID int64) (patients []*MSchedualPatientVM, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
- patient_info_str, _ := redis.Get(key).Result()
-
- if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&MSchedualPatientVM{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(patients) > 0 {
- //缓存数据
- patient_info_json, err := json.Marshal(&patients)
- if err == nil {
- redis.Set(key, patient_info_json, time.Second*60*60*18)
- }
- }
- return patients, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(patient_info_str), &patients)
- return patients, nil
- }
- }
-
- func GetAllDeviceNumberByListOne(orgID int64) (number []*MDeviceNumberVM, err error) {
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + ":device_number_all"
- number_info_str, _ := redis.Get(key).Result()
- if len(number_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&MDeviceNumberVM{}).Where("org_id=? and status=1", orgID).Find(&number).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(number) > 0 {
- //缓存数据
- device_number_json, err := json.Marshal(&number)
- if err == nil {
- redis.Set(key, device_number_json, time.Second*60*60*18)
- }
- }
- return number, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(number_info_str), &number)
- return number, nil
- }
- }
-
- func GetAllPrescriptionByListOne(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionTwenty, err error) {
-
- redis := RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":prescriptions_list_all"
-
- prescriptions_list_all, _ := redis.Get(key).Result()
-
- if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err = readDb.Model(&models.DialysisPrescriptionTwenty{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- } else {
- if len(prescriptions) > 0 {
- //缓存数据
- prescriptions_list_all, err := json.Marshal(&prescriptions)
- if err == nil {
- redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
- }
- }
- return prescriptions, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
- return prescriptions, nil
- }
- }
-
- func GetAllHisProjectPrescription(orgid int64, recorddate int64) (project []*models.HisPrescriptionProjectTwo, err error) {
- err = XTReadDB().Where("user_org_id = ? and record_date = ? and status = 1", orgid, recorddate).Find(&project).Error
- return project, err
- }
-
- func GetZoneCountList(orgid int64, schedule_date int64) (list []*models.XtScheduleSeven, err error) {
-
- db := XTReadDB().Model(&list).Where("status = 1")
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if schedule_date > 0 {
- db = db.Where("schedule_date =?", schedule_date)
- }
- err = db.Select("partition_id,count(id) as count").Group("partition_id").Scan(&list).Error
- return list, err
- }
-
- func GetPatientDialysisLongSolution(patient_id int64, page int64, limit int64, orgid int64) (solution []*models.DialysisSolution, total int64, err error) {
-
- db := XTReadDB().Model(&solution).Where("status = 1 and solution_status = 1")
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- offset := (page - 1) * limit
-
- err = db.Group("mode_id").Count(&total).Offset(offset).Limit(limit).Order("created_time desc").Find(&solution).Error
- return solution, total, err
- }
-
- func GetDialysisSolutionDetailList(orgid int64, patient_id int64, mode_id int64, page int64, limit int64) (solution []*models.DialysisSolution, total int64, err error) {
- offset := (page - 1) * limit
- db := XTReadDB().Model(&solution).Where("status = 1")
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if mode_id > 0 {
- db = db.Where("mode_id = ?", mode_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&solution).Order("created_time desc").Error
- return solution, total, err
- }
-
- func UpdateDialysisBefor(dislysis models.XtAssessmentBeforeDislysis, id int64) error {
-
- err := XTWriteDB().Model(&models.XtAssessmentBeforeDislysis{}).Where("id = ? and status= 1", id).Update(map[string]interface{}{"systolic_blood_pressure": dislysis.SystolicBloodPressure, "diastolic_blood_pressure": dislysis.DiastolicBloodPressure}).Error
- return err
- }
-
- func GetAllSchedulesByPatientInfo(org_id int64, patient_id int64, mode_id int64) ([]Schedule, error) {
- var record []Schedule
- loc, _ := time.LoadLocation("Local")
- date, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02")+" 00:00:00", loc)
-
- err := readDb.Model(&Schedule{}).Where("status = 1 AND schedule_date >= ? AND patient_id = ? AND user_org_id = ? AND mode_id= ?", date, patient_id, org_id, mode_id).Find(&record).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- }
- return record, nil
- }
-
- func UpdateScheduleByExport(org_id int64, shcheduledate int64) error {
- err := XTWriteDB().Model(models.XtSchedule{}).Where("user_org_id = ? and schedule_date > ?", org_id, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
|