123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- package controllers
-
- import (
- "Xcx_New/enums"
- "Xcx_New/models"
- "Xcx_New/service"
- "Xcx_New/utils"
- "fmt"
- "strconv"
- "strings"
- "time"
-
- "github.com/astaxie/beego"
- )
-
- func PatientDataConfigAPIControllerRegistRouters() {
- beego.Router("/api/patient/courses", &PatientDataConfigAPIController{}, "get:Courses")
- beego.Router("/api/patient/course/create", &PatientDataConfigAPIController{}, "get:CreateCourse")
- beego.Router("/api/patient/course/delete", &PatientDataConfigAPIController{}, "post:DeleteCourse")
- beego.Router("/api/patient/course/modify", &PatientDataConfigAPIController{}, "get:ModifyCourse")
-
- beego.Router("/api/patient/rescues", &PatientDataConfigAPIController{}, "get:Rescues")
- beego.Router("/api/patient/rescue/create", &PatientDataConfigAPIController{}, "post:CreateRescue")
- beego.Router("/api/patient/rescue/delete", &PatientDataConfigAPIController{}, "post:DeleteRescue")
- }
-
- type PatientDataConfigAPIController struct {
- BaseAuthAPIController
- }
-
- // /api/patient/courses [get]
- // @param patient_id:int
- // @param start_time:string (yyyy-MM-dd)
- // @param end_time:string (yyyy-MM-dd)
- func (this *PatientDataConfigAPIController) Courses() {
- patientID, _ := this.GetInt64("patient_id")
- startTimeYMDStr := this.GetString("start_time")
- endTimeYMDStr := this.GetString("end_time")
- if patientID <= 0 || len(startTimeYMDStr) == 0 || len(endTimeYMDStr) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTimeYMDHmsStr := endTimeYMDStr + " 23:59:59"
- startTime, parseStartTimeErr := utils.ParseTimeStringToTime("2006-01-02", startTimeYMDStr)
- endTime, parseEndTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
- if parseStartTimeErr != nil || parseEndTimeErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
- return
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- records, getRecordsErr := service.GetPatientCourseOfDisease(adminUserInfo.CurrentOrgId, patientID, startTime.Unix(), endTime.Unix())
- if getRecordsErr != nil {
- this.ErrorLog("获取患者病程记录失败:%v", getRecordsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- admins, getAllAdminsErr := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
- if getAllAdminsErr != nil {
- this.ErrorLog("获取所有管理员失败:%v", getAllAdminsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "records": records,
- "doctors": admins,
- })
- }
-
- // /api/patient/course/create [post]
- // @param patient_id:int
- // @param content:string
- func (this *PatientDataConfigAPIController) CreateCourse() {
- patientID, _ := this.GetInt64("patient_id")
- fmt.Println(patientID)
- content := this.GetString("content")
- fmt.Println("content22222222222222222222", content)
- record_time_str := this.GetString("record_time")
- title := this.GetString("title")
-
- if patientID <= 0 || len(content) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(record_time_str) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", record_time_str)
-
- adminUserInfo := this.GetAdminUserInfo()
- patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- now := time.Now().Unix()
- record := models.PatientDiseaseCourse{
- OrgID: adminUserInfo.CurrentOrgId,
- PatientID: patientID,
- Recorder: adminUserInfo.AdminUser.Id,
- RecordTime: checkDate.Unix(),
- Content: content,
- Status: 1,
- CreateTime: now,
- ModifyTime: now,
- Title: title,
- }
-
- createErr := service.CreatePatientCourseOfDisease(&record)
- if createErr != nil {
- this.ErrorLog("创建患者病程记录失败:%v", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- })
- }
-
- // /api/patient/course/delete
- // @param patient_id:int
- // @param ids:string 一个或多个record_id以逗号相隔 ("1,3,7")
- func (this *PatientDataConfigAPIController) DeleteCourse() {
- patientID, _ := this.GetInt64("patient_id")
- idsStr := this.GetString("ids")
- if patientID <= 0 || len(idsStr) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- recordIDStrs := strings.Split(idsStr, ",")
- recordIDs := make([]int64, 0, len(recordIDStrs))
- for _, idStr := range recordIDStrs {
- id, parseErr := strconv.Atoi(idStr)
- if parseErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordIDs = append(recordIDs, int64(id))
- }
-
- deleteErr := service.DeletePatientCoursesInBatch(adminUserInfo.CurrentOrgId, patientID, recordIDs)
- if deleteErr != nil {
- this.ErrorLog("删除患者病程记录失败:%v", deleteErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(nil)
- }
-
- // /api/patient/rescues [get]
- // @param patient_id:int
- // @param start_time:string (yyyy-MM-dd)
- // @param end_time:string (yyyy-MM-dd)
- func (this *PatientDataConfigAPIController) Rescues() {
- patientID, _ := this.GetInt64("patient_id")
- startTimeYMDStr := this.GetString("start_time")
- endTimeYMDStr := this.GetString("end_time")
- if patientID <= 0 || len(startTimeYMDStr) == 0 || len(endTimeYMDStr) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTimeYMDHmsStr := endTimeYMDStr + " 23:59:59"
- startTime, parseStartTimeErr := utils.ParseTimeStringToTime("2006-01-02", startTimeYMDStr)
- endTime, parseEndTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
- if parseStartTimeErr != nil || parseEndTimeErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
- return
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- records, getRecordsErr := service.GetPatientRescueRecords(adminUserInfo.CurrentOrgId, patientID, startTime.Unix(), endTime.Unix())
- if getRecordsErr != nil {
- this.ErrorLog("获取患者抢救记录失败:%v", getRecordsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- admins, getAllAdminsErr := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
- if getAllAdminsErr != nil {
- this.ErrorLog("获取所有管理员失败:%v", getAllAdminsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "records": records,
- "doctors": admins,
- })
- }
-
- // /api/patient/rescue/create [post]
- // @param patient_id:int
- // @param content:string
- func (this *PatientDataConfigAPIController) CreateRescue() {
- patientID, _ := this.GetInt64("patient_id")
- content := this.GetString("content")
- if patientID <= 0 || len(content) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- now := time.Now().Unix()
- record := models.PatientRescueRecord{
- OrgID: adminUserInfo.CurrentOrgId,
- PatientID: patientID,
- Recorder: adminUserInfo.AdminUser.Id,
- RecordTime: now,
- Content: content,
- Status: 1,
- CreateTime: now,
- ModifyTime: now,
- }
-
- createErr := service.CreatePatientRescueRecord(&record)
- if createErr != nil {
- this.ErrorLog("创建患者抢救记录失败:%v", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- })
- }
-
- // /api/patient/rescue/delete
- // @param patient_id:int
- // @param ids:string 一个或多个record_id以逗号相隔 ("1,3,7")
- func (this *PatientDataConfigAPIController) DeleteRescue() {
- patientID, _ := this.GetInt64("patient_id")
- idsStr := this.GetString("ids")
- if patientID <= 0 || len(idsStr) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- recordIDStrs := strings.Split(idsStr, ",")
- recordIDs := make([]int64, 0, len(recordIDStrs))
- for _, idStr := range recordIDStrs {
- id, parseErr := strconv.Atoi(idStr)
- if parseErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordIDs = append(recordIDs, int64(id))
- }
-
- deleteErr := service.DeletePatientResuceRecordsInBatch(adminUserInfo.CurrentOrgId, patientID, recordIDs)
- if deleteErr != nil {
- this.ErrorLog("删除患者抢救记录失败:%v", deleteErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(nil)
- }
-
- func (this *PatientDataConfigAPIController) ModifyCourse() {
- patientID, _ := this.GetInt64("patient_id")
- content := this.GetString("content")
- id, _ := this.GetInt64("id", 0)
- record_time_str := this.GetString("record_time")
- title := this.GetString("title")
-
- if patientID <= 0 || len(content) == 0 || id == 0 || len(record_time_str) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", record_time_str)
-
- adminUserInfo := this.GetAdminUserInfo()
- patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- now := time.Now().Unix()
-
- record := models.PatientDiseaseCourse{
- ID: id,
- OrgID: adminUserInfo.CurrentOrgId,
- PatientID: patientID,
- Recorder: adminUserInfo.AdminUser.Id,
- Content: content,
- Status: 1,
- CreateTime: now,
- ModifyTime: now,
- Title: title,
- RecordTime: checkDate.Unix(),
- }
-
- createErr := service.ModifyPatientCourses(&record)
- if createErr != nil {
- this.ErrorLog("创建患者抢救记录失败:%v", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- })
- }
|