123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- package new_mobile_api_controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "strconv"
- "strings"
- "time"
- )
-
- type NewDialysisApiController struct {
- NewMobileBaseAPIAuthController
- }
-
- func (this *NewDialysisApiController) GetIllnesslist() {
-
- illnesslist, err := service.GetIllnessListTwo()
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "illnesslist": illnesslist,
- })
- }
-
- func (this *NewDialysisApiController) GetPatient() {
- adminInfo := this.GetMobileAdminUserInfo()
- orgid := adminInfo.Org.Id
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- patient, total, err := service.GetBloodDialysisPatient(orgid, page, limit)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "total": total,
- })
- }
-
- func (this *NewDialysisApiController) GetAllPatient() {
- fmt.Print("--------------------触发了没有")
- adminInfo := this.GetMobileAdminUserInfo()
- orgid := adminInfo.Org.Id
- page, _ := this.GetInt64("page")
- fmt.Print("page", page)
- limit, _ := this.GetInt64("limit")
- fmt.Print("limit", limit)
- patient, err := service.GetAllPatient(orgid)
- fmt.Print("err--------------------", err)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (this *NewDialysisApiController) GetGeneratedialysisno() {
- adminInfo := this.GetMobileAdminUserInfo()
- orgid := adminInfo.Org.Id
- dialysisNo := service.ChechLastDialysisNoTwo(orgid)
- //fmt.Print("机构ID",adminUserInfo.CurrentOrgId)
- if dialysisNo == 0 {
- dialysisNo = 1
- } else {
- dialysisNo++
- }
- no := strconv.FormatInt(dialysisNo, 10)
-
- rep := 3 - len(no)
-
- if rep > 0 {
- no = strings.Repeat("0", rep) + no
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "no": no,
- })
- return
- }
-
- func (this *NewDialysisApiController) SavePatient() {
- adminInfo := this.GetMobileAdminUserInfo()
- orgid := adminInfo.Org.Id
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Print("err", err)
- name := dataBody["name"].(string)
- fmt.Println("姓名", name)
- sex := int64(dataBody["sex"].(float64))
- fmt.Print("性别", sex)
- idCard := dataBody["idCard"].(string)
- fmt.Print("身份证", idCard)
- birthday := dataBody["birthday"].(string)
- births := strings.Split(birthday, "-")
- fmt.Print("生日", birthday)
- birYear, _ := strconv.Atoi(births[0])
- age := time.Now().Year() - birYear
- ages := int64(age)
- fmt.Println("age是多少", ages)
- timeLayout := "2006-01-02 15:04:05"
- theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
- birth := theTime.Unix()
- fmt.Print(birth)
- phone := dataBody["phone"].(string)
- fmt.Print("电话号码", phone)
- patientType := dataBody["result"].([]interface{})
- fmt.Print("患者标签", patientType)
- dialysis := dataBody["dialysis"].(string)
- fmt.Print("透析号", dialysis)
- patientsoure := int64(dataBody["patientsoure"].(float64))
- fmt.Print("患者来源", patientsoure)
- lapseto := int64(dataBody["lapseto"].(float64))
- fmt.Print("留置状态", lapseto)
- contagions := dataBody["resultTwo"].([]interface{})
- fmt.Print("传染病", contagions)
- adminssionNumber := dataBody["admissionNumber"].(string)
- fmt.Print("住院号", adminssionNumber)
- fistdate := dataBody["fistDate"].(string)
- fmt.Print("首次透析日期", fistdate)
- times, err := utils.ParseTimeStringToTime(timeLayout, fistdate+"00:00:00")
- fisttime := times.Unix()
- fmt.Print(fisttime)
- diagonse := dataBody["diagnose"].(string)
- fmt.Print("诊断", diagonse)
- avatar := dataBody["avatar"].(string)
- fmt.Print("头像", avatar)
- //慢性病
- requipmentId := dataBody["requipmentId"].(string)
- fmt.Print("设备ID", requipmentId)
- slowContagions := dataBody["resultThree"].([]interface{})
- fmt.Print("慢性传染病", slowContagions)
- slowDisease := int64(dataBody["slowDisease"].(float64))
- fmt.Print("slowDisease", slowDisease)
- bloodPatient := int64(dataBody["bloodPatient"].(float64))
- fmt.Print("血透病人", bloodPatient)
- slowpatient := int64(dataBody["slowPatient"].(float64))
- fmt.Print("慢病病人", slowpatient)
- memberpatient := int64(dataBody["memberPatient"].(float64))
- fmt.Print("会员病人", memberpatient)
- //会员
- memberFistDate := dataBody["memberFistDate"].(string)
- fmt.Print("首次透析日期", memberFistDate)
- membertimes, err := utils.ParseTimeStringToTime(timeLayout, memberFistDate+"00:00:00")
- memtime := membertimes.Unix()
- fmt.Print(memtime)
- patient_type := int64(dataBody["patientType"].(float64))
- fmt.Print("病种", patient_type)
- treatmentmethod := int64(dataBody["treatmentMethod"].(float64))
- fmt.Print("治疗方式", treatmentmethod)
-
- _, errcode := service.GetPatientData(phone, orgid)
- if errcode == gorm.ErrRecordNotFound {
- patients := models.Patients{
- Name: name,
- Gender: sex,
- Birthday: birth,
- Age: ages,
- Phone: phone,
- Lapseto: lapseto,
- AdmissionNumber: adminssionNumber,
- FirstDialysisDate: fisttime,
- Diagnose: diagonse,
- Source: patientsoure,
- DialysisNo: dialysis,
- UserOrgId: orgid,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- Avatar: avatar,
- }
- err := service.CreateOldPatient(&patients)
- fmt.Print("报错-------------", err)
- patient, err := service.GetLastOldPatient(7957)
- fmt.Print("病人ID", patient.ID)
- patientsNew := models.XtPatientsNew{
- Name: name,
- Gender: sex,
- Birthday: birth,
- Age: ages,
- Phone: phone,
- Lapseto: lapseto,
- AdmissionNumber: adminssionNumber,
- FirstDialysisDate: fisttime,
- Diagnose: diagonse,
- Source: patientsoure,
- DialysisNo: dialysis,
- UserOrgId: orgid,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- Avatar: avatar,
- MemberPatients: memberpatient,
- BloodPatients: bloodPatient,
- SlowPatients: slowpatient,
- BloodId: patient.ID,
- }
- err = service.CreateNewPatient(&patientsNew)
- fmt.Print("报错", err)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patient": patientsNew,
- })
- } else if errcode == nil {
- fmt.Print("病人已存在")
- return
- } else {
-
- }
- }
-
- func (this *NewDialysisApiController) GetPatientDetail() {
- id, _ := this.GetInt64("id")
- //获取病人详情信息
- detail, err := service.GetPatientDetailTwo(id)
- //获取血透医嘱管理
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patientDetail": detail,
- })
- }
-
- func (this *NewDialysisApiController) GetDoctorAdvices() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- adminInfo := this.GetMobileAdminUserInfo()
- orgid := adminInfo.Org.Id
- id, _ := this.GetInt64("id")
- fmt.Print("id", id)
- //跟据新表id获取老表id
- newPatientInfo, _ := service.GetPatientDetailTwo(id)
- //获取病人ID
- doctor_type, _ := this.GetInt64("type")
- fmt.Print("医嘱内型", doctor_type)
- start := this.GetString("startime")
- fmt.Print("start", start)
- startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
- startime := startTimes.Unix()
- fmt.Print("开始时间", startime)
- end := this.GetString("endtime")
- fmt.Print("end", end)
- endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
- endtime := endTimes.Unix()
- fmt.Print("结束时间", endtime)
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- advice, total, err := service.GetNewDoctorAdvice(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- "total": total,
- })
- }
-
- func (this *NewDialysisApiController) GetDryWeight() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- id, _ := this.GetInt64("id")
- fmt.Print("id", id)
- patient, _ := service.GetPatientDetailTwo(id)
- start := this.GetString("startime")
- startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
- startime := startTimes.Unix()
- fmt.Print("startime", startime)
- end := this.GetString("endtime")
- endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
- endtime := endTimes.Unix()
- fmt.Print("endtime", endtime)
- limit, _ := this.GetInt64("limit")
- fmt.Print("limit", limit)
- page, _ := this.GetInt64("page")
- fmt.Print("page", page)
- adminInfo := this.GetMobileAdminUserInfo()
- orgid := adminInfo.Org.Id
- dryweight, total, err := service.GetDryWeight(patient.BloodId, startime, endtime, limit, page, orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "dryweight": dryweight,
- "total": total,
- })
- }
-
- func (this *NewDialysisApiController) ToSearch() {
- adminUser := this.GetMobileAdminUserInfo()
- orgId := adminUser.Org.Id
- name := this.GetString("name")
- search, err := service.ToSearch(orgId, name)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "search": search,
- })
- }
|