12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267 |
- package service
-
- import (
- "encoding/json"
- "fmt"
- "strconv"
- "strings"
- "time"
-
- "XT_New/models"
- "github.com/jinzhu/gorm"
- )
-
- func GetIllnessListTwo() (ills []*models.Illness, err error) {
- err = readUserDb.Where("status=1").Find(&ills).Error
- return
- }
-
- func GetBloodDialysisPatient(orgid int64, page int64, limit int64) (patients []*models.Patients, total int64, err error) {
- db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
- Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
- fmt.Println("err是什么", err)
- return
- }
-
- func GetAllBloodDialysisPatient(orgid int64, page int64, limit int64, lapseto int64, source int64) (patients []*models.XtPatientsNew, total int64, err error) {
- db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ? and x.blood_patients = 1", orgid)
- }
- if lapseto > 0 {
- db = db.Where("x.lapseto = ?", lapseto)
- }
- if source > 0 {
- db = db.Where("x.source = ?", source)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
- Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
- fmt.Println("err是什么", err)
- return
- }
-
- func GetAllSlowPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
- db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ? and x.slow_patients = 1", orgid)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
- Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
- fmt.Println("err是什么", err)
- return
- }
-
- func GetAllMemberPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
- db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ? and x.member_patients = 1", orgid)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
- Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
- fmt.Println("err是什么", err)
- return
- }
-
- func GetAllPatient(orgid int64) (patients []*models.PatientsNew, err error) {
- db := XTReadDB().Table("xt_patients_new as x")
-
- err = db.Raw("select id,name from xt_patients_new where user_org_id = ? and status =1", orgid).Scan(&patients).Error
- return
- }
-
- func ChechLastDialysisNoTwo(orgID int64) (dialysisNo int64) {
- var patient models.Patients
- err := readDb.Model(&models.Patients{}).Where("user_org_id=? and status = 1", 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 GetBloodPatientInfo(orgid int64, phone string) (*models.Patients, error) {
- patients := models.Patients{}
- var err error
- err = XTReadDB().Model(&patients).Where("user_org_id = ? and phone = ? and status = 1", orgid, phone).Find(&patients).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &patients, nil
- }
-
- func GetSlowPatientInfo(orgid int64, phone string) (*models.CdmPatients, error) {
- patients := models.CdmPatients{}
- var err error
- err = PatientReadDB().Model(&patients).Where("user_org_id = ? and phone = ? and status = 1", orgid, phone).Find(&patients).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &patients, nil
- }
-
- func GetMemberPatientInfo(orgid int64, phone string) (*models.SgjUserCustomer, error) {
- customer := models.SgjUserCustomer{}
- err := UserReadDB().Model(&customer).Where("user_org_id = ? and mobile = ? and status =1", orgid, phone).Find(&customer).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &customer, nil
- }
-
- func CreateOldPatient(patients *models.Patients) error {
-
- err := XTWriteDB().Create(&patients).Error
- return err
- }
-
- func GetLastOldPatient(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 AddContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64) (err error) {
- utx := writeDb.Begin()
- 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, patienid)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, createdtime)
- insertData = append(insertData, updatedtime)
- }
- thisSQL += strings.Join(insertParams, ",")
- err = utx.Exec(thisSQL, insertData...).Error
- fmt.Println("这个错误err", err)
- }
- utx.Commit()
- return
- }
-
- func AddSlowContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64, orgid int64) (err error) {
- utx := PatientWriteDB().Begin()
- if len(contagions) > 0 {
- thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time,user_org_id) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, contagion := range contagions {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?,?)")
- insertData = append(insertData, patienid)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, createdtime)
- insertData = append(insertData, updatedtime)
- insertData = append(insertData, orgid)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- return
- }
-
- func AddSlowDiseases(patienid int64, createdtime int64, updatedtime int64, diseases []int64, orgid int64) (err error) {
- utx := PatientWriteDB().Begin()
- if len(diseases) > 0 {
- thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time,user_org_id) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, disease := range diseases {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?,?)")
- insertData = append(insertData, patienid)
- insertData = append(insertData, disease)
- insertData = append(insertData, 1)
- insertData = append(insertData, createdtime)
- insertData = append(insertData, updatedtime)
- insertData = append(insertData, orgid)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- return
- }
-
- func CreateNewPatient(patientsNew *models.XtPatientsNew) error {
- err := XTWriteDB().Create(&patientsNew).Error
- return err
- }
-
- func CreateCdmPatient(cdmpatient *models.CdmPatients) error {
- err := PatientWriteDB().Create(&cdmpatient).Error
- return err
- }
-
- func CreateMemberPatient(customer *models.SgjUserCustomer) error {
-
- err := UserWriteDB().Create(&customer).Error
- return err
- }
-
- func GetOldCdmPatient(orgid int64) (models.CdmPatients, error) {
- patients := models.CdmPatients{}
- err := PatientReadDB().Model(&patients).Where("user_org_id = ? and status =1", orgid).Last(&patients).Error
- return patients, err
- }
-
- func GetPatientDetailTwo(id int64) (models.XtPatientsNew, error) {
- patients := models.XtPatientsNew{}
- err := XTReadDB().Where("id=? and status = 1", id).Find(&patients).Error
- return patients, err
- }
-
- func GetPatientNewId(id int64) (models.XtPatientsNew, error) {
- patientsNew := models.XtPatientsNew{}
- err := XTReadDB().Where("blood_id = ? and status = 1", id).Find(&patientsNew).Error
- return patientsNew, err
- }
-
- func GetPatientDiseasesTwo(id int64) []int64 {
- var dis []models.XtPatientsInfectiousDiseases
- ids := make([]int64, 0)
- err := XTReadDB().Model(&models.XtPatientsInfectiousDiseases{}).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 GetSlowPatientDiseases(id int64) (infeciousdisease []*models.CdmPatientsInfectiousDiseases, err error) {
- //var dis []models.CdmPatientsInfectiousDiseases
- //diseases := models.CdmPatientsChronicDiseases{}
- //ids := make([]int64, 0)
- //err := PatientReadDB().Model(&diseases).Where("patient_id = ? and status =1", id).Find(&ids).Error
- //if err != nil || len(dis) == 0 {
- // return ids
- //}
- //for _, item := range dis {
- // ids = append(ids, item.DiseaseId)
- //}
- //return ids
- err = PatientReadDB().Model(&infeciousdisease).Where("patient_id = ? and status =1", id).Find(&infeciousdisease).Error
- return infeciousdisease, err
- }
-
- func GetCronicDiseases(id int64) (chronic []*models.CdmPatientsChronicDiseases, err error) {
- //var dis []models.CdmPatientsChronicDiseases
- //ids := make([]int64, 0)
- //err := PatientReadDB().Model(&models.CdmPatientsChronicDiseases{}).Where("patient_id = ? and status =1", id).Find(&ids).Error
- //if err != nil || len(dis) == 0 {
- // return ids
- //}
- //for _, item := range dis {
- // ids = append(ids, item.DiseaseId)
- //}
- //return ids
- err = PatientReadDB().Model(&chronic).Where("patient_id = ? and status =1", id).Find(&chronic).Error
- return chronic, err
- }
-
- func CreatePatientTwo(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 FindPatientByMobileFive(mobile string, orgID int64) (patient models.XtPatientsNew, err error) {
- err = readDb.Model(&models.Patients{}).Where("phone=? and user_org_id=? and status=1", mobile, orgID).First(&patient).Error
- return
- }
-
- func FindPatientByDialysisNoFive(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 FindPatientByIdCardNoFive(orgID int64, idCardNo string) (patient models.XtPatientsNew, 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 FindPatientByIdCardNoOne(orgID int64, idCardNo string, id int64) (patient models.XtPatientsNew, err error) {
- err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=? and id<>?", orgID, idCardNo, id).First(&patient).Error
- return
- }
-
- func FindPatientByDialysisNoOne(orgID int64, dialysisNo string, id int64) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=? and id<>?", orgID, dialysisNo, id).First(&patient).Error
- return
- }
-
- func FindPatientByMobileOne(mobile string, orgID int64, id int64) (patient models.XtPatientsNew, err error) {
- err = readDb.Model(&models.XtPatientsNew{}).Where(" status=1 and user_org_id=? and phone=? and id<>?", orgID, mobile, id).First(&patient).Error
- return
- //db := readDb.Table("xt_patients_new as x")
- //err = db.Not("phone = ?", mobile).Where("user_org_id = ? and id = ? and status =1", orgID, id).Find(&patient).Error
- //return
- }
-
- func GetPatientData(phone string, orgid int64) (*models.XtPatientsNew, error) {
- var patientnew models.XtPatientsNew
- var err error
- err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status =? and blood_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &patientnew, nil
- }
-
- func GetSlowPatientData(phone string, orgid int64) (*models.CdmPatients, error) {
- var patientnew models.CdmPatients
- err = PatientReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ?", orgid, phone, 1).Find(&patientnew).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &patientnew, nil
- }
-
- func GetMemberNewPatient(phone string, orgid int64) (*models.XtPatientsNew, error) {
- var patientnew models.XtPatientsNew
- err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ? and member_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &patientnew, nil
- }
-
- func GetLastMemberPatient(orgid int64) (models.SgjUserCustomer, error) {
- customer := models.SgjUserCustomer{}
- err := UserReadDB().Model(&customer).Where("user_org_id = ? and status = 1", orgid).Last(&customer).Error
- return customer, err
- }
-
- func GetLastNewSlowPatient(phone string, orgid int64) (*models.XtPatientsNew, error) {
- var patientnew models.XtPatientsNew
- err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ? and slow_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &patientnew, nil
- }
-
- func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*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")
- tabletwo := readDb.Table("xt_dialysis_prescription as s").Where("s.status = 1")
- fmt.Print("table", table, tabletwo)
- 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 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
- if start > 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end > 0 {
- db = db.Where("x.start_time<=?", end)
- }
- //offset := (page - 1) * limit
- 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,s.dialyzer_perfusion_apparatus,s.anticoagulant,s.anticoagulant_shouji,s.anticoagulant_weichi,s.anticoagulant_zongliang,s.dialysis_dialyszers,s.dialysis_irrigation, 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").Joins("left join xt_dialysis_prescription as s on s.patient_id = x.patient_id and s.record_date = x.advice_date and s.user_org_id = ?", orgID).Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&doctoradvice).Error
- fmt.Print("err", err)
- return
-
- }
-
- func GetNewDoctorAdviceOne(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, 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", table)
- tabletwo := readDb.Table("xt_dialysis_prescription as s").Where("s.status = 1")
- fmt.Print("table", table, tabletwo)
- 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 {
- db = db.Where("x.advice_type = 2 or x.advice_type = 3")
- }
- if advice_type == 4 {
- db = db.Where("x.advice_type = ?", advice_type)
- }
-
- if start > 0 {
- db = db.Where("x.start_time>=?", start)
- }
- if end > 0 {
- db = db.Where("x.start_time<=?", end)
- }
- 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,s.dialyzer_perfusion_apparatus,s.anticoagulant,s.anticoagulant_shouji,s.anticoagulant_weichi,s.anticoagulant_zongliang,s.dialysis_dialyszers,s.dialysis_irrigation, 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").Joins("left join xt_dialysis_prescription as s on s.patient_id = x.patient_id and s.record_date = x.advice_date and s.user_org_id = ?", orgID).Scan(&doctoradvice).Error
- fmt.Print("错误是什么", err)
- return
- }
-
- func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
- db := XTReadDB().Table("xt_patient_dryweight as x").Where("x.status = 1")
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
- if startime > 0 {
- db = db.Where("x.ctime >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime <=?", endtime)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
- Select("x.id,x.dry_weight,x.creator,x.remakes,x.patient_id,x.ctime,x.adjusted_value,x.user_id,x.user_org_id,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creator").Scan(&dryWeight).Error
- return dryWeight, total, err
- }
-
- func ToSearch(orgId int64, name string) (patient []*models.XtPatientsNew, err error) {
- likeKey := "%" + name + "%"
- err = XTReadDB().Where("name like ? and user_org_id = ?", likeKey, orgId).Find(&patient).Error
- return patient, err
- }
-
- func GetCourseManagement(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (patientCourse []*models.PatientCourseOfDiseases, total int64, err error) {
- db := XTReadDB().Table("xt_patient_course_of_disease as x").Where("x.status = 1")
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.record_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.record_time <= ?", endtime)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
- Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.title,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Scan(&patientCourse).Error
- return patientCourse, total, err
- }
-
- func DeleteCouseManagement(patientid int64) error {
-
- err := XTWriteDB().Model(models.PatientCourseOfDisease{}).Where("id = ?", patientid).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetCouseManagentDetail(id int64) (models.PatientCourseOfDiseasess, error) {
- disease := models.PatientCourseOfDiseasess{}
- db := XTReadDB().Table("xt_patient_course_of_disease as x")
- err := db.Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.title,s.name,r.user_name").Joins("left join xt_patients as s on s.id = x.patient_id ").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Where("x.id = ?", id).Scan(&disease).Error
- return disease, err
- }
-
- func DeleteDryWeight(id int64) error {
- err := XTWriteDB().Model(models.SgjPatientDryweight{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetDryWeightDetail(id int64) (models.SgjPatientDryweights, error) {
- dryweight := models.SgjPatientDryweights{}
- db := XTReadDB().Table("xt_patient_dryweight as x")
- err := db.Select("x.id,x.dry_weight,x.creator,x.remakes,x.patient_id,x.adjusted_value,x.user_org_id,x.user_id,x.ctime,s.name,r.user_name").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.user_id").Where("x.id = ?", id).Scan(&dryweight).Error
- return dryweight, err
- }
-
- func GetlongDialysisrecord(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (prescription []*models.XtDialysisSolution, total int64, err error) {
- db := XTReadDB().Table("xt_dialysis_solution as x").Where("x.status = 1 and x.solution_status=1")
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.created_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.created_time <= ?", endtime)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).Group("x.id").
- Select("x.id,x.name,x.sub_name,x.user_org_id,x.patient_id,x.parent_id,x.type,x.period,x.times,x.anticoagulant,x.anticoagulant_shouji,x.anticoagulant_weichi,x.anticoagulant_zongliang,x.anticoagulant_gaimingcheng,x.anticoagulant_gaijiliang,x.mode_name,x.mode_id,x.dialysis_duration,x.replacement_way,x.hemodialysis_machine,x.blood_filter,x.perfusion_apparatus,x.blood_flow_volume,x.dewater,x.displace_liqui,x.glucose,x.dry_weight,x.dialysate_flow,x.kalium,x.sodium,x.calcium,x.bicarbonate,x.doctor,x.first_dialysis,x.remark,x.initiate_mode,x.affirm_state,x.use_state,x.status,x.registrars_id,x.created_time,x.updated_time,x.solution_type,x.dialysate_temperature,x.conductivity,x.dialysis_duration_hour,x.dialysis_duration_minute,x.target_ultrafiltration,x.dialysate_formulation,x.dialyzer,x.replacement_total,x.dialyzer_perfusion_apparatus,x.body_fluid,x.special_medicine,x.special_medicine_other,x.displace_liqui_part,x.displace_liqui_value,x.blood_access,x.ultrafiltration,x.body_fluid_other,x.target_ktv,x.dialysis_dialyszers,x.dialysis_irrigation").Find(&prescription).Error
-
- return
- }
-
- func GetRescuerecord(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (rescuerecord []*models.XtPatientRescueRecords, total int64, err error) {
- db := XTReadDB().Table("xt_patient_rescue_record as x").Where("x.status = 1")
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.record_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.record_time <= ?", endtime)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.record_time desc").Offset(offset).Limit(limit).Group("x.id").
- Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.status,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Scan(&rescuerecord).Error
- return
- }
-
- func GetScheduling(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64, modeType int64) (schedules []*models.XtSchedules, total int64, err error) {
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <= ?", endtime)
- }
- if modeType > 0 {
- db = db.Where("x.mode_id = ?", modeType)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.schedule_date desc").Offset(offset).Limit(limit).Group("x.id").
- Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.status,x.created_time,x.updated_time,s.number,z.name").Joins("left join xt_device_number as s on s.id = x.bed_id").Joins("left join xt_device_zone as z on z.id = x.partition_id").Scan(&schedules).Error
- return
- }
-
- func GetEducation(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (treatment []*models.XtTreatmentSummary, total int64, err error) {
-
- db := XTReadDB().Table("xt_treatment_summary as x").Where("x.status = 1")
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.assessment_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.assessment_date <= ?", endtime)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.assessment_date desc").Offset(offset).Limit(limit).Group("x.id").
- Select("x.id,x.user_org_id,x.patient_id,x.assessment_date,x.dialysis_order_id,x.mission,x.dialysis_summary,x.change,x.sj_nurse,x.zl_nurse,x.hd_nurse,x.xj_nurse,x.zl_doctor,x.channel_image,x.puncture,x.puncture_needle,x.puncture_direction,x.status,x.created_time,x.updated_time,x.creater,x.modifier").Scan(&treatment).Error
- return
- }
-
- func GetSchedulingDetail(id int64) (models.XtScheduless, error) {
- schedules := models.XtScheduless{}
- db := XTReadDB().Table("xt_schedule as x")
- err := db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,n.number,z.name").Joins("left join xt_device_number as n on n.id = x.bed_id").Joins("left join xt_device_zone as z on z.id = x.partition_id").Where("x.id =?", id).Scan(&schedules).Error
- return schedules, err
- }
-
- func GetSchedulingTwo(id int64) (models.XtScheduless, error) {
- schedules := models.XtScheduless{}
- db := XTReadDB().Table("xt_schedule as x")
- err := db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,z.name").Joins("left join xt_patients as z on z.id = x.patient_id").Where("x.id =?", id).Scan(&schedules).Error
- return schedules, err
- }
-
- func DeleteScheduling(id int64) error {
- err := XTWriteDB().Model(models.XtSchedules{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetEducationDetailOne(id int64) (models.XtTreatmentSummarys, error) {
- summarys := models.XtTreatmentSummarys{}
- db := XTReadDB().Table("xt_treatment_summary as x")
- err := db.Select("x.id,x.user_org_id,x.patient_id,x.assessment_date,x.dialysis_order_id,x.mission,x.dialysis_summary,x.change,x.sj_nurse,x.zl_nurse,x.hd_nurse,x.xj_nurse,x.zl_doctor,x.channel_image,x.puncture,x.puncture_needle,x.puncture_direction,x.status,x.created_time,x.creater,x.modifier,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.id = ?", id).Scan(&summarys).Error
- return summarys, err
- }
-
- func DeleteEducation(id int64) error {
- err := XTWriteDB().Model(models.XtTreatmentSummary{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetRescueRecordDetail(id int64) (models.XtPatientRescueRecords, error) {
- records := models.XtPatientRescueRecords{}
- db := XTReadDB().Table("xt_patient_rescue_record as x")
- err := db.Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.status,r.user_name,s.name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.id=?", id).Scan(&records).Error
- return records, err
- }
-
- func DeleteRescueRecord(id int64) error {
- err := XTWriteDB().Model(models.XtPatientRescueRecord{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func ToSearchePatient(keyword string, orgId int64) (paitents []*models.XtPatientsNew, err error) {
- likeKey := "%" + keyword + "%"
- err = XTReadDB().Where("user_org_id = ? and name like ? or dialysis_no like ?", orgId, likeKey, likeKey).Find(&paitents).Error
- return paitents, err
- }
-
- func SearchallPatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
- db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ? OR x.first_letter=?", likeKey, likeKey, likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.infectious_next_record_time,x.is_infectious,x.remind_cycle,x.response_result,x.is_open_remind,x.first_treatment_date,x.dialysis_age,x.expense_kind,x.tell_phone,x.contact_name,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id,x.member_fistdate,x.member_patienttype,x.member_treatement,x.equitment_id").Find(&patients).Error
- return patients, err
- }
-
- func GetSearchallBlood(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
-
- db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.blood_patients = 1")
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.infectious_next_record_time,x.is_infectious,x.remind_cycle,x.response_result,x.is_open_remind,x.first_treatment_date,x.dialysis_age,x.expense_kind,x.tell_phone,x.contact_name,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id,x.member_fistdate,x.member_patienttype,x.member_treatement,x.equitment_id").Find(&patients).Error
- return patients, err
- }
-
- func GetSlowSearchePatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
-
- db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.slow_patients = 1")
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.infectious_next_record_time,x.is_infectious,x.remind_cycle,x.response_result,x.is_open_remind,x.first_treatment_date,x.dialysis_age,x.expense_kind,x.tell_phone,x.contact_name,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id,x.member_fistdate,x.member_patienttype,x.member_treatement,x.equitment_id").Find(&patients).Error
- return patients, err
- }
-
- func GetMemberSearchPatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
- db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.member_patients = 1")
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.infectious_next_record_time,x.is_infectious,x.remind_cycle,x.response_result,x.is_open_remind,x.first_treatment_date,x.dialysis_age,x.expense_kind,x.tell_phone,x.contact_name,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id,x.member_fistdate,x.member_patienttype,x.member_treatement,x.equitment_id").Find(&patients).Error
- return patients, err
- }
-
- func GetLongDialysisDetail(id int64) (models.XtDialysisSolution, error) {
- solution := models.XtDialysisSolution{}
- err := XTReadDB().Model(&solution).Where("id=? and status =1", id).Find(&solution).Error
- return solution, err
- }
-
- func GetPatientName(id int64) (models.Patients, error) {
- patientsNew := models.Patients{}
- err := XTReadDB().Model(&patientsNew).Where("id = ? and status = 1", id).Find(&patientsNew).Error
- return patientsNew, err
- }
-
- func DeleteLongDialysis(id int64) error {
- err := XTWriteDB().Model(models.XtDialysisSolution{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetDialysisrecord(patientID int64, start int64, end int64, limit int64, page int64, orgID int64, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
- offset := (page - 1) * limit
- var total int64
- var err error
- var orders []*models.PatientDialysisRecord
-
- db := readDb.Table("xt_dialysis_order as do").
- Preload("MonitoringRecord", "patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).
- Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
- return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
- return readUserDb.Where("status = 1")
- })
- }).
- 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=? and status = 1", 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 and s.status = 1", orgID).
- Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 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.record_id=do.id")
- 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 GetAllDoctorTwo(orgid int64, appid int64) (appRole []*models.SgjUserAdminRole, err error) {
-
- err = UserReadDB().Where("org_id = ? and app_id = ?", orgid, appid).Find(&appRole).Error
- return appRole, err
- }
-
- func GetDoctorAdviceDetail(state int64, id int64, orgid int64) (advices []*models.DoctorAdvices, err error) {
-
- db := XTReadDB().Table("xt_doctor_advice as x")
- err = db.Order("x.id desc").Select("x.id,x.user_org_id,x.patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,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.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,s.name").Joins("left join xt_patients as s on s.id=x.patient_id").Where("x.start_time = ? and x.patient_id = ? and x.user_org_id = ? and x.status = 1", state, id, orgid).Scan(&advices).Error
-
- return advices, err
- }
-
- func DeleteManagement(groupid int64, orgid int64, patientid int64) error {
-
- err := XTWriteDB().Model(models.DoctorAdvice{}).Where("start_time =? and user_org_id = ? and patient_id =?", groupid, orgid, patientid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func DeleteChild(id int64) error {
-
- err := XTWriteDB().Model(models.DoctorAdvice{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func DeletePatient(id int64) error {
-
- err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id=? or parent_id = ?", id, id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetNewPatient(id int64) (models.XtPatientsNew, error) {
- patientsNew := models.XtPatientsNew{}
- err := XTReadDB().Model(&patientsNew).Where("id=?", id).Find(&patientsNew).Error
- return patientsNew, err
- }
-
- func UpdatedPatient(patients models.Patients, id int64) error {
-
- err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "admission_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "out_reason": patients.OutReason, "death_time": patients.DeathTime, "relative_phone": patients.RelativePhone, "sch_remark": patients.SchRemark, "treatment_plan": patients.TreatmentPlan, "patient_type": patients.PatientType}).Error
-
- return err
- }
-
- func UpdateXtPatientNew(patients models.XtPatientsNew, id int64) error {
-
- err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "admission_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "out_reason": patients.OutReason, "death_time": patients.DeathTime, "relative_phone": patients.RelativePhone, "sch_remark": patients.SchRemark, "treatment_plan": patients.TreatmentPlan, "patient_type": patients.PatientType}).Error
-
- return err
- }
-
- func UpdateXtPatientNewOne(patients models.XtPatientsNew, id int64) error {
-
- err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "adminssion_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "member_patienttype": patients.MemberPatienttype, "member_treatement": patients.MemberTreatement, "treatment_plan": patients.TreatmentPlan}).Error
- return err
- }
-
- func UpdateContagions(patientid int64) (models.XtPatientsInfectiousDiseases, error) {
- diseases := models.XtPatientsInfectiousDiseases{}
- err := XTWriteDB().Model(&diseases).Where("patient_id = ?", patientid).Update(map[string]interface{}{"status": 2, "updated_time": time.Now().Unix()}).Error
- return diseases, err
- }
-
- func UpdateCustomer(cdmpatient models.CdmPatients, id int64) error {
-
- err := PatientWriteDB().Model(&cdmpatient).Where("id=?", id).Update(map[string]interface{}{"name": cdmpatient.Name, "phone": cdmpatient.Phone, "gender": cdmpatient.Gender, "birthday": cdmpatient.Birthday, "diagnose": cdmpatient.Diagnose, "source": cdmpatient.Source, "avatar": cdmpatient.Avatar, "id_card_no": cdmpatient.IdCardNo, "updated_time": cdmpatient.UpdatedTime}).Error
- return err
- }
-
- func UpdatedCustomer(customer models.SgjUserCustomer, id int64) error {
- err := UserWriteDB().Model(&customer).Where("id = ?", id).Update(map[string]interface{}{"name": customer.Name, "mobile": customer.Mobile, "gender": customer.Gender, "birthday": customer.Birthday, "ill_date": customer.IllDate, "avatar": customer.Avatar, "illness_id": customer.IllnessId, "treat_type": customer.TreatType}).Error
- return err
- }
-
- func GetInspectionByOrgId(orgid int64) (*models.XtInspectionReference, error) {
- diseases := models.XtInspectionReference{}
- err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &diseases, nil
- }
-
- func GetAllProjectName(date int64, orgid int64, patientid int64) (inspection []*models.XtInspection, err error) {
- err = XTReadDB().Model(&inspection).Where("inspect_date = ? and org_id = ? and patient_id = ? and status = 1", date, orgid, patientid).Order("inspect_date desc").Group("project_name").Find(&inspection).Error
- return inspection, err
- }
-
- func GetAllInspection(orgid int64) (inspection []*models.XtInspectionReference, err error) {
- err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&inspection).Error
- return inspection, err
- }
-
- func GetInspection(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64, projectid int64) (inspection []*models.Inspection, total int64, err error) {
-
- db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
- if startime > 0 {
- db = db.Where("x.inspect_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.inspect_date<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if projectid > 0 {
- db = db.Where("x.project_id = ?", projectid)
- }
- err = db.Count(&total).Order("x.inspect_date desc").Group("x.id").
- Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.created_time").Find(&inspection).Error
- return inspection, total, err
- }
-
- func GetInspectionDetail(patientid int64, date int64, orgid int64, projectid int64) (inspection []*models.Inspections, err error) {
-
- db := XTReadDB().Table("xt_inspection as x").Where("x.status =1")
- table := XTReadDB().Table("xt_inspection_reference as r")
- fmt.Print("table", table)
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
-
- if date > 0 {
- db = db.Where("x.inspect_date = ?", date)
- }
- if orgid > 0 {
-
- db = db.Where("x.org_id = ?", orgid)
-
- }
- if projectid > 0 {
- db = db.Where("x.project_id = ?", projectid)
- }
- err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id = x.org_id) OR ( x.item_id = r.id AND r.org_id = 0) ").Scan(&inspection).Error
- return inspection, err
- }
-
- func CreateFeedBack(feedback *models.XtPatientFeedback) error {
-
- err := XTWriteDB().Model(&feedback).Create(&feedback).Error
- return err
- }
-
- func DeleteInspection(date int64, orgid int64) error {
-
- err := XTWriteDB().Model(models.Inspection{}).Where("inspect_date = ? and org_id = ?", date, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func DeleteChildInspection(name string, date int64, orgid int64) error {
-
- err := XTWriteDB().Model(models.Inspection{}).Where("project_name = ? and inspect_date = ? and org_id = ?", name, date, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func SaveMessage(id int64, orgid int64, role *models.SgjUserAdminRole) error {
-
- err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgid).Update(map[string]interface{}{"message": role.Message, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func SaveSex(id int64, role *models.SgjUserAdminRole) error {
- err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("admin_user_id = ?", id).Update(map[string]interface{}{"sex": role.Sex, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func SaveBirthday(id int64, role *models.SgjUserAdminRole) error {
- err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("admin_user_id = ?", id).Update(map[string]interface{}{"birthday": role.Birthday, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetPartitionByName(name string, orgid int64) (*models.DeviceZone, error) {
- zone := models.DeviceZone{}
- err := XTReadDB().Model(&zone).Where("name = ? and org_id = ? and status = 1", name, orgid).Find(&zone).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &zone, nil
- }
-
- func GetPartitionByNameOne(name string, orgid int64) (zone models.DeviceZone, err error) {
-
- err = XTReadDB().Model(&zone).Where("name = ? and org_id = ? and status = 1", name, orgid).First(&zone).Error
- return zone, err
- }
-
- func CreatedZone(zone *models.DeviceZone) error {
-
- err := XTWriteDB().Model(&zone).Create(&zone).Error
- return err
- }
-
- func GetAllZone(orgid int64, page int64, limit int64) (zone []*models.DeviceZones, total int64, err error) {
-
- db := XTReadDB().Table("xt_device_zone as x").Where("x.status =1")
- table := XTReadDB().Table("xt_device_number as n")
- fmt.Println("table", table)
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- offset := (page - 1) * limit
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.type,n.number").Joins("left join xt_device_number as n on n.zone_id = x.id AND n.status = 1").Scan(&zone).Error
- return zone, total, err
- }
-
- func DeleteZoneById(id int64) error {
-
- err := XTWriteDB().Model(models.DeviceZone{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetGroupByName(name string, orgid int64) (*models.DeviceGroup, error) {
- group := models.DeviceGroup{}
- err := XTReadDB().Model(&group).Where("name = ? and org_id = ? and status = 1", name, orgid).Find(&group).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &group, nil
- }
-
- func GetGroupByNameOne(name string, orgid int64) (group models.DeviceGroup, err error) {
- err = XTReadDB().Model(&group).Where("name = ? and org_id = ? and status =1", name, orgid).First(&group).Error
- return group, err
- }
-
- func SaveGroup(group *models.DeviceGroup) error {
- err := XTWriteDB().Model(&group).Create(&group).Error
- return err
- }
-
- func GetAllGroup(orgid int64, page int64, limit int64) (group []*models.DeviceGroups, total int64, err error) {
- db := XTReadDB().Table("xt_device_group as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_device_number as n")
- fmt.Println("table", table)
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- offset := (page - 1) * limit
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.status,x.ctime,x.mtime,n.number").Joins("left join xt_device_number as n on n.group_id = x.id And n.status = 1").Scan(&group).Error
- return group, total, err
- }
-
- func DeleteGroup(id int64) error {
- err := XTWriteDB().Model(models.DeviceGroup{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetAllZoneOne(orgid int64) (zone []*models.DeviceZone, err error) {
-
- err = XTReadDB().Model(&zone).Where("org_id = ? and status =1", orgid).Find(&zone).Error
- return zone, err
- }
-
- func GetAllBedNumberList(orgid int64) (number []*models.DeviceNumber, err error) {
-
- err = XTReadDB().Where("org_id =? and status =1", orgid).Find(&number).Error
- return number, err
- }
-
- func GetAllGroupOne(orgid int64) (group []*models.DeviceGroup, err error) {
-
- err = XTReadDB().Model(&group).Where("org_id =?", orgid).Find(&group).Error
- return group, err
- }
-
- func GetBedByName(name string, orgid int64) (*models.DeviceNumber, error) {
- number := models.DeviceNumber{}
- err := XTReadDB().Model(&number).Where("number=? and org_id = ? and status =1", name, orgid).Find(&number).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &number, nil
- }
-
- func GetBedByNameOne(name string, orgid int64) (number models.DeviceNumber, err error) {
-
- err = XTReadDB().Model(&number).Where("number=? and org_id = ? and status = 1", name, orgid).First(&number).Error
- return number, err
- }
-
- func CreateNumber(number *models.DeviceNumber) error {
-
- err := XTWriteDB().Model(&number).Create(&number).Error
- return err
- }
-
- func GetAllNumber(page int64, limit int64, orgid int64) (number []*models.DeviceNumber, total int64, err error) {
-
- db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime asc").Select("x.id,x.org_id,x.number,x.group_id,x.zone_id,x.status").Find(&number).Error
-
- return number, total, err
- }
-
- func GetSchedu(bedid int64, thetime int64, orgid int64) (*models.XtSchedule, error) {
- schedule := models.XtSchedule{}
- err := XTReadDB().Model(&schedule).Where("bed_id = ? and schedule_date = ? and user_org_id = ? and status = 1", bedid, thetime, orgid).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
-
- }
-
- func DeleteBed(id int64) error {
- err := XTWriteDB().Model(models.DeviceNumber{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "ctime": time.Now().Unix()}).Error
- return err
- }
-
- func GetMemberPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
-
- err = XTReadDB().Model(&patients).Where("user_org_id = ? AND member_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
- return patients, err
- }
-
- func GetSlowPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
-
- err = XTReadDB().Model(&patients).Where("user_org_id = ? AND slow_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
- return patients, err
-
- }
-
- func GetBloodPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
- err = XTReadDB().Model(&patients).Where("user_org_id = ? AND blood_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
- return patients, err
- }
-
- func SaveName(id int64, admin *models.SgjUserAdmin) error {
-
- err = UserWriteDB().Model(models.SgjUserAdmin{}).Where("id=?", id).Update(map[string]interface{}{"name": admin.Name, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetAdminUserId(id int64) (models.SgjUserAdminRole, error) {
-
- role := models.SgjUserAdminRole{}
- err := UserReadDB().Where("id=? and status =1", id).Find(&role).Error
- return role, err
- }
-
- func GetMyOrganaziton(id int64) (org []*models.SgjUserOrg, err error) {
-
- db := UserReadDB().Table("sgj_user_org as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin as a")
- fmt.Println("table", table)
- err = db.Select("x.id,x.creator,x.org_name,x.org_short_name,x.org_logo,x.org_introduction,x.illness,x.province,x.city,x.district,x.address,x.longitude,x.latitude,x.org_type,x.comments,x.evaluate,x.gallery,x.business_week,x.business_time,x.contact_name,x.telephone,x.claim,x.operating_state,x.source,x.ttype,x.ttid,x.tuid,x.reason,x.level,x.website,x.import,x.sortno,a.is_super_admin").Joins("left join sgj_user_admin as a on a.id = x.creator").Where("x.creator = ?", id).Scan(&org).Error
- return org, err
- }
-
- func GetOrgInformation(id int64) (models.SgjUserOrg, error) {
-
- org := models.SgjUserOrg{}
-
- err := UserReadDB().Where("id=? and status = 1", id).Find(&org).Error
- return org, err
- }
-
- func GetShortName(orgtype int64) (models.SgjUserOrgType, error) {
-
- orgType := models.SgjUserOrgType{}
- err := UserReadDB().Model(&orgType).Where("id=? and status = 1", orgtype).Find(&orgType).Error
- return orgType, err
- }
-
- func GetTypeName(id int64) (models.SgjUserOrgType, error) {
- orgType := models.SgjUserOrgType{}
- err := UserReadDB().Model(&orgType).Where("id=? and status = 1", id).Find(&orgType).Error
- return orgType, err
- }
-
- func GetOrgProvince(id int64) (models.SgjUserDistrict, error) {
-
- district := models.SgjUserDistrict{}
- err := UserReadDB().Model(&district).Where("id=?", id).Find(&district).Error
- return district, err
- }
-
- func GetAllOrgType() (orgType []*models.SgjUserOrgType, err error) {
-
- err = UserReadDB().Model(&models.SgjUserOrgType{}).Where("status= ? AND id = ? OR id = ? OR id = ? OR id = ? OR id = ? OR id = ?", 1, 1, 7, 12, 16, 21, 26).Find(&orgType).Error
- return
- }
-
- func UpdateOrg(id int64, org models.SgjUserOrg) error {
-
- err := UserWriteDB().Model(&org).Where("id = ?", id).Update(map[string]interface{}{"org_name": org.OrgName, "org_short_name": org.OrgShortName, "province": org.Province, "city": org.City, "district": org.District, "address": org.Address, "org_type": org.OrgType, "telephone": org.Telephone, "contact_name": org.ContactName, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetMyInfoName(id int64) (models.SgjUserAdminRole, error) {
- role := models.SgjUserAdminRole{}
- err := UserReadDB().Model(&role).Where("id=? and status = 1", id).Find(&role).Error
- return role, err
- }
-
- func GetAdminName(id int64, orgid int64) (models.AdminUsers, error) {
- user := models.AdminUsers{}
- //err := UserReadDB().Model(&user).Where("id=? and status =1", id).Find(&user).Error
- //return user, err
- db := UserReadDB().Table("sgj_user_admin as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- err := db.Group("x.id").Select("x.id,x.mobile,x.password,x.is_super_admin,x.source,x.name,r.admin_user_id,r.org_id,r.app_id,r.role_id,r.user_name,r.avatar,r.message,r.sex,r.birthday").Where("x.id = ?", id).Joins("left join sgj_user_admin_role as r on r.admin_user_id = x.id and r.org_id = ?", orgid).Scan(&user).Error
- return user, err
- }
-
- func GetCreatByOrgId(orgid int64) (models.SgjUserOrg, error) {
- org := models.SgjUserOrg{}
- err := UserReadDB().Model(&org).Where("id=? and status = 1", orgid).Find(&org).Error
- return org, err
- }
-
- func GetMyOrgInformationFour(creator int64, orgid int64) (models.SgjUserAdminRole, error) {
- role := models.SgjUserAdminRole{}
- err := UserReadDB().Model(&role).Where("admin_user_id = ? and org_id = ? and status = 1", creator, orgid).Find(&role).Error
- return role, err
- }
-
- func GetPartionDetail(id int64) (models.DeviceZone, error) {
-
- zone := models.DeviceZone{}
- err := XTReadDB().Model(&zone).Where("id=? and status = 1", id).Find(&zone).Error
- return zone, err
- }
-
- func UpdatePartition(id int64, zone *models.DeviceZone) error {
-
- err := XTWriteDB().Model(&zone).Where("id=?", id).Update(map[string]interface{}{"name": zone.Name, "type": zone.Type, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetGroupDetail(id int64) (models.DeviceGroup, error) {
- group := models.DeviceGroup{}
- err := XTReadDB().Model(&group).Where("id=? and status = 1", id).Find(&group).Error
- return group, err
- }
-
- func UpdateGroup(id int64, group *models.DeviceGroup) error {
-
- err := XTWriteDB().Model(&group).Where("id=?", id).Update(map[string]interface{}{"name": group.Name, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetBedDetail(id int64) (models.DeviceNumber, error) {
- number := models.DeviceNumber{}
- err := XTReadDB().Model(&number).Where("id=? and status =1", id).Find(&number).Error
- return number, err
- }
-
- func UpdatedBed(id int64, number *models.DeviceNumber) error {
-
- err = XTWriteDB().Model(&number).Where("id=?", id).Update(map[string]interface{}{"number": number.Number, "zone_id": number.ZoneID, "group_id": number.GroupID, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func CreateLoginLod(log *models.SgjUserAdminLoginLog) error {
-
- err := UserWriteDB().Model(&log).Create(&log).Error
- return err
- }
-
- func GetAppId(orgid int64) (models.OrgApp, error) {
- app := models.OrgApp{}
- err := UserReadDB().Model(&app).Where("org_id = ? and status = 1 and app_type = 3", orgid).Find(&app).Error
- return app, err
- }
-
- func GetRoleName(adminid int64, orgid int64, appid int64) (models.Roles, error) {
-
- role := models.Roles{}
- err := UserReadDB().Model(&role).Where("creator = ? and org_id = ? and app_id = ? and status =1", adminid, orgid, appid).Find(&role).Error
- return role, err
- }
-
- func GetRole(id int64) (models.Role, error) {
- role := models.Role{}
- err := UserReadDB().Model(&role).Where("id = ? and status =1", id).Find(&role).Error
- return role, err
- }
-
- func GetPositionName(adminid int64, orgid int64, appid int64) (models.App_Role, error) {
-
- role := models.App_Role{}
- err := UserReadDB().Model(&role).Where("admin_user_id = ? and org_id = ? and app_id = ?", adminid, orgid, appid).Find(&role).Error
- return role, err
- }
-
- func GetAdmin(id int64) (models.SgjUserAdmin, error) {
- admin := models.SgjUserAdmin{}
- err := UserReadDB().Model(&admin).Where("id=? and status =1", id).Find(&admin).Error
- return admin, err
- }
-
- func GetPosition(id int64) (models.SgjUserAdminRole, error) {
- roles := models.SgjUserAdminRole{}
- err = UserReadDB().Model(&roles).Where("id=? and status = 1", id).Find(&roles).Error
- return roles, err
- }
-
- func GetPositionOne(id int64) (models.SgjUserAdmin, error) {
-
- admin := models.SgjUserAdmin{}
- err = UserReadDB().Model(&admin).Where("id=? and status = 1", id).Find(&admin).Error
- return admin, err
- }
-
- func GetMyOrgInformation(id int64, appid int64) (models.SgjUserAdminRole, error) {
- admin := models.SgjUserAdminRole{}
- err := UserReadDB().Model(&admin).Where("admin_user_id=? and app_id = ? and status = 1", id, appid).First(&admin).Error
- return admin, err
- }
-
- func SaveNameTwo(id int64, orgid int64, role *models.SgjUserAdminRole) error {
-
- err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("admin_user_id =? and org_id = ?", id, orgid).Update(map[string]interface{}{"user_name": role.UserName, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func AddPatientLapseto(lapseto *models.PatientLapseto) error {
-
- err := XTWriteDB().Create(&lapseto).Error
- return err
- }
-
- func GetDialysAfterRecord(patientid int64, startime int64, endtime int64, orgid int64) (dislysis []*models.XtAssessmentAfterDislysis, err error) {
-
- db := XTReadDB().Model(&dislysis)
- if startime > 0 {
- db = db.Where("assessment_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("assessment_date <= ?", endtime)
- }
- if patientid > 0 {
- db = db.Where("patient_id = ?", patientid)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- err = db.Find(dislysis).Error
-
- return dislysis, err
- }
-
- func GetDialysisDateByDate(starTime int64, patientId int64, orgId int64) (*models.XtPatientVascularAccess, error) {
- access := models.XtPatientVascularAccess{}
- err := XTReadDB().Model(&access).Where("start_time = ? and patient_id = ? and user_org_id = ? and status = 1", starTime, patientId, orgId).Find(&access).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &access, nil
- }
-
- func GetDialysisDateByDateOne(starTime int64, patientId int64, orgId int64, id int64) (*models.XtPatientVascularAccess, error) {
- access := models.XtPatientVascularAccess{}
- err := XTReadDB().Model(&access).Where("start_time = ? and patient_id = ? and user_org_id = ? and status = 1 and id <> ?", starTime, patientId, orgId, id).Find(&access).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &access, nil
- }
-
- func SaveVascularAccess(access *models.XtPatientVascularAccess) error {
-
- err := XTWriteDB().Create(&access).Error
- return err
- }
-
- func GetAllVacualAccessList(orgid int64, limit int64, page int64, patientId int64) (vascular []*models.XtPatientVascularAccess, total int64, err error) {
-
- offset := (page - 1) * limit
- err = XTReadDB().Model(&vascular).Where("user_org_id = ? and status = 1 and patient_id = ?", orgid, patientId).Count(&total).Offset(offset).Limit(limit).Order("start_time desc").Find(&vascular).Error
- return vascular, total, err
- }
-
- func GetVasularAccessByDetail(id int64) (models.XtPatientVascularAccess, error) {
- access := models.XtPatientVascularAccess{}
- err := XTReadDB().Where("id = ? and status =1", id).Find(&access).Error
- return access, err
- }
-
- func UpdateVascularAccess(access *models.XtPatientVascularAccess, id int64) error {
-
- err := XTWriteDB().Model(&access).Where("id= ?", id).Updates(map[string]interface{}{"access_project": access.AccessProject, "blood_access_part_id": access.BloodAccessPartId, "inflow_pass": access.InflowPass, "start_time": access.StartTime, "first_start_time": access.FirstStartTime, "blood_access_part_opera_id": access.BloodAccessPartOperaId, "stop_reason": access.StopReason, "remark": access.Remark, "user_status": access.UserStatus, "modify": access.Modify, "stop_time": access.StopTime, "other_vascular": access.OtherVascular, "ci_type": access.CiType, "blood_cultupe": access.BloodCultupe, "sequelae_type": access.SequelaeType}).Error
- return err
- }
-
- func DeleteVasularAccess(id int64) error {
- access := models.XtPatientVascularAccess{}
- err := XTWriteDB().Model(&access).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func CreatePatientWayAssessment(assessment *models.XtPatientPasswayAssessment) error {
-
- err := XTWriteDB().Create(&assessment).Error
- return err
- }
-
- func GetAllPassWayAssessment(parent_id int64, patient_id int64, page int64, limit int64, orgid int64) (assessment []*models.XtPatientPasswayAssessment, total int64, err error) {
- offset := (page - 1) * limit
- err = XTReadDB().Model(&assessment).Where("parent_id = ? and patient_id = ? and user_org_id = ? and status =1", parent_id, patient_id, orgid).Count(&total).Offset(offset).Limit(limit).Order("start_time desc").Find(&assessment).Error
- return assessment, total, err
- }
-
- func GetPasswayAssesmentById(id int64) (models.XtPatientPasswayAssessment, error) {
-
- assessment := models.XtPatientPasswayAssessment{}
- err := XTReadDB().Model(&assessment).Where("id=? and status =1", id).Find(&assessment).Error
- return assessment, err
- }
-
- func UpdatePassWayAssesment(assessment *models.XtPatientPasswayAssessment, id int64) error {
-
- err := XTWriteDB().Model(&assessment).Where("id = ?", id).Updates(map[string]interface{}{"start_time": assessment.StartTime, "creator": assessment.Creator, "blood_project": assessment.BloodProject, "blood_result": assessment.BloodResult, "blood_dealwith": assessment.BloodDealwith, "modify": assessment.Modify, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func DeleteWayAssessment(id int64) error {
- assessment := models.XtPatientPasswayAssessment{}
- err := XTWriteDB().Model(&assessment).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetLastPassWayAssessment(orgid int64, patientId int64) (models.XtPatientVascularAccess, error) {
- assessment := models.XtPatientVascularAccess{}
- redis := RedisClient()
- defer redis.Close()
-
- // cur_date := time.Now().Format("2006-01-02")
- key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientId, 10) + ":pass_way_assessment_last"
- pass_way_assessment_last_str, _ := redis.Get(key).Result()
-
- if len(pass_way_assessment_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- err := XTReadDB().Model(&assessment).Where("user_org_id = ? and patient_id = ? and status =1 and user_status = 1", orgid, patientId).Order("start_time desc").Last(&assessment).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- if assessment.ID <= 0 {
- redis.Set(key, "pass_way_null", time.Second*60*60*18)
- }
- return assessment, nil
- } else {
- return assessment, err
- }
- } else {
- if assessment.ID > 0 {
- //缓存数据
- pass_way_assessment_last_str, err := json.Marshal(assessment)
- if err == nil {
- redis.Set(key, pass_way_assessment_last_str, time.Second*60*60*18)
- return assessment, nil
- }
- } else {
- redis.Set(key, "pass_way_null", time.Second*60*60*18)
- return assessment, nil
- }
- return assessment, nil
- }
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- if pass_way_assessment_last_str == "pass_way_null" {
- return assessment, nil
- } else {
- json.Unmarshal([]byte(pass_way_assessment_last_str), &assessment)
- return assessment, nil
- }
-
- }
- }
-
- func GetAccessList(orgid int64) (*models.Dataconfig, error) {
-
- dataconfig := models.Dataconfig{}
- err := XTReadDB().Model(&dataconfig).Where("org_id = 0 and name = '血管通路' and status = ?", 1).Find(&dataconfig).Error
- return &dataconfig, err
- }
-
- func GetParentAccessList(orgid int64, parentid int64) (dataconfig []*models.Dataconfig, err error) {
-
- err = XTReadDB().Model(&dataconfig).Where("org_id in(0,?) and parent_id = ? and status =1", orgid, parentid).Find(&dataconfig).Error
- return dataconfig, err
-
- }
-
- func GetBloodAccess(orgid int64) (*models.Dataconfig, error) {
- dataconfig := models.Dataconfig{}
- err := XTReadDB().Model(&dataconfig).Where("org_id = 0 and name = '血管通路部位' and status = 1 ").Find(&dataconfig).Error
- return &dataconfig, err
- }
-
- func GetPatientScheduleCount(orgid int64, startTime int64, endTime int64, ids []string) (schedule []*models.VmXtSchedule, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status =1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startTime > 0 {
- db = db.Where("x.schedule_date >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("x.schedule_date<=?", endTime)
- }
- if len(ids) > 0 {
- db = db.Where("x.partition_id in (?)", ids)
- }
- err = db.Select("count(x.id) as count,x.schedule_type,x.schedule_week").Group("x.schedule_week,x.schedule_type").Scan(&schedule).Error
- return schedule, err
- }
-
- func GetTotalBedNumber(orgid int64, ids []string) (list []*models.XtDeviceNumber, total int64, err error) {
-
- //err = XTReadDB().Model(&list).Where("org_id = ? and status = 1 ",orgid).Count(&total).Find(&list).Error
- //return list,total,err
- db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if len(ids) > 0 {
- db = db.Where("x.zone_id in (?)", ids)
- }
- err = db.Count(&total).Find(&list).Error
- return list, total, err
- }
-
- func GetInspectionMajorItem(startime int64, lasttime int64, orgid int64, patientid int64) (inspection []*models.XtInspection, err error) {
-
- db := XTReadDB().Table("xt_inspection")
-
- //err = db.Raw("select * from xt_inspection where id in(select max(id) from xt_inspection where org_id = ? and status = 1 and patient_id = ? and inspect_date>=? and inspect_date<=? group by project_id)", orgid, patientid, lasttime, startime).Scan(&inspection).Error
- err = db.Raw("select * from xt_inspection where org_id = ? and status = 1 and patient_id = ? and inspect_date>=? and inspect_date<=? group by project_id", orgid, patientid, lasttime, startime).Scan(&inspection).Error
- return inspection, err
- }
-
- func GetInspectionDetailByProject(project_id int64, patientid int64, inspect_date int64, orgid int64) (inspection []*models.VmInspection, err error) {
-
- db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_inspection_reference as t").Where("t.status = 1")
- fmt.Println(table)
- if inspect_date > 0 {
- db = db.Where("x.inspect_date=?", inspect_date)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if patientid > 0 {
- db = db.Where("x.patient_id = ?", patientid)
- }
- if project_id > 0 {
- db = db.Where("x.project_id = ?", project_id)
- }
- err = db.Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,t.range_max,t.range_min,t.range_value,t.unit").Joins("left join xt_inspection_reference as t on t.id = x.item_id").Scan(&inspection).Error
- return inspection, err
- }
-
- func GetInspectionItemlist(patientid int64, inspect_date []string, projectid []string) (inspection []*models.VmInspection, err error) {
-
- db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_inspection_reference as s").Where("s.status = 1")
- fmt.Println(table)
- if patientid > 0 {
- db = db.Where("x.patient_id = ? and x.inspect_value <> ''", patientid)
- }
- if len(inspect_date) > 0 {
- db = db.Where("x.inspect_date in(?)", inspect_date)
- }
-
- if len(projectid) > 0 {
- db = db.Where("x.project_id in(?)", projectid)
- }
-
- err = db.Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,t.range_max,t.range_min,t.range_value,t.unit").Joins("left join xt_inspection_reference as t on t.id = x.item_id").Scan(&inspection).Error
- return inspection, err
- }
-
- func GetDialysisBeforInitDateList(patient_id int64, startime int64, endtime int64) (models.PredialysisEvaluation, error) {
- befor := models.PredialysisEvaluation{}
- db := XTReadDB().Model(&befor).Where("status = 1")
- if patient_id > 0 {
- db = db.Where("patient_id = ? and assessment_date>=? and assessment_date<=? ", patient_id, startime, endtime)
- }
-
- err = db.Last(&befor).Error
- return befor, err
- }
-
- func GetDialysisPrescriptionDataList(patient_id int64, startime int64, endtime int64) (models.DialysisPrescription, error) {
-
- prescription := models.DialysisPrescription{}
- db := XTReadDB().Model(&prescription).Where("status = 1")
- if patient_id > 0 {
- db = db.Where("patient_id = ? and record_date>=? and record_date<=?", patient_id, startime, endtime)
- }
- err = db.Last(&prescription).Error
- return prescription, err
- }
-
- func GetDialysisAssementAfter(patient_id int64, startime int64, endtime int64) (models.AssessmentAfterDislysis, error) {
-
- after := models.AssessmentAfterDislysis{}
- db := XTReadDB().Model(&after).Where("status = 1")
- if patient_id > 0 {
- db = db.Where("patient_id = ? and assessment_date>=? and assessment_date<=?", patient_id, startime, endtime)
- }
- err = db.Last(&after).Error
- return after, err
- }
-
- func GetDialysisDialysisMode(patient_id int64, startime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
-
- db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
- table := readDb.Table("xt_schedule as s").Where("s.status = 1")
- fmt.Println(table)
- p := readDb.Table("xt_patients as p").Where("p.status = 1")
- fmt.Println(p)
- if startime > 0 {
- db = db.Where("o.dialysis_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("o.dialysis_date<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("o.user_org_id = ? and o.stage = 2", orgid)
- }
- if patient_id > 0 {
- db = db.Where("o.patient_id = ?", patient_id)
- }
- err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id and s.schedule_date = o.dialysis_date and s.status= 1").Joins("left join xt_patients as p on o.patient_id = p.id").Group("s.mode_id").Scan(&counts).Error
- return counts, err
- }
-
- func CreateSummary(summary *models.XtTemplateSummary) error {
-
- err = XTWriteDB().Create(&summary).Error
- return err
- }
-
- func UpdateTempalteSummary(summary *models.XtTemplateSummary) error {
-
- err = XTWriteDB().Save(&summary).Error
- return err
- }
-
- func GetTemplateSummaryList(patientid int64, orgid int64, startime int64, endtime int64) (summary []*models.XtTemplateSummary, err error) {
- db := XTReadDB().Model(&summary).Where("status = 1")
- if startime > 0 {
- db = db.Where("record_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("record_time<=?", endtime)
- }
- if patientid > 0 {
- db = db.Where("patient_id = ?", patientid)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- err = db.Order("record_time desc").Find(&summary).Error
- return summary, err
- }
-
- func GetTemplateSummaryDetail(id int64) (models.XtTemplateSummary, error) {
- summary := models.XtTemplateSummary{}
- err := XTReadDB().Model(&summary).Where("id=?", id).Find(&summary).Error
- return summary, err
- }
-
- func GetTemplateSummaryPrintDetail(id int64) (models.XtTemplateSummary, error) {
-
- summary := models.XtTemplateSummary{}
- err := XTReadDB().Model(&summary).Where("id=? and status = 1", id).Preload("Patients", "status = 1").Find(&summary).Error
- return summary, err
- }
-
- func GetTreateSummary(startime int64, endtime int64, limit int64, page int64, creater int64, patient_id int64) (list []*models.XtTemplateSummary, total int64, err error) {
-
- db := XTReadDB().Model(&list).Where("status = 1")
- offset := (page - 1) * limit
- if startime > 0 {
- db = db.Where("record_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("record_time<=?", endtime)
- }
- if creater > 0 {
- db = db.Where("admin_user_id = ?", creater)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("record_time desc").Find(&list).Error
- return list, total, err
- }
-
- func DeleteSummary(ids []string) error {
-
- summary := models.XtTemplateSummary{}
- err := XTWriteDB().Model(&summary).Where("id in(?)", ids).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CreateHisSummary(summary *models.XtHospitalSummary) error {
-
- err := XTWriteDB().Create(&summary).Error
- return err
- }
-
- func GetHospitalSummaryList(orgid int64, patient_id int64, startime int64, endtime int64) (list []*models.XtHospitalSummary, err error) {
-
- db := XTReadDB().Model(&list).Where("status = 1")
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("record_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("record_date <=?", endtime)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- err = db.Find(&list).Order("ctime desc").Error
- return list, err
- }
-
- func GetHospitalSummaryDetail(id int64) (models.XtHospitalSummary, error) {
-
- summary := models.XtHospitalSummary{}
- err := XTReadDB().Where("id = ? and status = 1", id).Find(&summary).Error
- return summary, err
- }
-
- func UpdateHospital(id int64, summary models.XtHospitalSummary) error {
-
- err := XTWriteDB().Model(&summary).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"title": summary.Title, "admission_time": summary.AdmissionTime, "discharge_time": summary.DischargeTime, "sick_personnel": summary.SickPersonnel, "xray": summary.Xray, "connecticut": summary.Connecticut, "nuclear_magnetic_resonance": summary.NuclearMagneticResonance, "ultrasound": summary.Ultrasound, "pathology": summary.Pathology, "admitting_diagnosis_id": summary.AdmittingDiagnosisId, "admitting_diagnosis": summary.AdmittingDiagnosis, "discharge_diagnosis_id": summary.DischargeDiagnosisId, "discharge_diagnosis": summary.DischargeDiagnosis, "diagnosis_admission_id": summary.DiagnosisAdmissionId, "diagnosis_admission": summary.DiagnosisAdmission, "treatment_id": summary.TreatmentId, "treatment": summary.Treatment, "illness_discharge_id": summary.IllnessDischargeId, "illness_discharge": summary.IllnessDischarge, "discharge_advice_id": summary.DischargeAdviceId, "discharge_advice": summary.DischargeAdvice, "mtime": summary.Mtime, "record_time": summary.RecordTime, "dean_id": summary.DeanId, "doctor": summary.Doctor, "record_date": summary.RecordDate}).Error
- return err
- }
-
- func DeleteHospitalSummary(id []string) error {
- err := XTWriteDB().Model(models.XtHospitalSummary{}).Where("id in (?) and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetAllPatientScheduleList(org_id int64) (patient []*models.PatientsThirty, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status = 1", org_id).Find(&patient).Error
-
- return patient, err
- }
-
- func GetAllDialysiOrderList(patient_id int64, org_id int64) (order []*models.DialysisOrder, err error) {
-
- err = XTReadDB().Where("patient_id = ? and user_org_id = ? and status= 1 and dialysis_date<=1672416000", patient_id, org_id).Find(&order).Error
-
- return order, err
- }
-
- func GetDialysisTotalCountThree(org_id int64, patient_id int64, dialysis_date int64) (models.BloodDialysisOrderCount, error) {
-
- order := models.BloodDialysisOrderCount{}
- db := XTReadDB().Table("xt_dialysis_order as o")
-
- err = 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 o.patient_id = ? and o.dialysis_date<=? and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id, dialysis_date).Scan(&order).Error
-
- return order, err
- }
-
- func UpdateDialysisOrderSix(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
-
- order := models.DialysisOrder{}
-
- err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"dialysis_total": dialysis_total}).Error
-
- return order, err
- }
-
- func CreatePatientFirstDisease(firstdisease models.XtPatientFirstDisease) error {
-
- err := XTWriteDB().Create(&firstdisease).Error
- return err
- }
-
- func GetPatientDiseaseList(org_id int64, patient_id int64, start_time int64, end_time int64) (disease []*models.XtPatientFirstDisease, err error) {
-
- db := XTReadDB().Model(&disease).Where("status=1")
-
- if org_id > 0 {
- db = db.Where("user_org_id =?", org_id)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if start_time > 0 {
- db = db.Where("record_date >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("record_date<=?", end_time)
- }
- err = db.Find(&disease).Error
- return disease, err
- }
-
- func GetFirstDetailById(id int64) (models.XtPatientFirstDisease, error) {
-
- disease := models.XtPatientFirstDisease{}
- err = XTReadDB().Where("id = ? and status= 1", id).Find(&disease).Error
- return disease, err
- }
-
- func UpdatePatientFirstDisease(disease models.XtPatientFirstDisease, id int64) error {
-
- err := XTWriteDB().Model(&models.XtPatientFirstDisease{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"title": disease.Title, "doctor": disease.Doctor, "record_date": disease.RecordDate, "main_content": disease.MainContent, "patient_case": disease.PatientCase, "tentative_diagnosis": disease.TentativeDiagnosis, "diagnostic_basis": disease.DiagnosticBasis, "differential_diagnosis": disease.DifferentialDiagnosis, "treatment_plan": disease.TreatmentPlan, "project_id": disease.ProjectId, "inspect_date": disease.InspectDate}).Error
- return err
- }
-
- func DeleteFirstDisease(id []string) error {
- err := XTWriteDB().Model(models.XtPatientFirstDisease{}).Where("id in (?) and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- type InspectionCount struct {
- Count int64
- }
-
- func GetNormalInspectionTotalByID(startime int64, endtime int64, orgid int64, item_name string, max_value float64, min_value float64) (total int64, err error) {
- var count []*InspectionCount
- err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1 WHERE (x.status = 1) AND (x.org_id = ? and x.item_name = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.org_id = ? and xti.item_name = ? and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.`inspect_value` <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, item_name, startime, endtime, orgid, item_name, startime, endtime, max_value, min_value).Scan(&count).Error
- for _, items := range count {
- total = total + items.Count
- }
- return total, err2
- }
- func GetUnusualInspectionTotalByID(startime int64, endtime int64, orgid int64, item_name string, max_value float64, min_value float64) (total int64, err error) {
- var count []*InspectionCount
- err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1 WHERE (x.status = 1) AND (x.org_id = ? and x.item_name = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.org_id = ? and xti.item_name = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value > ?) OR (xti.status = 1 AND xti.org_id = ? and xti.item_name = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, item_name, startime, endtime, orgid, item_name, startime, endtime, max_value, orgid, item_name, startime, endtime, min_value).Scan(&count).Error
- for _, items := range count {
- total = total + items.Count
- }
- return total, err2
- }
- func GetPatientNotInspectionTotal(startime int64, endtime int64, orgid int64, item_name string) (total int64, err error) {
- err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.item_name = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, item_name, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
- return total, err
- }
-
- func GetPatientInspectionByID(startime int64, endtime int64, orgid int64, patient_id int64, item_name string) (inspections []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_inspection as x").Select("patient_id,inspect_date,inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.inspect_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.inspect_date<=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- if len(item_name) > 0 {
- db = db.Where("x.item_name = ?", item_name)
- }
- if patient_id > 0 {
- db = db.Where("x.patient_id = ?", patient_id)
- }
- err = db.Find(&inspections).Error
- return inspections, err
- }
-
- func GetPatientKTVORURRInspectionByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, patient_id int64) (inspections []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_inspection as x").Select("patient_id,inspect_date,inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.inspect_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.inspect_date<=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if projectid > 0 {
- db = db.Where("x.project_id = ?", projectid)
- }
- if item_id > 0 {
- db = db.Where("x.item_id = ?", item_id)
- }
- if patient_id > 0 {
- db = db.Where("x.patient_id = ?", patient_id)
- }
- err = db.Find(&inspections).Error
- return inspections, err
- }
-
- func GetPatientKTVByID(startime int64, endtime int64, orgid int64, patient_id int64) (inspections []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_assessment_after_dislysis as x").Select("patient_id as patient_id,assessment_date as inspect_date,ktv as inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.assessment_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.assessment_date<=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if patient_id > 0 {
- db = db.Where("x.patient_id = ?", patient_id)
- }
- err = db.Find(&inspections).Error
- return inspections, err
- }
-
- func GetPatientURRByID(startime int64, endtime int64, orgid int64, patient_id int64) (inspections []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_assessment_after_dislysis as x").Select("patient_id as patient_id,assessment_date as inspect_date,urr as inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.assessment_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.assessment_date<=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if patient_id > 0 {
- db = db.Where("x.patient_id = ?", patient_id)
- }
- err = db.Find(&inspections).Error
- return inspections, err
- }
-
- func GetNormalInspectionPatientList(startime int64, endtime int64, orgid int64, item_name string, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_inspection as xti ")
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
- } else {
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
- }
- err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x WHERE (x.status = 1) AND (x.org_id = ? and x.item_name = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.org_id = ? and xti.item_name = ? and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.`inspect_value` <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, item_name, startime, endtime, orgid, item_name, startime, endtime, max_value, min_value).Scan(&xti).Error
- return xti, err2
- }
- func GetUnusualInspectionPatientList(startime int64, endtime int64, orgid int64, item_name string, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_inspection as xti ")
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
- } else {
-
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
- }
- err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x WHERE (x.status = 1) AND (x.org_id = ? and x.item_name = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.org_id = ? and xti.item_name = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value > ?) OR (xti.status = 1 AND xti.org_id = ? and xti.item_name = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, item_name, startime, endtime, orgid, item_name, startime, endtime, max_value, orgid, item_name, startime, endtime, min_value).Scan(&xti).Error
- return xti, err2
- }
- func GetPatientNotInspectionPatientList(startime int64, endtime int64, orgid int64, item_name string, keyword string) (patient []*models.XtPatientsTen, err error) {
- err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.item_name = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, item_name, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
- return patient, err
- }
-
- func GetUnusualKTVPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
- } else {
-
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
- }
- err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv +'0' < ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
- return xti, err2
- }
-
- func GetUnusualKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_inspection as xti ")
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
- } else {
-
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
- }
- err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.org_id = ? and xti.project_id = ? and xti.item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&xti).Error
- return xti, err2
- }
-
- func GetNormalKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_inspection as xti ")
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
- } else {
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
- }
- err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.org_id = ? and xti.project_id = ? and xti.item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&xti).Error
- return xti, err2
- }
-
- func GetPatientNotKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, keyword string) (patient []*models.XtPatientsTen, err error) {
- err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.project_id = ? and pd.item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
- return patient, err
- }
-
- func GetNormalKTVPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
- } else {
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
- }
- err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date<= ? and xti.ktv + '0' >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
- return xti, err2
- }
- func GetPatientNotKTVPatientList(startime int64, endtime int64, orgid int64) (patient []*models.XtPatientsTen, err error) {
- err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.ktv <> '' and pd.assessment_date >= ? and pd.assessment_date<=? ", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
- return patient, err
- }
-
- func GetNormalURRPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
- } else {
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
- }
- err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date<= ? and REPLACE(xti.urr, '%', '') + 0 >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
- return xti, err2
- }
- func GetUnusualURRPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
- db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
- if len(keyword) > 0 {
- keyword = "%" + keyword + "%"
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
- } else {
-
- db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
- }
- err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ?) group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '') + 0 < ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
- return xti, err2
- }
- func GetPatientNotURRPatientList(startime int64, endtime int64, orgid int64) (patient []*models.XtPatientsTen, err error) {
- err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and xti.urr <> '' and pd.assessment_date >= ? and pd.assessment_date<=? ", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
- return patient, err
- }
-
- func GetNormalKTVTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
- var count []*InspectionCount
- err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1 WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv + '0' >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
- for _, items := range count {
- total = total + items.Count
- }
- return total, err2
- }
- func GetUnusualKTVTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
- var count []*InspectionCount
- err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti ").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1 WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv + '0'< ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
- for _, items := range count {
- total = total + items.Count
- }
- return total, err2
- }
- func GetPatientNotKTVTotal(startime int64, endtime int64, orgid int64) (total int64, err error) {
- err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.user_org_id = ? and pd.assessment_date >= ? and pd.assessment_date<=? and pd.ktv <> ''", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
- return total, err
- }
-
- func GetNormalURRTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
- var count []*InspectionCount
- err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1 WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '') + 0 >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
- for _, items := range count {
- total = total + items.Count
- }
- return total, err2
- }
- func GetUnusualURRTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
- var count []*InspectionCount
- err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti ").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1 WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '')+ 0 < ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
- for _, items := range count {
- total = total + items.Count
- }
- return total, err2
- }
- func GetPatientNotURRTotal(startime int64, endtime int64, orgid int64) (total int64, err error) {
- err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.user_org_id = ? and pd.assessment_date >= ? and pd.assessment_date<=? and pd.urr <> ''", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
- return total, err
- }
-
- func GetNormalKTVORURRInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, min_value float64) (total int64, err error) {
- var count []*InspectionCount
- err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1 WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.org_id = ? and xti.project_id = ? and xti.item_id = ? and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&count).Error
- for _, items := range count {
- total = total + items.Count
- }
- return total, err2
- }
- func GetUnusualKTVORURRInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, min_value float64) (total int64, err error) {
- var count []*InspectionCount
- err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1 WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.org_id = ? and xti.project_id = ? and xti.item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&count).Error
- for _, items := range count {
- total = total + items.Count
- }
- return total, err2
- }
-
- func GetPatientNotKTVORURRInspectionTotal(startime int64, endtime int64, orgid int64, projectid int64, item_id int64) (total int64, err error) {
- err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.project_id = ? and pd.item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
- return total, err
- }
-
- func GetFiveInspectionPatientList(orgid int64, keyword string) (xti []*models.XtPatientsTenOne, err error) {
- keyword = "%" + keyword + "%"
- err = XTReadDB().Model(models.XtPatientsTenOne{}).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and xt_patients.lapseto = 1 and xt.patients.name like ?", orgid, keyword).Find(&xti).Error
- return
- }
-
- func GetPatientFiveInspectionByID(startime int64, endtime int64, orgid int64, keyword string) (inspections []models.InspectionTenOne, err error) {
- keyword = "%" + keyword + "%"
-
- db := XTReadDB().Table("xt_inspection i").Select("p.id AS patient_id,p.name AS patient_name,i.inspect_value,i.item_name,i.project_name,i.item_id").Joins("join xt_patients p ON i.patient_id = p.id").Joins("left join xt_quality_control_standard c ON i.item_id = c.`inspection_minor`").Where("i.org_id = ? and i.inspect_date >= ? and i.inspect_date <= ? and i.item_name <> 'KT/V' and i.item_name <> 'URR(%)'", orgid, startime, endtime)
-
- //db := XTReadDB().Table("xt_patients as p").Select("p.id as patient_id, p.name as name, IFNULL(a.inspect_value, '') AS 'ipth',IFNULL(b.inspect_value, '') AS 'xuejia',IFNULL(c.inspect_value, '') AS 'xuelin',IFNULL(d.inspect_value, '') AS 'bdb',IFNULL(e.inspect_value, '') AS 'xhdb'").Joins("LEFT JOIN `xt_inspection` a ON p.id = a.patient_id AND a.org_id = ? and a.`reference_item_id` = 171 and a.`reference_project_id` = 20 and a.`inspect_date` >= ? and a.`inspect_date` <= ? LEFT JOIN xt_inspection b ON p.id = b.patient_id AND b.org_id = ? and b.`reference_item_id` = 48 and b.`reference_project_id` = 4 and b.`inspect_date` >= ? and b.`inspect_date` <= ? LEFT JOIN xt_inspection c ON p.id = c.patient_id AND c.org_id = ? and c.`reference_item_id` = 169 and c.`reference_project_id` = 4 and c.`inspect_date` >= ? and c.`inspect_date` <= ? LEFT JOIN xt_inspection d ON p.id = d.patient_id AND d.org_id = ? and d.`reference_item_id` = 35 and d.`reference_project_id` = 2 and d.`inspect_date` >= ? and d.`inspect_date` <= ? LEFT JOIN xt_inspection e ON p.id = e.patient_id AND e.org_id = ? and e.`reference_item_id` = 17 and e.`reference_project_id` = 1 and e.`inspect_date` >= ? and e.`inspect_date` <= ?", orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime).Where("p.name like ? and p.user_org_id = ? and p.status = 1 and p.lapseto = 1 ", keyword, orgid).Group("p.id")
- err = db.Find(&inspections).Error
- return inspections, err
- }
|