his_api_controller.go 91KB

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