123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "github.com/astaxie/beego"
- "reflect"
- "strconv"
- "time"
- )
-
- type HisConfigApiController struct {
- BaseAuthAPIController
- }
-
- func HisConfigApiRegistRouters() {
- beego.Router("/api/his/patient/list", &HisConfigApiController{}, "get:GetAllHisPatientsList")
- 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")
- }
-
- func (c *HisConfigApiController) GetAllHisPatientsList() {
- patients, _, _ := service.GetAllPatientList(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
- }
- }
|