his_api_controller.go 110KB

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