12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073 |
- package service
-
- import (
- "XT_New/models"
- "github.com/jinzhu/gorm"
- "strconv"
- "strings"
- "time"
- )
-
- func GetDictionaryConfigList(orgID int64) (dataconfig interface{}, err error) {
- var configList []*models.DictionaryDataconfig
-
- err = readDb.Model(&models.DictionaryDataconfig{}).Where("(org_id in (0,?) and status = 1) or (status = 0 and delete_id_system > 0 and org_id = ?)", orgID, orgID).Order("orders asc, id asc").Find(&configList).Error
- if err != nil {
- return nil, err
- }
-
- // configResult := make([]*ConfigViewModel,0)
- childConfig := make(map[int64][]*models.DictionaryDataconfig)
- resultConfig := make(map[string][]*models.DictionaryConfigViewModel)
- deleteSystemChilds := make([]*models.DictionaryDataconfig, 0)
- editSystemChilds := make([]*models.DictionaryDataconfig, 0)
- for _, config := range configList {
- if config.Status == 1 && config.DeleteIdSystem > 0 {
- editSystemChilds = append(editSystemChilds, config)
- }
-
- if config.Status == 0 && config.DeleteIdSystem > 0 {
- deleteSystemChilds = append(deleteSystemChilds, config)
- }
- }
- continueFlag := false
- for _, config := range configList {
- continueFlag = false
- if config.ParentId == 0 {
- newConfig := &models.DictionaryConfigViewModel{
- ID: config.ID,
- ParentId: config.ParentId,
- Module: config.Module,
- OrgId: config.OrgId,
- Name: config.Name,
- FieldName: config.FieldName,
- Value: config.Value,
- CreateUserId: config.CreateUserId,
- Status: config.Status,
- Remark: config.Remark,
- Title: config.Title,
- Content: config.Content,
- }
- // configResult = append(configResult,newConfig)
- result := resultConfig[config.Module]
- if result == nil {
- result = make([]*models.DictionaryConfigViewModel, 0)
- }
- for _, vm := range editSystemChilds {
- if vm.DeleteIdSystem == config.ID {
- continueFlag = true
- break
- }
- }
-
- for _, _vm := range deleteSystemChilds {
- if _vm.DeleteIdSystem == config.ID {
- continueFlag = true
- break
- }
- }
- if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
- continue
- }
- if continueFlag {
- continue
- }
- result = append(result, newConfig)
- resultConfig[config.Module] = result
- } else {
- childs := childConfig[config.ParentId]
- if childs == nil {
- childs = make([]*models.DictionaryDataconfig, 0)
- }
- continueFlag := false
- for _, vm := range editSystemChilds {
- if vm.DeleteIdSystem == config.ID {
- continueFlag = true
- break
- }
- }
-
- for _, _vm := range deleteSystemChilds {
- if _vm.DeleteIdSystem == config.ID {
- continueFlag = true
- break
- }
- }
- if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
- continue
- }
- if continueFlag {
- continue
- }
-
- childs = append(childs, config)
- childConfig[config.ParentId] = childs
- }
- }
-
- for _, vm := range resultConfig {
- for _, _vm := range vm {
- _vm.Childs = childConfig[_vm.ID]
- }
- // vm.Childs = childConfig[vm.ID]
- }
- return resultConfig, err
- }
-
- func CreateDictionaryConfig(dataconfig *models.DictionaryDataconfig) (err error) {
- // readDb.Model(&models.Dataconfig{}).Where("module = ? and parent_id = 0 and org_id in (0,?)",dataconfig.Module,dataconfig.OrgId).Count(&total)
- err = readDb.Create(&dataconfig).Error
- return
- }
-
- func GetDictionaryChildValue(module string, parent_id int64, org_id int64) (value int) {
- readDb.Model(&models.DictionaryDataconfig{}).Where("module=? and parent_id=? and org_id in (0,?)", module, parent_id, org_id).Count(&value)
- return
- }
-
- func FindDictionaryConfigByTitle(module string, title string, org_id int64) (dataconfig models.DictionaryDataconfig, err error) {
- err = readDb.Model(&models.DictionaryDataconfig{}).Where("module=? and title=? and org_id in (0,?) and status = 1", module, title, org_id).First(&dataconfig).Error
- return
- }
-
- func UpdateDictionaryTemplate(dataconfig *models.DictionaryDataconfig) (err error) {
- err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"title": dataconfig.Title, "content": dataconfig.Content, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark}).Error
- return
- }
-
- func UpdateDictionaryChildConfig(dataconfig *models.DictionaryDataconfig) (err error) {
- err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"name": dataconfig.Name, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark, "orders": dataconfig.Order, "code": dataconfig.Code}).Error
- return
- }
-
- func DeleteDictionaryChildConfig(dataconfig *models.DictionaryDataconfig) (err error) {
- err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"status": dataconfig.Status, "update_time": dataconfig.UpdatedTime}).Error
- return
- }
-
- func CreateBaseDrugLib(lib *models.BaseDrugLib) (err error) {
- err = writeDb.Create(&lib).Error
- return
- }
-
- func UpdateBaseDrugLib(lib *models.BaseDrugLib) (err error) {
- err = writeDb.Save(lib).Error
- return
- }
-
- func FindBaseDrugLibRecordCount(lib *models.BaseDrugLib) (count int64) {
- readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND drug_name = ? AND drug_category = ? AND drug_spec=? AND drug_type=? AND status = 1", lib.OrgId, lib.DrugName, lib.DrugCategory, lib.DrugSpec, lib.DrugType).Count(&count)
- return
- }
-
- func FindBaseDrugLibRecordCountOne(lib *models.BaseDrugLib) (count int64) {
- readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? and drug_name = ? and dose = ? and dose_unit = ? and min_number = ? and min_unit = ? and max_unit = ? and manufacturer = ? and status = 1", lib.OrgId, lib.DrugName, lib.Dose, lib.DoseUnit, lib.MinNumber, lib.MinUnit, lib.MaxUnit, lib.Manufacturer).Count(&count)
- return
- }
-
- func FindAllDrugLibRecordTotal(org_id int64) (count int64) {
- readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Count(&count)
- return
- }
-
- func FindBaseDrugLibRecord(org_id int64, id int64) (lib models.BaseDrugLib, err error) {
- err = readDb.Model(&models.BaseDrugLib{}).Where("id = ? AND org_id = ? AND status = 1", id, org_id).First(&lib).Error
- return
- }
-
- func FindBaseDrugLibRecordSeven(org_id int64, id int64) (lib models.BaseDrugLibSeven, err error) {
- err = readDb.Select("id,drug_name,max_unit,min_number,min_unit,sum_count,is_user,is_pharmacy").Where("org_id = ? AND id = ? AND status = 1", org_id, id).First(&lib).Error
- return
- }
-
- func GetDrugAutoWarehouseOut(patient_id int64, advicedate int64, drugid int64) (*models.DrugWarehouseOutInfo, error) {
- detail := models.DrugWarehouseOutInfo{}
- err := XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1", patient_id, advicedate, drugid).Find(&detail).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &detail, nil
- }
-
- func GetDrugAutoWarehouseOutSeven(patient_id int64, advicedate int64, drugid int64, adviceid int64) (*models.DrugWarehouseOutInfo, error) {
- detail := models.DrugWarehouseOutInfo{}
- err := XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&detail).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &detail, nil
- }
-
- func GetDrugAutoWarehouseOutEight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (models.DrugWarehouseOutInfo, error) {
- detail := models.DrugWarehouseOutInfo{}
- err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&detail).Error
- return detail, err
- }
-
- func GetDrugAutoWarehouseOutTen(patient_id int64, advicedate int64, drugid int64, adviceid int64, warehouse_info_id int64) (models.DrugWarehouseOutInfo, error) {
- detail := models.DrugWarehouseOutInfo{}
- err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", patient_id, advicedate, drugid, adviceid, warehouse_info_id).Find(&detail).Error
- return detail, err
- }
-
- func GetDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&night).Error
- return night, err
- }
-
- func UpdateDrugWarehouse(id int64, info models.DrugWarehouseInfo) error {
- err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
- return err
- }
-
- func UpdateDrugWarehouseOne(id int64, info models.DrugWarehouseInfo) error {
- err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
- return err
- }
-
- func GetBaseDrugLibList(org_id int64, keyword string, page int64, limit int64, is_use int64, is_charge int64, is_inject int64, manufacturer int64, isRecord int64) (list []*models.BaseDrugLib, total int64, err error) {
-
- db := readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id)
- if len(keyword) != 0 {
- keyword = "%" + keyword + "%"
- db = db.Where("drug_name Like ?", keyword)
-
- }
-
- if is_use != 0 {
- if is_use == 2 {
- db = db.Where("find_in_set('停用',drug_status) = 0")
-
- } else {
- db = db.Where("find_in_set('停用',drug_status) > 0")
- }
- }
-
- if is_charge == 1 {
- //if is_charge == 1 {
- // db = db.Where("find_in_set('收费',drug_status) > 0")
- //
- //} else {
- // db = db.Where("find_in_set('收费',drug_status) = 0")
- //}
- db = db.Where("is_record = ?", is_charge)
- }
-
- if is_charge == 2 {
- db = db.Where("is_record= 0 || is_record = 2")
- }
-
- if is_inject != 0 {
- //db = db.Where("drug_name Like ?", keyword)
- if is_inject == 1 {
- db = db.Where("find_in_set('注射类',drug_status) > 0")
-
- } else {
- db = db.Where("find_in_set('注射类',drug_status) = 0")
- }
-
- }
-
- if manufacturer > 0 {
- db = db.Where("manufacturer = ?", manufacturer)
- }
- if isRecord > 0 {
- db = db.Where("is_mark = ?", isRecord)
- }
- offset := (page - 1) * limit
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
- return
- }
-
- func CreateMedicineInsurancePercentage(mip *models.MedicineInsurancePercentage) (err error) {
- err = writeDb.Create(mip).Error
- return
- }
-
- func CreateUnitSafeguard(dus *models.DrugUnitSafeguard) (err error) {
- err = writeDb.Create(dus).Error
- return
- }
-
- func AddSigleMZSick(dealer *models.OutpatientServiceSick) (error, *models.OutpatientServiceSick) {
- err := writeDb.Create(&dealer).Error
- return err, dealer
- }
-
- func ModifyMZSick(mesick *models.OutpatientServiceSick) error {
- err := writeDb.Save(&mesick).Error
-
- return err
- }
-
- func FindAllMZSickList(orgId int64, page int64, limit int64) (list []*models.OutpatientServiceSick, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.OutpatientServiceSick{})
- 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 DeleteMZSickById(id int64) error {
- err := writeDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
- return err
- }
-
- func FindMZSickById(id int64) (*models.OutpatientServiceSick, error) {
- dealer := &models.OutpatientServiceSick{}
- err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&dealer).Error
- return dealer, err
- }
-
- func GetDrugWareoutInfo(id int64) (*models.XtDrugWarehouseInfo, error) {
-
- info := models.XtDrugWarehouseInfo{}
- err = XTReadDB().Model(&info).Where("drug_id = ? and status = 1", id).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetDrugWareOutById(id int64) (*models.XtDrugWarehouseOutInfo, error) {
-
- info := models.XtDrugWarehouseOutInfo{}
- err := XTReadDB().Model(&info).Where("drug_id = ? and status = 1", id).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func DeleteBaseDrugById(id int64) error {
-
- drug := models.XtBaseDrug{}
- err := XTWriteDB().Model(&drug).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func AddSigleAddition(dealer *models.XtHisAddtionConfig) (error, *models.XtHisAddtionConfig) {
- err := writeDb.Create(&dealer).Error
- return err, dealer
- }
-
- func ModifyAddition(mesick *models.XtHisAddtionConfig) error {
- err := writeDb.Save(&mesick).Error
-
- return err
- }
-
- func FindAllAdditionList(orgId int64, page int64, limit int64) (list []*models.XtHisAddtionConfig, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.XtHisAddtionConfig{})
- 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 DeleteAdditionById(id int64) error {
- err := writeDb.Model(&models.XtHisAddtionConfig{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
- return err
- }
-
- func FindAdditionById(id int64) (*models.XtHisAddtionConfig, error) {
- dealer := &models.XtHisAddtionConfig{}
- err := readDb.Model(&models.XtHisAddtionConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
- return dealer, err
- }
-
- func AddSigleDiagnose(dealer *models.HisXtDiagnoseConfig) (error, *models.HisXtDiagnoseConfig) {
- err := writeDb.Create(&dealer).Error
- return err, dealer
- }
-
- func ModifyDiagnose(mesick *models.HisXtDiagnoseConfig) error {
- err := writeDb.Save(&mesick).Error
-
- return err
- }
-
- func FindAllDiagnoseList(orgId int64, page int64, limit int64) (list []*models.HisXtDiagnoseConfig, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.HisXtDiagnoseConfig{})
- db = db.Where("user_org_id = ? AND status = 1", orgId)
- err = db.Count(&total).Offset(offset).Limit(limit).Order("sort asc").Find(&list).Error
- return
- }
-
- func DeleteDiagnoseById(id int64) error {
- err := writeDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
- return err
- }
-
- func FindDiagnoseById(id int64) (*models.HisXtDiagnoseConfig, error) {
- dealer := &models.HisXtDiagnoseConfig{}
- err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
- return dealer, err
- }
-
- func GetDoseCode(dose_id int64, user_org_id int64) (error, string) {
- var data models.DictDataconfig
- err := readDb.Model(&models.DictDataconfig{}).Where(" (user_org_id = ? Or user_org_id = 0) AND parent_id = 4 AND module = 'system' AND status = 1 AND value = ?", user_org_id, dose_id).First(&data).Error
- return err, data.Code
- }
-
- func GetAllDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
-
- err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1", orgid).Find(&drug).Error
- return drug, err
- }
-
- //自动退库分装方法
-
- func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
-
- //查询该批次病人该药品出库数据
- info, _ := GetDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
- list, _ := GetDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
-
- storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
- //退库
- drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
-
- //如果剩余数量 + 退库数量 < 总入库数量
- if len(list) > 0 {
- for _, its := range list {
- //查询该批次病人该药品出库数据
- infos, _ := GetDrugAutoWarehouseOutTen(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID, its.WarehouseInfoId)
-
- //查询该药品出库批次总入库数量
- druginfo, _ := GetDrugInfoSix(its.WarehouseInfoId, infos.OrgId)
-
- var out_count int64 //该批次出库库存
- var sum_count int64 //该批次总库存
- var over_count int64 //剩余数量
-
- if druginfo.MaxUnit != druginfo.MinUnit {
- over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
- }
- if druginfo.MaxUnit == druginfo.MinUnit {
- over_count = druginfo.StockMaxNumber + druginfo.StockMinNumber
- }
-
- if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- out_count = infos.Count * drug.MinNumber
-
- }
- if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- out_count = infos.Count
- }
-
- if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
- out_count = infos.Count
- }
-
- if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- sum_count = druginfo.WarehousingCount * drug.MinNumber
- }
-
- if druginfo.MaxUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- sum_count = druginfo.WarehousingCount
- }
-
- if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
- sum_count = druginfo.WarehousingCount
- }
-
- if (over_count + out_count) <= sum_count {
- if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- //退库
- warehouseInfo := models.DrugWarehouseInfo{
- StockMinNumber: its.Count,
- }
- UpdateDrugWarehouse(its.WarehouseInfoId, warehouseInfo)
-
- //增加退库数量
- AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count)
- //出库数量减少
- UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count)
-
- }
- if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- warehouseInfo := models.DrugWarehouseInfo{
- StockMaxNumber: its.Count,
- }
- UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
-
- //增加退库数量
- AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
- //出库数量减少
- UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count*drug.MinNumber)
- }
-
- if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
- warehouseInfo := models.DrugWarehouseInfo{
- StockMaxNumber: its.Count,
- }
- UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
- //增加退库数量
- AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
- //出库数量减少
- UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count*drug.MinNumber)
- }
-
- }
- }
-
- floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
-
- if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
-
- operation_time := time.Now().Unix()
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: advice.UserOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: advice.AdviceDate,
- Dealer: info.Dealer,
- Manufacturer: info.Manufacturer,
- Type: 1,
- StorehouseId: storeHouseConfig.DrugStorehouseOut,
- IsCheck: 1,
- }
- AddSigleDrugCancelStock(&cancelStock)
-
- manufactureName, _ := GetManufactureById(info.Manufacturer)
- dealer, _ := GetDealerById(info.Dealer)
- cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
- cancelStockInfo := models.DrugCancelStockInfo{
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: advice.DrugId,
- Count: prescribingNumber,
- Status: 1,
- Ctime: ctime,
- OrgId: advice.UserOrgId,
- Type: 1,
- Manufacturer: manufactureName.ManufacturerName,
- Dealer: dealer.DealerName,
- Total: 0,
- RetailPrice: info.RetailPrice,
- RetailTotalPrice: info.RetailTotalPrice,
- Price: info.Price,
- RegisterAccount: "",
- Remark: info.Remark,
- BatchNumber: info.BatchNumber,
- MaxUnit: advice.PrescribingNumberUnit,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- BatchNumberId: info.WarehouseInfoId,
- StorehouseId: storeHouseConfig.DrugStorehouseOut,
- IsCheck: 1,
- PatientId: advice.PatientId,
- }
-
- //查询剩余库存
- stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == drug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- var count_one int64
- if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- count_one = prescribingNumber * drug.MinNumber
- }
- if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- count_one = prescribingNumber
- }
- if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
- count_one = prescribingNumber * drug.MinNumber
- }
- flow := models.DrugFlow{
- WarehousingId: info.WarehouseInfoId,
- DrugId: info.DrugId,
- Number: "",
- BatchNumber: info.BatchNumber,
- Count: count_one,
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfoId,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: info.ExpiryDate,
- ProductDate: info.ProductDate,
- MaxUnit: drug.MinUnit,
- MinUnit: "",
- AdviceId: info.AdviceId,
- StorehouseId: storeHouseConfig.DrugStorehouseOut,
- OverCount: sum_count,
- }
- CreatedCancelStock(cancelStockInfo)
- CreateDrugFlowOne(flow)
-
- //删除出库记录
- UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
- //删除流水
- UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
- }
- if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
-
- houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
-
- operation_time := time.Now().Unix()
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: advice.UserOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: advice.AdviceDate,
- Dealer: info.Dealer,
- Manufacturer: info.Manufacturer,
- Type: 1,
- StorehouseId: houseConfig.DrugStorehouseOut,
- IsCheck: 1,
- }
- AddSigleDrugCancelStock(&cancelStock)
-
- manufactureName, _ := GetManufactureById(info.Manufacturer)
- dealer, _ := GetDealerById(info.Dealer)
- cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
- cancelStockInfo := models.DrugCancelStockInfo{
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: info.DrugId,
- Count: prescribingNumber,
- Status: 1,
- Ctime: ctime,
- OrgId: advice.UserOrgId,
- Type: 1,
- Manufacturer: manufactureName.ManufacturerName,
- Dealer: dealer.DealerName,
- Total: 0,
- RetailPrice: info.RetailPrice,
- RetailTotalPrice: info.RetailTotalPrice,
- Price: info.Price,
- RegisterAccount: "",
- Remark: info.Remark,
- BatchNumber: info.BatchNumber,
- MaxUnit: advice.PrescribingNumberUnit,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- BatchNumberId: info.WarehouseInfoId,
- StorehouseId: houseConfig.DrugStorehouseOut,
- IsCheck: 1,
- }
- //查询剩余库存
- stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == drug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- var count_one int64
- if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
- count_one = prescribingNumber * drug.MinNumber
- }
- if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- count_one = prescribingNumber
- }
- if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
- count_one = prescribingNumber * drug.MinNumber
- }
-
- flow := models.DrugFlow{
- WarehousingId: info.WarehouseInfoId,
- DrugId: info.DrugId,
- Number: "",
- BatchNumber: info.BatchNumber,
- Count: count_one,
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfoId,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: info.ExpiryDate,
- ProductDate: info.ProductDate,
- MaxUnit: drug.MinUnit,
- MinUnit: "",
- AdviceId: info.AdviceId,
- StorehouseId: houseConfig.DrugStorehouseOut,
- OverCount: sum_count,
- }
- CreatedCancelStock(cancelStockInfo)
- CreateDrugFlowOne(flow)
- //删除出库记录
- UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
- //删除流水
- UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
- }
-
- if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
-
- houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
-
- operation_time := time.Now().Unix()
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: advice.UserOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: advice.AdviceDate,
- Dealer: info.Dealer,
- Manufacturer: info.Manufacturer,
- Type: 1,
- StorehouseId: houseConfig.DrugStorehouseOut,
- IsCheck: 1,
- }
- AddSigleDrugCancelStock(&cancelStock)
-
- manufactureName, _ := GetManufactureById(info.Manufacturer)
- dealer, _ := GetDealerById(info.Dealer)
- cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
- cancelStockInfo := models.DrugCancelStockInfo{
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: info.DrugId,
- Count: prescribingNumber,
- Status: 1,
- Ctime: ctime,
- OrgId: advice.UserOrgId,
- Type: 1,
- Manufacturer: manufactureName.ManufacturerName,
- Dealer: dealer.DealerName,
- Total: 0,
- RetailPrice: info.RetailPrice,
- RetailTotalPrice: info.RetailTotalPrice,
- Price: info.Price,
- RegisterAccount: "",
- Remark: info.Remark,
- BatchNumber: info.BatchNumber,
- MaxUnit: advice.PrescribingNumberUnit,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- BatchNumberId: info.WarehouseInfoId,
- StorehouseId: houseConfig.DrugStorehouseOut,
- IsCheck: 1,
- }
- //查询剩余库存
- stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == drug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- flow := models.DrugFlow{
- WarehousingId: info.WarehouseInfoId,
- DrugId: info.DrugId,
- Number: "",
- BatchNumber: info.BatchNumber,
- Count: prescribingNumber,
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfoId,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: info.ExpiryDate,
- ProductDate: info.ProductDate,
- MaxUnit: advice.PrescribingNumberUnit,
- MinUnit: "",
- AdviceId: info.AdviceId,
- StorehouseId: houseConfig.DrugStorehouseOut,
- OverCount: sum_count,
- }
- CreatedCancelStock(cancelStockInfo)
- CreateDrugFlowOne(flow)
- //删除出库记录
- UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
- //删除流水
- UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
- }
-
- //更新字典里面的库存
- stockInfo, _ := GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
- //查询改药品信息
- medical, _ := GetBaseDrugMedical(advice.DrugId)
- var sum_count_one int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count_one += its.StockMaxNumber + its.StockMinNumber
- }
- UpdateBaseDrugSumTwo(advice.DrugId, sum_count_one, advice.UserOrgId)
-
- //更新库存
- UpdateSumDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, sum_count_one)
-
- }
- return err
- }
-
- func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
-
- //查询已经出库数量
- info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId, good.OrderId)
- if len(info) > 0 {
- houseConfig, _ := GetAllStoreHouseConfig(good.UserOrgId)
-
- operation_time := time.Now().Unix()
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := FindAllCancelStockTotal(good.UserOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(good.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: good.UserOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: good.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := GetCancelStockDetailByOrderNumberOne(good.RecordDate, good.UserOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := GetLastCancelStockById(good.UserOrgId)
- for _, item := range info {
- manufacturer, _ := GetManufactureById(item.Manufacturer)
- deaerler, _ := GetDealerById(item.Dealer)
-
- cancelStockInfo := models.CancelStockInfo{
- GoodId: good.GoodId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: item.Count,
- Price: item.Price,
- Total: 0,
- ProductDate: item.ProductDate,
- ExpiryDate: item.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: good.UserOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: item.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: item.WarehouseInfotId,
- PatientId: item.PatientId,
- RecordDate: item.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- CreateCancelStockInfoOne(&cancelStockInfo)
- cancelInfo, _ := GetLastCancelStockInfoByGoodId(good.GoodId)
- goodList, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
- var over_count int64
- for _, it := range goodList {
- over_count += it.StockCount
- }
- flow := models.VmStockFlow{
- WarehousingId: item.WarehouseInfotId,
- GoodId: item.GoodId,
- Number: item.Number,
- LicenseNumber: item.LicenseNumber,
- Count: item.Count,
- UserOrgId: item.OrgId,
- PatientId: item.PatientId,
- SystemTime: item.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: item.WarehouseOutId,
- WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: item.Price,
- WarehousingDetailId: item.WarehouseInfotId,
- WarehouseOutDetailId: item.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count,
- }
- CreateStockFlowOne(flow)
-
- //回退库存
- UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
-
- //退库数量增加
- UpdateSumAddCancelCount(good.UserOrgId, good.GoodId, houseConfig.StorehouseOutInfo, good.Count)
- //出库数量减少
- UpdateSumCount(good.UserOrgId, houseConfig.StorehouseOutInfo, good.GoodId, good.Count)
- //删除出库表
- DeleteAutoRedeceDetailTenOne(good.UserOrgId, item.PatientId, item.SysRecordTime, item.GoodId, item.OrderId)
-
- goodListOne, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodListOne {
- flush_count += it.StockCount
- }
- //更新剩余库存
- UpdateSumGood(good.UserOrgId, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- }
- }
- return err
- }
-
- func CreatePatientDiagnose(diagnose models.XtPatientDiagnose) error {
-
- err := XTWriteDB().Create(&diagnose).Error
-
- return err
- }
-
- func GetPatientDiagnose(limit int64, page int64, orgid int64) (list []*models.XtPatientDiagnose, total int64, err error) {
-
- db := XTReadDB().Model(&list).Where("status =1")
-
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- offset := (page - 1) * limit
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("sort asc").Find(&list).Error
- return
- }
-
- func GetPatientDiagnoseDetail(id int64) (models.XtPatientDiagnose, error) {
-
- diagnose := models.XtPatientDiagnose{}
-
- err := XTReadDB().Where("id = ? and status =1", id).Find(&diagnose).Error
-
- return diagnose, err
- }
-
- func UpdatePatientCase(class_name string, sort int64, id int64) error {
-
- diagnose := models.XtPatientDiagnose{}
-
- err := XTReadDB().Model(&diagnose).Where("id = ? and status=1", id).Updates(map[string]interface{}{"class_name": class_name, "sort": sort}).Error
-
- return err
- }
-
- func DeletePatientDiagnose(id int64) error {
-
- err := XTWriteDB().Model(&models.XtPatientDiagnose{}).Where("id=? and status= 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
|