his_api_controller.go 73KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "io/ioutil"
  13. "math/rand"
  14. "net/http"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  35. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  36. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  39. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  40. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  41. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  42. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  43. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  44. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  45. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  46. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  47. //新增附加费用
  48. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  49. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  50. }
  51. func (c *HisApiController) GetHisPatientList() {
  52. types, _ := c.GetInt64("type", 0)
  53. record_date := c.GetString("record_date")
  54. timeLayout := "2006-01-02"
  55. loc, _ := time.LoadLocation("Local")
  56. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  57. if err != nil {
  58. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  59. return
  60. }
  61. recordDateTime := theTime.Unix()
  62. adminInfo := c.GetAdminUserInfo()
  63. patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  64. var total_one int64
  65. var total_two int64
  66. //获取当前用户的信息
  67. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  68. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  69. //获取所有科室信息
  70. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  71. for _, item := range patients {
  72. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  73. total_one = total_one + 1
  74. }
  75. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  76. total_two = total_two + 1
  77. }
  78. }
  79. if types == 0 {
  80. c.ServeSuccessJSON(map[string]interface{}{
  81. "list": patients,
  82. "total_one": total_one,
  83. "total_two": total_two,
  84. "info": adminUserInfo,
  85. "doctors": doctors,
  86. "department": department,
  87. })
  88. } else if types == 1 { //未就诊
  89. var patientsOne []*service.Schedule
  90. for _, item := range patients {
  91. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  92. patientsOne = append(patientsOne, item)
  93. }
  94. }
  95. c.ServeSuccessJSON(map[string]interface{}{
  96. "list": patientsOne,
  97. "total_one": total_one,
  98. "total_two": total_two,
  99. "info": adminUserInfo,
  100. "doctors": doctors,
  101. "department": department,
  102. })
  103. } else if types == 2 { //已就诊
  104. var patientsTwo []*service.Schedule
  105. for _, item := range patients {
  106. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  107. patientsTwo = append(patientsTwo, item)
  108. }
  109. }
  110. c.ServeSuccessJSON(map[string]interface{}{
  111. "list": patientsTwo,
  112. "total_one": total_one,
  113. "total_two": total_two,
  114. "info": adminUserInfo,
  115. "doctors": doctors,
  116. "department": department,
  117. })
  118. }
  119. }
  120. func (c *HisApiController) GetHisPatientInfo() {
  121. patient_id, _ := c.GetInt64("patient_id")
  122. record_date := c.GetString("record_date")
  123. number := c.GetString("number")
  124. timeLayout := "2006-01-02"
  125. loc, _ := time.LoadLocation("Local")
  126. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  127. if err != nil {
  128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  129. return
  130. }
  131. recordDateTime := theTime.Unix()
  132. admin := c.GetAdminUserInfo()
  133. his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  134. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  135. prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
  136. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  137. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  138. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  139. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  140. //addtions, _ := service.GetAllAdditionCharge(admin.CurrentOrgId, patient_id, recordDateTime)
  141. c.ServeSuccessJSON(map[string]interface{}{
  142. "his_info": his_patient_info,
  143. "xt_info": xt_patient_info,
  144. "prescription": prescriptions,
  145. "case_history": case_history,
  146. "info": patientPrescriptionInfo,
  147. "last_info": lastPatientPrescriptionInfo,
  148. "order": order,
  149. })
  150. return
  151. }
  152. func (c *HisApiController) GetHisPrescriptionConfig() {
  153. adminInfo := c.GetAdminUserInfo()
  154. //获取医嘱模版
  155. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  156. //获取所有基础药
  157. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  158. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  159. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  160. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  161. //获取所有科室信息
  162. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  163. //获取诊断信息
  164. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  165. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  166. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  167. c.ServeSuccessJSON(map[string]interface{}{
  168. "drugs": drugs,
  169. "advices_template": advices,
  170. "drugways": drugways,
  171. "efs": efs,
  172. "doctors": doctors,
  173. "department": department,
  174. "sick": sick,
  175. "additions": additions,
  176. "diagnose": diagnose,
  177. })
  178. }
  179. func (c *HisApiController) CreateHisPrescription() {
  180. record_date := c.GetString("record_date")
  181. patient_id, _ := c.GetInt64("patient_id")
  182. reg_type, _ := c.GetInt64("reg_type")
  183. diagnose, _ := c.GetInt64("diagnose")
  184. sick_type, _ := c.GetInt64("sick_type")
  185. sick_history := c.GetString("sick_history")
  186. doctor_id, _ := c.GetInt64("doctor", 0)
  187. department, _ := c.GetInt64("department", 0)
  188. his_patient_id, _ := c.GetInt64("his_patient_id")
  189. dataBody := make(map[string]interface{}, 0)
  190. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  191. if err != nil {
  192. utils.ErrorLog(err.Error())
  193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  194. return
  195. }
  196. timeLayout := "2006-01-02"
  197. loc, _ := time.LoadLocation("Local")
  198. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  199. if err != nil {
  200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  201. return
  202. }
  203. adminInfo := c.GetAdminUserInfo()
  204. recordDateTime := theTime.Unix()
  205. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  206. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  207. var hpInfo models.HisPrescriptionInfo
  208. if info.ID == 0 {
  209. var randNum int
  210. randNum = rand.Intn(10000) + 1000
  211. timestamp := time.Now().Unix()
  212. tempTime := time.Unix(timestamp, 0)
  213. timeFormat := tempTime.Format("20060102150405")
  214. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  215. hpInfo = models.HisPrescriptionInfo{
  216. UserOrgId: adminInfo.CurrentOrgId,
  217. RecordDate: theTime.Unix(),
  218. PatientId: patient_id,
  219. Status: 1,
  220. Ctime: time.Now().Unix(),
  221. Mtime: time.Now().Unix(),
  222. Creator: adminInfo.AdminUser.Id,
  223. Modifier: adminInfo.AdminUser.Id,
  224. Diagnosis: diagnose,
  225. SickHistory: sick_history,
  226. Departments: department,
  227. RegisterType: reg_type,
  228. PrescriptionNumber: p_number,
  229. PrescriptionStatus: 1,
  230. Doctor: role.UserName,
  231. DoctorId: doctor_id,
  232. SickType: sick_type,
  233. }
  234. service.SavePatientPrescriptionInfo(hpInfo)
  235. } else {
  236. hpInfo = models.HisPrescriptionInfo{
  237. ID: info.ID,
  238. UserOrgId: adminInfo.CurrentOrgId,
  239. RecordDate: info.RecordDate,
  240. PatientId: info.PatientId,
  241. Status: 1,
  242. Ctime: info.Ctime,
  243. Mtime: time.Now().Unix(),
  244. Creator: info.Creator,
  245. Modifier: adminInfo.AdminUser.Id,
  246. Diagnosis: diagnose,
  247. SickHistory: sick_history,
  248. Departments: department,
  249. RegisterType: reg_type,
  250. PrescriptionNumber: info.PrescriptionNumber,
  251. Doctor: role.UserName,
  252. PrescriptionStatus: info.PrescriptionStatus,
  253. DoctorId: doctor_id,
  254. SickType: sick_type,
  255. }
  256. service.SavePatientPrescriptionInfo(hpInfo)
  257. }
  258. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  259. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  260. if len(prescriptions) > 0 {
  261. for _, item := range prescriptions {
  262. items := item.(map[string]interface{})
  263. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  264. utils.ErrorLog("id")
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. id := int64(items["id"].(float64))
  269. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  270. utils.ErrorLog("type")
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  272. return
  273. }
  274. types := int64(items["type"].(float64))
  275. ctime := time.Now().Unix()
  276. prescription := &models.HisPrescription{
  277. ID: id,
  278. PatientId: patient_id,
  279. UserOrgId: adminInfo.CurrentOrgId,
  280. RecordDate: recordDateTime,
  281. Ctime: ctime,
  282. Mtime: ctime,
  283. Type: types,
  284. Modifier: adminInfo.AdminUser.Id,
  285. Creator: adminInfo.AdminUser.Id,
  286. Status: 1,
  287. Doctor: role.UserName,
  288. HisPatientId: his_patient_id,
  289. OrderStatus: 1,
  290. BatchNumber: "",
  291. PrescriptionNumber: hpInfo.PrescriptionNumber,
  292. }
  293. service.SaveHisPrescription(prescription)
  294. //更改患者挂号状态
  295. _, err := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  296. fmt.Println("更改失败", err)
  297. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  298. advices := items["advices"].([]interface{})
  299. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  300. groupNo := int64(0)
  301. ctime := time.Now().Unix()
  302. mtime := ctime
  303. if len(advices) > 0 {
  304. for _, advice := range advices {
  305. var s models.HisDoctorAdviceInfo
  306. s.PrescriptionId = prescription.ID
  307. s.AdviceType = 2
  308. s.AdviceDoctor = adminInfo.AdminUser.Id
  309. s.StopState = 2
  310. s.ExecutionState = 2
  311. s.AdviceDate = recordDateTime
  312. s.Status = 1
  313. s.UserOrgId = adminInfo.CurrentOrgId
  314. s.RecordDate = recordDateTime
  315. s.StartTime = recordDateTime
  316. s.Groupno = groupNo
  317. s.CreatedTime = ctime
  318. s.UpdatedTime = mtime
  319. s.PatientId = patient_id
  320. s.HisPatientId = his_patient_id
  321. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  322. if errcode > 0 {
  323. c.ServeFailJSONWithSGJErrorCode(errcode)
  324. return
  325. }
  326. service.CreateHisDoctorAdvice(&s)
  327. var randNum int
  328. randNum = rand.Intn(10000) + 1000
  329. timestamp := time.Now().Unix()
  330. tempTime := time.Unix(timestamp, 0)
  331. timeFormat := tempTime.Format("20060102150405")
  332. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  333. service.CreateHisDoctorAdvice(&s)
  334. }
  335. }
  336. }
  337. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  338. projects := items["project"].([]interface{})
  339. if len(projects) > 0 {
  340. for _, project := range projects {
  341. var p models.HisPrescriptionProject
  342. p.PrescriptionId = prescription.ID
  343. p.Ctime = time.Now().Unix()
  344. p.Mtime = time.Now().Unix()
  345. p.PatientId = patient_id
  346. p.RecordDate = recordDateTime
  347. p.UserOrgId = adminInfo.CurrentOrgId
  348. p.HisPatientId = his_patient_id
  349. p.Status = 1
  350. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  351. if errcode > 0 {
  352. c.ServeFailJSONWithSGJErrorCode(errcode)
  353. return
  354. }
  355. service.CreateHisProjectTwo(&p)
  356. var randNum int
  357. randNum = rand.Intn(10000) + 1000
  358. timestamp := time.Now().Unix()
  359. tempTime := time.Unix(timestamp, 0)
  360. timeFormat := tempTime.Format("20060102150405")
  361. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  362. service.SaveHisProjectTwo(&p)
  363. }
  364. }
  365. }
  366. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  367. addition := items["addition"].([]interface{})
  368. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  369. ctime := time.Now().Unix()
  370. mtime := ctime
  371. if len(addition) > 0 {
  372. for _, item := range addition {
  373. var s models.HisAdditionalCharge
  374. s.PrescriptionId = prescription.ID
  375. s.Status = 1
  376. s.UserOrgId = adminInfo.CurrentOrgId
  377. s.RecordDate = recordDateTime
  378. s.CreatedTime = ctime
  379. s.UpdatedTime = mtime
  380. s.PatientId = patient_id
  381. s.HisPatientId = his_patient_id
  382. errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}))
  383. if errcode > 0 {
  384. c.ServeFailJSONWithSGJErrorCode(errcode)
  385. return
  386. }
  387. service.CreateAdditionalCharge(&s)
  388. var randNum int
  389. randNum = rand.Intn(10000) + 1000
  390. timestamp := time.Now().Unix()
  391. tempTime := time.Unix(timestamp, 0)
  392. timeFormat := tempTime.Format("20060102150405")
  393. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  394. service.CreateAdditionalCharge(&s)
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. if err == nil {
  402. c.ServeSuccessJSON(map[string]interface{}{
  403. "msg": "保存成功",
  404. })
  405. return
  406. } else {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  408. return
  409. }
  410. }
  411. func (c *HisApiController) DeletePrescription() {
  412. prescription_id, _ := c.GetInt64("id")
  413. //TODO 需要判断是否已经结算
  414. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  415. if err == nil {
  416. c.ServeSuccessJSON(map[string]interface{}{
  417. "msg": "删除成功",
  418. })
  419. return
  420. } else {
  421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  422. return
  423. }
  424. }
  425. func (c *HisApiController) DeleteDoctorAdvice() {
  426. id, _ := c.GetInt64("id")
  427. //TODO 需要判断是否已经结算
  428. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  429. if err == nil {
  430. c.ServeSuccessJSON(map[string]interface{}{
  431. "msg": "删除成功",
  432. })
  433. return
  434. } else {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  436. return
  437. }
  438. }
  439. func (c *HisApiController) DeleteProject() {
  440. id, _ := c.GetInt64("id")
  441. //TODO 需要判断是否已经结算
  442. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  443. if err == nil {
  444. c.ServeSuccessJSON(map[string]interface{}{
  445. "msg": "删除成功",
  446. })
  447. return
  448. } else {
  449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  450. return
  451. }
  452. }
  453. func (c *HisApiController) CreateHisAdditionalCharge() {
  454. his_patient_id, _ := c.GetInt64("his_patient_id")
  455. patient_id, _ := c.GetInt64("patient_id")
  456. record_date := c.GetString("record_date")
  457. timeLayout := "2006-01-02"
  458. loc, _ := time.LoadLocation("Local")
  459. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  460. if err != nil {
  461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  462. return
  463. }
  464. adminInfo := c.GetAdminUserInfo()
  465. recordDateTime := theTime.Unix()
  466. dataBody := make(map[string]interface{}, 0)
  467. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  468. if err != nil {
  469. utils.ErrorLog(err.Error())
  470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  471. return
  472. }
  473. var additions []*models.HisAdditionalCharge
  474. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  475. additions, _ := dataBody["addition"].([]interface{})
  476. if len(additions) > 0 {
  477. for _, item := range additions {
  478. items := item.(map[string]interface{})
  479. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  480. utils.ErrorLog("item_id")
  481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  482. return
  483. }
  484. item_id := int64(items["item_id"].(float64))
  485. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  486. utils.ErrorLog("item_name")
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. item_name := items["item_name"].(string)
  491. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  492. utils.ErrorLog("price")
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  494. return
  495. }
  496. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  497. ctime := time.Now().Unix()
  498. additional := &models.HisAdditionalCharge{
  499. PatientId: patient_id,
  500. HisPatientId: his_patient_id,
  501. UserOrgId: adminInfo.CurrentOrgId,
  502. RecordDate: recordDateTime,
  503. CreatedTime: ctime,
  504. UpdatedTime: ctime,
  505. Modifier: adminInfo.AdminUser.Id,
  506. Creator: adminInfo.AdminUser.Id,
  507. Price: price,
  508. ItemName: item_name,
  509. ItemId: item_id,
  510. Status: 1,
  511. }
  512. additions = append(additions, additional)
  513. }
  514. }
  515. }
  516. for _, item := range additions {
  517. service.CreateAddtionalCharge(item)
  518. }
  519. c.ServeSuccessJSON(map[string]interface{}{
  520. "msg": "创建成功",
  521. })
  522. }
  523. func (c *HisApiController) CreateHisPatientCaseHistory() {
  524. blood_fat := c.GetString("blood_fat")
  525. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  526. fmt.Println("33333333", bloodfatfloat)
  527. blood_sugar := c.GetString("blood_sugar")
  528. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  529. fmt.Println(bloodsugarfloat)
  530. chief_conplaint := c.GetString("chief_conplaint")
  531. dbp := c.GetString("dbp")
  532. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  533. delivery_way, _ := c.GetInt64("delivery_way")
  534. diagnostic := c.GetString("diagnostic")
  535. fmt.Println("diagnostic", diagnostic)
  536. family_history := c.GetString("family_history")
  537. fmt.Println(family_history)
  538. height := c.GetString("height")
  539. history_of_present_illness := c.GetString("history_of_present_illness")
  540. is_infect, _ := c.GetInt64("is_infect")
  541. fmt.Println("is", is_infect)
  542. past_history := c.GetString("past_history")
  543. patient_id, _ := c.GetInt64("patient_id")
  544. his_patient_id, _ := c.GetInt64("his_patient_id")
  545. fmt.Println("patient_id", patient_id)
  546. personal_history := c.GetString("personal_history")
  547. pulse := c.GetString("pulse")
  548. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  549. sbp := c.GetString("sbp")
  550. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  551. heightfloat, _ := strconv.ParseFloat(height, 64)
  552. sicktype := c.GetString("sick_type")
  553. fmt.Println("sicketype", sicktype)
  554. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  555. symptom := c.GetString("symptom")
  556. sick_date := c.GetString("sick_date")
  557. temperatures := c.GetString("temperature")
  558. fmt.Println("temperatures", temperatures)
  559. temperature, _ := strconv.ParseFloat(temperatures, 64)
  560. record_date := c.GetString("record_date")
  561. breathing := c.GetString("breathing")
  562. doctor_advice := c.GetString("doctor_advice")
  563. remark := c.GetString("remark")
  564. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  565. fmt.Println("breathingfloat", breathingfloat)
  566. timeLayout := "2006-01-02"
  567. loc, _ := time.LoadLocation("Local")
  568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  569. if err != nil {
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  571. return
  572. }
  573. recordDateTime := theTime.Unix()
  574. fmt.Println("recordDataTime", recordDateTime)
  575. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  576. if err != nil {
  577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  578. return
  579. }
  580. sickTimes := sickTime.Unix()
  581. ctime := time.Now().Unix()
  582. caseHistory := models.HisPatientCaseHistory{
  583. HisPatientId: his_patient_id,
  584. PatientId: patient_id,
  585. Temperature: temperature,
  586. BloodSugar: bloodsugarfloat,
  587. Pulse: pulsefloat,
  588. Sbp: sbpfloat,
  589. Dbp: dbpfloat,
  590. Height: heightfloat,
  591. BloodFat: bloodfatfloat,
  592. SickType: sick_type,
  593. Symptom: symptom,
  594. SickDate: sickTimes,
  595. IsInfect: is_infect,
  596. HistoryOfPresentIllness: history_of_present_illness,
  597. PastHistory: past_history,
  598. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  599. ChiefConplaint: chief_conplaint,
  600. PersonalHistory: personal_history,
  601. FamilyHistory: family_history,
  602. Diagnostic: diagnostic,
  603. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  604. Status: 1,
  605. Ctime: ctime,
  606. Mtime: ctime,
  607. RecordDate: recordDateTime,
  608. DeliveryWay: delivery_way,
  609. Breathing: breathingfloat,
  610. DoctorAdvice: doctor_advice,
  611. Remark: remark,
  612. }
  613. err = service.SaveHisPatientCaseHistory(&caseHistory)
  614. if err != nil {
  615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  616. return
  617. }
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "caseHistory": caseHistory,
  620. })
  621. return
  622. //查询该患者是否有病历
  623. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  624. //if errcode == gorm.ErrRecordNotFound {
  625. // err = service.SaveHisPatientCaseHistory(caseHistory)
  626. // if err != nil {
  627. // c.ServeSuccessJSON(map[string]interface{}{
  628. // "msg": "保存成功",
  629. // })
  630. // }
  631. //} else if errcode == nil {
  632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  633. // return
  634. //}
  635. }
  636. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  637. patient_id, _ := c.GetInt64("patient_id", 0)
  638. adminUser := c.GetAdminUserInfo()
  639. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  640. c.ServeSuccessJSON(map[string]interface{}{
  641. "list": caseHistorys,
  642. })
  643. }
  644. func (c *HisApiController) GetHisPatientCaseHistory() {
  645. record_date, _ := c.GetInt64("record_date", 0)
  646. patient_id, _ := c.GetInt64("patient_id", 0)
  647. admin := c.GetAdminUserInfo()
  648. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  649. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  650. c.ServeSuccessJSON(map[string]interface{}{
  651. "info": info,
  652. "case_history": case_history,
  653. })
  654. }
  655. func (c *HisApiController) CreateCaseHistoryTemplate() {
  656. template_name := c.GetString("template_name")
  657. fmt.Println("template_name22222222222222", template_name)
  658. template_remark := c.GetString("template_remark")
  659. doctor := c.GetAdminUserInfo().AdminUser.Id
  660. diagnostic := c.GetString("diagnostic")
  661. chief_conplaint := c.GetString("chief_conplain")
  662. history_of_present_illness := c.GetString("history_of_present_illness")
  663. past_history := c.GetString("past_history")
  664. personal_history := c.GetString("personal_history")
  665. family_history := c.GetString("family_history")
  666. user_name := c.GetString("user_name")
  667. doctor_advice := c.GetString("doctor_advice")
  668. remark := c.GetString("remark")
  669. //record_date := c.GetString("record_date")
  670. //fmt.Println("record_date--------",record_date)
  671. //timeLayout := "2006-01-02"
  672. //loc, _ := time.LoadLocation("Local")
  673. //
  674. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  675. //if err != nil {
  676. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  677. // return
  678. //}
  679. //recordDateTime := theTime.Unix()
  680. ctime := time.Now().Unix()
  681. template := models.HisCaseHistoryTemplate{
  682. HistoryOfPresentIllness: history_of_present_illness,
  683. PastHistory: past_history,
  684. ChiefConplaint: chief_conplaint,
  685. PersonalHistory: personal_history,
  686. FamilyHistory: family_history,
  687. Diagnostic: diagnostic,
  688. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  689. Status: 1,
  690. Ctime: ctime,
  691. Mtime: ctime,
  692. RecordDate: time.Now().Unix(),
  693. TemplateName: template_name,
  694. TemplateRemark: template_remark,
  695. Creator: doctor,
  696. Modifier: doctor,
  697. UserName: user_name,
  698. DoctorAdvice: doctor_advice,
  699. Remark: remark,
  700. }
  701. err := service.SaveHisPatientCaseHistoryTemplate(template)
  702. if err == nil {
  703. c.ServeSuccessJSON(map[string]interface{}{
  704. "msg": "保存成功",
  705. })
  706. } else {
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  708. return
  709. }
  710. }
  711. func (c *HisApiController) GetCaseHistoryTemplate() {
  712. timeLayout := "2006-01-02"
  713. loc, _ := time.LoadLocation("Local")
  714. keyword := c.GetString("keyword")
  715. start_time := c.GetString("start_time")
  716. end_time := c.GetString("end_time")
  717. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  718. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  719. admin := c.GetAdminUserInfo()
  720. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  721. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  722. c.ServeSuccessJSON(map[string]interface{}{
  723. "template": template,
  724. //"history": history,
  725. })
  726. }
  727. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  728. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  729. utils.ErrorLog("drug_name")
  730. return enums.ErrorCodeParamWrong
  731. }
  732. adviceName, _ := json["drug_name"].(string)
  733. if len(adviceName) == 0 {
  734. utils.ErrorLog("len(advice_name) == 0")
  735. return enums.ErrorCodeParamWrong
  736. }
  737. advice.AdviceName = adviceName
  738. adviceDesc, _ := json["advice_desc"].(string)
  739. advice.AdviceDesc = adviceDesc
  740. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  741. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  742. advice.DrugSpec = drugSpec
  743. }
  744. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  745. remark, _ := json["remark"].(string)
  746. advice.Remark = remark
  747. }
  748. if json["id"] == nil {
  749. advice.DrugId = 0
  750. } else {
  751. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  752. drug_id := int64(json["id"].(float64))
  753. advice.DrugId = drug_id
  754. }
  755. }
  756. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  757. advice_id := int64(json["advice_id"].(float64))
  758. advice.ID = advice_id
  759. }
  760. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  761. drugSpecUnit, _ := json["min_unit"].(string)
  762. advice.DrugSpecUnit = drugSpecUnit
  763. }
  764. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  765. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  766. advice.SingleDose = singleDose
  767. }
  768. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  769. singleDoseUnit, _ := json["single_dose_unit"].(string)
  770. advice.SingleDoseUnit = singleDoseUnit
  771. }
  772. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  773. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  774. advice.PrescribingNumber = prescribingNumber
  775. }
  776. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  777. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  778. advice.PrescribingNumberUnit = prescribingNumberUnit
  779. }
  780. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  781. deliveryWay, _ := json["delivery_way"].(string)
  782. advice.DeliveryWay = deliveryWay
  783. }
  784. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  785. executionFrequency, _ := json["execution_frequency"].(string)
  786. advice.ExecutionFrequency = executionFrequency
  787. }
  788. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  789. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  790. advice.Price = price
  791. }
  792. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  793. med_list_codg, _ := json["medical_insurance_number"].(string)
  794. advice.MedListCodg = med_list_codg
  795. }
  796. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  797. day := int64(json["day"].(float64))
  798. advice.Day = day
  799. }
  800. return 0
  801. }
  802. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  803. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  804. id := int64(json["id"].(float64))
  805. project.ID = id
  806. }
  807. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  808. project_id := int64(json["project_id"].(float64))
  809. project.ProjectId = project_id
  810. fmt.Println(project_id)
  811. fmt.Println(project.ProjectId)
  812. }
  813. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  814. price := int64(json["price"].(float64))
  815. formatInt_price := strconv.FormatInt(price, 10)
  816. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  817. project.Price = float_price
  818. }
  819. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  820. total, _ := json["total"].(string)
  821. totals, _ := strconv.ParseInt(total, 10, 64)
  822. project.Count = totals
  823. }
  824. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  825. medical_code, _ := json["medical_code"].(string)
  826. project.MedListCodg = medical_code
  827. }
  828. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  829. single_dose, _ := json["single_dose"].(string)
  830. project.SingleDose = single_dose
  831. }
  832. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  833. delivery_way, _ := json["delivery_way"].(string)
  834. project.DeliveryWay = delivery_way
  835. }
  836. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  837. execution_frequency, _ := json["execution_frequency"].(string)
  838. project.ExecutionFrequency = execution_frequency
  839. }
  840. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  841. remark, _ := json["remark"].(string)
  842. project.Remark = remark
  843. }
  844. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  845. day, _ := json["number_days"].(string)
  846. project.Day = day
  847. }
  848. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  849. unit, _ := json["unit"].(string)
  850. project.Unit = unit
  851. }
  852. return 0
  853. }
  854. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}) int {
  855. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  856. id := int64(json["id"].(float64))
  857. additionalCharge.ID = id
  858. }
  859. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  860. item_id := int64(json["item_id"].(float64))
  861. additionalCharge.ItemId = item_id
  862. }
  863. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  864. price := int64(json["price"].(float64))
  865. formatInt_price := strconv.FormatInt(price, 10)
  866. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  867. additionalCharge.Price = float_price
  868. }
  869. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  870. count, _ := json["count"].(string)
  871. counts, _ := strconv.ParseInt(count, 10, 64)
  872. additionalCharge.Count = counts
  873. }
  874. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  875. item_name, _ := json["item_name"].(string)
  876. additionalCharge.ItemName = item_name
  877. }
  878. return 0
  879. }
  880. func (c *HisApiController) GetHisOrderList() {
  881. page, _ := c.GetInt64("page", -1)
  882. limit, _ := c.GetInt64("limit", -1)
  883. start_time := c.GetString("start_time")
  884. end_time := c.GetString("end_time")
  885. types, _ := c.GetInt64("type", 0)
  886. keywords := c.GetString("keywords")
  887. timeLayout := "2006-01-02"
  888. loc, _ := time.LoadLocation("Local")
  889. var startTime int64
  890. if len(start_time) > 0 {
  891. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  892. if err != nil {
  893. fmt.Println(err)
  894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  895. return
  896. }
  897. startTime = theTime.Unix()
  898. }
  899. var endTime int64
  900. if len(end_time) > 0 {
  901. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  902. if err != nil {
  903. utils.ErrorLog(err.Error())
  904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  905. return
  906. }
  907. endTime = theTime.Unix()
  908. }
  909. adminUser := c.GetAdminUserInfo()
  910. org_id := adminUser.CurrentOrgId
  911. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords)
  912. if err == nil {
  913. c.ServeSuccessJSON(map[string]interface{}{
  914. "order": order,
  915. "total": total,
  916. })
  917. } else {
  918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  919. return
  920. }
  921. }
  922. func (c *HisApiController) GetHisOrder() {
  923. patient_id, _ := c.GetInt64("patient_id", 0)
  924. number := c.GetString("number")
  925. adminInfo := c.GetAdminUserInfo()
  926. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  927. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.SettleAccountsDate, order.Number)
  928. if err == nil {
  929. c.ServeSuccessJSON(map[string]interface{}{
  930. "order": order,
  931. "prescription": prescriptions,
  932. })
  933. } else {
  934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  935. return
  936. }
  937. }
  938. func (c *HisApiController) GetHisPrescriptionList() {
  939. record_date := c.GetString("record_date")
  940. keywords := c.GetString("keywords")
  941. page, _ := c.GetInt64("page")
  942. limit, _ := c.GetInt64("limit")
  943. timeLayout := "2006-01-02"
  944. loc, _ := time.LoadLocation("Local")
  945. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  946. if err != nil {
  947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  948. return
  949. }
  950. recordDateTime := theTime.Unix()
  951. adminInfo := c.GetAdminUserInfo()
  952. prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  953. //adminInfo := c.GetAdminUserInfo()
  954. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  955. //fmt.Println(prescriptionOrder)
  956. if err == nil {
  957. c.ServeSuccessJSON(map[string]interface{}{
  958. "order": prescriptionOrder,
  959. "total": total,
  960. })
  961. } else {
  962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  963. return
  964. }
  965. }
  966. func (c *HisApiController) GetHisPrescriptionInfo() {
  967. id, _ := c.GetInt64("id")
  968. adminInfo := c.GetAdminUserInfo()
  969. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  970. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  971. if err == nil {
  972. c.ServeSuccessJSON(map[string]interface{}{
  973. "order": prescriptionOrder,
  974. "prescription": prescription,
  975. })
  976. } else {
  977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  978. return
  979. }
  980. }
  981. func (c *HisApiController) GetMedicalInsuranceConfig() {
  982. adminUser := c.GetAdminUserInfo()
  983. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  984. c.ServeSuccessJSON(map[string]interface{}{
  985. "config": config,
  986. })
  987. }
  988. type ResultTwo struct {
  989. ErrMsg interface{} `json:"err_msg"`
  990. InfRefmsgid string `json:"inf_refmsgid"`
  991. Infcode int64 `json:"infcode"`
  992. Output struct {
  993. Baseinfo struct {
  994. Age float64 `json:"age"`
  995. Brdy string `json:"brdy"`
  996. Certno string `json:"certno"`
  997. Gend string `json:"gend"`
  998. Naty string `json:"naty"`
  999. PsnCertType string `json:"psn_cert_type"`
  1000. PsnName string `json:"psn_name"`
  1001. PsnNo string `json:"psn_no"`
  1002. } `json:"baseinfo"`
  1003. Idetinfo []interface{} `json:"idetinfo"`
  1004. Iinfo []struct {
  1005. Balc int64 `json:"balc"`
  1006. CvlservFlag string `json:"cvlserv_flag"`
  1007. EmpName string `json:"emp_name"`
  1008. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1009. Insutype string `json:"insutype"`
  1010. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1011. PausInsuDate interface{} `json:"paus_insu_date"`
  1012. PsnInsuDate string `json:"psn_insu_date"`
  1013. PsnInsuStas string `json:"psn_insu_stas"`
  1014. PsnType string `json:"psn_type"`
  1015. } `json:"insuinfo"`
  1016. } `json:"output"`
  1017. RefmsgTime string `json:"refmsg_time"`
  1018. RespondTime string `json:"respond_time"`
  1019. Signtype interface{} `json:"signtype"`
  1020. WarnInfo interface{} `json:"warn_info"`
  1021. }
  1022. type ResultThree struct {
  1023. Cainfo interface{} `json:"cainfo"`
  1024. ErrMsg interface{} `json:"err_msg"`
  1025. InfRefmsgid string `json:"inf_refmsgid"`
  1026. Infcode int64 `json:"infcode"`
  1027. Output struct {
  1028. Data struct {
  1029. IptOtpNo string `json:"ipt_otp_no"`
  1030. MdtrtID string `json:"mdtrt_id"`
  1031. PsnNo string `json:"psn_no"`
  1032. } `json:"data"`
  1033. } `json:"output"`
  1034. RefmsgTime string `json:"refmsg_time"`
  1035. RespondTime string `json:"respond_time"`
  1036. Signtype interface{} `json:"signtype"`
  1037. WarnMsg interface{} `json:"warn_msg"`
  1038. }
  1039. type ResultFour struct {
  1040. Cainfo string `json:"cainfo"`
  1041. ErrMsg string `json:"err_msg"`
  1042. InfRefmsgid string `json:"inf_refmsgid"`
  1043. Infcode int64 `json:"infcode"`
  1044. Output struct {
  1045. Result []struct {
  1046. BasMednFlag string `json:"bas_medn_flag"`
  1047. ChldMedcFlag string `json:"chld_medc_flag"`
  1048. ChrgitmLv string `json:"chrgitm_lv"`
  1049. Cnt float64 `json:"cnt"`
  1050. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1051. DrtReimFlag string `json:"drt_reim_flag"`
  1052. FeedetlSn string `json:"feedetl_sn"`
  1053. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1054. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1055. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1056. ListSpItemFlag string `json:"list_sp_item_flag"`
  1057. LmtUsedFlag string `json:"lmt_used_flag"`
  1058. MedChrgitmType string `json:"med_chrgitm_type"`
  1059. Memo string `json:"memo"`
  1060. OverlmtAmt float64 `json:"overlmt_amt"`
  1061. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1062. Pric float64 `json:"pric"`
  1063. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1064. SelfpayProp float64 `json:"selfpay_prop"`
  1065. } `json:"result"`
  1066. } `json:"output"`
  1067. RefmsgTime string `json:"refmsg_time"`
  1068. RespondTime string `json:"respond_time"`
  1069. Signtype string `json:"signtype"`
  1070. WarnMsg string `json:"warn_msg"`
  1071. }
  1072. type ResultFive struct {
  1073. Insutype string `json:"insutype"`
  1074. }
  1075. type ResultSix struct {
  1076. Cainfo interface{} `json:"cainfo"`
  1077. ErrMsg interface{} `json:"err_msg"`
  1078. InfRefmsgid string `json:"inf_refmsgid"`
  1079. Infcode int64 `json:"infcode"`
  1080. Output struct {
  1081. } `json:"output"`
  1082. RefmsgTime string `json:"refmsg_time"`
  1083. RespondTime string `json:"respond_time"`
  1084. Signtype interface{} `json:"signtype"`
  1085. WarnMsg interface{} `json:"warn_msg"`
  1086. }
  1087. type ResultSeven struct {
  1088. Cainfo string `json:"cainfo"`
  1089. ErrMsg string `json:"err_msg"`
  1090. InfRefmsgid string `json:"inf_refmsgid"`
  1091. Infcode int64 `json:"infcode"`
  1092. Output struct {
  1093. Setldetail []interface{} `json:"setldetail"`
  1094. Setlinfo struct {
  1095. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1096. AcctPay float64 `json:"acct_pay"`
  1097. ActPayDedc float64 `json:"act_pay_dedc"`
  1098. Age float64 `json:"age"`
  1099. Balc float64 `json:"balc"`
  1100. Brdy string `json:"brdy"`
  1101. Certno string `json:"certno"`
  1102. ClrOptins string `json:"clr_optins"`
  1103. ClrType string `json:"clr_type"`
  1104. ClrWay string `json:"clr_way"`
  1105. CvlservFlag string `json:"cvlserv_flag"`
  1106. CvlservPay float64 `json:"cvlserv_pay"`
  1107. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1108. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1109. Gend string `json:"gend"`
  1110. HifesPay float64 `json:"hifes_pay"`
  1111. HifmiPay float64 `json:"hifmi_pay"`
  1112. HifobPay float64 `json:"hifob_pay"`
  1113. HifpPay float64 `json:"hifp_pay"`
  1114. HospPartAmt float64 `json:"hosp_part_amt"`
  1115. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1116. Insutype string `json:"insutype"`
  1117. MafPay float64 `json:"maf_pay"`
  1118. MdtrtCertType string `json:"mdtrt_cert_type"`
  1119. MdtrtID string `json:"mdtrt_id"`
  1120. MedType string `json:"med_type"`
  1121. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1122. MedinsSetlID string `json:"medins_setl_id"`
  1123. Naty string `json:"naty"`
  1124. OthPay float64 `json:"oth_pay"`
  1125. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1126. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1127. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1128. PsnCashPay float64 `json:"psn_cash_pay"`
  1129. PsnCertType string `json:"psn_cert_type"`
  1130. PsnName string `json:"psn_name"`
  1131. PsnNo string `json:"psn_no"`
  1132. PsnPartAmt float64 `json:"psn_part_amt"`
  1133. PsnType string `json:"psn_type"`
  1134. SetlID string `json:"setl_id"`
  1135. SetlTime string `json:"setl_time"`
  1136. } `json:"setlinfo"`
  1137. } `json:"output"`
  1138. RefmsgTime string `json:"refmsg_time"`
  1139. RespondTime string `json:"respond_time"`
  1140. Signtype interface{} `json:"signtype"`
  1141. WarnMsg interface{} `json:"warn_msg"`
  1142. }
  1143. type Custom struct {
  1144. DetItemFeeSumamt string
  1145. Cut string
  1146. FeedetlSn string
  1147. Price string
  1148. MedListCodg string
  1149. Type int64
  1150. AdviceId int64
  1151. ProjectId int64
  1152. ItemId int64
  1153. }
  1154. //获取个人信息----挂号-----上传就诊信息
  1155. func (c *HisApiController) GetRegisterInfo() {
  1156. id, _ := c.GetInt64("id")
  1157. record_time := c.GetString("record_time")
  1158. name := c.GetString("name")
  1159. gender, _ := c.GetInt64("gender")
  1160. age, _ := c.GetInt64("age")
  1161. birthday := c.GetString("birthday")
  1162. phone := c.GetString("phone")
  1163. medical_care, _ := c.GetInt64("medical_care")
  1164. id_card := c.GetString("id_card")
  1165. register_type, _ := c.GetInt64("register_type")
  1166. registration_fee, _ := c.GetFloat("registration_fee")
  1167. medical_expenses, _ := c.GetFloat("medical_expenses")
  1168. certificates, _ := c.GetInt64("certificates")
  1169. settlementValue, _ := c.GetInt64("settlement_value")
  1170. social_type, _ := c.GetInt64("social_type")
  1171. medical_insurance_card := c.GetString("medical_insurance_card")
  1172. timeLayout := "2006-01-02"
  1173. loc, _ := time.LoadLocation("Local")
  1174. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1175. birthUnix := birthdays.Unix()
  1176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1177. if err != nil {
  1178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1179. return
  1180. }
  1181. recordDateTime := theTime.Unix()
  1182. adminInfo := c.GetAdminUserInfo()
  1183. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  1184. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1185. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1186. if patient == nil {
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1188. return
  1189. }
  1190. if len(patient.IdCardNo) == 0 {
  1191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1192. return
  1193. }
  1194. //org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  1195. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1196. if config.IsOpen == 1 {
  1197. api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code
  1198. resp, requestErr := http.Get(api)
  1199. if requestErr != nil {
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1201. return
  1202. }
  1203. defer resp.Body.Close()
  1204. body, ioErr := ioutil.ReadAll(resp.Body)
  1205. if ioErr != nil {
  1206. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1208. return
  1209. }
  1210. var respJSON map[string]interface{}
  1211. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1212. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1214. return
  1215. }
  1216. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1217. userJSONBytes, _ := json.Marshal(userJSON)
  1218. var res ResultTwo
  1219. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1220. utils.ErrorLog("解析失败:%v", err)
  1221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1222. return
  1223. }
  1224. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1225. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1226. infoStr := string(Iinfos)
  1227. idetinfoStr := string(Idetinfos)
  1228. his := models.VMHisPatient{
  1229. PsnNo: res.Output.Baseinfo.PsnNo,
  1230. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1231. Certno: res.Output.Baseinfo.Certno,
  1232. PsnName: res.Output.Baseinfo.PsnName,
  1233. Gend: res.Output.Baseinfo.Gend,
  1234. Naty: res.Output.Baseinfo.Naty,
  1235. Brdy: res.Output.Baseinfo.Brdy,
  1236. Age: res.Output.Baseinfo.Age,
  1237. Iinfo: infoStr,
  1238. Idetinfo: idetinfoStr,
  1239. PatientId: patient.ID,
  1240. RecordDate: theTime.Unix(),
  1241. }
  1242. fmt.Println(his)
  1243. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  1244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  1245. return
  1246. }
  1247. timestamp := time.Now().Unix()
  1248. tempTime := time.Unix(timestamp, 0)
  1249. timeFormat := tempTime.Format("20060102150405")
  1250. chrgBchno := rand.Intn(100000) + 10000
  1251. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1252. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1253. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1254. if count <= 0 {
  1255. api := "http://127.0.0.1:9531/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  1256. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1257. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1258. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code
  1259. resp, requestErr := http.Get(api)
  1260. if requestErr != nil {
  1261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1262. return
  1263. }
  1264. defer resp.Body.Close()
  1265. body, ioErr := ioutil.ReadAll(resp.Body)
  1266. if ioErr != nil {
  1267. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1269. return
  1270. }
  1271. var respJSON map[string]interface{}
  1272. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1273. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1275. return
  1276. }
  1277. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1278. userJSONBytes, _ := json.Marshal(respJSON)
  1279. var res ResultThree
  1280. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1281. utils.ErrorLog("解析失败:%v", err)
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1283. return
  1284. }
  1285. if res.Infcode == -1 {
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1287. return
  1288. }
  1289. fmt.Println("000!!!!!!")
  1290. fmt.Println(res)
  1291. fmt.Println(res.Output.Data.MdtrtID)
  1292. fmt.Println(res.Output.Data.PsnNo)
  1293. fmt.Println(res.Output.Data.IptOtpNo)
  1294. his.Number = res.Output.Data.MdtrtID
  1295. his.PsnNo = res.Output.Data.PsnNo
  1296. his.IptOtpNo = res.Output.Data.IptOtpNo
  1297. his.IdCardNo = patient.IdCardNo
  1298. his.PhoneNumber = patient.Phone
  1299. his.UserOrgId = adminInfo.CurrentOrgId
  1300. his.Status = 1
  1301. his.Ctime = time.Now().Unix()
  1302. his.Mtime = time.Now().Unix()
  1303. err := service.CreateHisPatientTwo(&his)
  1304. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  1305. if err == nil {
  1306. api := "http://127.0.0.1:9531/" + "gdyb/four?psn_no=" + his.PsnNo +
  1307. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1308. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + "11" + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code
  1309. resp, requestErr := http.Get(api)
  1310. if requestErr != nil {
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1312. return
  1313. }
  1314. body, ioErr := ioutil.ReadAll(resp.Body)
  1315. if ioErr != nil {
  1316. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1318. return
  1319. }
  1320. var respJSON map[string]interface{}
  1321. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1322. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1324. return
  1325. }
  1326. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1327. userJSONBytes, _ := json.Marshal(respJSON)
  1328. fmt.Println(respJSON)
  1329. fmt.Println(userJSONBytes)
  1330. var res ResultSix
  1331. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1332. utils.ErrorLog("解析失败:%v", err)
  1333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1334. return
  1335. }
  1336. if res.Infcode == -1 {
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1338. return
  1339. }
  1340. c.ServeSuccessJSON(map[string]interface{}{
  1341. "his_info": his,
  1342. })
  1343. } else {
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1345. return
  1346. }
  1347. }
  1348. } else {
  1349. timeStr := time.Now().Format("2006-01-02")
  1350. timeArr := strings.Split(timeStr, "-")
  1351. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1352. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1353. var hisPatient models.XtHisPatient
  1354. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1355. hisPatient = models.XtHisPatient{
  1356. Name: name,
  1357. Age: age,
  1358. Gender: gender,
  1359. Birthday: birthUnix,
  1360. Phone: phone,
  1361. MedicalTreatmentType: medical_care,
  1362. IdType: certificates,
  1363. IdCardNo: id_card,
  1364. BalanceAccountsType: settlementValue,
  1365. SocialType: social_type,
  1366. MedicalInsuranceNumber: medical_insurance_card,
  1367. RegisterType: register_type,
  1368. RegisterCost: registration_fee,
  1369. TreatmentCost: medical_expenses,
  1370. AdminUserId: adminInfo.AdminUser.Id,
  1371. UserOrgId: adminInfo.CurrentOrgId,
  1372. Status: 1,
  1373. RecordDate: recordDateTime,
  1374. IsReturn: 1,
  1375. PatientId: patient.ID,
  1376. Ctime: time.Now().Unix(),
  1377. Mtime: time.Now().Unix(),
  1378. Number: str,
  1379. }
  1380. service.CreateHisPatient(&hisPatient)
  1381. }
  1382. c.ServeSuccessJSON(map[string]interface{}{
  1383. "his_info": hisPatient,
  1384. })
  1385. }
  1386. }
  1387. //上传明细----结算
  1388. func (c *HisApiController) GetUploadInfo() {
  1389. id, _ := c.GetInt64("id")
  1390. record_time := c.GetString("record_time")
  1391. pay_way, _ := c.GetInt64("pay_way")
  1392. pay_price, _ := c.GetFloat("pay_price")
  1393. pay_card_no := c.GetString("pay_card_no")
  1394. discount_price, _ := c.GetFloat("discount_price")
  1395. preferential_price, _ := c.GetFloat("preferential_price")
  1396. reality_price, _ := c.GetFloat("reality_price")
  1397. found_price, _ := c.GetFloat("found_price")
  1398. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1399. private_price, _ := c.GetFloat("private_price")
  1400. timeLayout := "2006-01-02"
  1401. loc, _ := time.LoadLocation("Local")
  1402. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1403. if err != nil {
  1404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1405. return
  1406. }
  1407. recordDateTime := theTime.Unix()
  1408. adminUser := c.GetAdminUserInfo()
  1409. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1410. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1411. timestamp := time.Now().Unix()
  1412. tempTime := time.Unix(timestamp, 0)
  1413. timeFormat := tempTime.Format("20060102150405")
  1414. chrgBchno := rand.Intn(100000) + 10000
  1415. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1416. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1417. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1418. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1419. client := &http.Client{}
  1420. data := make(map[string]interface{})
  1421. data["psn_no"] = his.PsnNo
  1422. data["mdtrt_id"] = his.Number
  1423. data["pre"] = prescriptions
  1424. data["chrg_bchno"] = chrg_bchno
  1425. data["org_name"] = miConfig.OrgName
  1426. data["doctor"] = patientPrescription.Doctor
  1427. data["dept"] = patientPrescription.Departments
  1428. data["fixmedins_code"] = miConfig.Code
  1429. var ids []int64
  1430. //var idsTwo []int64
  1431. //
  1432. for _, item := range prescriptions {
  1433. ids = append(ids, item.ID)
  1434. }
  1435. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1436. if config.IsOpen == 1 { //对接了医保,走医保流程
  1437. bytesData, _ := json.Marshal(data)
  1438. req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
  1439. resp, _ := client.Do(req)
  1440. defer resp.Body.Close()
  1441. body, ioErr := ioutil.ReadAll(resp.Body)
  1442. if ioErr != nil {
  1443. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1445. return
  1446. }
  1447. var respJSON map[string]interface{}
  1448. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1449. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1451. return
  1452. }
  1453. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1454. userJSONBytes, _ := json.Marshal(respJSON)
  1455. var res ResultFour
  1456. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1457. utils.ErrorLog("解析失败:%v", err)
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1459. return
  1460. }
  1461. if res.Infcode == 0 {
  1462. order := &models.HisOrder{
  1463. UserOrgId: adminUser.CurrentOrgId,
  1464. HisPatientId: his.ID,
  1465. PatientId: his.PatientId,
  1466. SettleAccountsDate: recordDateTime,
  1467. Ctime: time.Now().Unix(),
  1468. Mtime: time.Now().Unix(),
  1469. Status: 1,
  1470. Number: chrg_bchno,
  1471. Infcode: res.Infcode,
  1472. WarnMsg: res.WarnMsg,
  1473. Cainfo: res.Cainfo,
  1474. ErrMsg: res.ErrMsg,
  1475. RespondTime: res.RefmsgTime,
  1476. InfRefmsgid: res.InfRefmsgid,
  1477. OrderStatus: 1,
  1478. PayWay: pay_way,
  1479. PayPrice: pay_price,
  1480. PayCardNo: pay_card_no,
  1481. DiscountPrice: discount_price,
  1482. PreferentialPrice: preferential_price,
  1483. RealityPrice: reality_price,
  1484. FoundPrice: found_price,
  1485. MedicalInsurancePrice: medical_insurance_price,
  1486. PrivatePrice: private_price,
  1487. }
  1488. err = service.CreateOrder(order)
  1489. if err != nil {
  1490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1491. return
  1492. }
  1493. for _, item := range res.Output.Result {
  1494. temp := strings.Split(item.FeedetlSn, "-")
  1495. var advice_id int64 = 0
  1496. var project_id int64 = 0
  1497. var types int64 = 0
  1498. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1499. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1500. if temp[1] == "1" {
  1501. advice_id = id
  1502. project_id = 0
  1503. } else if temp[1] == "2" {
  1504. advice_id = 0
  1505. project_id = id
  1506. }
  1507. info := &models.HisOrderInfo{
  1508. OrderNumber: order.Number,
  1509. FeedetlSn: item.FeedetlSn,
  1510. UploadDate: time.Now().Unix(),
  1511. AdviceId: advice_id,
  1512. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1513. Cnt: item.Cnt,
  1514. Pric: float64(item.Pric),
  1515. PatientId: his.PatientId,
  1516. PricUplmtAmt: item.PricUplmtAmt,
  1517. SelfpayProp: item.SelfpayProp,
  1518. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1519. OverlmtAmt: item.OverlmtAmt,
  1520. PreselfpayAmt: item.PreselfpayAmt,
  1521. BasMednFlag: item.BasMednFlag,
  1522. MedChrgitmType: item.MedChrgitmType,
  1523. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1524. Status: 1,
  1525. Memo: item.Memo,
  1526. Mtime: time.Now().Unix(),
  1527. InscpScpAmt: item.InscpScpAmt,
  1528. DrtReimFlag: item.DrtReimFlag,
  1529. Ctime: time.Now().Unix(),
  1530. ListSpItemFlag: item.ListSpItemFlag,
  1531. ChldMedcFlag: item.ChldMedcFlag,
  1532. LmtUsedFlag: item.LmtUsedFlag,
  1533. ChrgitmLv: item.ChrgitmLv,
  1534. UserOrgId: adminUser.CurrentOrgId,
  1535. HisPatientId: his.ID,
  1536. OrderId: order.ID,
  1537. ProjectId: project_id,
  1538. Type: types,
  1539. }
  1540. service.CreateOrderInfo(info)
  1541. }
  1542. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1543. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1544. var total float64
  1545. for _, item := range prescriptions {
  1546. if item.Type == 1 { //药品
  1547. for _, subItem := range item.HisDoctorAdviceInfo {
  1548. total = total + (subItem.Price * subItem.PrescribingNumber)
  1549. }
  1550. }
  1551. if item.Type == 2 { //项目
  1552. for _, subItem := range item.HisPrescriptionProject {
  1553. total = total + (subItem.Price * float64(subItem.Count))
  1554. }
  1555. }
  1556. }
  1557. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1558. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1559. allTotal := fmt.Sprintf("%.2f", total)
  1560. if res.Infcode == 0 {
  1561. var rf []*ResultFive
  1562. json.Unmarshal([]byte(his.Iinfo), &rf)
  1563. psn_no := his.PsnNo
  1564. mdtrt_id := his.Number
  1565. chrg_bchno := chrg_bchno
  1566. cert_no := his.Certno
  1567. insutype := rf[0].Insutype
  1568. api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1569. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1570. "&total=" + allTotal + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code
  1571. resp, requestErr := http.Get(api)
  1572. if requestErr != nil {
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1574. return
  1575. }
  1576. defer resp.Body.Close()
  1577. body, ioErr := ioutil.ReadAll(resp.Body)
  1578. if ioErr != nil {
  1579. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1581. return
  1582. }
  1583. var respJSON map[string]interface{}
  1584. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1585. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1587. return
  1588. }
  1589. fmt.Println(respJSON)
  1590. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1591. userJSONBytes, _ := json.Marshal(respJSON)
  1592. var res ResultSeven
  1593. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1594. utils.ErrorLog("解析失败:%v", err)
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1596. return
  1597. }
  1598. if res.Infcode == -1 {
  1599. errlog := &models.HisOrderError{
  1600. UserOrgId: adminUser.CurrentOrgId,
  1601. Ctime: time.Now().Unix(),
  1602. Mtime: time.Now().Unix(),
  1603. Number: chrg_bchno,
  1604. ErrMsg: res.ErrMsg,
  1605. Status: 1,
  1606. PatientId: id,
  1607. RecordTime: recordDateTime,
  1608. Stage: 7,
  1609. }
  1610. service.CreateErrMsgLog(errlog)
  1611. } else {
  1612. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1613. order.OrderStatus = 2
  1614. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1615. order.SetlId = res.Output.Setlinfo.SetlID
  1616. order.PsnNo = res.Output.Setlinfo.PsnNo
  1617. order.PsnName = res.Output.Setlinfo.PsnName
  1618. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1619. order.Certno = res.Output.Setlinfo.Certno
  1620. order.Gend = res.Output.Setlinfo.Gend
  1621. order.Naty = res.Output.Setlinfo.Naty
  1622. order.Age = res.Output.Setlinfo.Age
  1623. order.Insutype = res.Output.Setlinfo.Insutype
  1624. order.PsnType = res.Output.Setlinfo.PsnType
  1625. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1626. order.SetlTime = res.Output.Setlinfo.SetlTime
  1627. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1628. order.MedType = res.Output.Setlinfo.MedType
  1629. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1630. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1631. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1632. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1633. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1634. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1635. order.HifpPay = res.Output.Setlinfo.HifpPay
  1636. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1637. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1638. order.HifesPay = res.Output.Setlinfo.HifesPay
  1639. order.HifobPay = res.Output.Setlinfo.HifobPay
  1640. order.MafPay = res.Output.Setlinfo.MafPay
  1641. order.OthPay = res.Output.Setlinfo.OthPay
  1642. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1643. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1644. order.AcctPay = res.Output.Setlinfo.AcctPay
  1645. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1646. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1647. order.Balc = res.Output.Setlinfo.Balc
  1648. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1649. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1650. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1651. order.ClrWay = res.Output.Setlinfo.ClrWay
  1652. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1653. detailStr := string(setlDetail)
  1654. order.SetlDetail = detailStr
  1655. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1656. err = service.UpDateOrder(order)
  1657. if err == nil {
  1658. c.ServeSuccessJSON(map[string]interface{}{
  1659. "msg": "结算成功",
  1660. })
  1661. }
  1662. }
  1663. } else {
  1664. }
  1665. } else {
  1666. }
  1667. } else {
  1668. var total float64
  1669. for _, item := range prescriptions {
  1670. if item.Type == 1 { //药品
  1671. for _, subItem := range item.HisDoctorAdviceInfo {
  1672. total = total + (subItem.Price * subItem.PrescribingNumber)
  1673. }
  1674. }
  1675. if item.Type == 2 { //项目
  1676. for _, subItem := range item.HisPrescriptionProject {
  1677. total = total + (subItem.Price * float64(subItem.Count))
  1678. }
  1679. }
  1680. for _, subItem := range item.HisAdditionalCharge {
  1681. total = total + (subItem.Price * float64(subItem.Count))
  1682. }
  1683. }
  1684. allTotal := fmt.Sprintf("%.2f", total)
  1685. totals, _ := strconv.ParseFloat(allTotal, 64)
  1686. order := &models.HisOrder{
  1687. UserOrgId: adminUser.CurrentOrgId,
  1688. HisPatientId: his.ID,
  1689. PatientId: id,
  1690. SettleAccountsDate: recordDateTime,
  1691. Ctime: time.Now().Unix(),
  1692. Mtime: time.Now().Unix(),
  1693. Status: 1,
  1694. OrderStatus: 2,
  1695. Number: chrg_bchno,
  1696. MedfeeSumamt: totals,
  1697. PayWay: pay_way,
  1698. PayPrice: pay_price,
  1699. PayCardNo: pay_card_no,
  1700. DiscountPrice: discount_price,
  1701. PreferentialPrice: preferential_price,
  1702. RealityPrice: reality_price,
  1703. FoundPrice: found_price,
  1704. MedicalInsurancePrice: medical_insurance_price,
  1705. PrivatePrice: private_price,
  1706. }
  1707. err = service.CreateOrder(order)
  1708. if err != nil {
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1710. return
  1711. }
  1712. var customs []*Custom
  1713. for _, item := range prescriptions {
  1714. if item.Type == 1 { //药品
  1715. for _, subItem := range item.HisDoctorAdviceInfo {
  1716. cus := &Custom{
  1717. AdviceId: subItem.ID,
  1718. ProjectId: 0,
  1719. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1720. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1721. FeedetlSn: subItem.FeedetlSn,
  1722. Price: fmt.Sprintf("%.2f", subItem.Price),
  1723. MedListCodg: subItem.MedListCodg,
  1724. Type: 1,
  1725. }
  1726. customs = append(customs, cus)
  1727. }
  1728. }
  1729. if item.Type == 2 { //项目
  1730. for _, subItem := range item.HisPrescriptionProject {
  1731. cus := &Custom{
  1732. AdviceId: 0,
  1733. ProjectId: subItem.ID,
  1734. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1735. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1736. FeedetlSn: subItem.FeedetlSn,
  1737. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1738. MedListCodg: subItem.MedListCodg,
  1739. Type: 2,
  1740. }
  1741. customs = append(customs, cus)
  1742. }
  1743. }
  1744. for _, item := range item.HisAdditionalCharge {
  1745. cus := &Custom{
  1746. ItemId: item.ID,
  1747. AdviceId: 0,
  1748. ProjectId: 0,
  1749. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1750. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1751. FeedetlSn: item.FeedetlSn,
  1752. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1753. MedListCodg: item.XtHisAddtionConfig.Code,
  1754. Type: 3,
  1755. }
  1756. customs = append(customs, cus)
  1757. }
  1758. }
  1759. for _, item := range customs {
  1760. var advice_id int64 = 0
  1761. var project_id int64 = 0
  1762. var item_id int64 = 0
  1763. var types int64 = 0
  1764. if item.Type == 1 {
  1765. advice_id = item.AdviceId
  1766. project_id = 0
  1767. item_id = 0
  1768. } else if item.Type == 2 {
  1769. advice_id = 0
  1770. item_id = 0
  1771. project_id = item.ProjectId
  1772. } else if item.Type == 3 {
  1773. advice_id = 0
  1774. item_id = item.ItemId
  1775. project_id = 0
  1776. }
  1777. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1778. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1779. pric, _ := strconv.ParseFloat(item.Price, 32)
  1780. info := &models.HisOrderInfo{
  1781. OrderNumber: order.Number,
  1782. UploadDate: time.Now().Unix(),
  1783. AdviceId: advice_id,
  1784. DetItemFeeSumamt: detItemFeeSumamt,
  1785. Cnt: cut,
  1786. Pric: pric,
  1787. PatientId: id,
  1788. Status: 1,
  1789. Mtime: time.Now().Unix(),
  1790. Ctime: time.Now().Unix(),
  1791. UserOrgId: adminUser.CurrentOrgId,
  1792. HisPatientId: his.ID,
  1793. OrderId: order.ID,
  1794. ProjectId: project_id,
  1795. Type: types,
  1796. ItemId: item_id,
  1797. }
  1798. service.CreateOrderInfo(info)
  1799. }
  1800. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1801. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1802. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1803. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1804. if err == nil {
  1805. c.ServeSuccessJSON(map[string]interface{}{
  1806. "msg": "结算成功",
  1807. })
  1808. }
  1809. }
  1810. }
  1811. //退款
  1812. func (c *HisApiController) Refund() {
  1813. order_id, _ := c.GetInt64("order_id")
  1814. number := c.GetString("number")
  1815. adminUser := c.GetAdminUserInfo()
  1816. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1817. if config.IsOpen == 1 { //对接了医保,走医保流程
  1818. } else {
  1819. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1820. if err == nil {
  1821. c.ServeSuccessJSON(map[string]interface{}{
  1822. "msg": "退费成功",
  1823. })
  1824. } else {
  1825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1826. return
  1827. }
  1828. }
  1829. }
  1830. func (this *HisApiController) AdditionalCharge() {
  1831. dataBody := make(map[string]interface{}, 0)
  1832. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1833. fmt.Println(err)
  1834. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  1835. patient_id := int64(dataBody["patient_id"].(float64))
  1836. medicineData, _ := dataBody["medicineData"].([]interface{})
  1837. adminUserInfo := this.GetAdminUserInfo()
  1838. orgId := adminUserInfo.CurrentOrgId
  1839. admin_user_id := adminUserInfo.AdminUser.Id
  1840. timeStr := time.Now().Format("2006-01-02")
  1841. timeLayout := "2006-01-02 15:04:05"
  1842. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1843. timenow := timeStringToTime.Unix()
  1844. var additionalCharges []*models.HisAdditionalCharge
  1845. for _, item := range medicineData {
  1846. var randNum int
  1847. randNum = rand.Intn(10000) + 1000
  1848. timestamp := time.Now().Unix()
  1849. tempTime := time.Unix(timestamp, 0)
  1850. timeFormat := tempTime.Format("20060102150405")
  1851. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1852. items := item.(map[string]interface{})
  1853. money := items["price"].(string)
  1854. item_id_str := items["item_id"].(string)
  1855. name := items["name"].(string)
  1856. id_str := items["id"].(string)
  1857. moneys, _ := strconv.ParseInt(money, 10, 64)
  1858. monStr := strconv.FormatInt(moneys, 10)
  1859. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  1860. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  1861. id, _ := strconv.ParseInt(id_str, 10, 64)
  1862. additionalCharge := &models.HisAdditionalCharge{
  1863. ID: id,
  1864. HisPatientId: his_patient_id,
  1865. UserOrgId: orgId,
  1866. PatientId: patient_id,
  1867. RecordDate: timenow,
  1868. Price: monneyStr,
  1869. Status: 1,
  1870. ItemName: name,
  1871. ItemId: item_id,
  1872. AdminUserId: admin_user_id,
  1873. CreatedTime: time.Now().Unix(),
  1874. OrderStatus: 0,
  1875. PrescriptionNumber: "",
  1876. BatchNumber: "",
  1877. FeedetlSn: p_number,
  1878. }
  1879. service.CreateAdditionalCharge(additionalCharge)
  1880. additionalCharges = append(additionalCharges, additionalCharge)
  1881. }
  1882. this.ServeSuccessJSON(map[string]interface{}{
  1883. "msg": "添加成功",
  1884. "additional_charges": additionalCharges,
  1885. })
  1886. }
  1887. func (this *HisApiController) DeleteAddition() {
  1888. id, _ := this.GetInt64("id")
  1889. //TODO 需要判断是否已经结算
  1890. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  1891. if err == nil {
  1892. this.ServeSuccessJSON(map[string]interface{}{
  1893. "msg": "删除成功",
  1894. })
  1895. return
  1896. } else {
  1897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1898. return
  1899. }
  1900. }
  1901. func (this *HisApiController) GetAdminUsers() {
  1902. adminUser := this.GetAdminUserInfo()
  1903. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  1904. this.ServeSuccessJSON(map[string]interface{}{
  1905. "doctors": doctors,
  1906. })
  1907. }