123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- package new_mobile_api_controllers
-
- import (
- "XT_New/controllers"
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "strconv"
- "time"
- )
-
- type CommonApiController struct {
- controllers.BaseAuthAPIController
- }
-
- func (this *CommonApiController) GetInspectionMajor() {
-
- major, err := service.GetInspectionMajor(0)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspection": major,
- })
- }
-
- func (this *CommonApiController) GetInspectionMinor() {
- id, _ := this.GetInt64("id")
- minor, err := service.GetInspectionMinor(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspection": minor,
- })
- }
-
- func (this *CommonApiController) GetInspectionRange() {
- id, _ := this.GetInt64("id")
- fmt.Println("id", id)
- inspectionRange, err := service.GetInspectionRange(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspectionRange": inspectionRange,
- })
- }
-
- func (this *CommonApiController) SaveConfiguration() {
- adminInfo := this.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
- fmt.Println("大项", inspectionmajor)
- inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
- fmt.Println("小项", inspectionMinor)
- minrange := dataBody["min_range"].(string)
- fmt.Println("minragne", minrange)
- largerange := dataBody["large_range"].(string)
- fmt.Println("largerange", largerange)
- sort := dataBody["sort"].(string)
- sorts, err := strconv.ParseInt(sort, 10, 64)
- fmt.Println("sort", sort)
-
- _, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
- if errcode == gorm.ErrRecordNotFound {
- standard := models.XtQualityControlStandard{
- InspectionMajor: inspectionmajor,
- InspectionMinor: inspectionMinor,
- MinRange: minrange,
- LargeRange: largerange,
- Sort: sorts,
- UserOrgId: orgid,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- }
- fmt.Println(standard)
- err = service.SaveInspection(&standard)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "standard": standard,
- })
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
-
- func (this *CommonApiController) GetConfigurationlist() {
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- configurationlist, total, err := service.GetConfigurationlist(orgid, limit, page)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configurationlist": configurationlist,
- "total": total,
- })
- }
-
- func (this *CommonApiController) GetConfigurationDetail() {
- id, _ := this.GetInt64("id")
- fmt.Println("id是", id)
- detail, err := service.GetConfigurationDetail(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configurationdetail": detail,
- })
- }
-
- func (this *CommonApiController) GetAllInspectionminor() {
-
- minor, err := service.GetAllInspectionMinor(0)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "minor": minor,
- })
- }
-
- func (this *CommonApiController) UpdateConfiguration() {
- id, _ := this.GetInt64("id")
- fmt.Println("id", id)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
- fmt.Println("大项", inspectionmajor)
- inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
- fmt.Println("小项", inspectionMinor)
- minrange := dataBody["min_range"].(string)
- fmt.Println("minragne", minrange)
- largerange := dataBody["large_range"].(string)
- fmt.Println("largerange", largerange)
- sort := int64(dataBody["sort"].(float64))
- fmt.Println("排序", sort)
- adminInfo := this.GetAdminUserInfo()
- orgId := adminInfo.CurrentOrgId
- configuration, err := service.GetConfigurationByIdTwo(inspectionmajor, inspectionMinor, orgId)
- fmt.Println("err", err)
- if configuration.ID > 0 && configuration.ID != id {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- standard := models.XtQualityControlStandard{
- InspectionMajor: inspectionmajor,
- InspectionMinor: inspectionMinor,
- MinRange: minrange,
- LargeRange: largerange,
- Sort: sort,
- }
- err = service.UpdarteConfiguration(&standard, id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "standard": standard,
- })
- }
-
- func (this *CommonApiController) DeleteConfiguration() {
- id, _ := this.GetInt64("id")
- err := service.DeleteConfiguration(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
- return
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *CommonApiController) GetAllInspectiondata() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
-
- //查询该机构是否有数据
- _, errcode := service.GetAllInspectionData(orgid)
- if errcode == gorm.ErrRecordNotFound {
- inspection, err := service.GetAllInspectiondatatwo(0)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspection": inspection,
- })
- } else if errcode == nil {
- inspection, err := service.GetAllInspectiondatatwo(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspection": inspection,
- })
- }
-
- }
-
- func (this *CommonApiController) SaveCheckConfiguration() {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
- fmt.Println("大项", inspectionmajor)
- frequency := dataBody["frequency"].(string)
- fmt.Println("凭次", frequency)
- sort := dataBody["sort"].(string)
- sorts, err := strconv.ParseInt(sort, 10, 64)
- fmt.Println("sort", sort)
- _, errcode := service.GetInspectionMajorById(inspectionmajor, orgid)
- if errcode == gorm.ErrRecordNotFound {
- configuration := models.XtCheckConfiguration{
- InspectionMajor: inspectionmajor,
- InspectionFrequency: frequency,
- Sort: sorts,
- UserOrgId: orgid,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- }
- err := service.CreateCheckConfiguration(&configuration)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configuration": configuration,
- })
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (this *CommonApiController) GetAllCheckList() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- fmt.Println("org", orgid)
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- checkList, total, err := service.GetAllCheckList(orgid, page, limit)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "checklist": checkList,
- "total": total,
- })
- }
-
- func (this *CommonApiController) GetCheckdetail() {
-
- id, _ := this.GetInt64("id")
- detail, err := service.GetCheckDetail(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "checkdetail": detail,
- })
- }
-
- func (this *CommonApiController) UpdateCheck() {
- id, _ := this.GetInt64("id")
- fmt.Println(id)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
- fmt.Println("大项", inspectionmajor)
- frequency := dataBody["frequency"].(string)
- fmt.Println("凭次", frequency)
- sort := int64(dataBody["sort"].(float64))
- fmt.Println("sort", sort)
- adminInfo := this.GetAdminUserInfo()
- orgId := adminInfo.CurrentOrgId
- Inspection, err := service.GetInspectionMajorByIdTwo(inspectionmajor, orgId)
- if Inspection.ID > 0 && Inspection.ID != id {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- configuration := models.XtCheckConfiguration{
- InspectionMajor: inspectionmajor,
- InspectionFrequency: frequency,
- Sort: sort,
- }
-
- err = service.UpdateCheck(&configuration, id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configuration": configuration,
- })
- }
-
- func (this *CommonApiController) DeleteCheck() {
- id, _ := this.GetInt64("id")
- err := service.DeleteCheck(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
- return
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *CommonApiController) GetDialysisModeType() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startime := this.GetString("startime")
- endtime := this.GetString("endtime")
- fmt.Println("endtime", endtime)
- startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
- startimes := startTimes.Unix()
- // fmt.Println("startime",startimes)
- endtimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 00:00:00", loc)
- endtimeData := endtimes.Unix()
- // fmt.Println("结束日期",endtimeData)
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- //统计透析总量
- _, total, _ := service.GetDialysiTotal(startimes, endtimeData, orgid)
-
- modeType, err := service.GetDialysisCountMode(startimes, endtimeData, orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "modetype": modeType,
- })
- }
-
- func (this *CommonApiController) GetTotalLapseCount() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- startime, _ := this.GetInt64("startime")
- fmt.Println("startime", startime)
- endtime, _ := this.GetInt64("endtime")
- fmt.Println("endtime", endtime)
-
- //统计一个月内转出的病人
- //patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
- //统计该机构的转出人数
- patients, total, err := service.GetTotalRollOutPatients(orgid)
- //统计总共病人
- // _, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
- count := service.GetPatientTotalCount(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- "total": total,
- "count": count,
- })
- }
-
- func (this *CommonApiController) GetTotalSexCount() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- fmt.Println("orgid", orgid)
- startime, _ := this.GetInt64("startime")
- fmt.Println("开始时间", startime)
- endtime, _ := this.GetInt64("endtime")
- fmt.Println("结束时间", endtime)
- total := service.GetPatientTotalCount(orgid)
- _, totalSex, err := service.GetManPatientTotal(orgid)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "totalSex": totalSex,
- })
- }
-
- func (this *CommonApiController) GetTotalInfectiouscount() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- fmt.Println("orgid", orgid)
- startime, _ := this.GetInt64("startime")
- fmt.Println("开始时间", startime)
- endtime, _ := this.GetInt64("endtime")
- fmt.Println("结束时间", endtime)
- //统计透析总人数
- total := service.GetPatientTotalCount(orgid)
- //统计透析人数传染病所占比例
- count, err := service.GetPatientInfectiousCount(orgid)
- //统计其他
- _, otherTotal, err := service.GetPatientOtherInfectious(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "count": count,
- "otherTotal": otherTotal,
- })
- }
-
- func (this *CommonApiController) GetTotalAgeCount() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- fmt.Println("orgid", orgid)
- startime, _ := this.GetInt64("startime")
- fmt.Println("开始时间", startime)
- endtime, _ := this.GetInt64("endtime")
- fmt.Println("结束时间", endtime)
- //统计透析总人数
- total := service.GetPatientTotalCount(orgid)
- agecount, err := service.GetTotalAgeCount(orgid)
- //two, err := service.GetTotalAgeCountTwo(orgid, startime, endtime)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "ageCount": agecount,
- })
- }
-
- func (this *CommonApiController) GetTotalDialysisCount() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- fmt.Println("org", orgid)
- startime, _ := this.GetInt64("startime")
- fmt.Println(startime)
- endtime, _ := this.GetInt64("endtime")
- fmt.Println(endtime)
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- fmt.Println("parseDateErr", parseDateErr)
- nowtime := recordDate.Unix()
- //统计透析总人数
- total := service.GetPatientTotalCount(orgid)
- fmt.Println("total", total)
- //获取该机构下的所有病人数据
- patients, err := service.GetTotalDialysisAgeCount(orgid)
- fmt.Println("patients", patients)
-
- //统计透年龄
- dataage, _ := service.GetDialysisAgeData(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "patients": patients,
- "nowtime": nowtime,
- "dataage": dataage,
- })
- }
-
- func (this *CommonApiController) GetCurentOrgPatients() {
-
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- patients, err := service.GetCurentOrgPatients(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- }
-
- func (this *CommonApiController) GetDialysislist() {
- startime := this.GetString("startime")
- fmt.Println("startime", startime)
- endtime := this.GetString("endtime")
- fmt.Println("enditme", endtime)
-
- startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
- fmt.Println("parseDateErr", parseDateErr)
- statime := startDate.Unix()
- fmt.Println("开始时间", statime)
- endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
-
- entime := endDate.Unix()
- fmt.Println("开始时间", statime)
- page, _ := this.GetInt64("page")
- fmt.Println("page", page)
- limit, _ := this.GetInt64("limit")
- fmt.Println("limit", limit)
- adminUser := this.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
-
- dialysislist, total, err := service.GetDialysisList(statime, entime, page, limit, orgId)
- fmt.Println("err", err)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "dialysislist": dialysislist,
- "total": total,
- })
- }
-
- func (this *CommonApiController) GetLastSort() {
-
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- standard, err := service.GetLastSort(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "standard": standard,
- })
- }
-
- func (this *CommonApiController) GetLastCheckList() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- checkList, err := service.GetLastCheckList(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "checkList": checkList,
- })
- }
|