123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776 |
- package service
-
- import (
- "XT_New/models"
- "github.com/jinzhu/gorm"
- "time"
- )
-
- func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargePatient, err error) {
- if len(keyword) == 0 {
- switch item_type {
- case 0:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 1:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id > 0 AND project_id = 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 2:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 3:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
-
- }
-
- } else {
- keyword := "%" + keyword + "%"
- switch item_type {
- case 0:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
- case 1:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id > 0 AND project_id = 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
- case 2:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
- case 3:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
-
- }
-
- }
-
- return
- }
-
- func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargeDetail, err error) {
- if len(keyword) == 0 {
- switch item_type {
- case 0:
- err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
- Joins(" JOIN xt_base_drug drug on a.drug_id = drug.id").
- Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
- break
- case 1:
- err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
- Joins(" JOIN xt_base_drug drug on a.drug_id = drug.id").
- Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
- break
-
- }
-
- } else {
- keyword := "%" + keyword + "%"
- switch item_type {
- case 0:
- err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
- Joins(" JOIN xt_base_drug drug on a.drug_id = drug.id").
- Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- break
- case 1:
- err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
- Joins(" JOIN xt_base_drug drug on a.drug_id = drug.id").
- Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- break
-
- }
-
- }
-
- return
- }
- func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargeDetail, err error) {
- if len(keyword) == 0 {
- switch item_type {
- case 0:
- err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
- Joins(" left join xt_his_project project on p.project_id = project.id").
- Joins(" left join xt_good_information good on p.project_id = good.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
- Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- //err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
- // return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
- // Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- // return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- // Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- // return db.Preload("Drug", "status = 1").Where("status = 1")
- // }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- // return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- // return db.Select("id,project_name,unit").Where("status = 1 ")
- // }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- // return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- // }).Where("status = 1 ")
- // }).Where("status = 1")
- // }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
- //}).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 2:
- err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
- Joins("left join xt_his_project project on p.project_id = project.id").
- Joins("left join xt_good_information good on p.project_id = good.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
- Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- break
- case 3:
- err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
- Joins("left join xt_his_project project on p.project_id = project.id").
- Joins("left join xt_good_information good on p.project_id = good.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
- Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- break
-
- }
-
- } else {
- keyword := "%" + keyword + "%"
- switch item_type {
- case 0:
- err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
- Joins("left join xt_his_project project on p.project_id = project.id").
- Joins("left join xt_good_information good on p.project_id = good.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
- Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- break
-
- case 2:
- err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
- Joins("left join xt_his_project project on p.project_id = project.id").
- Joins("left join xt_good_information good on p.project_id = good.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
- Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- break
- case 3:
- err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
- Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
- Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
- Joins("left join xt_his_project project on p.project_id = project.id").
- Joins("left join xt_good_information good on p.project_id = good.id").
- Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
- Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- break
-
- }
-
- }
-
- return
- }
-
- func GetAllPatientChargeSettle(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.SettlePatient, err error) {
- if len(keyword) == 0 {
- switch item_type {
- case 0:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 1:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 1 ", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 2:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 0", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 3:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 14", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 4:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 11", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 5:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2 AND orders.insutype = 390", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 ", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
- case 6:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2 AND orders.insutype = 310 ", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
-
- break
-
- }
-
- } else {
- keyword = "%" + keyword + "%"
- switch item_type {
- case 0:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
- case 1:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 1 ", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
- case 2:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 0", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
- case 3:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 14", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
- case 4:
- err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status,p.id_card_no").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 11", start_time, end_time, org_id).Order("ctime")
- }).Where("p.status = 1 AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
-
- break
-
- }
- }
-
- return
- }
-
- func GetLabelPrintList(page int64, limit int64, user_org_id int64, record_time int64, is_print int64, keywors string, tube_color int64) (labels []*models.HisLabelPrintInfo, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.HisLabelPrintInfo{})
- db = db.Preload("HisProjectTeam", "status = 1")
-
- if is_print > 0 {
- db = db.Where("is_print = ?", is_print)
- }
- if len(keywors) > 0 {
- keywors = "%" + keywors + "%"
- db = db.Where("patient_name Like ?", keywors)
-
- }
- if tube_color > 0 {
- db = db.Joins("Right join xt_his_project_team as team on team.id = his_label_print_info.item_id AND his_label_print_info.item_id <> 0 and team.status = 1 and team.tube_color = ?", tube_color)
- //db = db.Joins("Right join xt_his_project as pro on pro.id = his_label_print_info.project_id AND his_label_print_info.item_id = 0 and his_label_print_info.project_id > 0 and pro.status = 1 and pro.tube_color = ?",tube_color)
- }
-
- err = db.Where("his_label_print_info.user_org_id = ? AND his_label_print_info.record_date = ? AND his_label_print_info.status = 1 ", user_org_id, record_time).Count(&total).Offset(offset).Limit(limit).Find(&labels).Error
- return
- }
- func GetLabelPrintListTwo(page int64, limit int64, user_org_id int64, record_time int64, is_print int64, keywors string, tube_color int64) (labels []*models.HisLabelPrintInfo, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.HisLabelPrintInfo{})
- db = db.Preload("HisProjectTeam", "status = 1")
- if is_print > 0 {
- db = db.Where("is_print = ?", is_print)
- }
- if len(keywors) > 0 {
- keywors = "%" + keywors + "%"
- db = db.Where("patient_name Like ?", keywors)
-
- }
- if tube_color > 0 {
- //db = db.Joins("Right join xt_his_project_team as team on team.id = his_label_print_info.item_id AND his_label_print_info.item_id <> 0 and team.status = 1 and team.tube_color = ?",tube_color)
- db = db.Joins("Right join xt_his_project as pro on pro.id = his_label_print_info.project_id AND his_label_print_info.item_id = 0 and his_label_print_info.project_id > 0 and pro.status = 1 and pro.tube_color = ?", tube_color)
- }
-
- err = db.Where("his_label_print_info.user_org_id = ? AND his_label_print_info.record_date = ? AND his_label_print_info.status = 1 ", user_org_id, record_time).Count(&total).Offset(offset).Limit(limit).Find(&labels).Error
- return
- }
-
- func GetLabelPrintListThree(user_org_id int64, record_time int64, is_print int64, keywors string, tube_color int64) (labels []*models.HisLabelPrintInfo, total int64, err error) {
- db := readDb.Model(&models.HisLabelPrintInfo{})
-
- db = db.Preload("HisProjectTeam", "status = 1")
- if is_print > 0 {
- db = db.Where("is_print = ?", is_print)
- }
- if len(keywors) > 0 {
- keywors = "%" + keywors + "%"
- db = db.Where("patient_name Like ?", keywors)
-
- }
- //if tube_color > 0 {
- // db = db.Joins("Right join xt_his_project_team as team on team.id = his_label_print_info.item_id AND his_label_print_info.item_id <> 0 and team.status = 1 and team.tube_color = ?", tube_color)
- //}
-
- err = db.Where("his_label_print_info.user_org_id = ? AND his_label_print_info.record_date = ? AND his_label_print_info.status = 1 ", user_org_id, record_time).Count(&total).Find(&labels).Error
- return
- }
-
- //func GetLabelPrintListFour(user_org_id int64, record_time int64, is_print int64, keywors string, tube_color int64) (labels []*models.HisLabelPrintInfo, total int64, err error) {
- // db := readDb.Model(&models.HisLabelPrintInfo{})
- // db = db.Preload("HisProjectTeam", "status = 1")
- //
- // if is_print > 0 {
- // db = db.Where("is_print = ?", is_print)
- // }
- // if len(keywors) > 0 {
- // keywors = "%" + keywors + "%"
- // db = db.Where("patient_name Like ?", keywors)
- //
- // }
- // //if tube_color > 0 {
- // // //db = db.Joins("Right join xt_his_project_team as team on team.id = his_label_print_info.item_id AND his_label_print_info.item_id <> 0 and team.status = 1 and team.tube_color = ?",tube_color)
- // // db = db.Joins("Right join xt_his_project as pro on pro.id = his_label_print_info.project_id AND his_label_print_info.item_id = 0 and his_label_print_info.project_id > 0 and pro.status = 1 and pro.tube_color = ?", tube_color)
- // //}
- //
- // err = db.Where("his_label_print_info.user_org_id = ? AND his_label_print_info.record_date = ? AND his_label_print_info.status = 1 ", user_org_id, record_time).Count(&total).Find(&labels).Error
- // return
- //}
-
- func GetLabelPrintInfo(id int64) (labels models.HisLabelPrintInfo, err error) {
- db := readDb.Model(&models.HisLabelPrintInfo{})
- err = db.Where("id = ?", id).First(&labels).Error
- return
- }
-
- func AddSigleFapiaoRecord(dealer *models.HisFapiaoRecord) (err error, record *models.HisFapiaoRecord) {
- err = writeDb.Create(&dealer).Error
- return err, dealer
- }
-
- func ModifyFapiao(mesick *models.HisFapiaoRecord) error {
- err := writeDb.Save(&mesick).Error
-
- return err
- }
-
- func UpdateFapiaoIsUse(org_id int64) {
- writeDb.Model(&models.HisFapiaoRecord{}).Where("user_org_id = ?", org_id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "is_use": 0})
-
- }
-
- func FindAllFapiaoList(orgId int64, page int64, limit int64) (list []*models.HisFapiaoRecord, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.HisFapiaoRecord{})
- db = db.Where("user_org_id = ? AND status = 1", orgId)
- err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
- return
- }
-
- func DeleteFapiaoById(id int64) error {
- err := writeDb.Model(&models.HisFapiaoRecord{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
- return err
- }
-
- func FindFapiaoById(id int64) (*models.HisFapiaoRecord, error) {
- dealer := &models.HisFapiaoRecord{}
- err := readDb.Model(&models.HisFapiaoRecord{}).Where("id = ? AND status = 1", id).First(&dealer).Error
- return dealer, err
- }
-
- func FindFapiaoByIsUse(org_id int64) (models.HisFapiaoRecord, error) {
- record := models.HisFapiaoRecord{}
- err := readDb.Model(&models.HisFapiaoRecord{}).Where("user_org_id = ? AND status = 1 AND is_use = 1", org_id).First(&record).Error
- return record, err
- }
-
- func FindHisYidiClearRecord(org_id int64) (records []*models.HisYidiClearRecord, err error) {
- err = readDb.Model(&models.HisYidiClearRecord{}).Where("user_org_id = ? AND status = 1", org_id).Find(&records).Error
- return
- }
-
- func GetHisYidiClearRecordById(org_id int64, id int64) (record models.HisYidiClearRecord, err error) {
- err = readDb.Model(&models.HisYidiClearRecord{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&record).Error
- return
- }
-
- func GetAllPatientTwo(org_id int64) (patients []*models.ChargePatientTwo, err error) {
- err = readDb.Model(&models.ChargePatientTwo{}).Where("user_org_id = ? AND status = 1", org_id).Find(&patients).Error
- return
- }
-
- func GetPatientChargeDetails(patient_id int64, org_id int64, start_time int64, end_time int64, keyword string, item_type int64, settle_type int64) (patients []*models.HisChargeOrderTwo, err error) {
- if len(keyword) == 0 {
- switch item_type {
- case 0:
- readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- })
- }).Where("status = 1 AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
- break
- case 1:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Where("status = 1 AND advice_id > 0 AND project_id = 0")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
-
- break
- case 2:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
- })
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
-
- break
- case 3:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
- })
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
- break
- }
-
- } else {
- //keyword := "%" + keyword + "%"
- switch item_type {
- case 0:
- readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- })
- }).Where("status = 1 AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
- break
- case 1:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Where("status = 1 AND advice_id > 0 AND project_id = 0")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
-
- break
- case 2:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
- })
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
-
- break
- case 3:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
- })
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
- break
- }
-
- }
- return
- }
-
- func GetPatientGather(patient_id int64, org_id int64, start_time int64, end_time int64, keyword string, item_type int64, settle_type int64) (patients []*models.HisChargeOrderTwo, err error) {
- if len(keyword) == 0 {
- switch item_type {
- case 0:
- readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- })
- }).Where("status = 1 AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
- break
- case 1:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Where("status = 1 AND advice_id > 0 AND project_id = 0")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
-
- break
- case 2:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
- })
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
-
- break
- case 3:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
- })
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
- break
- }
-
- } else {
- //keyword := "%" + keyword + "%"
- switch item_type {
- case 0:
- readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- })
- }).Where("status = 1 AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
- break
- case 1:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).Where("status = 1 AND advice_id > 0 AND project_id = 0")
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
-
- break
- case 2:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
- })
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
-
- break
- case 3:
- readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
- })
- }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
- break
- }
-
- }
- return
- }
-
- func GetAllChargeDetailsTwo(org_id int64, start_time int64, end_time int64) (patients []*models.HisChargeOrder, err error) {
- err = readDb2.Model(&models.HisChargeOrder{}).Preload("Patients", "status = 1").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
- Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Preload("Drug", "status = 1").Where("status = 1")
- }).
- Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").
- Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit").Where("status = 1 ")
- }).
- Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
- }).Where("status = 1 ")
- }).Where("status = 1")
- }).Where("status = 1 AND user_org_id = ? AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND order_status = 2", org_id, start_time, end_time).Group("id").Find(&patients).Error
-
- return
- }
-
- func GetAllLisDataFor10191(org_id int64) (list []models.HisLabelPrintStatusInfo, err error) {
- err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Preload("Patient", "status = 1").Where("user_org_id = ? AND status = 1 and apply_code = ''", org_id).Find(&list).Error
- return
- }
|