package controllers

import (
	"XT_New/enums"
	"XT_New/models"
	"XT_New/service"
	"encoding/json"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/jinzhu/gorm"
	"reflect"
	"strconv"
	"time"
)

func SignWeighAPIControllerRegistRouters() {
	beego.Router("/api/sign/patients", &SignWeighAPIController{}, "Get:GetPatients")
	beego.Router("/api/sign/patientsign", &SignWeighAPIController{}, "Get:GetPatientSign")

	beego.Router("/api/signweign", &SignWeighAPIController{}, "Post:EditPatientSign")

	beego.Router("/api/sign/getDialysisInforInfomation", &SignWeighAPIController{}, "Get:GetPatientList")

	beego.Router("/api/sign/getDialysisAfterInfomation", &SignWeighAPIController{}, "Get:GetInforByPatientId")

	beego.Router("/api/sign/savaData", &SignWeighAPIController{}, "Post:SaveData")

	beego.Router("/api/sign/editdata", &SignWeighAPIController{}, "Post:EditData")

	beego.Router("/api/sigh/sighdata", &SignWeighAPIController{}, "Post:Sighdata")

	beego.Router("/api/sign/updateSignweight", &SignWeighAPIController{}, "Post:UpdateSignweight")

}

type SignWeighAPIController struct {
	BaseAuthAPIController
}

// /api/sign/patients [get]
func (c *SignWeighAPIController) GetPatients() {
	keywrods := c.GetString("keywords")
	fmt.Println("关键字" + keywrods)
	scheduleType, _ := c.GetInt64("schedule_type", 0)
	needScheduleType, _ := c.GetInt64("need_schedule_type", 0)
	nowDateTime := time.Now()
	nowDate := nowDateTime.Format("2006-01-02")
	today := nowDate
	nowDate += " 00:00:00"

	//认为没有选择{0:'全部'，1:'上午',2:'下午'3:'晚上' }中的一个
	if scheduleType < 0 || scheduleType > 3 {
		nowH := nowDateTime.Hour()

		if nowH < 12 {
			scheduleType = 1
		} else if nowH < 18 {
			scheduleType = 2
		} else {
			scheduleType = 3
		}
	}

	timeLayout := "2006-01-02"
	loc, _ := time.LoadLocation("Local")
	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
		return
	}
	dateTime := theTime.Unix()
	fmt.Println("dataTime是多少", dateTime)
	adminUserInfo := c.GetAdminUserInfo()

	patients, err := service.GetSignPatients(adminUserInfo.CurrentOrgId, keywrods, dateTime, scheduleType)

	fmt.Println("病人信息", patients)
	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
		return
	}

	panel := make(map[int64]map[string]int64, 0)
	if needScheduleType == 1 {
		panel, _ = service.GetSignPanels(adminUserInfo.CurrentOrgId, dateTime)
		fmt.Println("panel是什么", panel)
	}

	c.ServeSuccessJSON(map[string]interface{}{
		"patients":      patients,
		"today":         today,
		"schedule_type": scheduleType,
		"panel":         panel,
	})
	return
}

func (c *SignWeighAPIController) GetPatientSign() {
	patientID, _ := c.GetInt64("patient_id", 0)
	dateTime := c.GetString("date_time")
	timeLayout := "2006-01-02"
	loc, _ := time.LoadLocation("Local")
	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	dateTimeStam := theTime.Unix()

	adminUserInfo := c.GetAdminUserInfo()

	sign, err := service.GetPatientDateSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)

	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
		return
	}

	c.ServeSuccessJSON(map[string]interface{}{
		"sign": sign,
	})
	return
}

