1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201 |
- package controllers
-
- import (
- "encoding/json"
- "fmt"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- )
-
- 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")
-
- beego.Router("/api/getnewinspectionList", &InspectionApiController{}, "Get:GetNewInspectionList")
-
- beego.Router("/api/getnewinspectiondetaillist", &InspectionApiController{}, "Get:GetNewInspectionDetailList")
-
- beego.Router("/api/editpatientnewinspection", &InspectionApiController{}, "Post:EditPatientNewInspection")
-
- beego.Router("/api/getinspecitonbypatientgroup", &InspectionApiController{}, "Get:GetInpsectionByPatientGroup")
-
- beego.Router("/api/getinspectionchildlist", &InspectionApiController{}, "Get:GetInspectionChildList")
-
- }
- 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[string]models.Inspection)
- for _, item := range insp {
- a := strconv.FormatInt(item.ProjectId, 10) + "-" + strconv.FormatInt(item.ItemId, 10)
- inspMap[a] = item
- }
-
- addinsp := make([]models.Inspection, 0)
- editinsp := make([]models.Inspection, 0)
- noMap := make([]int64, 0)
-
- fmt.Println("00000000000000000000000000000000000000000000000000000")
-
- for _, item := range from.FormItem {
- fmt.Println("name:", item.ItemId, "value:", item.Value)
-
- ref, _ := service.GetInspectionReferenceById(item.ItemId)
- //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 {
- //fmt.Println(item.ID)
- a := strconv.FormatInt(item.ProjectId, 10) + "-" + strconv.FormatInt(ref.ItemId, 10)
- fmt.Println(a)
- fmt.Println(inspMap)
-
- inspection := inspMap[a]
- inspection.ID = item.ID
- 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.InspectValue = item.Value
- inspection.InspectDate = date
- inspection.UpdatedTime = time.Now().Unix()
- editinsp = append(editinsp, inspection)
- noMap = append(noMap, item.ID)
- //}
-
- }
- //fmt.Println(editinsp)
- //return
- 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
-
- }
-
- func (c *InspectionApiController) GetNewInspectionList() {
-
- patient, _ := c.GetInt64("patient")
-
- project_id, _ := c.GetInt64("project_id")
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- inspection, _ := service.GetNewInspectionList(patient, project_id, orgId)
-
- inspectionGroup, _ := service.GetNewGroupInspectionList(patient, project_id, orgId)
-
- inspectionInspectDateGroup, _ := service.GetNewGroupInspectionInspectionList(patient, project_id, orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "inspectionGroup": inspectionGroup,
- "inspection": inspection,
- "list": inspectionInspectDateGroup,
- })
- }
-
- func (c *InspectionApiController) GetNewInspectionDetailList() {
-
- project_id, _ := c.GetInt64("project_id")
-
- inspect_date, _ := c.GetInt64("inspect_date")
-
- patient_id, _ := c.GetInt64("patient_id")
-
- inspection, _ := service.GetNewInspectionDetailList(project_id, inspect_date, patient_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspection": inspection,
- })
- }
-
- func (c *InspectionApiController) EditPatientNewInspection() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- inspection := models.Inspection{}
-
- if dataBody["id"] == nil || reflect.TypeOf(dataBody["id"]).String() != "float64" {
- utils.ErrorLog("id")
- return
- }
-
- id := int64(dataBody["id"].(float64))
-
- inspection.ID = id
-
- }
-
- func (c *InspectionApiController) GetInpsectionByPatientGroup() {
-
- patient_id, _ := c.GetInt64("patient_id")
-
- org_id := c.GetAdminUserInfo().CurrentOrgId
-
- //patient, _ := service.GetPatientDetailTwo(patient_id)
- inspection, _ := service.GetInspectionGroup(patient_id, org_id)
-
- if len(inspection) > 0 {
- for _, item := range inspection {
- lastInspection, _ := service.GetLastInspectionProject(patient_id, org_id, item.ProjectId)
- item.InspectDate = lastInspection.InspectDate
- inspecList, _ := service.GetInspectionByProjectId(patient_id, org_id, item.ProjectId)
- item.Count = int64(len(inspecList))
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspection": inspection,
- })
- }
-
- func (c *InspectionApiController) GetInspectionChildList() {
-
- patient_id, _ := c.GetInt64("patient_id")
-
- project_id, _ := c.GetInt64("project_id")
-
- org_id := c.GetAdminUserInfo().CurrentOrgId
-
- //patient, _ := service.GetPatientDetailTwo(patient_id)
-
- referenceList, _ := service.GetInSpctionRerefce(project_id, org_id)
-
- inspection, _ := service.GetInspectionGroupByRecordDate(patient_id, project_id, org_id)
-
- if len(inspection) > 0 {
- for _, item := range inspection {
- inspeclist, _ := service.GetInspectionByProject(patient_id, project_id, org_id, item.InspectDate)
- for _, it := range inspeclist {
- item.Child = append(item.Child, it)
- }
- }
- }
-
- patients, _ := service.GetPatientByIDOne(org_id, patient_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "inspection": inspection,
- "patients": patients,
- "referenceList": referenceList,
- })
- }
|