1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861 |
- 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"
- "github.com/astaxie/beego/config"
- "golang.org/x/sync/errgroup"
- )
-
- type HisConfigApiController struct {
- BaseAuthAPIController
- }
-
- const (
- AddTypeDrug = 1 //药品
- AddTypeProject = 2 //项目
- )
-
- func HisConfigApiRegistRouters() {
- beego.Router("/api/his/patient/list", &HisConfigApiController{}, "get:GetAllHisPatientsList")
- beego.Router("/api/his/patient/getpatientlisttwenty", &HisConfigApiController{}, "get:GetPatientListTwenty")
- beego.Router("/api/his/prescriptiontemplate/list", &HisConfigApiController{}, "get:GetPrescriptionTemplateList")
- beego.Router("/api/his/prescriptiontemplate/info", &HisConfigApiController{}, "get:GetPrescriptionTemplateInfo")
- beego.Router("/api/his/prescriptiontemplate/create", &HisConfigApiController{}, "post:CreatePrescriptionTemplate") //批量添加
- beego.Router("/api/his/prescriptiontemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionTemplate")
- beego.Router("/api/his/prescriptioninfotemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionInfoTemplate")
- beego.Router("/api/his/advicetemplate/delete", &HisConfigApiController{}, "post:DeleteAdviceTemplate")
- beego.Router("/api/his/projecttemplate/delete", &HisConfigApiController{}, "post:DeleteProjectTemplate")
- //beego.Router("/api/his/responsibilitydoctor/get", &HisConfigApiController{}, "get:GetResponsibilityDoctor")
-
- beego.Router("/api/his/getmodetemplatename", &HisConfigApiController{}, "get:GetModeTemplateName")
- beego.Router("/api/his/getprescriptiontemplatedetail", &HisConfigApiController{}, "get:GetPrescriptionTemplateDetail")
- beego.Router("/api/his/prescriptionmodetemplate/create", &HisConfigApiController{}, "post:CreatePrescriptionModeTemplate")
- beego.Router("/api/his/prescriptionmodetemplate/info", &HisConfigApiController{}, "get:GetPrescriptionModeTemplateInfo")
- beego.Router("/api/his/prescriptionmodetemplate/delete", &HisConfigApiController{}, "post:DeleteModePrescriptionTemplate")
- beego.Router("/api/his/projectmodetemplate/delete", &HisConfigApiController{}, "post:DeleteModeProjectTemplate")
- beego.Router("/api/his/advicempdetemplate/delete", &HisConfigApiController{}, "post:DeleteModeAdviceTemplate")
- beego.Router("/api/his/prescriptioninfomodetemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionInfoModeTemplate")
- beego.Router("/api/his/getdialysismodename", &HisConfigApiController{}, "get:GetDialysisModeName") //根据透析模式获取患者姓名
- beego.Router("/api/his/getdrugsname", &HisConfigApiController{}, "get:GetDrugsName") //根据类型获取药品名称
- beego.Router("/api/his/getmodeconfigs", &HisConfigApiController{}, "get:GetModeConfigs")
- beego.Router("/api/his/getdrugsinformation", &HisConfigApiController{}, "get:GetDrugsInformation") //根据id获取药品耗材项目基本信息
- beego.Router("/api/his/replacepeoplename", &HisConfigApiController{}, "get:ReplacePeopleName") //替换——获取患者名字
- beego.Router("/api/his/replaceconfig", &HisConfigApiController{}, "get:ReplaceConfig")
- beego.Router("/api/his/replacesavedrug", &HisConfigApiController{}, "post:ReplaceSaveDrug") //替换——药品保存
- beego.Router("/api/his/replacesaveproject", &HisConfigApiController{}, "post:ReplaceSaveProject") //替换——项目保存
- beego.Router("/api/his/deletedrugsbatch", &HisConfigApiController{}, "get:DeleteDrugsBatch") //批量删除——药品
- beego.Router("/api/his/batchdeleteitems", &HisConfigApiController{}, "get:BatchDeleteItems") //批量删除——项目
- beego.Router("/api/his/addstemplate", &HisConfigApiController{}, "post:AddsTemplate") //批量添加
- beego.Router("/api/his/ptemplateinformation", &HisConfigApiController{}, "get:PTemplateInformation") //根据患者id、透析模式获取处方模板信息
- beego.Router("/api/his/deleteone", &HisConfigApiController{}, "get:DeleteOne") //删除单条处方模板
-
- beego.Router("/api/his/exportmdtrtcerttype", &HisConfigApiController{}, "get:ExportMdtrtCertType") //删除单条处方模板
-
- }
-
- func (c *HisConfigApiController) ExportMdtrtCertType() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- start_time = start_time + " 00:00:00"
- end_time = end_time + " 23:00:00"
- os, _ := service.GetHisMdtrtCertType(start_time, end_time, c.GetAdminUserInfo().CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": os,
- })
- }
-
- func (c *HisConfigApiController) GetAllHisPatientsList() {
- patients, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- })
- }
-
- func (c *HisConfigApiController) GetPatientListTwenty() {
- patients, _, _ := service.GetAllPatientListTwenty(c.GetAdminUserInfo().CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- })
- }
-
- func (c *HisConfigApiController) GetPrescriptionTemplateList() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- if patient_id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- templates, total, _ := service.GetHisPrescriptionTemplatesList(patient_id, c.GetAdminUserInfo().CurrentOrgId, page, limit)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": templates,
- "total": total,
- })
-
- }
-
- func (c *HisConfigApiController) GetPrescriptionTemplateInfo() {
- id, _ := c.GetInt64("id", 0)
- template, _ := service.GetHisPrescriptionTemplateByID(id)
- prescriptions, _ := service.GetHisPrescriptionTemplate(template.ID, c.GetAdminUserInfo().CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- "prescriptions": prescriptions,
- })
- }
-
- func (c *HisConfigApiController) CreatePrescriptionTemplate() {
- id, _ := c.GetInt64("id")
- name := c.GetString("name")
- mode_id, _ := c.GetInt64("mode_id", 0)
- types, _ := c.GetInt64("type", 0)
- patient_id, _ := c.GetInt64("patient_id", 0)
- types = 1
- adminInfo := c.GetAdminUserInfo()
-
- if id == 0 {
- mode_template, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, adminInfo.CurrentOrgId)
- if mode_template.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
- return
- }
- }
- if id > 0 {
- mode_template, _ := service.GetHisPrescriptionTemplateByModeIdTwo(mode_id, patient_id, adminInfo.CurrentOrgId, id)
- if mode_template.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
- return
- }
- }
- src_template, _ := service.GetHisPrescriptionTemplateByID(id)
- if src_template.ID == 0 {
- template := models.HisPrescriptionTemplate{
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: patient_id,
- Type: types,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Name: name,
- Mode: mode_id,
- }
- src_template = template
- service.CreateHisPrescriptionTemplate(&src_template)
- } else {
- src_template.Name = name
- src_template.Mode = mode_id
- service.SaveHisPrescriptionTemplate(&src_template)
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- id := int64(items["id"].(float64))
-
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- ctime := time.Now().Unix()
- prescription := &models.HisPrescriptionInfoTemplate{
- ID: id,
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- PTemplateId: src_template.ID,
- MedType: med_type,
- }
- service.CreateHisPrescriptionInfoTemplate(prescription)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- groupNo := int64(0)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisPrescriptionAdviceTemplate
- s.PrescriptionId = prescription.ID
- s.AdviceType = 2
- s.StopState = 2
- s.ExecutionState = 2
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.Groupno = groupNo
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = patient_id
- errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisPrescriptionAdviceTemplate(&s)
- }
- }
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- var p models.HisPrescriptionProjectTemplate
- p.PrescriptionId = prescription.ID
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.PatientId = patient_id
- p.UserOrgId = adminInfo.CurrentOrgId
- p.Status = 1
- errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisPrescriptionProjectTemplate(&p)
-
- }
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "创建成功",
- })
- }
- }
-
- }
-
- func (c *HisConfigApiController) DeletePrescriptionTemplate() {
- id, _ := c.GetInt64("id")
- err := service.DelelteHisPrescriptionTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (c *HisConfigApiController) DeletePrescriptionInfoTemplate() {
-
- prescription_id, _ := c.GetInt64("id")
- err := service.DelelteHisPrescriptionInfoTemplate(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisConfigApiController) DeleteAdviceTemplate() {
- id, _ := c.GetInt64("id")
- err := service.DelelteHisPrescriptionAdviceTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (c *HisConfigApiController) DeleteProjectTemplate() {
- id, _ := c.GetInt64("id")
- err := service.DelelteHisPrescriptionProjectTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisConfigApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
-
- if json["advice_id"] != nil || reflect.TypeOf(json["advice_id"]).String() == "float64" {
- advice_id := int64(json["advice_id"].(float64))
- advice.ID = advice_id
- }
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
- if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
- groupno := int64(json["groupno"].(float64))
- advice.Groupno = groupno
- }
-
- if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- frequency_type := int64(json["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- day_count := int64(json["day_count"].(float64))
- advice.DayCount = day_count
- }
-
- if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
- week_day, _ := json["week_day"].(string)
- advice.WeekDay = week_day
- }
- return 0
- }
-
- func (c *HisConfigApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
-
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- project.ID = id
- }
- if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- frequency_type := int64(json["frequency_type"].(float64))
- project.FrequencyType = frequency_type
- }
-
- if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- day_count := int64(json["day_count"].(float64))
- project.DayCount = day_count
- }
-
- if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
- week_day, _ := json["week_day"].(string)
- project.WeekDay = week_day
- }
-
- if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
- types := int64(json["type"].(float64))
- project.Type = types
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
- }
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- //totals, _ := strconv.ParseInt(total, 10, 64)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
- return 0
- }
-
- func (this *HisConfigApiController) GetModeTemplateName() {
-
- mode_id, _ := this.GetInt64("mode_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- modeTeplate, err := service.GetModeTemplateName(mode_id, orgId)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "modeTeplate": modeTeplate,
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
- }
-
- func (this *HisConfigApiController) GetPrescriptionTemplateDetail() {
-
- mode_id, _ := this.GetInt64("mode_id")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- template, _ := service.GetModeTemplateNameDetail(mode_id, orgId)
-
- prescriptions, err := service.GetHisPrescriptionModeTemplate(template.ID, orgId)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- "prescriptions": prescriptions,
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
- }
-
- func (c *HisConfigApiController) CreatePrescriptionModeTemplate() {
- id, _ := c.GetInt64("id")
- name := c.GetString("name")
- mode_id, _ := c.GetInt64("mode_id", 0)
- types, _ := c.GetInt64("type", 0)
- patient_id, _ := c.GetInt64("patient_id", 0)
- types = 1
- adminInfo := c.GetAdminUserInfo()
-
- if id == 0 {
- mode_template, _ := service.GetHisModePrescriptionTemplateByModeId(mode_id, patient_id, adminInfo.CurrentOrgId)
- if mode_template.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
- return
- }
- }
- if id > 0 {
- mode_template, _ := service.GetHisModePrescriptionTemplateByModeIdTwo(mode_id, patient_id, adminInfo.CurrentOrgId, id)
- if mode_template.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
- return
- }
- }
- src_template, _ := service.GetHisModePrescriptionTemplateByID(id)
-
- if src_template.ID == 0 {
- template := models.HisPrescriptionModeTemplate{
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: patient_id,
- Type: types,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Name: name,
- Mode: mode_id,
- }
- src_template = template
- service.CreateHisModePrescriptionTemplate(&src_template)
- } else {
- src_template.Name = name
- src_template.Mode = mode_id
- service.SaveHisModePrescriptionTemplate(&src_template)
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- id := int64(items["id"].(float64))
-
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- ctime := time.Now().Unix()
- prescription := &models.HisPrescriptionInfoModeTemplate{
- ID: id,
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- PTemplateId: src_template.ID,
- MedType: med_type,
- }
- service.CreateHisModePrescriptionInfoTemplate(prescription)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- groupNo := int64(0)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisPrescriptionAdviceModeTemplate
- s.PrescriptionId = prescription.ID
- s.AdviceType = 2
- s.StopState = 2
- s.ExecutionState = 2
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.Groupno = groupNo
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = patient_id
- errcode := c.setAdviceModeTemplateWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisModePrescriptionAdviceTemplate(&s)
- }
- }
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- var p models.HisPrescriptionProjectModeTemplate
- p.PrescriptionId = prescription.ID
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.PatientId = patient_id
- p.UserOrgId = adminInfo.CurrentOrgId
- p.Status = 1
- errcode := c.setProjectModeTemplateWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisModePrescriptionProjectTemplate(&p)
-
- }
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "创建成功",
- })
- }
- }
-
- }
-
- func (c *HisConfigApiController) GetPrescriptionModeTemplateInfo() {
-
- id, _ := c.GetInt64("id", 0)
- template, _ := service.GetHisModePrescriptionTemplateByID(id)
- prescriptions, _ := service.GetHisPrescriptionModeTemplate(template.ID, c.GetAdminUserInfo().CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- "prescriptions": prescriptions,
- })
- }
-
- func (c *HisConfigApiController) setAdviceModeTemplateWithJSON(advice *models.HisPrescriptionAdviceModeTemplate, json map[string]interface{}) int {
-
- if json["advice_id"] != nil || reflect.TypeOf(json["advice_id"]).String() == "float64" {
- advice_id := int64(json["advice_id"].(float64))
- advice.ID = advice_id
- }
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
- if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
- groupno := int64(json["groupno"].(float64))
- advice.Groupno = groupno
- }
-
- if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- frequency_type := int64(json["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- day_count := int64(json["day_count"].(float64))
- advice.DayCount = day_count
- }
-
- if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
- week_day, _ := json["week_day"].(string)
- advice.WeekDay = week_day
- }
- return 0
- }
-
- func (c *HisConfigApiController) setProjectModeTemplateWithJSON(project *models.HisPrescriptionProjectModeTemplate, json map[string]interface{}) int {
-
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- project.ID = id
- }
- if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- frequency_type := int64(json["frequency_type"].(float64))
- project.FrequencyType = frequency_type
- }
-
- if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- day_count := int64(json["day_count"].(float64))
- project.DayCount = day_count
- }
-
- if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
- week_day, _ := json["week_day"].(string)
- project.WeekDay = week_day
- }
-
- if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
- types := int64(json["type"].(float64))
- project.Type = types
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
- }
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- //totals, _ := strconv.ParseInt(total, 10, 64)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
- return 0
- }
-
- func (c *HisConfigApiController) DeleteModePrescriptionTemplate() {
- id, _ := c.GetInt64("id")
- err := service.DelelteHisModePrescriptionTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (c *HisConfigApiController) DeleteModeProjectTemplate() {
- id, _ := c.GetInt64("id")
- err := service.DelelteHisModePrescriptionProjectTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisConfigApiController) DeleteModeAdviceTemplate() {
- id, _ := c.GetInt64("id")
- err := service.DelelteHisModePrescriptionAdviceTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisConfigApiController) DeletePrescriptionInfoModeTemplate() {
- prescription_id, _ := c.GetInt64("id")
- err := service.DelelteHisPrescriptionInfoModeTemplate(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisConfigApiController) GetDialysisModeName() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- orgid := c.GetAdminUserInfo().CurrentOrgId
- mode, _ := c.GetInt64("mode")
- var list []*models.DialysisPatient
- list, err = service.GetDialysisModePatient(orgid, mode)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
-
- }
- func (c *HisConfigApiController) GetDrugsName() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- orgid := c.GetAdminUserInfo().CurrentOrgId
- addtype, _ := c.GetInt("addtype")
- //special,_ := c.GetInt("special")
- //tmpBool := false
- //if special == IsSpecialDiseases{
- // tmpBool = true
- //}
-
- tmp := make(map[string]interface{}, 0)
- if addtype == AddTypeDrug {
- var list []*models.ReplacementDrugs
- list, err = service.ReplacementDrugs(orgid, true)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- var list2 []*models.ReplacementDrugs
- list2, err = service.ReplacementDrugs(orgid, false)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- tmp["list"] = list
- tmp["list2"] = list2
- } else if addtype == AddTypeProject {
- var list3 []*models.DropDownList
- list3, err = service.ProjectConsumables2(orgid, true)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- var list4 []*models.DropDownList
- list4, err = service.ProjectConsumables2(orgid, false)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- tmp["list"] = list3
- tmp["list2"] = list4
- } else {
- err = fmt.Errorf("类型解析错误")
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- }
- c.ServeSuccessJSON(tmp)
- return
-
- }
-
- // 配置项
- func (c *HisConfigApiController) GetModeConfigs() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- orgid := c.GetAdminUserInfo().CurrentOrgId
- var drugways []*models.DrugwayDic
- var efs []*models.ExecutionFrequencyDic
- var dataconfig []*models.DictDataconfig
- drugways, _, err = service.GetDrugWayDics(orgid)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- efs, _, err = service.GetExecutionFrequencyDics(orgid)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- dataconfig, err = service.GetDataConfig(orgid)
- c.ServeSuccessJSON(map[string]interface{}{
- "drugways": drugways,
- "efs": efs,
- "dataconfig": dataconfig, //组
- })
- return
- }
- func (c *HisConfigApiController) GetDrugsInformation() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- orgid := c.GetAdminUserInfo().CurrentOrgId
- id := c.GetString("id", "")
- if len(id) == 0 {
- err = fmt.Errorf("参数错误")
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- var list interface{}
- list, err = service.QueryFourTables(id, orgid)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- func (c *HisConfigApiController) ReplacePeopleName() {
- var g errgroup.Group
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- orgid := c.GetAdminUserInfo().CurrentOrgId
- mode, _ := c.GetInt64("mode") //透析模式
- id := c.GetString("id", "") //药品/项目/耗材id
- if id == "" {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
- return
- }
- var list []*models.DialysisPatient
- finlist := make([]*models.DialysisPatient, 0) //筛选后的列表
- list, err = service.GetDialysisModePatient(orgid, mode)
- fmt.Println("list-----------------", list)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- for _, v := range list {
- v := v
- g.Go(func() error {
- //判断该患者是否有使用该药品/项目/耗材
- tmpid := id[:1]
- bo := false
- if tmpid == "p" {
- pid := id[1:]
- tmpisid, _ := strconv.ParseInt(pid, 10, 64)
- tp := service.FindPatientXiang(orgid, v.ID, tmpisid, mode)
- if tp {
- bo = true
- }
-
- } else if tmpid == "i" {
- pid := id[1:]
- tmpisid, _ := strconv.ParseInt(pid, 10, 64)
- tp := service.FindPatientXiang2(orgid, v.ID, tmpisid, mode)
- if tp {
- bo = true
- }
- } else {
- pid := id
- tmpisid, _ := strconv.ParseInt(pid, 10, 64)
- tp := service.FindPatientDrug(orgid, v.ID, tmpisid, mode)
- if tp {
- bo = true
- }
- }
- if bo {
- finlist = append(finlist, v)
- }
- return nil
- })
- }
- if err = g.Wait(); err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": finlist,
- })
- return
- }
- func (c *HisConfigApiController) ReplaceConfig() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- orgid := c.GetAdminUserInfo().CurrentOrgId
- tmp := make(map[string]interface{}, 0)
- var list []*models.ReplacementDrugs
- var list2 []*models.DropDownList
- list, err = service.ReplacementDrugsT(orgid)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- tmp["list"] = list
- list2, err = service.ProjectConsumables2T(orgid)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- tmp["list2"] = list2
- c.ServeSuccessJSON(tmp)
- return
-
- }
-
- // 批量替换——药品
- func (c *HisConfigApiController) ReplaceSaveDrug() {
- var g errgroup.Group
- var err error
- tx := service.XTWriteDB().Begin()
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
- types, _ := c.GetInt64("type", 1) //1.药品 2.项目
- patient_id := c.GetString("patient_id") //患者
- replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
- orgid := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- t_ids := ""
- if patient_id[len(patient_id)-1] == 44 {
- t_ids = patient_id[:len(patient_id)-1]
- } else {
- t_ids = patient_id
- }
- tmp_id := strings.Split(t_ids, ",")
- ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
- drugid, _ := strconv.ParseInt(replaced, 10, 64)
- for _, v := range tmp_id {
- v := v
- g.Go(func() error {
- pp, _ := strconv.ParseInt(v, 10, 64) //患者id
- var err error
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- var s models.HisPrescriptionAdviceTemplate
- var tmpdrugid int64
- if items["drug_name"] != nil && reflect.TypeOf(items["drug_name"]).String() == "string" {
- tmpdrugid, _ = strconv.ParseInt(items["drug_name"].(string), 10, 64)
- }
- if items["drug_name"] != nil && reflect.TypeOf(items["drug_name"]).String() == "float64" {
- tmpdrugid = int64(items["drug_name"].(float64))
- }
- s.AdviceName = service.FindDrugsName(tmpdrugid) //药品名称
- if items["id"] == nil {
- err = fmt.Errorf("缺少参数")
- return err
- } else {
- if items["id"] != nil && reflect.TypeOf(items["id"]).String() == "string" {
- tmp_drugid := items["id"].(string)
- drug_id, _ := strconv.ParseInt(tmp_drugid, 10, 64)
- s.DrugId = drug_id //药品id
- }
- if items["id"] != nil && reflect.TypeOf(items["id"]).String() == "float64" {
- drug_id := int64(items["id"].(float64))
- s.DrugId = drug_id
- }
- }
- if items["remark"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
- remark, _ := items["remark"].(string)
- s.Remark = remark //备注
- }
- if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
- s.SingleDose = singleDose
- }
- if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "float64" {
- singleDose := items["single_dose"].(float64)
- s.SingleDose = singleDose
- }
- if items["single_dose_unit"] != nil && reflect.TypeOf(items["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := items["single_dose_unit"].(string)
- s.SingleDoseUnit = singleDoseUnit
- }
- if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
- s.PrescribingNumber = prescribingNumber
- }
- if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "float64" {
- prescribingNumber := items["prescribing_number"].(float64)
- s.PrescribingNumber = prescribingNumber
- }
- if items["prescribing_number_unit"] != nil && reflect.TypeOf(items["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := items["prescribing_number_unit"].(string)
- s.PrescribingNumberUnit = prescribingNumberUnit
- }
- if items["delivery_way"] != nil && reflect.TypeOf(items["delivery_way"]).String() == "string" {
- deliveryWay, _ := items["delivery_way"].(string)
- s.DeliveryWay = deliveryWay
- }
- if items["execution_frequency"] != nil && reflect.TypeOf(items["execution_frequency"]).String() == "string" {
- executionFrequency, _ := items["execution_frequency"].(string)
- s.ExecutionFrequency = executionFrequency
- }
- if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- s.Price = price
- }
- if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "float64" {
- price := items["price"].(float64)
- s.Price = price
- }
- if items["day"] != nil && reflect.TypeOf(items["day"]).String() == "string" {
- day, _ := strconv.ParseInt(items["day"].(string), 10, 64)
- s.Day = day
- }
- if items["day"] != nil && reflect.TypeOf(items["day"]).String() == "float64" {
- day := int64(items["day"].(float64))
- s.Day = day
- }
- s.FrequencyType = 1
- err = service.ReplaceDrugPrescriptionTemplate(orgid, pp, drugid, ids, s, tx)
- if err != nil {
- return err
- }
-
- }
- return nil
- }
- }
- return err
- })
- }
- if errs := g.Wait(); errs != nil {
- err = errs
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": "替换成功",
- })
- return
- }
-
- // 批量替换项目
- func (c *HisConfigApiController) ReplaceSaveProject() {
- var g errgroup.Group
- var err error
- tx := service.XTWriteDB().Begin()
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
- types, _ := c.GetInt64("type", 2) //1.药品 2.项目
- patient_id := c.GetString("patient_id") //患者
- replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
- orgid := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- t_ids := ""
- if patient_id[len(patient_id)-1] == 44 {
- t_ids = patient_id[:len(patient_id)-1]
- } else {
- t_ids = patient_id
- }
- tmp_id := strings.Split(t_ids, ",")
- ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
- drugid, _ := strconv.ParseInt(replaced[1:], 10, 64)
- for _, v := range tmp_id {
- v := v
- g.Go(func() error {
- pp, _ := strconv.ParseInt(v, 10, 64) //患者id
- var err error
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- var s models.HisPrescriptionProjectTemplate
- if items["id"] != nil {
- id := items["id"].(string)
- if id != "" {
- tmpPid := id[1:]
- project_id, _ := strconv.ParseInt(tmpPid, 10, 64)
- if id[0] == 112 {
- s.Type = 2
- }
- if id[0] == 105 {
- s.Type = 3
- }
- s.ProjectId = project_id
- } else {
- s.ProjectId = int64(0)
- }
-
- }
- if items["frequency_type"] != nil && reflect.TypeOf(items["frequency_type"]).String() == "string" {
- tmp_drugid := items["frequency_type"].(string)
- frequency_type, _ := strconv.ParseInt(tmp_drugid, 10, 64)
- s.FrequencyType = frequency_type
- }
- if items["frequency_type"] != nil && reflect.TypeOf(items["frequency_type"]).String() == "float64" {
- frequency_type := int64(items["frequency_type"].(float64))
- s.FrequencyType = frequency_type
- }
- if items["day_count"] != nil && reflect.TypeOf(items["day_count"]).String() == "string" {
- tmp_drugid := items["day_count"].(string)
- day_count, _ := strconv.ParseInt(tmp_drugid, 10, 64)
- s.DayCount = day_count
- }
- if items["day_count"] != nil && reflect.TypeOf(items["day_count"]).String() == "float64" {
- day_count := int64(items["day_count"].(float64))
- s.DayCount = day_count
- }
- if items["week_day"] != nil && reflect.TypeOf(items["week_day"]).String() == "string" {
- week_day, _ := items["week_day"].(string)
- s.WeekDay = week_day
- }
- if items["week_day"] != nil && reflect.TypeOf(items["week_day"]).String() == "float64" {
- week_day := config.ToString(items["week_day"].(float64))
- s.WeekDay = week_day
- }
- if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- s.Price = price
- }
-
- if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "float64" {
- price := items["price"].(float64)
- s.Price = price
- }
- if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "string" {
- total, _ := items["prescribing_number"].(string)
- //totals, _ := strconv.ParseInt(total, 10, 64)
- s.Count = total
- }
- if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "float64" {
- total := config.ToString(items["prescribing_number"].(float64))
- //totals, _ := strconv.ParseInt(total, 10, 64)
- s.Count = total
- }
- if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "string" {
- single_dose, _ := items["single_dose"].(string)
- s.SingleDose = single_dose
- }
- if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "float64" {
- single_dose := config.ToString(items["single_dose"].(float64))
- s.SingleDose = single_dose
- }
- if items["delivery_way"] != nil && reflect.TypeOf(items["delivery_way"]).String() == "string" {
- delivery_way, _ := items["delivery_way"].(string)
- s.DeliveryWay = delivery_way
- }
- if items["execution_frequency"] != nil && reflect.TypeOf(items["execution_frequency"]).String() == "string" {
- execution_frequency, _ := items["execution_frequency"].(string)
- s.ExecutionFrequency = execution_frequency
- }
- if items["remark"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
- remark, _ := items["remark"].(string)
- s.Remark = remark
- }
- if items["day"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
- day, _ := items["number_days"].(string)
- s.Day = day
- }
- if items["day"] != nil && reflect.TypeOf(items["remark"]).String() == "float64" {
- day := config.ToString(items["number_days"].(float64))
- s.Day = day
- }
-
- if items["unit"] != nil && reflect.TypeOf(items["unit"]).String() == "string" {
- unit, _ := items["unit"].(string)
- s.Unit = unit
- }
- err = service.ReplaceProjectPrescriptionTemplate(orgid, pp, drugid, ids, s, tx)
- if err != nil {
- return err
- }
-
- }
- return nil
- }
- }
- return err
- })
- }
- if errs := g.Wait(); errs != nil {
- err = errs
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": "替换成功",
- })
- return
- }
-
- // 批量删除项目
- func (c *HisConfigApiController) BatchDeleteItems() {
- var g errgroup.Group
- var err error
- tx := service.XTWriteDB().Begin()
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
- types, _ := c.GetInt64("type", 2) //1.药品 2.项目
- patient_id := c.GetString("patient_id") //患者
- replaced := c.GetString("replaced", "") //被删除的药品、项目、耗材id
- orgid := c.GetAdminUserInfo().CurrentOrgId
- t_ids := ""
- if patient_id[len(patient_id)-1] == 44 {
- t_ids = patient_id[:len(patient_id)-1]
- } else {
- t_ids = patient_id
- }
- tmp_id := strings.Split(t_ids, ",")
- ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
- drugid, _ := strconv.ParseInt(replaced[1:], 10, 64)
- for _, v := range tmp_id {
- v := v
- g.Go(func() error {
- pp, _ := strconv.ParseInt(v, 10, 64) //患者id
- var err error
- err = service.DeleteProjectTemplate(orgid, pp, drugid, ids, tx)
- return err
- })
- }
- if errs := g.Wait(); errs != nil {
- err = errs
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": "删除成功",
- })
- return
- }
-
- // 批量删除药品
- func (c *HisConfigApiController) DeleteDrugsBatch() {
- var g errgroup.Group
- var err error
- tx := service.XTWriteDB().Begin()
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
- types, _ := c.GetInt64("type", 1) //1.药品 2.项目
- patient_id := c.GetString("patient_id") //患者
- replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
- orgid := c.GetAdminUserInfo().CurrentOrgId
- t_ids := ""
- if patient_id[len(patient_id)-1] == 44 {
- t_ids = patient_id[:len(patient_id)-1]
- } else {
- t_ids = patient_id
- }
- tmp_id := strings.Split(t_ids, ",")
- ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
- drugid, _ := strconv.ParseInt(replaced, 10, 64)
- for _, v := range tmp_id {
- v := v
- g.Go(func() error {
- pp, _ := strconv.ParseInt(v, 10, 64) //患者id
- var err error
- err = service.DeletePrescriptionTemplate(orgid, pp, drugid, ids, tx)
- return err
- })
- }
- if errs := g.Wait(); errs != nil {
- err = errs
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": "删除成功",
- })
- return
- }
-
- // 批量添加
- func (c *HisConfigApiController) AddsTemplate() {
- var g errgroup.Group
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- //id, _ := c.GetInt64("id")
- name := c.GetString("name", "")
- mode_id, _ := c.GetInt64("mode_id", 0)
- types, _ := c.GetInt64("type", 1) //没啥用
- patient_id := c.GetString("patient_id")
- //patient_id, _ := c.GetInt64("patient_id", 0)
- if name == "" {
- name = service.DialysisModeName(mode_id)
- }
- adminInfo := c.GetAdminUserInfo()
- dataBody := make(map[string]interface{}, 0)
- err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- t_ids := ""
- if patient_id[len(patient_id)-1] == 44 {
- t_ids = patient_id[:len(patient_id)-1]
- } else {
- t_ids = patient_id
- }
- tmp_id := strings.Split(t_ids, ",")
- for _, v := range tmp_id {
- v := v
- g.Go(func() error {
- var err error
- pa, _ := strconv.ParseInt(v, 10, 64)
- tmp_bool_id := service.IsDialysisMode(adminInfo.CurrentOrgId, pa, mode_id)
-
- var src_template models.HisPrescriptionTemplate
- if !tmp_bool_id {
- template := models.HisPrescriptionTemplate{
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: pa,
- Type: types,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Name: name,
- Mode: mode_id,
- }
- src_template = template
- service.CreateHisPrescriptionTemplate(&src_template)
- } else {
- //查询出该模板的id
- src_template, err = service.IdOfTheTemplate(adminInfo.CurrentOrgId, pa, mode_id)
- if err != nil {
- return err
- }
- src_template.Name = name
- src_template.Mode = mode_id
- service.SaveHisPrescriptionTemplate(&src_template)
- }
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
-
- id := int64(0)
- //fmt.Println("111111111111111111111")
- //if items["type"] == nil {
- // utils.ErrorLog("type")
- // //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // fmt.Println("222222222222222")
- // err = fmt.Errorf("参数错误")
- // return err
- //}
- //fmt.Println("33333333333")
- //type1 := types
- med_type := ""
- var tmps float64
- if items["patient_value"] != nil && reflect.TypeOf(items["patient_value"]).String() == "float64" {
- tmps = items["patient_value"].(float64)
- }
- if items["patient_value"] != nil && reflect.TypeOf(items["patient_value"]).String() == "string" {
- tmps, _ = strconv.ParseFloat(items["patient_value"].(string), 64)
- }
- if tmps == 1 {
- med_type = "11"
- } else if tmps == 2 {
- med_type = "14"
- } else {
- err = fmt.Errorf("医疗类型参数错误")
- }
-
- ctime := time.Now().Unix()
- prescription := &models.HisPrescriptionInfoTemplate{
- ID: id,
- PatientId: pa,
- UserOrgId: adminInfo.CurrentOrgId,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- PTemplateId: src_template.ID,
- MedType: med_type,
- }
- service.CreateHisPrescriptionInfoTemplate(prescription)
-
- if items["tableDatas"] != nil && reflect.TypeOf(items["tableDatas"]).String() == "[]interface {}" {
- advices := items["tableDatas"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- groupNo := int64(0)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for k, advice := range advices {
- var s models.HisPrescriptionAdviceTemplate
- s.PrescriptionId = prescription.ID
- s.AdviceType = 2
- s.StopState = 2
- s.ExecutionState = 2
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.Groupno = groupNo
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = pa
- errcode := service.FensetAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- //c.ServeFailJSONWithSGJErrorCode(errcode)
- err = fmt.Errorf("参数错误")
- return err
- }
- if s.FrequencyType == 0 {
- s.FrequencyType = 1
- }
- s.Groupno = int64(k + 1) //序号
- if s.DrugId != 0 {
- service.CreateHisPrescriptionAdviceTemplate(&s)
- }
- }
- }
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- var p models.HisPrescriptionProjectTemplate
- p.PrescriptionId = prescription.ID
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.PatientId = pa
- p.UserOrgId = adminInfo.CurrentOrgId
- p.Status = 1
- errcode := service.FensetProjectTemplateWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- //c.ServeFailJSONWithSGJErrorCode(errcode)
- err = fmt.Errorf("参数错误")
- return err
- }
- if p.FrequencyType == 0 {
- p.FrequencyType = 1
- }
- if p.ProjectId != 0 {
- service.CreateHisPrescriptionProjectTemplate(&p)
- }
-
- }
- }
- }
- }
- return nil
- }
- }
- return err
- })
- }
- if errs := g.Wait(); errs != nil {
- err = errs
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": "创建成功",
- })
- return
-
- }
-
- // 根据透析模式和患者id获取该患者的处方内容
- func (c *HisConfigApiController) PTemplateInformation() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- orgid := c.GetAdminUserInfo().CurrentOrgId
- mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
- patient_id, _ := c.GetInt64("patient_id") //患者
- list, err := service.PTemplateInformation(orgid, mode_id, patient_id)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- // 删除单条记录
- func (c *HisConfigApiController) DeleteOne() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- orgid := c.GetAdminUserInfo().CurrentOrgId
- types, _ := c.GetInt64("type") //透析模式
- id, _ := c.GetInt64("id") //患者
- err = service.DeleteOne(types, id)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- err = service.Scavenger(orgid)
- if err != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": "成功",
- })
- return
- }
|