func (c *SignWeighAPIController) EditPatientSign() {
	patientID, _ := c.GetInt64("patient_id", 0)
	dateTime := c.GetString("date_time")

	timeLayout := "2006-01-02"
	loc, _ := time.LoadLocation("Local")
	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	dateTimeStam := theTime.Unix()

	adminUserInfo := c.GetAdminUserInfo()

	sign, err := service.GetPatientDateSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)

	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
		return
	}

	var signForm models.SigninAndWeigh
	if sign != nil {
		signForm = *sign
		signForm.UpdatedTime = time.Now().Unix()

	} else {
		signForm.PatientId = patientID
		signForm.RecordDate = dateTimeStam
		signForm.UserOrgId = adminUserInfo.CurrentOrgId
		signForm.SignTime = time.Now().Unix()
		signForm.Status = 1
		signForm.CreatedTime = time.Now().Unix()
		signForm.UpdatedTime = time.Now().Unix()
	}

	signData := make(map[string]interface{}, 0)
	err = json.Unmarshal(c.Ctx.Input.RequestBody, &signData)
	if err != nil {
		//utils.ErrorLog(err.Error())
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
	}

	if signData["dry_weight"] == nil || reflect.TypeOf(signData["dry_weight"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	dryWeight, _ := strconv.ParseFloat(signData["dry_weight"].(string), 64)
	signForm.DryWeight = dryWeight

	if signData["clothes_weight"] == nil || reflect.TypeOf(signData["clothes_weight"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	clothesWeight, _ := strconv.ParseFloat(signData["clothes_weight"].(string), 64)
	signForm.ClothingWeight = clothesWeight

	if signData["weigh_before"] == nil || reflect.TypeOf(signData["weigh_before"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	weighBefore, _ := strconv.ParseFloat(signData["weigh_before"].(string), 64)
	signForm.WeighingBefore = weighBefore

	if signData["dehydrated_weight"] == nil || reflect.TypeOf(signData["dehydrated_weight"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	dehydratedWeight, _ := strconv.ParseFloat(signData["dehydrated_weight"].(string), 64)
	signForm.TargetDewatering = dehydratedWeight

	if signData["weight_before"] == nil || reflect.TypeOf(signData["weight_before"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	weightBefore, _ := strconv.ParseFloat(signData["weight_before"].(string), 64)
	signForm.WeightBefore = weightBefore

	if signData["temperature_before"] == nil || reflect.TypeOf(signData["temperature_before"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	temperatureBefore, _ := strconv.ParseFloat(signData["temperature_before"].(string), 64)
	signForm.TemperatureBefore = temperatureBefore

	if signData["pulse_rate_before"] == nil || reflect.TypeOf(signData["pulse_rate_before"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	pulseRateBefore, _ := strconv.ParseFloat(signData["pulse_rate_before"].(string), 64)
	signForm.PulseFrequencyBefore = pulseRateBefore

	if signData["respiratory_rate_before"] == nil || reflect.TypeOf(signData["respiratory_rate_before"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	respiratoryRateBefore, _ := strconv.ParseFloat(signData["respiratory_rate_before"].(string), 64)
	signForm.BreathingRateBefore = respiratoryRateBefore

	if signData["DBP_before"] == nil || reflect.TypeOf(signData["DBP_before"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	DBPBefore, _ := strconv.ParseFloat(signData["DBP_before"].(string), 64)
	signForm.DiastolicBloodPressureBefore = DBPBefore

	if signData["SBP_before"] == nil || reflect.TypeOf(signData["SBP_before"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	SBPBefore, _ := strconv.ParseFloat(signData["SBP_before"].(string), 64)
	signForm.SystolicBloodPressureBefore = SBPBefore

	if signData["weigh_after"] == nil || reflect.TypeOf(signData["weigh_after"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	weighAfter, _ := strconv.ParseFloat(signData["weigh_after"].(string), 64)
	signForm.WeighingAfter = weighAfter

	if signData["weight_reduce_after"] == nil || reflect.TypeOf(signData["weight_reduce_after"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	weightReduceAfter, _ := strconv.ParseFloat(signData["weight_reduce_after"].(string), 64)
	signForm.WeightLoss = weightReduceAfter

	if signData["weight_after"] == nil || reflect.TypeOf(signData["weight_after"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	weightAfter, _ := strconv.ParseFloat(signData["weight_after"].(string), 64)
	signForm.WeightAfter = weightAfter

	if signData["temperature_after"] == nil || reflect.TypeOf(signData["temperature_after"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	temperatureAfter, _ := strconv.ParseFloat(signData["temperature_after"].(string), 64)
	signForm.TemperatureAfter = temperatureAfter

	if signData["pulse_rate_after"] == nil || reflect.TypeOf(signData["pulse_rate_after"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	pulseRateAfter, _ := strconv.ParseFloat(signData["pulse_rate_after"].(string), 64)
	signForm.PulseFrequencyAfter = pulseRateAfter

	if signData["respiratory_rate_after"] == nil || reflect.TypeOf(signData["respiratory_rate_after"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	respiratoryRateAfter, _ := strconv.ParseFloat(signData["respiratory_rate_after"].(string), 64)
	signForm.BreathingRateAfter = respiratoryRateAfter

	if signData["DBP_after"] == nil || reflect.TypeOf(signData["DBP_after"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	DBPAfter, _ := strconv.ParseFloat(signData["DBP_after"].(string), 64)
	signForm.DiastolicBloodPressureAfter = DBPAfter

	if signData["SBP_after"] == nil || reflect.TypeOf(signData["SBP_after"]).String() != "string" {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	SBPAfter, _ := strconv.ParseFloat(signData["SBP_after"].(string), 64)
	signForm.SystolicBloodPressureAfter = SBPAfter

	if signForm.WeighingAfter > 0 {
		signForm.WeighTime = time.Now().Unix()
	}
	if signForm.WeighingBefore > 0 {
		signForm.WeighBeforeTime = time.Now().Unix()
	}

	err = service.EditPatientSign(&signForm)

	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
		return
	}

	c.ServeSuccessJSON(map[string]interface{}{
		"sign": signForm,
	})
	return
}

func (c *SignWeighAPIController) GetPatientList() {
	patientID, _ := c.GetInt64("patient_id", 0)
	fmt.Println("patientID是设么", patientID)
	adminUserInfo := c.GetAdminUserInfo()
	nowDateTime := time.Now()
	nowDate := nowDateTime.Format("2006-01-02")
	nowDate += " 00:00:00"
	timeLayout := "2006-01-02"
	loc, _ := time.LoadLocation("Local")
	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
	datetime := theTime.Unix()

	list := service.GetPatientInformationList(adminUserInfo.CurrentOrgId, patientID, datetime)
	c.ServeSuccessJSON(map[string]interface{}{
		"patientlist": list,
	})
	return
}

func (c *SignWeighAPIController) GetInforByPatientId() {
	patientID, _ := c.GetInt64("patient_id", 0)
	adminUserInfo := c.GetAdminUserInfo()
	nowDateTime := time.Now()
	nowDate := nowDateTime.Format("2006-01-02")
	nowDate += " 00:00:00"
	timeLayout := "2006-01-02"
	loc, _ := time.LoadLocation("Local")
	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
	datetime := theTime.Unix()
	patient := service.GetInforByPatient(adminUserInfo.CurrentOrgId, patientID, datetime)
	fmt.Println("patient是什么", patient)
	c.ServeSuccessJSON(map[string]interface{}{
		"patientinfor": patient,
	})
}

func (c *SignWeighAPIController) SaveData() {
	adminUserInfo := c.GetAdminUserInfo()
	orgId := adminUserInfo.CurrentOrgId
	patient_id, _ := c.GetInt64("patient_id", 0)
	weight_before, _ := c.GetFloat("weight_before", 0)
	dry_weight, _ := c.GetFloat("dry_weight", 0)
	temperature, _ := c.GetFloat("temperature", 0)
	pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
	breathing_rate, _ := c.GetFloat("breathing_rate", 0)
	systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
	diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)

	predialysisevaluation := &models.PredialysisEvaluation{
		WeightBefore:           weight_before,
		DryWeight:              dry_weight,
		Temperature:            temperature,
		PulseFrequency:         pulse_frequency,
		BreathingRate:          breathing_rate,
		SystolicBloodPressure:  systolic_blood_pressure,
		DiastolicBloodPressure: diastolic_blood_pressure,
	}
	data := service.SaveData(predialysisevaluation, patient_id, orgId)
	c.ServeSuccessJSON(map[string]interface{}{
		"params": data,
	})
}

func (c *SignWeighAPIController) EditData() {
	adminUserInfo := c.GetAdminUserInfo()
	orgId := adminUserInfo.CurrentOrgId
	patient_id, _ := c.GetInt64("patient_id", 0)
	weight_after, _ := c.GetFloat("weight_after", 0)
	dry_weight, _ := c.GetFloat("dry_weight", 0)
	temperature, _ := c.GetFloat("temperature", 0)
	pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
	breathing_rate, _ := c.GetFloat("breathing_rate", 0)
	systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
	diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)

	assessmentafterdislysis := &models.AssessmentAfterDislysis{
		WeightAfter:            weight_after,
		DryWeight:              dry_weight,
		Temperature:            temperature,
		PulseFrequency:         pulse_frequency,
		BreathingRate:          breathing_rate,
		SystolicBloodPressure:  systolic_blood_pressure,
		DiastolicBloodPressure: diastolic_blood_pressure,
	}
	editdata := service.Editdata(assessmentafterdislysis, patient_id, orgId)
	c.ServeSuccessJSON(map[string]interface{}{
		"params": editdata,
	})
}

func (c *SignWeighAPIController) Sighdata() {
	fmt.Println("哈哈哈哈哈哈哈哈哈哈")
	patientID, _ := c.GetInt64("patient_id", 0)
	fmt.Println("patientID", patientID)
	dateTime := c.GetString("date_time")
	fmt.Println(patientID, dateTime)

	timeLayout := "2006-01-02"
	loc, _ := time.LoadLocation("Local")
	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	dateTimeStam := theTime.Unix()
	fmt.Println("datatimestam是什么", dateTimeStam)
	adminUserInfo := c.GetAdminUserInfo()
	fmt.Println(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
	sign, errord := service.GetSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
	fmt.Println("sigh是什么东西", sign)
	fmt.Println(err)
	weighbefore, _ := c.GetFloat("weight_before", 0)
	dryweightbefore, _ := c.GetFloat("dry_weight", 0)
	temperaturebefore, _ := c.GetFloat("temperature", 0)
	pulsefrequencybefore, _ := c.GetFloat("pulse_frequency", 0)
	breathinratebefore, _ := c.GetFloat("breathing_rate", 0)
	systolicbloodpressurebefore, _ := c.GetFloat("systolic_blood_pressure", 0)
	diastorlicbloodpressurebefore, _ := c.GetFloat("diastolic_blood_pressure", 0)
	weightafter, _ := c.GetFloat("weight_after", 0)
	temperatureafter, _ := c.GetFloat("temperatureafter", 0)
	pulsefrequencyafter, _ := c.GetFloat("pulse_frequencyafter", 0)
	breathingrateafter, _ := c.GetFloat("breathing_rateafter", 0)
	systolicbloodpressureafter, _ := c.GetFloat("systolic_blood_pressureafter", 0)
	diastolicbloodpressureafter, _ := c.GetFloat("diastolic_blood_pressureafter", 0)
	fmt.Println("请查看数据")
	fmt.Println("透前称重:", weighbefore, "干体重:", dryweightbefore, "透前温度", temperaturebefore, "透前脉搏", pulsefrequencybefore, "透前呼吸", breathinratebefore, "透前舒张压", systolicbloodpressurebefore, "透前伸缩呀", diastorlicbloodpressurebefore)
	fmt.Println("透后体重", weightafter, "透后温度", temperatureafter, "透后脉搏", pulsefrequencyafter, "透后呼吸", breathingrateafter, "透后舒张压", systolicbloodpressureafter, "透后圣索亚", diastolicbloodpressureafter)

	var sighForm models.SignWeight

	sighForm.WeightBefore = weighbefore
	sighForm.DryWeightBefore = dryweightbefore
	sighForm.TemperatureBefore = temperaturebefore
	sighForm.PulseFrequencyBefore = pulsefrequencybefore
	sighForm.BreathingRateBefore = breathinratebefore
	sighForm.SystolicBloodPressureBefore = systolicbloodpressurebefore
	sighForm.DiastolicBloodPressureBefore = diastorlicbloodpressurebefore
	sighForm.WeightAfter = weightafter
	sighForm.TemperatureAfter = temperatureafter
	sighForm.PulseFrequencyAfter = pulsefrequencyafter
	sighForm.BreathingRateAfter = breathingrateafter
	sighForm.SystolicBloodPressureAfter = systolicbloodpressureafter
	sighForm.DiastolicBloodPressureAfter = diastolicbloodpressureafter
	sighForm.PatientId = patientID
	sighForm.RecordDate = dateTimeStam
	sighForm.UserOrgId = adminUserInfo.CurrentOrgId
	sighForm.SignTime = time.Now().Unix()
	sighForm.Status = 1
	sighForm.CreatedTime = time.Now().Unix()

	if sighForm.WeightBefore > 0 {
		sighForm.WeighBeforeTime = time.Now().Unix()
	}

	if sighForm.WeightAfter > 0 {
		sighForm.WeighTime = time.Now().Unix()
	}
	fmt.Println("sightForm是什么", sighForm)
	if errord == gorm.ErrRecordNotFound {
		fmt.Println("aaaaaaaaaaaaaa")
		savesignweigh := service.Savesignweigh(&sighForm)
		fmt.Println("savesignweight", savesignweigh)
		c.ServeSuccessJSON(map[string]interface{}{
			"signs": sighForm,
		})
		//signweigh := service.GetSignweigh(adminUserInfo.CurrentOrgId, patientID)
		//fmt.Println("signweigh是什么？",signweigh)
		fmt.Println(sighForm)
	} else if errord == nil {
		service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
	} else {
		fmt.Println("ccccccccccccc")
		service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
	}
	return
}

func (c *SignWeighAPIController) UpdateSignweight() {
	patientID, _ := c.GetInt64("patient_id", 0)
	dateTime := c.GetString("date_time")
	fmt.Println("病人ID", patientID, dateTime)
	timeLayout := "2006-01-02"
	loc, _ := time.LoadLocation("Local")
	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", dateTime+" 00:00:00", loc)
	if err != nil {
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
		return
	}
	dateTimeStam := theTime.Unix()
	fmt.Println("datatimestam是什么", dateTimeStam)
	adminUserInfo := c.GetAdminUserInfo()
	fmt.Println(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
	//透前
	weight_before, _ := c.GetFloat("weight_before", 0)
	dry_weight, _ := c.GetFloat("dry_weight", 0)
	temperature, _ := c.GetFloat("temperature", 0)
	pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
	systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
	diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
	fmt.Println("dry_weight", dry_weight)
	var predialysisevaluation models.PredialysisEvaluation
	predialysisevaluation.PatientId = patientID
	predialysisevaluation.UserOrgId = adminUserInfo.CurrentOrgId
	predialysisevaluation.AssessmentDate = dateTimeStam
	predialysisevaluation.WeightBefore = weight_before
	predialysisevaluation.DryWeight = dry_weight
	predialysisevaluation.Temperature = temperature
	predialysisevaluation.PulseFrequency = pulse_frequency
	predialysisevaluation.SystolicBloodPressure = systolic_blood_pressure
	predialysisevaluation.DiastolicBloodPressure = diastolic_blood_pressure
	predialysisevaluation.CreatedTime = time.Now().Unix()
	predialysisevaluation.Status = 1

	predialysis, errcode := service.GetDislysisBerfore(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
	fmt.Println("sigh是什么东西", predialysis)
	fmt.Println("错误装太:", errcode)
	if errcode == gorm.ErrRecordNotFound {
		fmt.Println("aaaaa")
		service.SaveDislysisiBefore(&predialysisevaluation)
	} else if errcode == nil {
		fmt.Println("bbbbbbbbb")
		service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
	} else {
		service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
	}

	//透后
	weight_after, _ := c.GetFloat("weight_after", 0)
	temperatureafter, _ := c.GetFloat("temperatureafter", 0)
	pulsefrequencyafter, _ := c.GetFloat("pulse_frequencyafter", 0)
	systolicbloodpressureafter, _ := c.GetFloat("systolic_blood_pressureafter", 0)
	diastolicbloodpressureafter, _ := c.GetFloat("diastolic_blood_pressureafter", 0)
	fmt.Println("aaaa")
	fmt.Println(weight_after, temperatureafter, pulsefrequencyafter, systolicbloodpressureafter, diastolicbloodpressureafter)

	var assessmentafterdislysis models.AssessmentAfterDislysis
	assessmentafterdislysis.PatientId = patientID
	assessmentafterdislysis.UserOrgId = adminUserInfo.CurrentOrgId
	assessmentafterdislysis.AssessmentDate = dateTimeStam
	assessmentafterdislysis.WeightAfter = weight_after
	assessmentafterdislysis.Temperature = temperatureafter
	assessmentafterdislysis.PulseFrequency = pulsefrequencyafter
	assessmentafterdislysis.SystolicBloodPressure = systolicbloodpressureafter
	assessmentafterdislysis.DiastolicBloodPressure = diastolicbloodpressureafter
	assessmentafterdislysis.CreatedTime = time.Now().Unix()
	assessmentafterdislysis.Status = 1
	dislysis, errcoder := service.GetAssessmentaafterdislysis(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
	fmt.Println("sigh是什么东西", dislysis)
	fmt.Println("错误装太:", errcoder)

	if errcoder == gorm.ErrRecordNotFound {
		fmt.Println("oooooooo")
		service.SaveAssessmentafter(&assessmentafterdislysis)
		c.ServeSuccessJSON(map[string]interface{}{
			"signs": predialysisevaluation,
		})
	} else if errcoder == nil {
		fmt.Println("ffffffffffffffff")
		service.UpdataAssessment(&assessmentafterdislysis, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
		c.ServeSuccessJSON(map[string]interface{}{
			"signs": predialysisevaluation,
		})
	} else {
		service.UpdataAssessment(&assessmentafterdislysis, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
	}
}

//func (c *SignWeighAPIController) GetForenoonData()  {
//	nowDateTime := time.Now()
//	nowDate := nowDateTime.Format("2006-01-02")
//	nowDate += " 00:00:00"
//	timeLayout := "2006-01-02"
//	loc, _ := time.LoadLocation("Local")
//	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
//	datetime := theTime.Unix()
//	fmt.Println("hhhhhhhhhhhhhhhhhhh")
//	fmt.Println("datetime",datetime)
//	adminUserInfo := c.GetAdminUserInfo()
//	orgId := adminUserInfo.CurrentOrgId
//	fmt.Println("orgid是什么",orgId)
//	total, schedule, err := service.GetForenoonData(datetime, orgId, 1)
//	fmt.Println("total",total)
//	fmt.Println("schedule",schedule)
//	if err != nil {
//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
//		return
//	}
//
//	c.ServeSuccessJSON(map[string]interface{}{
//		"total": total,
//	})
//
//}
