12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121 |
- 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, time_type string) (patients []*models.NewChargeDetail, err error) {
- if len(keyword) == 0 {
- switch item_type {
- case 0:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("-1000 as cost_classify, 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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
-
- err = readDb.Table("his_order_info as oi").Select("-1000 as cost_classify,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:
- if time_type == "0" {
-
- err = readDb.Table("his_order_info as oi").Select("-1000 as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("-1000 as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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:
- if time_type == "0" {
-
- err = readDb.Table("his_order_info as oi").Select("-1000 as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
-
- err = readDb.Table("his_order_info as oi").Select("-1000 as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("-1000 as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
-
- err = readDb.Table("his_order_info as oi").Select("-1000 as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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, time_type string) (patients []*models.NewChargeDetail, err error) {
- if len(keyword) == 0 {
- switch item_type {
- case 0:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,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:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,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:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,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
- case 4:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 3", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 and project.cost_classify = 3 ", org_id, start_time, end_time).Scan(&patients).Error
-
- }
-
- break
- case 5:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 2", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 and project.cost_classify = 2", org_id, start_time, end_time).Scan(&patients).Error
-
- }
-
- break
- case 6:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 6", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 and project.cost_classify = 6", org_id, start_time, end_time).Scan(&patients).Error
- }
- break
- case 7:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 11", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 and project.cost_classify = 11", org_id, start_time, end_time).Scan(&patients).Error
-
- }
- break
- }
- } else {
- keyword := "%" + keyword + "%"
- switch item_type {
- case 0:
- if time_type == "0" {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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:
- if time_type == "0" {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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:
- if time_type == "0" {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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
-
- } else {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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
-
- }
- case 4:
- if time_type == "0" {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 3 ", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 and project.cost_classify = 3 ", org_id, start_time, end_time).Scan(&patients).Error
-
- }
- case 5:
- if time_type == "0" {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 2", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 and project.cost_classify = 2 ", org_id, start_time, end_time).Scan(&patients).Error
-
- }
- case 6:
- if time_type == "0" {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 10", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 and project.cost_classify = 10", org_id, start_time, end_time).Scan(&patients).Error
-
- }
- case 7:
- if time_type == "0" {
-
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') 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 o.settle_accounts_date >= ? and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 11", org_id, start_time, end_time).Scan(&patients).Error
-
- } else {
- err = readDb.Table("his_order_info as oi").Select("(case p.type when 2 then project.cost_classify when 3 then -100 END) as cost_classify,FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 and project.cost_classify = 11", 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
- }
-
- func GetHisPrescriptionDrugDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, patient_id int64, item_type int64) (patients []*models.NewPDetail, err error) {
- db := readDb.Table("his_doctor_advice_info as oi").Select("oo.setl_time as setl_time, drug.id as item_id,1 as p_type,oi.id as advice_id,0 as project_id,pp.id as p_id,pp.name as p_name,FROM_UNIXTIME(o.`record_date`, '%Y-%m-%d') as record_date, drug.drug_type as item_cost_type,o.med_type as med_type,oi.`prescribing_number` as cnt,oi.`price` as pric,drug.drug_name as item_name,CONCAT(drug.dose, \"\", drug.dose_unit, \"*\", drug.min_number, \"\", drug.min_unit, \"/\", drug.max_unit) as spec,o.order_status as order_status,oi.`prescribing_number_unit` as unit").
- Joins("JOIN xt_base_drug drug ON oi.drug_id = drug.id ")
- if patient_id == 0 {
- db = db.Joins("JOIN xt_patients pp on oi.patient_id = pp.id")
-
- } else {
- db = db.Joins("JOIN xt_patients pp on oi.patient_id = pp.id and pp.id = ?", patient_id)
-
- }
- if item_type == 0 {
- db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.status = 1", start_time_str, end_time_str)
- } else {
- if item_type == 2 {
- db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.status = 1 and o.order_status = 2", start_time_str, end_time_str)
- } else {
- db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.status = 1 and o.order_status <> 2", start_time_str, end_time_str)
- }
- }
- db = db.Joins("left JOIN `his_order` oo on oo.`number` = o.`batch_number` and oo.user_org_id = ?", org_id)
-
- err = db.Where(" oi.user_org_id = ? AND o.record_date >= ? AND o.record_date <= ? AND oi.status = 1", org_id, start_time, end_time).Group("oi.id").Scan(&patients).Error
-
- return
- }
-
- func GetHisPrescriptionProjectDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, patient_id int64, item_type int64) (patients []*models.NewPDetail, err error) {
- db := readDb.Table("`his_prescription_project` AS oi").Select("oo.setl_time as setl_time,(case oi.type\n\t\t\tWHEN 2 THEN\n\t\t\tproject.id\n\t\t\tWHEN 3 THEN\n\t\t\tgood.id END) AS item_id,oi.type as p_type,oi.id as project_id,0 as advice_id,pp.id as p_id,(case oi.type\n\t\t\tWHEN 2 THEN\n\t\t\tproject.`cost_classify`\n\t\t\tWHEN 3 THEN\n\t\t\t-100 END) AS item_cost_type,\n\t o.med_type as med_type,\n\t oi.count AS cnt,\n \t oi.price AS pric,\n \t pp.name AS p_name, \n \tFROM_UNIXTIME(o.`record_date`,'%Y-%m-%d') as record_date,\n\t\t (case oi.type\n\tWHEN 2 THEN\n\tproject.project_name\n\tWHEN 3 THEN\n\tgood.good_name END) AS item_name,\n\t\t (case oi.type\n\tWHEN 2 THEN\n\t\"\"\n\tWHEN 3 THEN\n\tgood.`specification_name` END) AS spec,\n\toi.`unit` as unit,o.order_status as order_status")
- db = db.Joins("LEFT JOIN xt_his_project project\n\tON oi.project_id = project.id").
- Joins("LEFT JOIN xt_good_information good\n\tON oi.project_id = good.id\n")
- //Joins("JOIN his_order ord ON o.batch_number = ord.number ")
- if patient_id > 0 {
- db = db.Joins("JOIN xt_patients pp on oi.patient_id = pp.id and pp.id = ?", patient_id)
- } else {
- db = db.Joins("JOIN xt_patients pp on oi.patient_id = pp.id")
- }
-
- if item_type > 0 {
- if item_type == 2 {
- db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.status = 1 and o.order_status = 2", start_time_str, end_time_str)
- } else {
- db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.status = 1 and o.order_status <> 2", start_time_str, end_time_str)
- }
- } else {
- db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.status = 1", start_time_str, end_time_str)
- }
- db = db.Joins("left JOIN `his_order` oo on oo.`number` = o.`batch_number` and oo.user_org_id = ?", org_id)
-
- err = db.Where(" oi.user_org_id = ? AND o.record_date >= ? AND o.record_date <= ? AND oi.status = 1", org_id, start_time, end_time).Group("oi.id").Scan(&patients).Error
- return
- }
|