123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- package service
-
- import (
- "XT_New/models"
- "github.com/jinzhu/gorm"
- "time"
- )
-
- func GetHisSummaryDetailList(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (patients []*models.ChargePatient, err error) {
-
- err = XTReadDB().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 and orders.patient_id = ?", start_time, end_time, org_id, patient_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,psn_cash_pay,acct_pay,fund_pay_sumamt,is_medicine_insurance,medfee_sumamt,maf_pay,hifes_pay,hifp_pay,hifmi_pay").
- 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,fulamt_ownpay_amt,overlmt_amt,preselfpay_amt,pric_uplmt_amt").Where("status = 1").
- 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,unit,remark").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,project_name,unit,medical_coverage,cost_classify").Where("status = 1 ")
- }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Select("id,good_name,good_unit,specification_name,packing_unit,medical_insurance_level").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.id = ?", org_id, patient_id).Group("id").Find(&patients).Error
-
- return
-
- }
-
- func GetModeTemplateName(mode_id int64, user_org_id int64) (template []*models.HisPrescriptionModeTemplate, err error) {
-
- err = XTReadDB().Where("mode = ? and user_org_id = ? and patient_id = ? and status = 1", mode_id, user_org_id, 0).Find(&template).Error
- return template, err
- }
-
- func GetModeTemplateNameDetail(mode_id int64, user_org_id int64) (models.HisPrescriptionModeTemplate, error) {
-
- template := models.HisPrescriptionModeTemplate{}
- err := XTReadDB().Where("mode = ? and user_org_id = ? and status = 1 and patient_id= 0", mode_id, user_org_id).Find(&template).Error
- return template, err
- }
-
- func GetModeTemplateInfo(id int64, user_org_id int64) (models.HisPrescriptionInfoTemplate, error) {
-
- template := models.HisPrescriptionInfoTemplate{}
- err := XTReadDB().Where("p_template_id = ? and user_org_id = ? and status = 1", id, user_org_id).Find(&template).Error
- return template, err
- }
-
- func GetPrescriptionAdviceTemplateDetail(template_id int64, orgid int64) (template []*models.HisPrescriptionAdviceTemplate, err error) {
-
- err = XTReadDB().Where("prescription_id in(?) and user_org_id = ? and status = 1", template_id, orgid).Find(&template).Error
- return template, err
- }
-
- func GetPrescriptionProjectTemplateDetail(template_id int64, orgid int64) (template []*models.HisPrescriptionProjectTemplate, err error) {
- err = XTReadDB().Where("prescription_id in(?) and user_org_id = ? and status = 1", template_id, orgid).Find(&template).Error
- return template, err
- }
-
- func GetHisPrescriptionModeTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoModeTemplate, err error) {
- err = readDb.Model(&models.HisPrescriptionInfoModeTemplate{}).
- Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
- }).
- Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
- }).
- Where("status = 1 AND p_template_id = ? ", template_id).
- Find(&prescription).Error
- return
- }
-
- func GetHisModePrescriptionTemplateByID(template_id int64) (prescription models.HisPrescriptionModeTemplate, err error) {
- err = readDb.Model(&models.HisPrescriptionModeTemplate{}).Where("id = ? AND status = 1 ", template_id).First(&prescription).Error
- return
- }
-
- func CreateHisModePrescriptionTemplate(template *models.HisPrescriptionModeTemplate) (err error) {
- err = writeDb.Create(&template).Error
- return
-
- }
-
- func SaveHisModePrescriptionTemplate(template *models.HisPrescriptionModeTemplate) (err error) {
- err = writeDb.Save(&template).Error
- return
-
- }
-
- func CreateHisModePrescriptionInfoTemplate(s *models.HisPrescriptionInfoModeTemplate) (err error) {
- err = writeDb.Save(&s).Error
- return
- }
-
- func CreateHisModePrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceModeTemplate) (err error) {
- err = writeDb.Save(&s).Error
- return
- }
-
- func GetHisModePrescriptionTemplateByModeId(mode_id int64, patient_id int64, user_org_id int64) (prescription models.HisPrescriptionModeTemplate, err error) {
- err = readDb.Model(&models.HisPrescriptionModeTemplate{}).Where("mode = ? AND status = 1 AND patient_id = ? and user_org_id = ?", mode_id, patient_id, user_org_id).First(&prescription).Error
- return
- }
-
- func GetHisModePrescriptionTemplateByModeIdTwo(mode_id int64, patient_id int64, user_org_id int64, id int64) (prescription models.HisPrescriptionModeTemplate, err error) {
- err = readDb.Model(&models.HisPrescriptionModeTemplate{}).Where("mode = ? AND status = 1 AND patient_id = ? and user_org_id = ? and id <> ?", mode_id, patient_id, user_org_id, id).First(&prescription).Error
- return
- }
-
- func CreateHisModePrescriptionProjectTemplate(project *models.HisPrescriptionProjectModeTemplate) (err error) {
- err = writeDb.Save(&project).Error
- return
- }
-
- func DelelteHisModePrescriptionTemplate(id int64, user_org_id int64) (err error) {
- err = writeDb.Model(&models.HisPrescriptionModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0}).Error
- err = writeDb.Model(&models.HisPrescriptionInfoModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DelelteHisModePrescriptionProjectTemplate(id int64, user_org_id int64) (err error) {
- err = writeDb.Model(&models.HisPrescriptionProjectModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
-
- return
- }
-
- func DelelteHisModePrescriptionAdviceTemplate(id int64, user_org_id int64) (err error) {
- err = writeDb.Model(&models.HisPrescriptionAdviceModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DelelteHisPrescriptionInfoModeTemplate(id int64, user_org_id int64) (err error) {
- err = writeDb.Model(&models.HisPrescriptionInfoModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- err = writeDb.Model(&models.HisPrescriptionAdviceModeTemplate{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- err = writeDb.Model(&models.HisPrescriptionProjectModeTemplate{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func GetAdviceGatherDetaiList(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (orderInfo []*models.VmHisOrderInfo, err error) {
-
- db := XTReadDB().Model(&orderInfo).Where("status = 1")
-
- if org_id > 0 {
- db = db.Where("user_org_id = ? and advice_id > 0", org_id)
- }
- if start_time > 0 {
- db = db.Where("ctime >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("ctime <=?", end_time)
- }
- err = db.Preload("VmHisDoctorAdviceInfo", "patient_id = ? and advice_date>=? and advice_date<=?", patient_id, start_time, end_time).Group("advice_id").Scan(&orderInfo).Error
- return orderInfo, err
- }
-
- func GetProjectGatherDetailList(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (orderInfo []*models.VmHisOrderInfo, err error) {
- db := XTReadDB().Model(&orderInfo).Where("status = 1")
-
- if org_id > 0 {
- db = db.Where("user_org_id = ? and project_id > 0", org_id)
- }
- if start_time > 0 {
- db = db.Where("ctime >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("ctime <=?", end_time)
- }
- err = db.Group("project_id").Preload("HisPrescriptionProject", "patient_id = ? and record_date>=? and record_date<=?", patient_id, start_time, end_time).Find(&orderInfo).Error
- return orderInfo, err
- }
-
- func GetGatherHisOrder(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (order []*models.GatherHisOrder, err error) {
-
- db := XTReadDB().Model(&order).Where("status = 1")
-
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- if start_time > 0 {
- db = db.Where("settle_accounts_date >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("settle_accounts_date<=?", end_time)
- }
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if len(keyword) > 0 {
-
- }
-
- err = db.Find(&order).Error
-
- return order, err
- }
-
- func GetGatherHisOrderTwo(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (models.GatherHisOrder, error) {
-
- hisOrder := models.GatherHisOrder{}
- db := XTReadDB().Model(&hisOrder).Where("status = 1")
-
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- if start_time > 0 {
- db = db.Where("settle_accounts_date >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("settle_accounts_date<=?", end_time)
- }
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if len(keyword) > 0 {
-
- }
-
- err = db.Last(&hisOrder).Error
-
- return hisOrder, err
- }
-
- func GetHisSummaryPatientInfo(org_id int64, patient_id int64, start_time int64, end_time int64) (info models.HisPatient, err error) {
- err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?", org_id, start_time, end_time, patient_id).Last(&info).Error
- return
- }
-
- func GetHisSummaryPatientInfoSix(org_id int64, patient_id int64, start_time int64, end_time int64) (info models.HisHospitalCheckRecord, err error) {
- err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?", org_id, start_time, end_time, patient_id).Last(&info).Error
- return
- }
-
- func GetDetailPatients(keywords string, org_id int64) (patients []*models.ChargePatientTwo, err error) {
- if len(keywords) == 0 {
- err = readDb.Model(&models.ChargePatientTwo{}).Where("user_org_id = ? AND status = 1", org_id).Find(&patients).Error
- }
-
- if len(keywords) > 0 {
- keyword := "%" + keywords + "%"
- err = readDb.Model(&models.ChargePatientTwo{}).Where("user_org_id = ? AND status = 1 and name like ?", org_id, keyword).Find(&patients).Error
- }
-
- return
- }
-
- func GetHisDepatment(user_org_id int64) (hisdepartment []*models.XtHisDepartment, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&hisdepartment).Error
- return hisdepartment, err
- }
-
- func GetHisPatientInfoFive(org_id int64, patient_id int64, startime int64, endtime int64) (info models.HisPatient, err error) {
- err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 and patient_id = ? AND record_date >= ? and record_date <=?", org_id, patient_id, startime, endtime).Last(&info).Error
- return
- }
-
- func GetHisPrescriptionTenty(org_id int64, patient_id int64, start_time int64, end_time int64, keyword string, item_type int64) (prescription []*models.HisPrescription, err error) {
-
- db := readDb.Model(&models.HisPrescription{}).Where("status = 1")
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- if start_time > 0 {
- db = db.Where("record_date >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("record_date <=?", end_time)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if len(keyword) > 0 {
- err = db.Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
- }).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
- }).Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).Find(&prescription).Error
- } else {
- err = db.Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
- }).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
- }).
- Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).Find(&prescription).Error
- }
-
- return
- }
-
- func GetHisLastOrder(org_id int64, patient_id int64, start_time int64, end_time int64) (models.HisOrder, error) {
-
- order := models.HisOrder{}
-
- err := XTReadDB().Where("user_org_id = ? and patient_id = ? and ctime>=? and ctime<=? and status = 1", org_id, patient_id, start_time, end_time).Last(&order).Error
- return order, err
- }
-
- func GetHisSchedule(patient_id int64, org_id int64, start_time int64, end_time int64) (schedule []*models.XtSchedule, err error) {
-
- err = XTReadDB().Where("patient_id = ? and user_org_id = ? and schedule_date >=? and schedule_date<=? and status = 1", patient_id, org_id, start_time, end_time).Find(&schedule).Error
- return schedule, err
- }
-
- func GetHisChargeOrder(org_id int64, patient_id int64, start_time int64, end_time int64, keyword string, item_type int64) (order []*models.HisChargeOrder, err error) {
-
- db := XTReadDB().Model(&order).Where("status = 1")
-
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if start_time > 0 {
- db = db.Where("settle_accounts_date>=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("settle_accounts_date<=?", end_time)
- }
- err = db.Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1").Preload("HisChargePrescriptionProject", "status=1").Preload("HisChargeDoctorAdviceInfo", "status=1")
- }).Error
- return order, err
- }
-
- func GetAllHisOrderList(org_id int64, patient_id int64, start_time int64, end_time int64) (order []*models.VmHisOrder, err error) {
-
- db := XTReadDB().Model(&order).Where("status = 1")
-
- if org_id > 0 {
- db = db.Where("user_org_id = ?", org_id)
- }
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if start_time > 0 {
- db = db.Where("settle_accounts_date >=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("settle_accounts_date<=?", end_time)
- }
-
- err = db.Find(&order).Error
-
- return order, err
- }
-
- func GetHisOrderListByMedChrgitemType(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderInfoTwenty, err error) {
-
- db := XTReadDB().Model(&models.HisOrderInfoTwenty{}).Where("status = 1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if startime > 0 {
- db = db.Where("settle_accounts_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("settle_accounts_date<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- err = db.Group("med_chrgitm_type").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status = 1").Find(&info).Error
- return info, err
- }
-
- func GetOrderInfoList(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderInfoTwenty, err error) {
- db := XTReadDB().Model(&models.HisOrderInfoTwenty{}).Where("status = 1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
- if startime > 0 {
- db = db.Where("upload_date >= ?", startime)
- }
-
- if endtime > 0 {
- db = db.Where("upload_date<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- err = db.Preload("HisOrderTenty", "status = 1").Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", orgid).Preload("HisProject").Preload("GoodInfo", "status=1")
- }).Preload("HisDoctorAdvice", "status = 1").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status = 1").Find(&info).Error
- return info, err
- }
-
- func GetHisOrderListTwenty(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderTenty, err error) {
-
- db := XTReadDB().Model(&models.HisOrderTenty{}).Where("status = 1")
-
- if patient_id > 0 {
- db = db.Where("patient_id = ?", patient_id)
- }
-
- if startime > 0 {
- db = db.Where("settle_accounts_date>=?", startime)
- }
-
- if endtime > 0 {
- db = db.Where("settle_accounts_date<=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
-
- err = db.Preload("HisOrderInfoTwenty", "status=1").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status=1").Order("settle_accounts_date asc").Find(&info).Error
- return info, err
- }
-
- func GetHisAdviceOrderList() {
-
- }
|