his_api_controller.go 20KB

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