his_api_controller.go 84KB

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