his_api_controller.go 84KB

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