12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112 |
- package controllers
-
- import (
- "encoding/json"
- "fmt"
- "reflect"
- "strconv"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- )
-
- 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")
- 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)
- 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)
- dryWeight, _ := service.GetPatientLastDryWeight(patientID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patientlist": list,
- "dryWeight": dryWeight,
- })
- 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.GetString("breathing_rate")
- 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.GetString("breathing_rate")
- 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() {
-
- 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()
- adminUserInfo := c.GetAdminUserInfo()
- sign, errord := service.GetSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
- fmt.Println("sign", 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)
-
- 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()
- }
-
- if errord == gorm.ErrRecordNotFound {
-
- savesignweigh := service.Savesignweigh(&sighForm)
- fmt.Println("savesignweight", savesignweigh)
- c.ServeSuccessJSON(map[string]interface{}{
- "signs": sighForm,
- })
-
- } else if errord == nil {
- service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "signs": sighForm,
- })
- } else {
-
- service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "signs": sighForm,
- })
- }
- return
- }
-
- func (c *SignWeighAPIController) UpdateSignweight() {
- 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()
- 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)
- 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)
-
- lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.CurrentOrgId, patientID, dateTimeStam)
-
- if lastPredialysisEvaluation != nil {
- predialysisevaluation.DryWeight = lastPredialysisEvaluation.DryWeight
- predialysisevaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
- predialysisevaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin
- predialysisevaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
- predialysisevaluation.Catheter = lastPredialysisEvaluation.Catheter
- predialysisevaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend
- predialysisevaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
- predialysisevaluation.PunctureNeedleDirection = lastPredialysisEvaluation.PunctureNeedleDirection
- predialysisevaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
- predialysisevaluation.PointPuncture = lastPredialysisEvaluation.PointPuncture
- predialysisevaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage
- predialysisevaluation.ThromubusType = lastPredialysisEvaluation.ThromubusType
- predialysisevaluation.Skin = lastPredialysisEvaluation.Skin
- predialysisevaluation.Complication = lastPredialysisEvaluation.Complication
- predialysisevaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
- predialysisevaluation.LastPostDialysisOther = lastPredialysisEvaluation.LastPostDialysisOther
- }
-
- if errcode == gorm.ErrRecordNotFound {
-
- service.SaveDislysisiBefore(&predialysisevaluation)
- } else if errcode == nil {
-
- service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
- } else {
- service.UpdataDislysisiBefore(&predialysisevaluation, patientID, adminUserInfo.CurrentOrgId, dateTimeStam)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- }
-
- // 计算透析处方的相关超滤量
- schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patientID, dateTimeStam)
-
- var lastDialysisPrescribe *models.DialysisPrescription
- var dialysisSolution *models.DialysisSolution
- var dialysisPrescribe *models.DialysisPrescription
- var system_dialysisPrescribe *models.SystemPrescription
-
- dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patientID, dateTimeStam)
-
- var dewater_amount float64
-
- dewater_amount = predialysisevaluation.WeightBefore - predialysisevaluation.DryWeight - predialysisevaluation.AdditionalWeight
-
- dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patientID, schedual.ModeId)
-
- // 插入透析处方
- if dialysisPrescribe == nil && dialysisSolution != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = dialysisSolution.UserOrgId
- newprescribe.PatientId = dialysisSolution.PatientId
- newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
- newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
- newprescribe.ModeId = dialysisSolution.ModeId
- newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
- newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
- newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
- newprescribe.BloodFilter = dialysisSolution.BloodFilter
- newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
- newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
- newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
- newprescribe.Glucose = dialysisSolution.Glucose
- newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
- newprescribe.Kalium = dialysisSolution.Kalium
- newprescribe.Sodium = dialysisSolution.Sodium
- newprescribe.Calcium = dialysisSolution.Calcium
- newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
- newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
- newprescribe.Conductivity = dialysisSolution.Conductivity
- newprescribe.BodyFluid = dialysisSolution.BodyFluid
- newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
- newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
- newprescribe.BloodAccess = dialysisSolution.BloodAccess
- newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
- newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
- newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
- newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
- newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
- newprescribe.Dialyzer = dialysisSolution.Dialyzer
- newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
- newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
- newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
- newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
- newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
- newprescribe.TargetKtv = dialysisSolution.TargetKtv
-
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = dateTimeStam
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.PrescriptionWater = dewater_amount
- newprescribe.Chaptalization = dialysisSolution.Chaptalization
- newprescribe.PrescribingNumber = 1
- newprescribe.BloodAccessPartId = dialysisSolution.BloodAccessPartId
- newprescribe.Status = 1
- if adminUserInfo.CurrentOrgId != 10013 && adminUserInfo.CurrentOrgId != 10014 && adminUserInfo.CurrentOrgId != 10016 {
- newprescribe.Remark = dialysisSolution.Remark
- }
-
- if adminUserInfo.CurrentOrgId == 10340 {
- newprescribe.TargetUltrafiltration = 0
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- newprescribe.TargetUltrafiltration = 0
- }
- // 针对新化博翔
- if adminUserInfo.CurrentOrgId == 10447 {
- newprescribe.DisplaceLiquiPart = 1
- newprescribe.DisplaceLiquiValue = 32
- newprescribe.DialysateFlow = 500
- }
-
- if adminUserInfo.CurrentOrgId == 10121 {
- newprescribe.DialysisDurationHour = 4
- newprescribe.DialysisDurationMinute = 0
- newprescribe.BloodAccess = dialysisSolution.BloodAccess
- }
-
- if adminUserInfo.CurrentOrgId == 10445 {
- lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
- newprescribe.Remark = lastDialysisPrescription.Remark
- }
-
- //恒泰
- if adminUserInfo.CurrentOrgId == 10490 || adminUserInfo.CurrentOrgId == 10016 {
- newprescribe.Remark = ""
- }
-
- if adminUserInfo.CurrentOrgId == 10599 {
- // 获取透析模版
- solutionone, _ := service.MobileGetDialysisSolutionByModeIdSevenTwety(adminUserInfo.CurrentOrgId, patientID, schedual.ModeId)
- if solutionone.Anticoagulant > 0 {
- newprescribe.Anticoagulant = solutionone.Anticoagulant
- newprescribe.AnticoagulantShouji = solutionone.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = solutionone.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = solutionone.AnticoagulantZongliang
- newprescribe.BloodAccess = solutionone.BloodAccess
- newprescribe.DialysisDurationHour = solutionone.DialysisDurationHour
- newprescribe.DialysisDurationMinute = solutionone.DialysisDurationMinute
- newprescribe.DialysisIrrigation = solutionone.DialysisIrrigation
- newprescribe.DialysisDialyszers = solutionone.DialysisDialyszers
- newprescribe.DialysisStrainer = solutionone.DialysisStrainer
-
- }
-
- }
-
- //针对普宁和揭阳
- if adminUserInfo.CurrentOrgId == 10597 || adminUserInfo.CurrentOrgId == 10599 {
- prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
- if prescriptionTwenty.ID == 0 {
- //插入透析处方
- service.AddSigleRecord(&newprescribe)
- } else {
- //插入透析处方
- service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
- }
- } else {
- //插入透析处方
- service.AddSigleRecord(&newprescribe)
- }
-
- //记录日志
- byterequest, _ := json.Marshal(newprescribe)
- prescriptionLog := models.XtDialysisPrescriptionLog{
- UserOrgId: newprescribe.UserOrgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- RecordDate: newprescribe.RecordDate,
- PatientId: newprescribe.PatientId,
- Source: "物联网上传",
- Status: 1,
- }
-
- service.CreatePrescriptionLog(prescriptionLog)
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- thisTime := time.Now()
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- }
-
- if dialysisPrescribe == nil && dialysisSolution == nil {
- if lastDialysisPrescribe != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
- newprescribe.PatientId = lastDialysisPrescribe.PatientId
- newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
- newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
- newprescribe.ModeId = lastDialysisPrescribe.ModeId
- newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
- newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
- newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
- newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
- newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
- newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
- newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
- newprescribe.Glucose = lastDialysisPrescribe.Glucose
- newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
- newprescribe.Kalium = lastDialysisPrescribe.Kalium
- newprescribe.Sodium = lastDialysisPrescribe.Sodium
- newprescribe.Calcium = lastDialysisPrescribe.Calcium
- newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
- newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
- newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
- newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
- newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
- newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
- newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
- newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
- newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
- newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
- newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
- newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
- newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
- newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
- newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
- newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
- newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
- newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
- newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = dateTimeStam
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.PrescriptionWater = dewater_amount
- newprescribe.Status = 1
-
- if adminUserInfo.CurrentOrgId == 10490 || adminUserInfo.CurrentOrgId == 10016 {
- newprescribe.Remark = ""
- }
-
- newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
- newprescribe.PrescribingNumber = 1
- if adminUserInfo.CurrentOrgId == 10340 {
- newprescribe.TargetUltrafiltration = 0
- }
- if adminUserInfo.CurrentOrgId == 10121 {
- newprescribe.DialysisDurationHour = 4
- newprescribe.DialysisDurationMinute = 0
- newprescribe.BloodAccess = dialysisSolution.BloodAccess
- }
-
- if adminUserInfo.CurrentOrgId == 10445 {
- lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
- newprescribe.Remark = lastDialysisPrescription.Remark
- }
- //err := service.AddSigleRecord(&newprescribe)
- var err error
- if adminUserInfo.CurrentOrgId == 10597 || adminUserInfo.CurrentOrgId == 10599 || adminUserInfo.CurrentOrgId == 3877 {
- prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
- if prescriptionTwenty.ID == 0 {
- //插入透析处方
- service.AddSigleRecord(&newprescribe)
- } else {
- //插入透析处方
- service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
- }
- } else {
- //插入透析处方
- err = service.AddSigleRecord(&newprescribe)
- }
- //记录日志
- byterequest, _ := json.Marshal(newprescribe)
- prescriptionLog := models.XtDialysisPrescriptionLog{
- UserOrgId: adminUserInfo.CurrentOrgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- RecordDate: newprescribe.RecordDate,
- PatientId: patientID,
- Source: "物联网上传",
- Status: 1,
- }
-
- service.CreatePrescriptionLog(prescriptionLog)
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- thisTime := time.Now()
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- } else if system_dialysisPrescribe != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
- newprescribe.PatientId = patientID
- newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
- newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
- newprescribe.ModeId = system_dialysisPrescribe.ModeId
- newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
- newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
- newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
- newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
- newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
- newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
- newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
- newprescribe.Glucose = system_dialysisPrescribe.Glucose
- newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
- newprescribe.Kalium = system_dialysisPrescribe.Kalium
- newprescribe.Sodium = system_dialysisPrescribe.Sodium
- newprescribe.Calcium = system_dialysisPrescribe.Calcium
- newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
- newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
- newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
- newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
- newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
- newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
- newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
- newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
- newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
- newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
- newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
- newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
- newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
- newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
- newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
- newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
- newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = dateTimeStam
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
- newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
- newprescribe.Status = 1
- newprescribe.PrescribingNumber = 1
-
- if adminUserInfo.CurrentOrgId == 10340 {
- newprescribe.TargetUltrafiltration = 0
- }
- if adminUserInfo.CurrentOrgId == 10121 {
- newprescribe.DialysisDurationHour = 4
- newprescribe.DialysisDurationMinute = 0
- newprescribe.BloodAccess = dialysisSolution.BloodAccess
- }
- if adminUserInfo.CurrentOrgId == 10445 {
- lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
- newprescribe.Remark = lastDialysisPrescription.Remark
- }
-
- if adminUserInfo.CurrentOrgId == 10597 || adminUserInfo.CurrentOrgId == 10599 || adminUserInfo.CurrentOrgId == 3877 {
- prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
- if prescriptionTwenty.ID == 0 {
- //插入透析处方
- service.AddSigleRecord(&newprescribe)
- } else {
- //插入透析处方
- service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
- }
- } else {
- service.AddSigleRecord(&newprescribe)
- }
-
- //记录日志
- byterequest, _ := json.Marshal(newprescribe)
- prescriptionLog := models.XtDialysisPrescriptionLog{
- UserOrgId: adminUserInfo.CurrentOrgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- RecordDate: newprescribe.RecordDate,
- PatientId: patientID,
- Source: "物联网上传",
- Status: 1,
- }
-
- service.CreatePrescriptionLog(prescriptionLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- thisTime := time.Now()
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
-
- } else {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
- newprescribe.PatientId = patientID
- newprescribe.ModeId = schedual.ModeId
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = dateTimeStam
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
- if adminUserInfo.CurrentOrgId == 10445 {
- lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
- newprescribe.Remark = lastDialysisPrescription.Remark
- }
- err := service.AddSigleRecord(&newprescribe)
- //记录日志
- byterequest, _ := json.Marshal(newprescribe)
- prescriptionLog := models.XtDialysisPrescriptionLog{
- UserOrgId: adminUserInfo.CurrentOrgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- RecordDate: newprescribe.RecordDate,
- PatientId: patientID,
- Source: "物联网上传",
- Status: 1,
- }
-
- service.CreatePrescriptionLog(prescriptionLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- thisTime := time.Now()
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
- }
-
- if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
- dialysisPrescribe.UpdatedTime = time.Now().Unix()
- dialysisPrescribe.RecordDate = dateTimeStam
- dialysisPrescribe.DewaterAmount = dewater_amount
- dialysisPrescribe.TargetUltrafiltration = dewater_amount
- dialysisPrescribe.Status = 1
- if adminUserInfo.CurrentOrgId == 10340 {
- dialysisPrescribe.TargetUltrafiltration = 0
- }
- if adminUserInfo.CurrentOrgId == 10445 {
- lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminUserInfo.CurrentOrgId)
- dialysisPrescribe.Remark = lastDialysisPrescription.Remark
- }
- updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
- //记录日志
- byterequest, _ := json.Marshal(dialysisPrescribe)
- prescriptionLog := models.XtDialysisPrescriptionLog{
- UserOrgId: adminUserInfo.CurrentOrgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- RecordDate: dialysisPrescribe.RecordDate,
- PatientId: patientID,
- Source: "物联网上传",
- Status: 1,
- }
-
- service.CreatePrescriptionLog(prescriptionLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":" + strconv.FormatInt(schedual.ModeId, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dateTimeStam, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- thisTime := time.Now()
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- if updateErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
-
- //透后
- 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)
-
- 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 {
- service.SaveAssessmentafter(&assessmentafterdislysis)
- c.ServeSuccessJSON(map[string]interface{}{
- "signs": predialysisevaluation,
- })
- } else if errcoder == nil {
- 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,
- // })
- //
- //}
|