his_api_controller.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "reflect"
  11. "strconv"
  12. "time"
  13. )
  14. type HisApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func HisManagerApiRegistRouters() {
  18. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  19. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  20. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  21. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  22. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  23. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  24. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "post:CreateHisPatientCaseHistory")
  25. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "post:CreateCaseHistoryTemplate")
  26. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  27. beego.Router("/api/doctorworkstation/printcasehistory/get", &HisApiController{}, "get:GetPrintHisPatientCaseHistory")
  28. }
  29. func (c *HisApiController) GetHisPatientList() {
  30. types, _ := c.GetInt64("type", 0)
  31. record_date := c.GetString("record_date")
  32. timeLayout := "2006-01-02"
  33. loc, _ := time.LoadLocation("Local")
  34. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  35. if err != nil {
  36. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  37. return
  38. }
  39. recordDateTime := theTime.Unix()
  40. adminInfo := c.GetAdminUserInfo()
  41. patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  42. if types == 0 {
  43. c.ServeSuccessJSON(map[string]interface{}{
  44. "list": patients,
  45. })
  46. } else if types == 1 { //未就诊
  47. var patientsOne []*service.Schedule
  48. for _, item := range patients {
  49. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  50. patientsOne = append(patientsOne, item)
  51. }
  52. }
  53. c.ServeSuccessJSON(map[string]interface{}{
  54. "list": patientsOne,
  55. })
  56. } else if types == 2 { //已就诊
  57. var patientsTwo []*service.Schedule
  58. for _, item := range patients {
  59. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  60. patientsTwo = append(patientsTwo, item)
  61. }
  62. }
  63. c.ServeSuccessJSON(map[string]interface{}{
  64. "list": patientsTwo,
  65. })
  66. }
  67. }
  68. func (c *HisApiController) GetHisPatientInfo() {
  69. patient_id, _ := c.GetInt64("patient_id")
  70. record_date := c.GetString("record_date")
  71. timeLayout := "2006-01-02"
  72. loc, _ := time.LoadLocation("Local")
  73. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  74. if err != nil {
  75. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  76. return
  77. }
  78. recordDateTime := theTime.Unix()
  79. admin := c.GetAdminUserInfo()
  80. his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  81. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  82. prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
  83. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
  84. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  85. c.ServeSuccessJSON(map[string]interface{}{
  86. "his_info": his_patient_info,
  87. "xt_info": xt_patient_info,
  88. "prescription": prescriptions,
  89. "case_history": case_history,
  90. })
  91. return
  92. }
  93. func (c *HisApiController) GetHisPrescriptionConfig() {
  94. adminInfo := c.GetAdminUserInfo()
  95. //获取医嘱模版
  96. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  97. //获取所有基础药
  98. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  99. //drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  100. //drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  101. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  102. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  103. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  104. c.ServeSuccessJSON(map[string]interface{}{
  105. "drugs": drugs,
  106. "advices_template": advices,
  107. "drugways": drugways,
  108. "efs": efs,
  109. "doctors": doctors,
  110. })
  111. }
  112. func (c *HisApiController) CreateHisPrescription() {
  113. record_date := c.GetString("record_date")
  114. fmt.Println("record_date", record_date)
  115. patient_id, _ := c.GetInt64("patient_id")
  116. //diagnose := c.GetString("diagnose")
  117. //sick_history := c.GetString("sick_history")
  118. doctor, _ := c.GetInt64("doctor")
  119. //departm/**/ent, _ := c.GetInt64("department")
  120. his_patient_id, _ := c.GetInt64("his_patient_id")
  121. dataBody := make(map[string]interface{}, 0)
  122. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  123. if err != nil {
  124. utils.ErrorLog(err.Error())
  125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  126. return
  127. }
  128. timeLayout := "2006-01-02"
  129. loc, _ := time.LoadLocation("Local")
  130. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  131. if err != nil {
  132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  133. return
  134. }
  135. adminInfo := c.GetAdminUserInfo()
  136. recordDateTime := theTime.Unix()
  137. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  138. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  139. if len(prescriptions) > 0 {
  140. for _, item := range prescriptions {
  141. items := item.(map[string]interface{})
  142. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  143. utils.ErrorLog("type")
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. types := int64(items["type"].(float64))
  148. ctime := time.Now().Unix()
  149. prescription := &models.HisPrescription{
  150. PatientId: patient_id,
  151. UserOrgId: adminInfo.CurrentOrgId,
  152. RecordDate: recordDateTime,
  153. Ctime: ctime,
  154. Mtime: ctime,
  155. Type: types,
  156. Modifier: adminInfo.AdminUser.Id,
  157. Creator: adminInfo.AdminUser.Id,
  158. Status: 1,
  159. Doctor: doctor,
  160. HisPatientId: his_patient_id,
  161. }
  162. service.SaveHisPrescription(prescription)
  163. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  164. advices := items["advices"].([]interface{})
  165. group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  166. groupNo := group + 1
  167. ctime := time.Now().Unix()
  168. mtime := ctime
  169. if len(advices) > 0 {
  170. for _, advice := range advices {
  171. var s models.HisDoctorAdviceInfo
  172. s.PrescriptionId = prescription.ID
  173. s.AdviceType = 2
  174. s.AdviceDoctor = adminInfo.AdminUser.Id
  175. s.StopState = 2
  176. s.ExecutionState = 2
  177. s.AdviceDate = recordDateTime
  178. s.Status = 1
  179. s.UserOrgId = adminInfo.CurrentOrgId
  180. s.RecordDate = recordDateTime
  181. s.StartTime = recordDateTime
  182. s.Groupno = groupNo
  183. s.CreatedTime = ctime
  184. s.UpdatedTime = mtime
  185. s.PatientId = patient_id
  186. s.HisPatientId = his_patient_id
  187. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  188. if errcode > 0 {
  189. c.ServeFailJSONWithSGJErrorCode(errcode)
  190. return
  191. }
  192. service.CreateHisDoctorAdvice(&s)
  193. }
  194. }
  195. }
  196. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  197. projects := items["project"].([]interface{})
  198. if len(projects) > 0 {
  199. for _, project := range projects {
  200. var p models.HisPrescriptionProject
  201. p.PrescriptionId = prescription.ID
  202. p.Ctime = time.Now().Unix()
  203. p.Mtime = time.Now().Unix()
  204. p.PatientId = patient_id
  205. p.RecordDate = recordDateTime
  206. p.UserOrgId = adminInfo.CurrentOrgId
  207. p.HisPatientId = his_patient_id
  208. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  209. if errcode > 0 {
  210. c.ServeFailJSONWithSGJErrorCode(errcode)
  211. return
  212. }
  213. service.CreateHisProjectTwo(&p)
  214. }
  215. }
  216. }
  217. }
  218. }
  219. //查询患者今日处方信息
  220. //_, errcode := service.GetHisPrescriptionTwo(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
  221. //if errcode == nil{
  222. // //改变患者信息状态
  223. // service.UpdatedHisPatient(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
  224. //
  225. //}
  226. }
  227. if err == nil {
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "msg": "保存成功",
  230. })
  231. return
  232. } else {
  233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  234. return
  235. }
  236. }
  237. func (c *HisApiController) CreateHisAdditionalCharge() {
  238. his_patient_id, _ := c.GetInt64("his_patient_id")
  239. patient_id, _ := c.GetInt64("patient_id")
  240. record_date := c.GetString("record_date")
  241. timeLayout := "2006-01-02"
  242. loc, _ := time.LoadLocation("Local")
  243. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  244. if err != nil {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. return
  247. }
  248. adminInfo := c.GetAdminUserInfo()
  249. recordDateTime := theTime.Unix()
  250. dataBody := make(map[string]interface{}, 0)
  251. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  252. if err != nil {
  253. utils.ErrorLog(err.Error())
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. var additions []*models.HisAdditionalCharge
  258. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  259. additions, _ := dataBody["addition"].([]interface{})
  260. if len(additions) > 0 {
  261. for _, item := range additions {
  262. items := item.(map[string]interface{})
  263. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  264. utils.ErrorLog("item_id")
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. item_id := int64(items["item_id"].(float64))
  269. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  270. utils.ErrorLog("item_name")
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  272. return
  273. }
  274. item_name := items["item_name"].(string)
  275. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  276. utils.ErrorLog("price")
  277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  278. return
  279. }
  280. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  281. ctime := time.Now().Unix()
  282. additional := &models.HisAdditionalCharge{
  283. PatientId: patient_id,
  284. HisPatientId: his_patient_id,
  285. UserOrgId: adminInfo.CurrentOrgId,
  286. RecordDate: recordDateTime,
  287. CreatedTime: ctime,
  288. UpdatedTime: ctime,
  289. Modifier: adminInfo.AdminUser.Id,
  290. Creator: adminInfo.AdminUser.Id,
  291. Price: price,
  292. ItemName: item_name,
  293. ItemId: item_id,
  294. Status: 1,
  295. }
  296. additions = append(additions, additional)
  297. }
  298. }
  299. }
  300. for _, item := range additions {
  301. service.CreateAddtionalCharge(item)
  302. }
  303. c.ServeSuccessJSON(map[string]interface{}{
  304. "msg": "创建成功",
  305. })
  306. }
  307. func (c *HisApiController) CreateHisPatientCaseHistory() {
  308. diagnostic := c.GetString("diagnostic")
  309. temperature, _ := c.GetFloat("temperature")
  310. blood_sugar, _ := c.GetFloat("blood_sugar")
  311. pulse, _ := c.GetFloat("pulse")
  312. sbp, _ := c.GetFloat("sbp")
  313. dbp, _ := c.GetFloat("dbp")
  314. blood_fat, _ := c.GetFloat("blood_fat")
  315. height, _ := c.GetFloat("height")
  316. sick_type, _ := c.GetInt64("sick_type")
  317. symptom := c.GetString("symptom")
  318. sick_date := c.GetString("sick_date")
  319. is_infect, _ := c.GetInt64("is_infect")
  320. chief_conplaint := c.GetString("chief_conplaint")
  321. history_of_present_illness := c.GetString("history_of_present_illness")
  322. past_history := c.GetString("past_history")
  323. personal_history := c.GetString("personal_history")
  324. family_history := c.GetString("family_history")
  325. record_date := c.GetString("record_date")
  326. patient_id, _ := c.GetInt64("patient_id")
  327. timeLayout := "2006-01-02"
  328. loc, _ := time.LoadLocation("Local")
  329. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  330. if err != nil {
  331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  332. return
  333. }
  334. recordDateTime := theTime.Unix()
  335. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  336. if err != nil {
  337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  338. return
  339. }
  340. sickTimes := sickTime.Unix()
  341. ctime := time.Now().Unix()
  342. caseHistory := models.HisPatientCaseHistory{
  343. HisPatientId: patient_id,
  344. Temperature: temperature,
  345. BloodSugar: blood_sugar,
  346. Pulse: pulse,
  347. Sbp: sbp,
  348. Dbp: dbp,
  349. Height: height,
  350. BloodFat: blood_fat,
  351. SickType: sick_type,
  352. Symptom: symptom,
  353. SickDate: sickTimes,
  354. IsInfect: is_infect,
  355. HistoryOfPresentIllness: history_of_present_illness,
  356. PastHistory: past_history,
  357. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  358. ChiefConplaint: chief_conplaint,
  359. PersonalHistory: personal_history,
  360. FamilyHistory: family_history,
  361. Diagnostic: diagnostic,
  362. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  363. Status: 1,
  364. Ctime: ctime,
  365. Mtime: ctime,
  366. RecordDate: recordDateTime,
  367. }
  368. err = service.SaveHisPatientCaseHistory(caseHistory)
  369. if err != nil {
  370. c.ServeSuccessJSON(map[string]interface{}{
  371. "msg": "保存成功",
  372. })
  373. }
  374. }
  375. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  376. patient_id, _ := c.GetInt64("patient_id", 0)
  377. adminUser := c.GetAdminUserInfo()
  378. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  379. c.ServeSuccessJSON(map[string]interface{}{
  380. "list": caseHistorys,
  381. })
  382. }
  383. func (c *HisApiController) GetHisPatientCaseHistory() {
  384. record_date, _ := c.GetInt64("record_date", 0)
  385. patient_id, _ := c.GetInt64("patient_id", 0)
  386. admin := c.GetAdminUserInfo()
  387. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  388. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "info": info,
  391. "case_history": case_history,
  392. })
  393. }
  394. func (c *HisApiController) CreateCaseHistoryTemplate() {
  395. template_name := c.GetString("template_name")
  396. template_remark := c.GetString("template_remark")
  397. doctor := c.GetAdminUserInfo().AdminUser.Id
  398. diagnostic := c.GetString("diagnostic")
  399. chief_conplaint := c.GetString("chief_conplaint")
  400. history_of_present_illness := c.GetString("history_of_present_illness")
  401. past_history := c.GetString("past_history")
  402. personal_history := c.GetString("personal_history")
  403. family_history := c.GetString("family_history")
  404. record_date := c.GetString("record_date")
  405. timeLayout := "2006-01-02"
  406. loc, _ := time.LoadLocation("Local")
  407. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  408. if err != nil {
  409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  410. return
  411. }
  412. recordDateTime := theTime.Unix()
  413. ctime := time.Now().Unix()
  414. template := models.HisCaseHistoryTemplate{
  415. HistoryOfPresentIllness: history_of_present_illness,
  416. PastHistory: past_history,
  417. ChiefConplaint: chief_conplaint,
  418. PersonalHistory: personal_history,
  419. FamilyHistory: family_history,
  420. Diagnostic: diagnostic,
  421. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  422. Status: 1,
  423. Ctime: ctime,
  424. Mtime: ctime,
  425. RecordDate: recordDateTime,
  426. TemplateName: template_name,
  427. TemplateRemark: template_remark,
  428. Creator: doctor,
  429. Modifier: doctor,
  430. }
  431. err = service.SaveHisPatientCaseHistoryTemplate(template)
  432. if err == nil {
  433. c.ServeSuccessJSON(map[string]interface{}{
  434. "msg": "保存成功",
  435. })
  436. } else {
  437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  438. return
  439. }
  440. }
  441. func (c *HisApiController) GetCaseHistoryTemplate() {
  442. admin := c.GetAdminUserInfo()
  443. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId)
  444. c.ServeSuccessJSON(map[string]interface{}{
  445. "template": template,
  446. })
  447. }
  448. func (c *HisApiController) GetPrintHisPatientCaseHistory() {
  449. }
  450. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  451. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  452. utils.ErrorLog("drug_name")
  453. return enums.ErrorCodeParamWrong
  454. }
  455. adviceName, _ := json["drug_name"].(string)
  456. if len(adviceName) == 0 {
  457. utils.ErrorLog("len(advice_name) == 0")
  458. return enums.ErrorCodeParamWrong
  459. }
  460. advice.AdviceName = adviceName
  461. adviceDesc, _ := json["advice_desc"].(string)
  462. advice.AdviceDesc = adviceDesc
  463. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  464. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  465. advice.DrugSpec = drugSpec
  466. }
  467. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  468. remark, _ := json["remark"].(string)
  469. advice.Remark = remark
  470. }
  471. if json["id"] == nil {
  472. advice.DrugId = 0
  473. } else {
  474. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  475. drug_id := int64(json["id"].(float64))
  476. advice.DrugId = drug_id
  477. }
  478. }
  479. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  480. drugSpecUnit, _ := json["min_unit"].(string)
  481. advice.DrugSpecUnit = drugSpecUnit
  482. }
  483. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  484. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  485. advice.SingleDose = singleDose
  486. }
  487. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  488. singleDoseUnit, _ := json["min_unit"].(string)
  489. advice.SingleDoseUnit = singleDoseUnit
  490. }
  491. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  492. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  493. advice.PrescribingNumber = prescribingNumber
  494. }
  495. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  496. prescribingNumberUnit, _ := json["min_unit"].(string)
  497. advice.PrescribingNumberUnit = prescribingNumberUnit
  498. }
  499. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  500. deliveryWay, _ := json["delivery_way"].(string)
  501. advice.DeliveryWay = deliveryWay
  502. }
  503. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  504. executionFrequency, _ := json["execution_frequency"].(string)
  505. advice.ExecutionFrequency = executionFrequency
  506. }
  507. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  508. remark, _ := json["remark"].(string)
  509. advice.Remark = remark
  510. }
  511. //if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  512. // advice.Price = json["retail_price"].(float64)
  513. //}
  514. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  515. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  516. advice.Price = price
  517. }
  518. return 0
  519. }
  520. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  521. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  522. project_id := int64(json["id"].(float64))
  523. project.ProjectId = project_id
  524. }
  525. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  526. price := int64(json["price"].(float64))
  527. formatInt_price := strconv.FormatInt(price, 10)
  528. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  529. project.Price = float_price
  530. }
  531. return 0
  532. }