123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "bytes"
- "compress/gzip"
- "encoding/json"
- "github.com/astaxie/beego"
- "net/http"
- "time"
- )
-
- type HisChargeApiController struct {
- BaseAuthAPIController
- }
-
- func HisChargeApiRegistRouters() {
- beego.Router("/api/his/chargestatistics/detail", &HisChargeApiController{}, "get:GetChargeStatisticsDetail")
- beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
- //beego.InsertFilter("/api/his/chargestatistics/detail", beego.BeforeRouter, GzipFilter)
-
- beego.Router("/api/his/patient", &HisChargeApiController{}, "get:GetAllPatient")
- //beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
-
- beego.Router("/api/his/inspectionlist/get", &HisChargeApiController{}, "get:GetHisInspectionList")
-
- beego.Router("/api/his/inspectionlisttwo/get", &HisChargeApiController{}, "get:GetHisInspectionListTwo")
-
- beego.Router("/api/his/inspectioninfo/get", &HisChargeApiController{}, "get:GetHisInspectionInfo")
-
- //发票
- beego.Router("/api/fapiao/create", &HisChargeApiController{}, "post:CreateFaPiaoRecord")
- beego.Router("/api/fapiao/modify", &HisChargeApiController{}, "post:ModifyFaPiaoRecord")
- beego.Router("/api/fapiao/list", &HisChargeApiController{}, "get:GetFaPiaoRecordList")
- beego.Router("/api/fapiao/delete", &HisChargeApiController{}, "post:DeleteFaPiaoRecord")
- beego.Router("/api/fapiao", &HisChargeApiController{}, "get:GetFaPiaoRecord")
- beego.Router("/api/fapiao/is_use", &HisChargeApiController{}, "post:UpdateFaPiaoRecordIsUse")
-
- beego.Router("/api/his/getyidiclear", &HisChargeApiController{}, "get:GetHisYidiClearRecord")
-
- beego.Router("/api/his/getexportdata", &HisChargeApiController{}, "get:GetExportData")
-
- }
-
- func (c *HisChargeApiController) GetExportData() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- adminUser := c.GetAdminUserInfo()
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
- chargePatient, err := service.GetAllChargeDetailsTwo(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": chargePatient,
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
-
- func (c *HisChargeApiController) UpdateFaPiaoRecordIsUse() {
- id, _ := c.GetInt64("id", 0)
- is_use, _ := c.GetInt64("is_use")
- if id <= 0 {
- utils.ErrorLog("id == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- record, _ := service.FindFapiaoById(id)
- adminUserInfo := c.GetAdminUserInfo()
- service.UpdateFapiaoIsUse(adminUserInfo.CurrentOrgId)
- records := models.HisFapiaoRecord{
- ID: id,
- FapiaoCode: record.FapiaoCode,
- FapiaoNumber: record.FapiaoNumber,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- IsUse: is_use,
- }
- err := service.ModifyFapiao(&records)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "fapiao_record": records,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *HisChargeApiController) CreateFaPiaoRecord() {
- fapiao_code := c.GetString("fapiao_code")
- fapiao_number := c.GetString("fapiao_number")
- if len(fapiao_code) <= 0 {
- utils.ErrorLog("len(fapiao_code) == 0")
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(fapiao_number) <= 0 {
- utils.ErrorLog("len(fapiao_number) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- record := models.HisFapiaoRecord{
- FapiaoCode: fapiao_code,
- FapiaoNumber: fapiao_number,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- IsUse: 0,
- }
-
- err, records := service.AddSigleFapiaoRecord(&record)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "fapiao_record": records,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
-
- }
-
- }
- func (c *HisChargeApiController) ModifyFaPiaoRecord() {
- id, _ := c.GetInt64("id", 0)
- fapiao_code := c.GetString("fapiao_code")
- fapiao_number := c.GetString("fapiao_number")
-
- if id <= 0 {
- utils.ErrorLog("id == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(fapiao_code) <= 0 {
- utils.ErrorLog("len(fapiao_code) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(fapiao_number) <= 0 {
- utils.ErrorLog("len(fapiao_number) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- record, _ := service.FindFapiaoById(id)
- adminUserInfo := c.GetAdminUserInfo()
- records := models.HisFapiaoRecord{
- ID: id,
- FapiaoCode: fapiao_code,
- FapiaoNumber: fapiao_number,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- IsUse: record.IsUse,
- }
-
- err := service.ModifyFapiao(&records)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "fapiao_record": records,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *HisChargeApiController) GetFaPiaoRecordList() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 7)
- adminUserInfo := c.GetAdminUserInfo()
- fapiaoRecord, total, err := service.FindAllFapiaoList(adminUserInfo.CurrentOrgId, page, limit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "fapiao_record": fapiaoRecord,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *HisChargeApiController) DeleteFaPiaoRecord() {
- id, _ := c.GetInt64("id", 0)
- err := service.DeleteFapiaoById(id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *HisChargeApiController) GetFaPiaoRecord() {
- id, _ := c.GetInt64("id", 0)
- fapiaoRecord, err := service.FindFapiaoById(id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "fapiao_record": fapiaoRecord,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *HisChargeApiController) GetChargeStatisticsDetail() {
- //c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "接口优化升级,如有数据需要,请联系客服!",
- //})
- //return
-
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- keyword := c.GetString("keyword")
- item_type, _ := c.GetInt64("type")
-
- adminUser := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
-
- switch item_type {
- case 0:
- chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
- chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
- chargeDrug = append(chargeDrug, chargeProject...)
- b, _ := structToBytes(chargeDrug)
- //cd, _ := compressData(b)
- // 使用 Gzip 压缩数据
- var compressedData bytes.Buffer
- writer := gzip.NewWriter(&compressedData)
- _, err = writer.Write(b)
- if err != nil {
- c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
- c.Ctx.WriteString(err.Error())
- return
- }
- writer.Close()
-
- // 设置响应头,表明数据经过了 Gzip 压缩
- c.Ctx.Output.Header("Content-Encoding", "gzip")
- // 发送压缩后的数据
- c.Ctx.ResponseWriter.Write(compressedData.Bytes())
- break
- case 1:
- chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
- //chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
- //chargeDrug = append(chargeDrug, chargeProject...)
- b, _ := structToBytes(chargeDrug)
- //cd, _ := compressData(b)
- // 使用 Gzip 压缩数据
- var compressedData bytes.Buffer
- writer := gzip.NewWriter(&compressedData)
- _, err = writer.Write(b)
- if err != nil {
- c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
- c.Ctx.WriteString(err.Error())
- return
- }
- writer.Close()
-
- // 设置响应头,表明数据经过了 Gzip 压缩
- c.Ctx.Output.Header("Content-Encoding", "gzip")
- // 发送压缩后的数据
- c.Ctx.ResponseWriter.Write(compressedData.Bytes())
- break
- case 2:
- //chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
- chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
- //chargeDrug = append(chargeDrug, chargeProject...)
- b, _ := structToBytes(chargeProject)
- //cd, _ := compressData(b)
- // 使用 Gzip 压缩数据
- var compressedData bytes.Buffer
- writer := gzip.NewWriter(&compressedData)
- _, err = writer.Write(b)
- if err != nil {
- c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
- c.Ctx.WriteString(err.Error())
- return
- }
- writer.Close()
-
- // 设置响应头,表明数据经过了 Gzip 压缩
- c.Ctx.Output.Header("Content-Encoding", "gzip")
- // 发送压缩后的数据
- c.Ctx.ResponseWriter.Write(compressedData.Bytes())
- break
-
- case 3:
- //chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
- chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
- //chargeDrug = append(chargeDrug, chargeProject...)
- b, _ := structToBytes(chargeProject)
- //cd, _ := compressData(b)
- // 使用 Gzip 压缩数据
- var compressedData bytes.Buffer
- writer := gzip.NewWriter(&compressedData)
- _, err = writer.Write(b)
- if err != nil {
- c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
- c.Ctx.WriteString(err.Error())
- return
- }
- writer.Close()
-
- // 设置响应头,表明数据经过了 Gzip 压缩
- c.Ctx.Output.Header("Content-Encoding", "gzip")
- // 发送压缩后的数据
- c.Ctx.ResponseWriter.Write(compressedData.Bytes())
- break
-
- }
-
- }
-
- func structToBytes(p []*models.NewChargeDetail) ([]byte, error) {
- data, err := json.Marshal(p)
- if err != nil {
- return nil, err
- }
- return data, nil
- }
-
- func compressData(data []byte) ([]byte, error) {
- var compressedData bytes.Buffer
- writer := gzip.NewWriter(&compressedData)
-
- _, err := writer.Write(data)
- if err != nil {
- return nil, err
- }
-
- err = writer.Close()
- if err != nil {
- return nil, err
- }
-
- return compressedData.Bytes(), nil
- }
-
- func (c *HisChargeApiController) GetChargeStatisticsSettle() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- keyword := c.GetString("keyword")
- item_type, _ := c.GetInt64("type")
- adminUser := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
- chargePatient, err := service.GetAllPatientChargeSettle(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": chargePatient,
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
-
- func (c *HisChargeApiController) GetHisInspectionList() {
- record_date := c.GetString("record_date")
- keyword := c.GetString("keyword")
- is_print, _ := c.GetInt64("is_print")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- tube_color, _ := c.GetInt64("tube_color")
-
- adminUser := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
-
- }
- record_time := startTime.Unix()
- var labels []*models.HisLabelPrintInfo
- var labels_two []*models.HisLabelPrintInfo
-
- var total int64
- var total_two int64
- //var err error
- if tube_color == 0 {
- labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
- } else {
- labels, total, err = service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
- labels_two, total_two, err = service.GetLabelPrintListTwo(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
- total = total + total_two
- labels = append(labels, labels_two...)
- }
-
- if err == nil {
-
- c.ServeSuccessJSON(map[string]interface{}{
- "labels": labels,
- "total": total,
- })
- return
-
- } else {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
-
- func (c *HisChargeApiController) GetHisInspectionListTwo() {
- record_date := c.GetString("record_date")
- keyword := c.GetString("keyword")
- is_print, _ := c.GetInt64("is_print")
- tube_color, _ := c.GetInt64("tube_color")
- adminUser := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
-
- }
- record_time := startTime.Unix()
- var labels []*models.HisLabelPrintInfo
- //var labels_two []*models.HisLabelPrintInfo
-
- //var total int64
- //var total_two int64
-
- labels, _, err = service.GetLabelPrintListThree(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
- //labels_two, total_two, err = service.GetLabelPrintListFour(adminUser.CurrentOrgId, record_time, is_print, keyword, tube_color)
- //total = total + total_two
- //labels = append(labels, labels_two...)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "labels": labels,
- //"total": total,
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (c *HisChargeApiController) GetHisInspectionInfo() {
- id, _ := c.GetInt64("id")
- label, err := service.GetLabelPrintInfo(id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "label": label,
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisChargeApiController) GetHisYidiClearRecord() {
- records, err := service.FindHisYidiClearRecord(c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": records,
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisChargeApiController) GetAllPatient() {
- patients, err := service.GetAllPatientTwo(c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisChargeApiController) GetStatisticsDetail() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- keyword := c.GetString("keyword")
- item_type, _ := c.GetInt64("type")
- p_type, _ := c.GetInt64("p_type")
- patinet_id, _ := c.GetInt64("patinet_id")
-
- adminUser := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
-
- chargePatient, err := service.GetPatientChargeDetails(patinet_id, adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type, p_type)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": chargePatient,
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
-
- func (c *HisChargeApiController) GetStatisticsGather() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- keyword := c.GetString("keyword")
- item_type, _ := c.GetInt64("type")
- adminUser := c.GetAdminUserInfo()
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
-
- chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": chargePatient,
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
|