his_api_controller.go 74KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105
  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. sick, _ := c.GetInt64("sick")
  567. diagnose, _ := c.GetInt64("diagnose")
  568. timeLayout := "2006-01-02"
  569. loc, _ := time.LoadLocation("Local")
  570. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  571. if err != nil {
  572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  573. return
  574. }
  575. recordDateTime := theTime.Unix()
  576. fmt.Println("recordDataTime", recordDateTime)
  577. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  578. if err != nil {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  580. return
  581. }
  582. sickTimes := sickTime.Unix()
  583. ctime := time.Now().Unix()
  584. caseHistory := models.HisPatientCaseHistory{
  585. HisPatientId: his_patient_id,
  586. PatientId: patient_id,
  587. Temperature: temperature,
  588. BloodSugar: bloodsugarfloat,
  589. Pulse: pulsefloat,
  590. Sbp: sbpfloat,
  591. Dbp: dbpfloat,
  592. Height: heightfloat,
  593. BloodFat: bloodfatfloat,
  594. SickType: sick_type,
  595. Symptom: symptom,
  596. SickDate: sickTimes,
  597. IsInfect: is_infect,
  598. HistoryOfPresentIllness: history_of_present_illness,
  599. PastHistory: past_history,
  600. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  601. ChiefConplaint: chief_conplaint,
  602. PersonalHistory: personal_history,
  603. FamilyHistory: family_history,
  604. Diagnostic: diagnostic,
  605. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  606. Status: 1,
  607. Ctime: ctime,
  608. Mtime: ctime,
  609. RecordDate: recordDateTime,
  610. DeliveryWay: delivery_way,
  611. Breathing: breathingfloat,
  612. DoctorAdvice: doctor_advice,
  613. Remark: remark,
  614. Sick: sick,
  615. Diagnose: diagnose,
  616. }
  617. err = service.SaveHisPatientCaseHistory(&caseHistory)
  618. if err != nil {
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  620. return
  621. }
  622. c.ServeSuccessJSON(map[string]interface{}{
  623. "caseHistory": caseHistory,
  624. })
  625. return
  626. //查询该患者是否有病历
  627. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  628. //if errcode == gorm.ErrRecordNotFound {
  629. // err = service.SaveHisPatientCaseHistory(caseHistory)
  630. // if err != nil {
  631. // c.ServeSuccessJSON(map[string]interface{}{
  632. // "msg": "保存成功",
  633. // })
  634. // }
  635. //} else if errcode == nil {
  636. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  637. // return
  638. //}
  639. }
  640. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  641. patient_id, _ := c.GetInt64("patient_id", 0)
  642. adminUser := c.GetAdminUserInfo()
  643. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  644. c.ServeSuccessJSON(map[string]interface{}{
  645. "list": caseHistorys,
  646. })
  647. }
  648. func (c *HisApiController) GetHisPatientCaseHistory() {
  649. record_date, _ := c.GetInt64("record_date", 0)
  650. patient_id, _ := c.GetInt64("patient_id", 0)
  651. admin := c.GetAdminUserInfo()
  652. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  653. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  654. c.ServeSuccessJSON(map[string]interface{}{
  655. "info": info,
  656. "case_history": case_history,
  657. })
  658. }
  659. func (c *HisApiController) CreateCaseHistoryTemplate() {
  660. template_name := c.GetString("template_name")
  661. fmt.Println("template_name22222222222222", template_name)
  662. template_remark := c.GetString("template_remark")
  663. doctor := c.GetAdminUserInfo().AdminUser.Id
  664. diagnostic := c.GetString("diagnostic")
  665. chief_conplaint := c.GetString("chief_conplain")
  666. history_of_present_illness := c.GetString("history_of_present_illness")
  667. past_history := c.GetString("past_history")
  668. personal_history := c.GetString("personal_history")
  669. family_history := c.GetString("family_history")
  670. user_name := c.GetString("user_name")
  671. doctor_advice := c.GetString("doctor_advice")
  672. remark := c.GetString("remark")
  673. //record_date := c.GetString("record_date")
  674. //fmt.Println("record_date--------",record_date)
  675. //timeLayout := "2006-01-02"
  676. //loc, _ := time.LoadLocation("Local")
  677. //
  678. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  679. //if err != nil {
  680. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  681. // return
  682. //}
  683. //recordDateTime := theTime.Unix()
  684. ctime := time.Now().Unix()
  685. template := models.HisCaseHistoryTemplate{
  686. HistoryOfPresentIllness: history_of_present_illness,
  687. PastHistory: past_history,
  688. ChiefConplaint: chief_conplaint,
  689. PersonalHistory: personal_history,
  690. FamilyHistory: family_history,
  691. Diagnostic: diagnostic,
  692. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  693. Status: 1,
  694. Ctime: ctime,
  695. Mtime: ctime,
  696. RecordDate: time.Now().Unix(),
  697. TemplateName: template_name,
  698. TemplateRemark: template_remark,
  699. Creator: doctor,
  700. Modifier: doctor,
  701. UserName: user_name,
  702. DoctorAdvice: doctor_advice,
  703. Remark: remark,
  704. }
  705. err := service.SaveHisPatientCaseHistoryTemplate(template)
  706. if err == nil {
  707. c.ServeSuccessJSON(map[string]interface{}{
  708. "msg": "保存成功",
  709. })
  710. } else {
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  712. return
  713. }
  714. }
  715. func (c *HisApiController) GetCaseHistoryTemplate() {
  716. timeLayout := "2006-01-02"
  717. loc, _ := time.LoadLocation("Local")
  718. keyword := c.GetString("keyword")
  719. start_time := c.GetString("start_time")
  720. end_time := c.GetString("end_time")
  721. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  722. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  723. admin := c.GetAdminUserInfo()
  724. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  725. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  726. c.ServeSuccessJSON(map[string]interface{}{
  727. "template": template,
  728. //"history": history,
  729. })
  730. }
  731. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  732. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  733. utils.ErrorLog("drug_name")
  734. return enums.ErrorCodeParamWrong
  735. }
  736. adviceName, _ := json["drug_name"].(string)
  737. if len(adviceName) == 0 {
  738. utils.ErrorLog("len(advice_name) == 0")
  739. return enums.ErrorCodeParamWrong
  740. }
  741. advice.AdviceName = adviceName
  742. adviceDesc, _ := json["advice_desc"].(string)
  743. advice.AdviceDesc = adviceDesc
  744. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  745. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  746. advice.DrugSpec = drugSpec
  747. }
  748. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  749. remark, _ := json["remark"].(string)
  750. advice.Remark = remark
  751. }
  752. if json["id"] == nil {
  753. advice.DrugId = 0
  754. } else {
  755. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  756. drug_id := int64(json["id"].(float64))
  757. advice.DrugId = drug_id
  758. }
  759. }
  760. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  761. advice_id := int64(json["advice_id"].(float64))
  762. advice.ID = advice_id
  763. }
  764. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  765. drugSpecUnit, _ := json["min_unit"].(string)
  766. advice.DrugSpecUnit = drugSpecUnit
  767. }
  768. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  769. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  770. advice.SingleDose = singleDose
  771. }
  772. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  773. singleDoseUnit, _ := json["single_dose_unit"].(string)
  774. advice.SingleDoseUnit = singleDoseUnit
  775. }
  776. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  777. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  778. advice.PrescribingNumber = prescribingNumber
  779. }
  780. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  781. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  782. advice.PrescribingNumberUnit = prescribingNumberUnit
  783. }
  784. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  785. deliveryWay, _ := json["delivery_way"].(string)
  786. advice.DeliveryWay = deliveryWay
  787. }
  788. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  789. executionFrequency, _ := json["execution_frequency"].(string)
  790. advice.ExecutionFrequency = executionFrequency
  791. }
  792. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  793. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  794. advice.Price = price
  795. }
  796. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  797. med_list_codg, _ := json["medical_insurance_number"].(string)
  798. advice.MedListCodg = med_list_codg
  799. }
  800. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  801. day := int64(json["day"].(float64))
  802. advice.Day = day
  803. }
  804. return 0
  805. }
  806. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  807. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  808. id := int64(json["id"].(float64))
  809. project.ID = id
  810. }
  811. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  812. project_id := int64(json["project_id"].(float64))
  813. project.ProjectId = project_id
  814. fmt.Println(project_id)
  815. fmt.Println(project.ProjectId)
  816. }
  817. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  818. price := int64(json["price"].(float64))
  819. formatInt_price := strconv.FormatInt(price, 10)
  820. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  821. project.Price = float_price
  822. }
  823. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  824. total, _ := json["total"].(string)
  825. totals, _ := strconv.ParseInt(total, 10, 64)
  826. project.Count = totals
  827. }
  828. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  829. medical_code, _ := json["medical_code"].(string)
  830. project.MedListCodg = medical_code
  831. }
  832. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  833. single_dose, _ := json["single_dose"].(string)
  834. project.SingleDose = single_dose
  835. }
  836. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  837. delivery_way, _ := json["delivery_way"].(string)
  838. project.DeliveryWay = delivery_way
  839. }
  840. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  841. execution_frequency, _ := json["execution_frequency"].(string)
  842. project.ExecutionFrequency = execution_frequency
  843. }
  844. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  845. remark, _ := json["remark"].(string)
  846. project.Remark = remark
  847. }
  848. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  849. day, _ := json["number_days"].(string)
  850. project.Day = day
  851. }
  852. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  853. unit, _ := json["unit"].(string)
  854. project.Unit = unit
  855. }
  856. return 0
  857. }
  858. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}) int {
  859. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  860. id := int64(json["id"].(float64))
  861. additionalCharge.ID = id
  862. }
  863. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  864. item_id := int64(json["item_id"].(float64))
  865. additionalCharge.ItemId = item_id
  866. }
  867. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  868. price := int64(json["price"].(float64))
  869. formatInt_price := strconv.FormatInt(price, 10)
  870. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  871. additionalCharge.Price = float_price
  872. }
  873. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  874. count, _ := json["count"].(string)
  875. counts, _ := strconv.ParseInt(count, 10, 64)
  876. additionalCharge.Count = counts
  877. }
  878. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  879. item_name, _ := json["item_name"].(string)
  880. additionalCharge.ItemName = item_name
  881. }
  882. return 0
  883. }
  884. func (c *HisApiController) GetHisOrderList() {
  885. page, _ := c.GetInt64("page", -1)
  886. limit, _ := c.GetInt64("limit", -1)
  887. start_time := c.GetString("start_time")
  888. end_time := c.GetString("end_time")
  889. types, _ := c.GetInt64("type", 0)
  890. keywords := c.GetString("keywords")
  891. timeLayout := "2006-01-02"
  892. loc, _ := time.LoadLocation("Local")
  893. var startTime int64
  894. if len(start_time) > 0 {
  895. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  896. if err != nil {
  897. fmt.Println(err)
  898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  899. return
  900. }
  901. startTime = theTime.Unix()
  902. }
  903. var endTime int64
  904. if len(end_time) > 0 {
  905. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  906. if err != nil {
  907. utils.ErrorLog(err.Error())
  908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  909. return
  910. }
  911. endTime = theTime.Unix()
  912. }
  913. adminUser := c.GetAdminUserInfo()
  914. org_id := adminUser.CurrentOrgId
  915. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords)
  916. if err == nil {
  917. c.ServeSuccessJSON(map[string]interface{}{
  918. "order": order,
  919. "total": total,
  920. })
  921. } else {
  922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  923. return
  924. }
  925. }
  926. func (c *HisApiController) GetHisOrder() {
  927. patient_id, _ := c.GetInt64("patient_id", 0)
  928. number := c.GetString("number")
  929. adminInfo := c.GetAdminUserInfo()
  930. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  931. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.SettleAccountsDate, order.Number)
  932. if err == nil {
  933. c.ServeSuccessJSON(map[string]interface{}{
  934. "order": order,
  935. "prescription": prescriptions,
  936. })
  937. } else {
  938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  939. return
  940. }
  941. }
  942. func (c *HisApiController) GetHisPrescriptionList() {
  943. record_date := c.GetString("record_date")
  944. keywords := c.GetString("keywords")
  945. page, _ := c.GetInt64("page")
  946. limit, _ := c.GetInt64("limit")
  947. timeLayout := "2006-01-02"
  948. loc, _ := time.LoadLocation("Local")
  949. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  950. if err != nil {
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  952. return
  953. }
  954. recordDateTime := theTime.Unix()
  955. adminInfo := c.GetAdminUserInfo()
  956. prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  957. //adminInfo := c.GetAdminUserInfo()
  958. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  959. //fmt.Println(prescriptionOrder)
  960. if err == nil {
  961. c.ServeSuccessJSON(map[string]interface{}{
  962. "order": prescriptionOrder,
  963. "total": total,
  964. })
  965. } else {
  966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  967. return
  968. }
  969. }
  970. func (c *HisApiController) GetHisPrescriptionInfo() {
  971. id, _ := c.GetInt64("id")
  972. adminInfo := c.GetAdminUserInfo()
  973. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  974. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  975. if err == nil {
  976. c.ServeSuccessJSON(map[string]interface{}{
  977. "order": prescriptionOrder,
  978. "prescription": prescription,
  979. })
  980. } else {
  981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  982. return
  983. }
  984. }
  985. func (c *HisApiController) GetMedicalInsuranceConfig() {
  986. adminUser := c.GetAdminUserInfo()
  987. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "config": config,
  990. })
  991. }
  992. type ResultTwo struct {
  993. ErrMsg interface{} `json:"err_msg"`
  994. InfRefmsgid string `json:"inf_refmsgid"`
  995. Infcode int64 `json:"infcode"`
  996. Output struct {
  997. Baseinfo struct {
  998. Age float64 `json:"age"`
  999. Brdy string `json:"brdy"`
  1000. Certno string `json:"certno"`
  1001. Gend string `json:"gend"`
  1002. Naty string `json:"naty"`
  1003. PsnCertType string `json:"psn_cert_type"`
  1004. PsnName string `json:"psn_name"`
  1005. PsnNo string `json:"psn_no"`
  1006. } `json:"baseinfo"`
  1007. Idetinfo []interface{} `json:"idetinfo"`
  1008. Iinfo []struct {
  1009. Balc int64 `json:"balc"`
  1010. CvlservFlag string `json:"cvlserv_flag"`
  1011. EmpName string `json:"emp_name"`
  1012. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1013. Insutype string `json:"insutype"`
  1014. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1015. PausInsuDate interface{} `json:"paus_insu_date"`
  1016. PsnInsuDate string `json:"psn_insu_date"`
  1017. PsnInsuStas string `json:"psn_insu_stas"`
  1018. PsnType string `json:"psn_type"`
  1019. } `json:"insuinfo"`
  1020. } `json:"output"`
  1021. RefmsgTime string `json:"refmsg_time"`
  1022. RespondTime string `json:"respond_time"`
  1023. Signtype interface{} `json:"signtype"`
  1024. WarnInfo interface{} `json:"warn_info"`
  1025. }
  1026. type ResultThree struct {
  1027. Cainfo interface{} `json:"cainfo"`
  1028. ErrMsg interface{} `json:"err_msg"`
  1029. InfRefmsgid string `json:"inf_refmsgid"`
  1030. Infcode int64 `json:"infcode"`
  1031. Output struct {
  1032. Data struct {
  1033. IptOtpNo string `json:"ipt_otp_no"`
  1034. MdtrtID string `json:"mdtrt_id"`
  1035. PsnNo string `json:"psn_no"`
  1036. } `json:"data"`
  1037. } `json:"output"`
  1038. RefmsgTime string `json:"refmsg_time"`
  1039. RespondTime string `json:"respond_time"`
  1040. Signtype interface{} `json:"signtype"`
  1041. WarnMsg interface{} `json:"warn_msg"`
  1042. }
  1043. type ResultFour struct {
  1044. Cainfo string `json:"cainfo"`
  1045. ErrMsg string `json:"err_msg"`
  1046. InfRefmsgid string `json:"inf_refmsgid"`
  1047. Infcode int64 `json:"infcode"`
  1048. Output struct {
  1049. Result []struct {
  1050. BasMednFlag string `json:"bas_medn_flag"`
  1051. ChldMedcFlag string `json:"chld_medc_flag"`
  1052. ChrgitmLv string `json:"chrgitm_lv"`
  1053. Cnt float64 `json:"cnt"`
  1054. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1055. DrtReimFlag string `json:"drt_reim_flag"`
  1056. FeedetlSn string `json:"feedetl_sn"`
  1057. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1058. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1059. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1060. ListSpItemFlag string `json:"list_sp_item_flag"`
  1061. LmtUsedFlag string `json:"lmt_used_flag"`
  1062. MedChrgitmType string `json:"med_chrgitm_type"`
  1063. Memo string `json:"memo"`
  1064. OverlmtAmt float64 `json:"overlmt_amt"`
  1065. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1066. Pric float64 `json:"pric"`
  1067. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1068. SelfpayProp float64 `json:"selfpay_prop"`
  1069. } `json:"result"`
  1070. } `json:"output"`
  1071. RefmsgTime string `json:"refmsg_time"`
  1072. RespondTime string `json:"respond_time"`
  1073. Signtype string `json:"signtype"`
  1074. WarnMsg string `json:"warn_msg"`
  1075. }
  1076. type ResultFive struct {
  1077. Insutype string `json:"insutype"`
  1078. }
  1079. type ResultSix struct {
  1080. Cainfo interface{} `json:"cainfo"`
  1081. ErrMsg interface{} `json:"err_msg"`
  1082. InfRefmsgid string `json:"inf_refmsgid"`
  1083. Infcode int64 `json:"infcode"`
  1084. Output struct {
  1085. } `json:"output"`
  1086. RefmsgTime string `json:"refmsg_time"`
  1087. RespondTime string `json:"respond_time"`
  1088. Signtype interface{} `json:"signtype"`
  1089. WarnMsg interface{} `json:"warn_msg"`
  1090. }
  1091. type ResultSeven struct {
  1092. Cainfo string `json:"cainfo"`
  1093. ErrMsg string `json:"err_msg"`
  1094. InfRefmsgid string `json:"inf_refmsgid"`
  1095. Infcode int64 `json:"infcode"`
  1096. Output struct {
  1097. Setldetail []interface{} `json:"setldetail"`
  1098. Setlinfo struct {
  1099. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1100. AcctPay float64 `json:"acct_pay"`
  1101. ActPayDedc float64 `json:"act_pay_dedc"`
  1102. Age float64 `json:"age"`
  1103. Balc float64 `json:"balc"`
  1104. Brdy string `json:"brdy"`
  1105. Certno string `json:"certno"`
  1106. ClrOptins string `json:"clr_optins"`
  1107. ClrType string `json:"clr_type"`
  1108. ClrWay string `json:"clr_way"`
  1109. CvlservFlag string `json:"cvlserv_flag"`
  1110. CvlservPay float64 `json:"cvlserv_pay"`
  1111. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1112. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1113. Gend string `json:"gend"`
  1114. HifesPay float64 `json:"hifes_pay"`
  1115. HifmiPay float64 `json:"hifmi_pay"`
  1116. HifobPay float64 `json:"hifob_pay"`
  1117. HifpPay float64 `json:"hifp_pay"`
  1118. HospPartAmt float64 `json:"hosp_part_amt"`
  1119. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1120. Insutype string `json:"insutype"`
  1121. MafPay float64 `json:"maf_pay"`
  1122. MdtrtCertType string `json:"mdtrt_cert_type"`
  1123. MdtrtID string `json:"mdtrt_id"`
  1124. MedType string `json:"med_type"`
  1125. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1126. MedinsSetlID string `json:"medins_setl_id"`
  1127. Naty string `json:"naty"`
  1128. OthPay float64 `json:"oth_pay"`
  1129. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1130. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1131. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1132. PsnCashPay float64 `json:"psn_cash_pay"`
  1133. PsnCertType string `json:"psn_cert_type"`
  1134. PsnName string `json:"psn_name"`
  1135. PsnNo string `json:"psn_no"`
  1136. PsnPartAmt float64 `json:"psn_part_amt"`
  1137. PsnType string `json:"psn_type"`
  1138. SetlID string `json:"setl_id"`
  1139. SetlTime string `json:"setl_time"`
  1140. } `json:"setlinfo"`
  1141. } `json:"output"`
  1142. RefmsgTime string `json:"refmsg_time"`
  1143. RespondTime string `json:"respond_time"`
  1144. Signtype interface{} `json:"signtype"`
  1145. WarnMsg interface{} `json:"warn_msg"`
  1146. }
  1147. type Custom struct {
  1148. DetItemFeeSumamt string
  1149. Cut string
  1150. FeedetlSn string
  1151. Price string
  1152. MedListCodg string
  1153. Type int64
  1154. AdviceId int64
  1155. ProjectId int64
  1156. ItemId int64
  1157. }
  1158. //获取个人信息----挂号-----上传就诊信息
  1159. func (c *HisApiController) GetRegisterInfo() {
  1160. id, _ := c.GetInt64("id")
  1161. record_time := c.GetString("record_time")
  1162. name := c.GetString("name")
  1163. gender, _ := c.GetInt64("gender")
  1164. age, _ := c.GetInt64("age")
  1165. birthday := c.GetString("birthday")
  1166. phone := c.GetString("phone")
  1167. medical_care, _ := c.GetInt64("medical_care")
  1168. id_card := c.GetString("id_card")
  1169. register_type, _ := c.GetInt64("register_type")
  1170. registration_fee, _ := c.GetFloat("registration_fee")
  1171. medical_expenses, _ := c.GetFloat("medical_expenses")
  1172. certificates, _ := c.GetInt64("certificates")
  1173. settlementValue, _ := c.GetInt64("settlement_value")
  1174. social_type, _ := c.GetInt64("social_type")
  1175. medical_insurance_card := c.GetString("medical_insurance_card")
  1176. timeLayout := "2006-01-02"
  1177. loc, _ := time.LoadLocation("Local")
  1178. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1179. birthUnix := birthdays.Unix()
  1180. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1181. if err != nil {
  1182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. recordDateTime := theTime.Unix()
  1186. adminInfo := c.GetAdminUserInfo()
  1187. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  1188. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1189. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1190. if patient == nil {
  1191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1192. return
  1193. }
  1194. if len(patient.IdCardNo) == 0 {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1196. return
  1197. }
  1198. //org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  1199. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1200. if config.IsOpen == 1 {
  1201. api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1202. resp, requestErr := http.Get(api)
  1203. if requestErr != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1205. return
  1206. }
  1207. defer resp.Body.Close()
  1208. body, ioErr := ioutil.ReadAll(resp.Body)
  1209. if ioErr != nil {
  1210. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1212. return
  1213. }
  1214. var respJSON map[string]interface{}
  1215. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1216. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1218. return
  1219. }
  1220. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1221. userJSONBytes, _ := json.Marshal(userJSON)
  1222. var res ResultTwo
  1223. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1224. utils.ErrorLog("解析失败:%v", err)
  1225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1226. return
  1227. }
  1228. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1229. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1230. infoStr := string(Iinfos)
  1231. idetinfoStr := string(Idetinfos)
  1232. his := models.VMHisPatient{
  1233. PsnNo: res.Output.Baseinfo.PsnNo,
  1234. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1235. Certno: res.Output.Baseinfo.Certno,
  1236. PsnName: res.Output.Baseinfo.PsnName,
  1237. Gend: res.Output.Baseinfo.Gend,
  1238. Naty: res.Output.Baseinfo.Naty,
  1239. Brdy: res.Output.Baseinfo.Brdy,
  1240. Age: res.Output.Baseinfo.Age,
  1241. Iinfo: infoStr,
  1242. Idetinfo: idetinfoStr,
  1243. PatientId: patient.ID,
  1244. RecordDate: theTime.Unix(),
  1245. }
  1246. fmt.Println(his)
  1247. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  1249. return
  1250. }
  1251. timestamp := time.Now().Unix()
  1252. tempTime := time.Unix(timestamp, 0)
  1253. timeFormat := tempTime.Format("20060102150405")
  1254. chrgBchno := rand.Intn(100000) + 10000
  1255. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1256. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1257. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1258. //department_id := strconv.FormatInt(department.ID, 10)
  1259. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1260. if count <= 0 {
  1261. api := "http://127.0.0.1:9531/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  1262. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1263. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1264. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1265. resp, requestErr := http.Get(api)
  1266. if requestErr != nil {
  1267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1268. return
  1269. }
  1270. defer resp.Body.Close()
  1271. body, ioErr := ioutil.ReadAll(resp.Body)
  1272. if ioErr != nil {
  1273. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1275. return
  1276. }
  1277. var respJSON map[string]interface{}
  1278. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1279. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1281. return
  1282. }
  1283. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1284. userJSONBytes, _ := json.Marshal(respJSON)
  1285. var res ResultThree
  1286. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1287. utils.ErrorLog("解析失败:%v", err)
  1288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1289. return
  1290. }
  1291. if res.Infcode == -1 {
  1292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1293. return
  1294. }
  1295. fmt.Println("000!!!!!!")
  1296. fmt.Println(res)
  1297. fmt.Println(res.Output.Data.MdtrtID)
  1298. fmt.Println(res.Output.Data.PsnNo)
  1299. fmt.Println(res.Output.Data.IptOtpNo)
  1300. his.Number = res.Output.Data.MdtrtID
  1301. his.PsnNo = res.Output.Data.PsnNo
  1302. his.IptOtpNo = res.Output.Data.IptOtpNo
  1303. his.IdCardNo = patient.IdCardNo
  1304. his.PhoneNumber = patient.Phone
  1305. his.UserOrgId = adminInfo.CurrentOrgId
  1306. his.Status = 1
  1307. his.Ctime = time.Now().Unix()
  1308. his.Mtime = time.Now().Unix()
  1309. err := service.CreateHisPatientTwo(&his)
  1310. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  1311. if err == nil {
  1312. api := "http://127.0.0.1:9531/" + "gdyb/four?psn_no=" + his.PsnNo +
  1313. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1314. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + "11" + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  1315. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1316. resp, requestErr := http.Get(api)
  1317. if requestErr != nil {
  1318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1319. return
  1320. }
  1321. body, ioErr := ioutil.ReadAll(resp.Body)
  1322. if ioErr != nil {
  1323. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1325. return
  1326. }
  1327. var respJSON map[string]interface{}
  1328. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1329. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1331. return
  1332. }
  1333. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1334. userJSONBytes, _ := json.Marshal(respJSON)
  1335. fmt.Println(respJSON)
  1336. fmt.Println(userJSONBytes)
  1337. var res ResultSix
  1338. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1339. utils.ErrorLog("解析失败:%v", err)
  1340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1341. return
  1342. }
  1343. if res.Infcode == -1 {
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1345. return
  1346. }
  1347. c.ServeSuccessJSON(map[string]interface{}{
  1348. "his_info": his,
  1349. })
  1350. } else {
  1351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1352. return
  1353. }
  1354. }
  1355. } else {
  1356. timeStr := time.Now().Format("2006-01-02")
  1357. timeArr := strings.Split(timeStr, "-")
  1358. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1359. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1360. var hisPatient models.XtHisPatient
  1361. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1362. hisPatient = models.XtHisPatient{
  1363. Name: name,
  1364. Age: age,
  1365. Gender: gender,
  1366. Birthday: birthUnix,
  1367. Phone: phone,
  1368. MedicalTreatmentType: medical_care,
  1369. IdType: certificates,
  1370. IdCardNo: id_card,
  1371. BalanceAccountsType: settlementValue,
  1372. SocialType: social_type,
  1373. MedicalInsuranceNumber: medical_insurance_card,
  1374. RegisterType: register_type,
  1375. RegisterCost: registration_fee,
  1376. TreatmentCost: medical_expenses,
  1377. AdminUserId: adminInfo.AdminUser.Id,
  1378. UserOrgId: adminInfo.CurrentOrgId,
  1379. Status: 1,
  1380. RecordDate: recordDateTime,
  1381. IsReturn: 1,
  1382. PatientId: patient.ID,
  1383. Ctime: time.Now().Unix(),
  1384. Mtime: time.Now().Unix(),
  1385. Number: str,
  1386. }
  1387. service.CreateHisPatient(&hisPatient)
  1388. }
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "his_info": hisPatient,
  1391. })
  1392. }
  1393. }
  1394. //上传明细----结算
  1395. func (c *HisApiController) GetUploadInfo() {
  1396. id, _ := c.GetInt64("id")
  1397. record_time := c.GetString("record_time")
  1398. pay_way, _ := c.GetInt64("pay_way")
  1399. pay_price, _ := c.GetFloat("pay_price")
  1400. pay_card_no := c.GetString("pay_card_no")
  1401. discount_price, _ := c.GetFloat("discount_price")
  1402. preferential_price, _ := c.GetFloat("preferential_price")
  1403. reality_price, _ := c.GetFloat("reality_price")
  1404. found_price, _ := c.GetFloat("found_price")
  1405. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1406. private_price, _ := c.GetFloat("private_price")
  1407. timeLayout := "2006-01-02"
  1408. loc, _ := time.LoadLocation("Local")
  1409. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1410. if err != nil {
  1411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1412. return
  1413. }
  1414. recordDateTime := theTime.Unix()
  1415. adminUser := c.GetAdminUserInfo()
  1416. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1417. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1418. timestamp := time.Now().Unix()
  1419. tempTime := time.Unix(timestamp, 0)
  1420. timeFormat := tempTime.Format("20060102150405")
  1421. chrgBchno := rand.Intn(100000) + 10000
  1422. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1423. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1424. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1425. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1426. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1427. strconv.FormatInt(his.PatientId, 10)
  1428. client := &http.Client{}
  1429. data := make(map[string]interface{})
  1430. data["psn_no"] = his.PsnNo
  1431. data["mdtrt_id"] = his.Number
  1432. data["pre"] = prescriptions
  1433. data["chrg_bchno"] = chrg_bchno
  1434. data["org_name"] = miConfig.OrgName
  1435. data["doctor"] = patientPrescription.Doctor
  1436. data["dept"] = patientPrescription.Departments
  1437. data["fixmedins_code"] = miConfig.Code
  1438. data["dept_code"] = department.Number
  1439. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1440. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1441. data["secret_key"] = miConfig.SecretKey
  1442. var ids []int64
  1443. //var idsTwo []int64
  1444. //
  1445. for _, item := range prescriptions {
  1446. ids = append(ids, item.ID)
  1447. }
  1448. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1449. if config.IsOpen == 1 { //对接了医保,走医保流程
  1450. bytesData, _ := json.Marshal(data)
  1451. req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
  1452. resp, _ := client.Do(req)
  1453. defer resp.Body.Close()
  1454. body, ioErr := ioutil.ReadAll(resp.Body)
  1455. if ioErr != nil {
  1456. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1458. return
  1459. }
  1460. var respJSON map[string]interface{}
  1461. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1462. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1464. return
  1465. }
  1466. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1467. userJSONBytes, _ := json.Marshal(respJSON)
  1468. var res ResultFour
  1469. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1470. utils.ErrorLog("解析失败:%v", err)
  1471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1472. return
  1473. }
  1474. if res.Infcode == 0 {
  1475. order := &models.HisOrder{
  1476. UserOrgId: adminUser.CurrentOrgId,
  1477. HisPatientId: his.ID,
  1478. PatientId: his.PatientId,
  1479. SettleAccountsDate: recordDateTime,
  1480. Ctime: time.Now().Unix(),
  1481. Mtime: time.Now().Unix(),
  1482. Status: 1,
  1483. Number: chrg_bchno,
  1484. Infcode: res.Infcode,
  1485. WarnMsg: res.WarnMsg,
  1486. Cainfo: res.Cainfo,
  1487. ErrMsg: res.ErrMsg,
  1488. RespondTime: res.RefmsgTime,
  1489. InfRefmsgid: res.InfRefmsgid,
  1490. OrderStatus: 1,
  1491. PayWay: pay_way,
  1492. PayPrice: pay_price,
  1493. PayCardNo: pay_card_no,
  1494. DiscountPrice: discount_price,
  1495. PreferentialPrice: preferential_price,
  1496. RealityPrice: reality_price,
  1497. FoundPrice: found_price,
  1498. MedicalInsurancePrice: medical_insurance_price,
  1499. PrivatePrice: private_price,
  1500. }
  1501. err = service.CreateOrder(order)
  1502. if err != nil {
  1503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1504. return
  1505. }
  1506. for _, item := range res.Output.Result {
  1507. temp := strings.Split(item.FeedetlSn, "-")
  1508. var advice_id int64 = 0
  1509. var project_id int64 = 0
  1510. var types int64 = 0
  1511. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1512. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1513. if temp[1] == "1" {
  1514. advice_id = id
  1515. project_id = 0
  1516. } else if temp[1] == "2" {
  1517. advice_id = 0
  1518. project_id = id
  1519. }
  1520. info := &models.HisOrderInfo{
  1521. OrderNumber: order.Number,
  1522. FeedetlSn: item.FeedetlSn,
  1523. UploadDate: time.Now().Unix(),
  1524. AdviceId: advice_id,
  1525. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1526. Cnt: item.Cnt,
  1527. Pric: float64(item.Pric),
  1528. PatientId: his.PatientId,
  1529. PricUplmtAmt: item.PricUplmtAmt,
  1530. SelfpayProp: item.SelfpayProp,
  1531. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1532. OverlmtAmt: item.OverlmtAmt,
  1533. PreselfpayAmt: item.PreselfpayAmt,
  1534. BasMednFlag: item.BasMednFlag,
  1535. MedChrgitmType: item.MedChrgitmType,
  1536. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1537. Status: 1,
  1538. Memo: item.Memo,
  1539. Mtime: time.Now().Unix(),
  1540. InscpScpAmt: item.InscpScpAmt,
  1541. DrtReimFlag: item.DrtReimFlag,
  1542. Ctime: time.Now().Unix(),
  1543. ListSpItemFlag: item.ListSpItemFlag,
  1544. ChldMedcFlag: item.ChldMedcFlag,
  1545. LmtUsedFlag: item.LmtUsedFlag,
  1546. ChrgitmLv: item.ChrgitmLv,
  1547. UserOrgId: adminUser.CurrentOrgId,
  1548. HisPatientId: his.ID,
  1549. OrderId: order.ID,
  1550. ProjectId: project_id,
  1551. Type: types,
  1552. }
  1553. service.CreateOrderInfo(info)
  1554. }
  1555. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1556. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1557. var total float64
  1558. for _, item := range prescriptions {
  1559. if item.Type == 1 { //药品
  1560. for _, subItem := range item.HisDoctorAdviceInfo {
  1561. total = total + (subItem.Price * subItem.PrescribingNumber)
  1562. }
  1563. }
  1564. if item.Type == 2 { //项目
  1565. for _, subItem := range item.HisPrescriptionProject {
  1566. total = total + (subItem.Price * float64(subItem.Count))
  1567. }
  1568. }
  1569. }
  1570. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1571. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1572. allTotal := fmt.Sprintf("%.2f", total)
  1573. if res.Infcode == 0 {
  1574. var rf []*ResultFive
  1575. json.Unmarshal([]byte(his.Iinfo), &rf)
  1576. psn_no := his.PsnNo
  1577. mdtrt_id := his.Number
  1578. chrg_bchno := chrg_bchno
  1579. cert_no := his.Certno
  1580. insutype := rf[0].Insutype
  1581. api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1582. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1583. "&total=" + allTotal + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1584. resp, requestErr := http.Get(api)
  1585. if requestErr != nil {
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1587. return
  1588. }
  1589. defer resp.Body.Close()
  1590. body, ioErr := ioutil.ReadAll(resp.Body)
  1591. if ioErr != nil {
  1592. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1594. return
  1595. }
  1596. var respJSON map[string]interface{}
  1597. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1598. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1600. return
  1601. }
  1602. fmt.Println(respJSON)
  1603. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1604. userJSONBytes, _ := json.Marshal(respJSON)
  1605. var res ResultSeven
  1606. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1607. utils.ErrorLog("解析失败:%v", err)
  1608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1609. return
  1610. }
  1611. if res.Infcode == -1 {
  1612. errlog := &models.HisOrderError{
  1613. UserOrgId: adminUser.CurrentOrgId,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: time.Now().Unix(),
  1616. Number: chrg_bchno,
  1617. ErrMsg: res.ErrMsg,
  1618. Status: 1,
  1619. PatientId: id,
  1620. RecordTime: recordDateTime,
  1621. Stage: 7,
  1622. }
  1623. service.CreateErrMsgLog(errlog)
  1624. } else {
  1625. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1626. order.OrderStatus = 2
  1627. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1628. order.SetlId = res.Output.Setlinfo.SetlID
  1629. order.PsnNo = res.Output.Setlinfo.PsnNo
  1630. order.PsnName = res.Output.Setlinfo.PsnName
  1631. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1632. order.Certno = res.Output.Setlinfo.Certno
  1633. order.Gend = res.Output.Setlinfo.Gend
  1634. order.Naty = res.Output.Setlinfo.Naty
  1635. order.Age = res.Output.Setlinfo.Age
  1636. order.Insutype = res.Output.Setlinfo.Insutype
  1637. order.PsnType = res.Output.Setlinfo.PsnType
  1638. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1639. order.SetlTime = res.Output.Setlinfo.SetlTime
  1640. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1641. order.MedType = res.Output.Setlinfo.MedType
  1642. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1643. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1644. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1645. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1646. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1647. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1648. order.HifpPay = res.Output.Setlinfo.HifpPay
  1649. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1650. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1651. order.HifesPay = res.Output.Setlinfo.HifesPay
  1652. order.HifobPay = res.Output.Setlinfo.HifobPay
  1653. order.MafPay = res.Output.Setlinfo.MafPay
  1654. order.OthPay = res.Output.Setlinfo.OthPay
  1655. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1656. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1657. order.AcctPay = res.Output.Setlinfo.AcctPay
  1658. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1659. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1660. order.Balc = res.Output.Setlinfo.Balc
  1661. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1662. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1663. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1664. order.ClrWay = res.Output.Setlinfo.ClrWay
  1665. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1666. detailStr := string(setlDetail)
  1667. order.SetlDetail = detailStr
  1668. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1669. err = service.UpDateOrder(order)
  1670. if err == nil {
  1671. c.ServeSuccessJSON(map[string]interface{}{
  1672. "msg": "结算成功",
  1673. })
  1674. }
  1675. }
  1676. } else {
  1677. }
  1678. } else {
  1679. }
  1680. } else {
  1681. var total float64
  1682. for _, item := range prescriptions {
  1683. if item.Type == 1 { //药品
  1684. for _, subItem := range item.HisDoctorAdviceInfo {
  1685. total = total + (subItem.Price * subItem.PrescribingNumber)
  1686. }
  1687. }
  1688. if item.Type == 2 { //项目
  1689. for _, subItem := range item.HisPrescriptionProject {
  1690. total = total + (subItem.Price * float64(subItem.Count))
  1691. }
  1692. }
  1693. for _, subItem := range item.HisAdditionalCharge {
  1694. total = total + (subItem.Price * float64(subItem.Count))
  1695. }
  1696. }
  1697. allTotal := fmt.Sprintf("%.2f", total)
  1698. totals, _ := strconv.ParseFloat(allTotal, 64)
  1699. order := &models.HisOrder{
  1700. UserOrgId: adminUser.CurrentOrgId,
  1701. HisPatientId: his.ID,
  1702. PatientId: id,
  1703. SettleAccountsDate: recordDateTime,
  1704. Ctime: time.Now().Unix(),
  1705. Mtime: time.Now().Unix(),
  1706. Status: 1,
  1707. OrderStatus: 2,
  1708. Number: chrg_bchno,
  1709. MedfeeSumamt: totals,
  1710. PayWay: pay_way,
  1711. PayPrice: pay_price,
  1712. PayCardNo: pay_card_no,
  1713. DiscountPrice: discount_price,
  1714. PreferentialPrice: preferential_price,
  1715. RealityPrice: reality_price,
  1716. FoundPrice: found_price,
  1717. MedicalInsurancePrice: medical_insurance_price,
  1718. PrivatePrice: private_price,
  1719. }
  1720. err = service.CreateOrder(order)
  1721. if err != nil {
  1722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1723. return
  1724. }
  1725. var customs []*Custom
  1726. for _, item := range prescriptions {
  1727. if item.Type == 1 { //药品
  1728. for _, subItem := range item.HisDoctorAdviceInfo {
  1729. cus := &Custom{
  1730. AdviceId: subItem.ID,
  1731. ProjectId: 0,
  1732. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1733. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1734. FeedetlSn: subItem.FeedetlSn,
  1735. Price: fmt.Sprintf("%.2f", subItem.Price),
  1736. MedListCodg: subItem.MedListCodg,
  1737. Type: 1,
  1738. }
  1739. customs = append(customs, cus)
  1740. }
  1741. }
  1742. if item.Type == 2 { //项目
  1743. for _, subItem := range item.HisPrescriptionProject {
  1744. cus := &Custom{
  1745. AdviceId: 0,
  1746. ProjectId: subItem.ID,
  1747. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1748. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1749. FeedetlSn: subItem.FeedetlSn,
  1750. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1751. MedListCodg: subItem.MedListCodg,
  1752. Type: 2,
  1753. }
  1754. customs = append(customs, cus)
  1755. }
  1756. }
  1757. for _, item := range item.HisAdditionalCharge {
  1758. cus := &Custom{
  1759. ItemId: item.ID,
  1760. AdviceId: 0,
  1761. ProjectId: 0,
  1762. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1763. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1764. FeedetlSn: item.FeedetlSn,
  1765. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1766. MedListCodg: item.XtHisAddtionConfig.Code,
  1767. Type: 3,
  1768. }
  1769. customs = append(customs, cus)
  1770. }
  1771. }
  1772. for _, item := range customs {
  1773. var advice_id int64 = 0
  1774. var project_id int64 = 0
  1775. var item_id int64 = 0
  1776. var types int64 = 0
  1777. if item.Type == 1 {
  1778. advice_id = item.AdviceId
  1779. project_id = 0
  1780. item_id = 0
  1781. } else if item.Type == 2 {
  1782. advice_id = 0
  1783. item_id = 0
  1784. project_id = item.ProjectId
  1785. } else if item.Type == 3 {
  1786. advice_id = 0
  1787. item_id = item.ItemId
  1788. project_id = 0
  1789. }
  1790. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1791. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1792. pric, _ := strconv.ParseFloat(item.Price, 32)
  1793. info := &models.HisOrderInfo{
  1794. OrderNumber: order.Number,
  1795. UploadDate: time.Now().Unix(),
  1796. AdviceId: advice_id,
  1797. DetItemFeeSumamt: detItemFeeSumamt,
  1798. Cnt: cut,
  1799. Pric: pric,
  1800. PatientId: id,
  1801. Status: 1,
  1802. Mtime: time.Now().Unix(),
  1803. Ctime: time.Now().Unix(),
  1804. UserOrgId: adminUser.CurrentOrgId,
  1805. HisPatientId: his.ID,
  1806. OrderId: order.ID,
  1807. ProjectId: project_id,
  1808. Type: types,
  1809. ItemId: item_id,
  1810. }
  1811. service.CreateOrderInfo(info)
  1812. }
  1813. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1814. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1815. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1816. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1817. if err == nil {
  1818. c.ServeSuccessJSON(map[string]interface{}{
  1819. "msg": "结算成功",
  1820. })
  1821. }
  1822. }
  1823. }
  1824. //退款
  1825. func (c *HisApiController) Refund() {
  1826. order_id, _ := c.GetInt64("order_id")
  1827. number := c.GetString("number")
  1828. adminUser := c.GetAdminUserInfo()
  1829. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1830. if config.IsOpen == 1 { //对接了医保,走医保流程
  1831. } else {
  1832. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1833. if err == nil {
  1834. c.ServeSuccessJSON(map[string]interface{}{
  1835. "msg": "退费成功",
  1836. })
  1837. } else {
  1838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1839. return
  1840. }
  1841. }
  1842. }
  1843. func (this *HisApiController) AdditionalCharge() {
  1844. dataBody := make(map[string]interface{}, 0)
  1845. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1846. fmt.Println(err)
  1847. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  1848. patient_id := int64(dataBody["patient_id"].(float64))
  1849. medicineData, _ := dataBody["medicineData"].([]interface{})
  1850. adminUserInfo := this.GetAdminUserInfo()
  1851. orgId := adminUserInfo.CurrentOrgId
  1852. admin_user_id := adminUserInfo.AdminUser.Id
  1853. timeStr := time.Now().Format("2006-01-02")
  1854. timeLayout := "2006-01-02 15:04:05"
  1855. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1856. timenow := timeStringToTime.Unix()
  1857. var additionalCharges []*models.HisAdditionalCharge
  1858. for _, item := range medicineData {
  1859. var randNum int
  1860. randNum = rand.Intn(10000) + 1000
  1861. timestamp := time.Now().Unix()
  1862. tempTime := time.Unix(timestamp, 0)
  1863. timeFormat := tempTime.Format("20060102150405")
  1864. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1865. items := item.(map[string]interface{})
  1866. money := items["price"].(string)
  1867. item_id_str := items["item_id"].(string)
  1868. name := items["name"].(string)
  1869. id_str := items["id"].(string)
  1870. moneys, _ := strconv.ParseInt(money, 10, 64)
  1871. monStr := strconv.FormatInt(moneys, 10)
  1872. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  1873. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  1874. id, _ := strconv.ParseInt(id_str, 10, 64)
  1875. additionalCharge := &models.HisAdditionalCharge{
  1876. ID: id,
  1877. HisPatientId: his_patient_id,
  1878. UserOrgId: orgId,
  1879. PatientId: patient_id,
  1880. RecordDate: timenow,
  1881. Price: monneyStr,
  1882. Status: 1,
  1883. ItemName: name,
  1884. ItemId: item_id,
  1885. AdminUserId: admin_user_id,
  1886. CreatedTime: time.Now().Unix(),
  1887. OrderStatus: 0,
  1888. PrescriptionNumber: "",
  1889. BatchNumber: "",
  1890. FeedetlSn: p_number,
  1891. }
  1892. service.CreateAdditionalCharge(additionalCharge)
  1893. additionalCharges = append(additionalCharges, additionalCharge)
  1894. }
  1895. this.ServeSuccessJSON(map[string]interface{}{
  1896. "msg": "添加成功",
  1897. "additional_charges": additionalCharges,
  1898. })
  1899. }
  1900. func (this *HisApiController) DeleteAddition() {
  1901. id, _ := this.GetInt64("id")
  1902. //TODO 需要判断是否已经结算
  1903. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  1904. if err == nil {
  1905. this.ServeSuccessJSON(map[string]interface{}{
  1906. "msg": "删除成功",
  1907. })
  1908. return
  1909. } else {
  1910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1911. return
  1912. }
  1913. }
  1914. func (this *HisApiController) GetAdminUsers() {
  1915. adminUser := this.GetAdminUserInfo()
  1916. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  1917. this.ServeSuccessJSON(map[string]interface{}{
  1918. "doctors": doctors,
  1919. })
  1920. }