12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "strconv"
- "strings"
- "time"
- )
-
- type InspectionApiController struct {
- BaseAuthAPIController
- }
-
- func InspectionApiRegistRouters() {
- beego.Router("/api/patient/inspection/list", &InspectionApiController{}, "Get:GetPatientInspections")
- beego.Router("/api/patient/inspection/reference", &InspectionApiController{}, "Get:PatientInspectionReference")
- beego.Router("/api/patient/inspection/create", &InspectionApiController{}, "Post:CreatePatientInspection")
- beego.Router("/api/patient/inspection/edit", &InspectionApiController{}, "Put:EditPatientInspection")
- beego.Router("/api/patient/inspection/delete", &InspectionApiController{}, "Delete:DeletePatientInspection")
-
- beego.Router("/api/patient/inspection/get", &InspectionApiController{}, "Get:GetAllPatientInspection")
- beego.Router("/api/patient/inspectioninit/get", &InspectionApiController{}, "Get:GetInitInsepction")
-
- beego.Router("/api/patient/pic_inspection/create", &InspectionApiController{}, "Post:CreatePatientPicInspection")
- beego.Router("/api/patient/pic_inspection/edit", &InspectionApiController{}, "Post:EditPatientPicInspection")
-
- beego.Router("/api/patient/inspection_remind/get", &InspectionApiController{}, "Get:GetInspectionRemind")
-
- beego.Router("/api/patient/inspection_remind/set", &InspectionApiController{}, "Get:SetInspectionRemind")
-
- }
- func (c *InspectionApiController) SetInspectionRemind() {
- remind_cycle, _ := c.GetInt64("remind_cycle", 0)
- patient, _ := c.GetInt64("patient", 0)
- project_id, _ := c.GetInt64("project_id", 0)
- is_open, _ := c.GetInt64("is_open", 0)
-
- if remind_cycle > 0 {
- infectiousRecord, _ := service.FindLastRecordDate(c.GetAdminUserInfo().CurrentOrgId, patient, project_id)
- fmt.Println(infectiousRecord.InspectDate)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
- fmt.Println(record_time)
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- fmt.Println(record_time)
-
- break
- }
- var errs error
-
- if infectiousRecord.ID == 0 {
- record_time = 0
- }
- //根据project_id查找是否存在提醒记录,没有的话新建,有的话更新提醒时间
- reminds, _ := service.GetCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, project_id)
- if reminds.ID == 0 {
- remind := models.XtCheckRemind{
- ProjectId: project_id,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- Status: 1,
- LastRemindDate: record_time,
- PatientId: patient,
- RemindCycle: remind_cycle,
- IsOpen: is_open,
- }
- errs = service.CreateRemind(remind)
- } else {
- errs = service.UpDateCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, record_time, project_id, remind_cycle)
- }
- fmt.Println(errs)
- c.ServeSuccessJSON(map[string]interface{}{
- "remind_cycle": remind_cycle,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- }
-
- func (c *InspectionApiController) GetInspectionRemind() {
- patient, _ := c.GetInt64("patient")
- project_id, _ := c.GetInt64("project_id")
- remind, _ := service.GetCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, project_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "remind": remind,
- })
- }
-
- // PatientInspectionReference 请求检验检查大小项目
- // [get]: /api/patient/inspection/reference
- func (c *InspectionApiController) PatientInspectionReference() {
- patient, _ := c.GetInt64("patient")
- inspect_type, _ := c.GetInt64("type")
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- references, err := service.GetInspectionReference(adminUserInfo.CurrentOrgId, inspect_type)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- patient_info, _ := service.GetFaPiaoPatientByID(adminUserInfo.CurrentOrgId, patient)
-
- counts, err := service.GetPatientInspectionProjectCount(adminUserInfo.CurrentOrgId, patient)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- countsMap := make(map[int64]int64, 0)
- for _, count := range counts {
- countsMap[count.ProjectId] = count.Count
- }
-
- referenceMap := make(map[string]*models.InspectionReferenceMap, 0)
-
- for _, reference := range references {
- if _, exist := referenceMap[reference.ProjectName]; !exist {
- referenceMap[reference.ProjectName] = new(models.InspectionReferenceMap)
- referenceMap[reference.ProjectName].Project = reference.Project
- referenceMap[reference.ProjectName].ProjectId = reference.ProjectId
- referenceMap[reference.ProjectName].ProjectName = reference.ProjectName
- if _, cexit := countsMap[reference.ProjectId]; cexit {
- referenceMap[reference.ProjectName].Count = countsMap[reference.ProjectId]
- }
- referenceMap[reference.ProjectName].InspectionReference = make([]models.InspectionReference, 0)
- }
- referenceMap[reference.ProjectName].InspectionReference = append(referenceMap[reference.ProjectName].InspectionReference, *reference)
-
- }
-
- reference := make([]*models.InspectionReferenceMap, 0)
- for _, item := range referenceMap {
- reference = append(reference, item)
- }
-
- rl := len(reference)
- for index := 0; index < rl-1; index++ {
- for jndex := 0; jndex < rl-1-index; jndex++ {
- if reference[jndex].ProjectId > reference[jndex+1].ProjectId {
- var item models.InspectionReferenceMap
- item = *reference[jndex]
- reference[jndex] = reference[jndex+1]
- reference[jndex+1] = &item
- }
- }
- }
-
- list, err := service.GetInspectionReferenceByOrgId(0)
- c.ServeSuccessJSON(map[string]interface{}{
- "reference": reference,
- "patient_info": patient_info,
- "list": list,
- })
- return
-
- }
-
- func (c *InspectionApiController) CreatePatientInspection() {
- patient, _ := c.GetInt64("patient", 0)
- remind_cycle, _ := c.GetInt64("remind_cycle", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var from models.InepectionForm
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
- return
- }
-
- if len(from.FormItem) == 0 {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未填写项目")
- return
- }
-
- date := theTime.Unix()
- insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, from.ProjectId)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(insp) > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateExit)
- return
- }
-
- inspections := make([]models.Inspection, 0)
- for _, item := range from.FormItem {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient
- inspection.ProjectId = from.ProjectId
- inspection.ItemId = item.ItemId
- inspection.ItemName = item.ItemName
- inspection.ProjectName = item.ProjectName
- inspection.InspectType = item.RangeType
- inspection.InspectValue = item.Value
- inspection.InspectDate = date
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
- }
-
- err = service.CreatePatientInspection(inspections)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
- return
- }
- if inspections[0].ProjectId == 14 {
- if remind_cycle > 0 {
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
- fmt.Println(infectiousRecord.InspectDate)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
- fmt.Println(record_time)
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- fmt.Println(record_time)
-
- break
- }
- var errs error
- if inspections[0].ProjectId == 14 {
- errs = service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient, record_time, remind_cycle)
- }
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- "remind_cycle": remind_cycle,
- })
- } else {
- //更新提醒时间
- reminds, _ := service.GetCheckRemindRecordTime(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
- if reminds.ID > 0 {
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
- var record_time int64
- switch reminds.RemindCycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
- fmt.Println(record_time)
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- fmt.Println(record_time)
-
- break
- }
- errs := service.UpDateCheckRemindRecordTimeTwo(adminUserInfo.CurrentOrgId, patient, record_time, inspections[0].ProjectId)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- })
- }
-
- return
- }
- func (c *InspectionApiController) CreatePatientPicInspection() {
- patient, _ := c.GetInt64("patient", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var from models.InepectionPICForm
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
- return
- }
- if len(from.Imags) == 0 {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未上传图片")
- return
- }
-
- date := theTime.Unix()
- insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, from.ProjectId)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(insp) > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateExit)
- return
- }
-
- inspection_re, _ := service.GetInspectionReferenceTwo(from.ProjectId)
-
- inspections := make([]models.Inspection, 0)
- for index, item := range from.Imags {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient
- inspection.ProjectId = from.ProjectId
- inspection.ItemId = inspection_re[index].ID
- inspection.ItemName = item.Desc
- inspection.ProjectName = ""
- inspection.InspectType = 3
- inspection.InspectValue = item.ImgUrl
- inspection.InspectDesc = item.Desc
- inspection.InspectDate = date
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
- }
- err = service.CreatePatientInspection(inspections)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
- return
- }
-
- if inspections[0].ProjectId != 14 {
- //更新提醒时间
- reminds, _ := service.GetCheckRemindRecordTime(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
- if reminds.ID > 0 {
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
- var record_time int64
- switch reminds.RemindCycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
- fmt.Println(record_time)
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- fmt.Println(record_time)
-
- break
- }
- errs := service.UpDateCheckRemindRecordTimeTwo(adminUserInfo.CurrentOrgId, patient, record_time, inspections[0].ProjectId)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- })
- return
- }
- func (c *InspectionApiController) EditPatientPicInspection() {
- patient, _ := c.GetInt64("patient", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var from models.InepectionPICForm
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
- return
- }
- if len(from.Imags) == 0 {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未上传图片")
- return
- }
-
- date := theTime.Unix()
- inspection_re, _ := service.GetInspectionReferenceTwo(from.ProjectId)
- inspections := make([]models.Inspection, 0)
- for index, item := range from.Imags {
- if item.ID == 0 {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient
- inspection.ProjectId = from.ProjectId
- inspection.ItemId = inspection_re[index].ID
- inspection.ItemName = item.Desc
- inspection.ProjectName = ""
- inspection.InspectType = 3
- inspection.InspectValue = item.ImgUrl
- inspection.InspectDesc = item.Desc
- inspection.InspectDate = date
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
-
- } else {
- var inspection models.Inspection
- inspection.ID = item.ID
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient
- inspection.ProjectId = from.ProjectId
- inspection.ItemId = inspection_re[index].ID
- inspection.ItemName = item.Desc
- inspection.ProjectName = ""
- inspection.InspectType = 3
- inspection.InspectValue = item.ImgUrl
- inspection.InspectDesc = item.Desc
- inspection.InspectDate = date
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- err = service.SavePatientInspection(inspection)
- }
-
- }
-
- for _, item := range from.DeleteImg {
- service.DeleteInspectionTwo(item.ID)
- }
- if len(inspections) > 0 {
- err = service.CreatePatientInspection(inspections)
- }
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- })
- return
- }
-
- func (c *InspectionApiController) EditPatientInspection() {
- patient, _ := c.GetInt64("patient", 0)
- remind_cycle, _ := c.GetInt64("remind_cycle", 0)
- // dates := c.GetString("dates")
- // projectid := c.GetString("projectid")
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var from models.InepectionForm
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
- return
- }
-
- oldTime, olderr := time.ParseInLocation(timeLayout, from.OldInspectDate, loc)
- if olderr != nil {
- utils.ErrorLog(olderr.Error())
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
- return
- }
-
- if len(from.FormItem) == 0 {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未填写项目")
- return
- }
-
- date := theTime.Unix()
- oldDate := oldTime.Unix()
- insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, oldDate, from.ProjectId)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(insp) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
- return
- }
- inspMap := make(map[int64]*models.Inspection)
- for _, item := range insp {
- inspMap[item.ID] = item
- }
-
- addinsp := make([]models.Inspection, 0)
- editinsp := make([]models.Inspection, 0)
- noMap := make([]int64, 0)
- fmt.Println(from.FormItem)
-
- for _, item := range from.FormItem {
- fmt.Println(item.ID)
- if item.ID == 0 {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient
- inspection.ProjectId = from.ProjectId
- inspection.ItemId = item.ItemId
- inspection.ItemName = item.ItemName
- inspection.ProjectName = item.ProjectName
- inspection.InspectType = item.RangeType
- inspection.InspectValue = item.Value
- inspection.InspectDate = date
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- addinsp = append(addinsp, inspection)
- } else {
- inspection := *inspMap[item.ID]
- inspection.InspectValue = item.Value
- inspection.InspectDate = date
- inspection.UpdatedTime = time.Now().Unix()
- editinsp = append(editinsp, inspection)
- noMap = append(noMap, item.ID)
- }
-
- }
-
- err = service.EditPatientInspection(addinsp, editinsp, noMap, patient, adminUserInfo.CurrentOrgId, from.ProjectId, date)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionEditFail)
- return
- }
-
- inspections := make([]models.Inspection, 0)
- inspections = append(inspections, editinsp...)
- inspections = append(inspections, addinsp...)
-
- if remind_cycle > 0 {
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, 14)
- fmt.Println(infectiousRecord.InspectDate)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
-
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- break
- }
- fmt.Println(record_time)
- errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient, record_time, remind_cycle)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- "remind_cycle": remind_cycle,
- })
- return
- }
-
- func (c *InspectionApiController) DeletePatientInspection() {
- patient, _ := c.GetInt64("patient", 0)
- ProjectId, _ := c.GetInt64("project_id", 0)
- InspectDate := c.GetString("date")
- if patient <= 0 || ProjectId <= 0 || len(InspectDate) < 10 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, InspectDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- date := theTime.Unix()
- insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, ProjectId)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(insp) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
- return
- }
-
- err = service.DeletePatientInspection(adminUserInfo.CurrentOrgId, patient, ProjectId, date)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDeleteFail)
- return
- }
-
- //更新提醒时间
- reminds, _ := service.GetCheckRemindRecordTime(adminUserInfo.CurrentOrgId, patient, ProjectId)
- if reminds.ID > 0 {
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, ProjectId)
- fmt.Println(infectiousRecord)
- if infectiousRecord.ID > 0 {
- var record_time int64
- switch reminds.RemindCycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
- fmt.Println(record_time)
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- fmt.Println(record_time)
-
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- fmt.Println(record_time)
-
- break
- }
- errs := service.UpDateCheckRemindRecordTimeTwo(adminUserInfo.CurrentOrgId, patient, record_time, ProjectId)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- } else {
- errs := service.UpDateCheckRemindRecordTimeTwo(adminUserInfo.CurrentOrgId, patient, 0, ProjectId)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- }
-
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *InspectionApiController) GetPatientInspections() {
- patient, _ := c.GetInt64("patient", 0)
- projectId, _ := c.GetInt64("project_id", 0)
- if patient <= 0 || projectId <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- page, _ := c.GetInt64("page", 0)
- if page <= 0 {
- page = 1
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- inspections, total, dateTime, err := service.GetPatientInspections(adminUserInfo.CurrentOrgId, patient, projectId, page)
- fmt.Println("inspections", inspections)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- date := ""
- if len(inspections) > 0 {
- date = time.Unix(dateTime, 0).Format("2006-01-02 15:04")
- }
-
- remind, _ := service.GetCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, projectId)
-
- //remind, _ := service.GetCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, projectId)
- config, _ := service.GetCheckRemindConfigById(c.GetAdminUserInfo().CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- "total": total,
- "date": date,
- "remind": remind,
- "config": config,
- })
- return
-
- }
-
- func (c *InspectionApiController) GetAllPatientInspection() {
- patient, _ := c.GetInt64("patient", 0)
- projectStr := c.GetString("project")
- start_time, _ := c.GetInt64("start_time")
- end_time, _ := c.GetInt64("end_time")
- upload_type, _ := c.GetInt64("type")
-
- ids := strings.Split(projectStr, "-")
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- page, _ := c.GetInt64("page", 0)
- if page <= 0 {
- page = 1
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- switch upload_type {
- case 1:
- var inspections []*models.Inspection
-
- for _, item := range ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
- // fmt.Println(err)
- //
- // if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- for _, inspection_item := range inspection {
- inspections = append(inspections, inspection_item)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- "type": upload_type,
- })
- break
-
- case 2:
- id_one, _ := strconv.ParseInt(ids[0], 10, 64)
- id_two, _ := strconv.ParseInt(ids[1], 10, 64)
- id_three, _ := strconv.ParseInt(ids[2], 10, 64)
- inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
- inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
- inspection_three, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_three, start_time, end_time)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections_one": inspection_one,
- "inspections_two": inspection_two,
- "inspections_three": inspection_three,
- "type": upload_type,
- })
-
- break
- case 3:
- var inspections []*models.Inspection
-
- for _, item := range ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
- // fmt.Println(err)
- //
- // if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- for _, inspection_item := range inspection {
- inspections = append(inspections, inspection_item)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- "type": upload_type,
- })
-
- break
- case 4:
- id_one, _ := strconv.ParseInt(ids[0], 10, 64)
- id_two, _ := strconv.ParseInt(ids[1], 10, 64)
- id_three, _ := strconv.ParseInt(ids[2], 10, 64)
- id_four, _ := strconv.ParseInt(ids[3], 10, 64)
- id_five, _ := strconv.ParseInt(ids[4], 10, 64)
-
- inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
- inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
- inspection_three, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_three, start_time, end_time)
- inspection_four, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_four, start_time, end_time)
- inspection_five, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_five, start_time, end_time)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections_one": inspection_one,
- "inspections_two": inspection_two,
- "inspections_three": inspection_three,
- "inspections_four": inspection_four,
- "inspections_five": inspection_five,
- "type": upload_type,
- })
-
- break
- case 5:
- id_one, _ := strconv.ParseInt(ids[0], 10, 64)
- id_two, _ := strconv.ParseInt(ids[1], 10, 64)
- inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
- inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections_one": inspection_one,
- "inspections_two": inspection_two,
- "type": upload_type,
- })
-
- break
- case 6:
- var inspections []*models.Inspection
-
- for _, item := range ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
- // fmt.Println(err)
- //
- // if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- for _, inspection_item := range inspection {
- inspections = append(inspections, inspection_item)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- "type": upload_type,
- })
-
- break
- case 7:
- var inspections []*models.Inspection
-
- for _, item := range ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
- // fmt.Println(err)
- //
- // if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- for _, inspection_item := range inspection {
- inspections = append(inspections, inspection_item)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspections": inspections,
- "type": upload_type,
- })
-
- break
-
- }
-
- return
-
- }
-
- func (c *InspectionApiController) GetInitInsepction() {
- references, _ := service.GetAllInspectionReference(0)
- c.ServeSuccessJSON(map[string]interface{}{
- "references": references,
- })
- return
-
- }
|