his_service.go 131KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strings"
  7. "time"
  8. "encoding/json"
  9. "strconv"
  10. )
  11. type VMSchedule struct {
  12. ID int64 `gorm:"column:id" json:"id" form:"id"`
  13. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  14. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  15. Status int64 `gorm:"column:status" json:"status" form:"status"`
  16. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  17. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  18. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  19. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  20. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  21. }
  22. func (VMSchedule) TableName() string {
  23. return "xt_schedule"
  24. }
  25. type HisPatient struct {
  26. ID int64 `gorm:"column:id" json:"id" form:"id"`
  27. Name string `gorm:"column:name" json:"name" form:"name"`
  28. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  29. Total float64 `gorm:"column:total" json:"total" form:"total"`
  30. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  31. Status int64 `gorm:"column:status" json:"status" form:"status"`
  32. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  33. HisPrescription []*HisPrescription `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  34. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  35. Number string `gorm:"column:number" json:"number" form:"number"`
  36. VMHisOrders []*VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"orders"`
  37. VMHisOrder VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"order"`
  38. }
  39. func (HisPatient) TableName() string {
  40. return "his_patient"
  41. }
  42. type Schedule struct {
  43. ID int64 `gorm:"column:id" json:"id" form:"id"`
  44. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  45. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  46. Status int64 `gorm:"column:status" json:"status" form:"status"`
  47. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  48. }
  49. func (Schedule) TableName() string {
  50. return "xt_schedule"
  51. }
  52. type VMHisPrescriptionInfo struct {
  53. ID int64 `gorm:"column:id" json:"id" form:"id"`
  54. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  55. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  56. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  57. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  58. Status int64 `gorm:"column:status" json:"status" form:"status"`
  59. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  60. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  61. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  62. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  63. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  64. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  65. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  66. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  67. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  68. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  69. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  70. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  71. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  72. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  73. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  74. }
  75. func (VMHisPrescriptionInfo) TableName() string {
  76. return "his_prescription_info"
  77. }
  78. type VMHisOrder struct {
  79. ID int64 `gorm:"column:id" json:"id" form:"id"`
  80. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  81. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  82. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  83. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  84. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  85. Status int64 `gorm:"column:status" json:"status" form:"status"`
  86. Number string `gorm:"column:number" json:"number" form:"number"`
  87. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  88. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  89. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  90. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  91. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  92. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  93. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  94. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  95. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  96. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  97. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  98. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  99. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  100. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  101. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  102. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  103. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  104. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  105. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  106. }
  107. func (VMHisOrder) TableName() string {
  108. return "his_order"
  109. }
  110. type Patients struct {
  111. ID int64 `gorm:"column:id" json:"id" form:"id"`
  112. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  113. Name string `gorm:"column:name" json:"name" form:"name"`
  114. Status int64 `gorm:"column:status" json:"status" form:"status"`
  115. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  116. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  117. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  118. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  119. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  120. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  121. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  122. }
  123. func (Patients) TableName() string {
  124. return "xt_patients"
  125. }
  126. type HisPrescription struct {
  127. ID int64 `gorm:"column:id" json:"id" form:"id"`
  128. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  129. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  130. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  131. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  132. Status int64 `gorm:"column:status" json:"status" form:"status"`
  133. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  134. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  135. }
  136. func (HisPrescription) TableName() string {
  137. return "his_prescription"
  138. }
  139. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
  140. db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  141. if sch_type != 0 {
  142. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  143. } else {
  144. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  145. }
  146. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  147. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  148. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  149. return
  150. }
  151. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  152. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  153. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  154. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  155. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  156. return
  157. }
  158. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  159. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  160. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  161. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  162. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  163. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  164. return
  165. }
  166. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  167. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  168. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  169. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  170. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  171. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  172. return
  173. }
  174. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  175. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  176. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  177. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  178. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  179. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  180. return
  181. }
  182. type PatientTwo struct {
  183. ID int64 `gorm:"column:id" json:"id" form:"id"`
  184. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  185. Name string `gorm:"column:name" json:"name" form:"name"`
  186. Status int64 `gorm:"column:status" json:"status" form:"status"`
  187. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  188. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  189. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  190. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  191. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  192. }
  193. func (PatientTwo) TableName() string {
  194. return "xt_patients"
  195. }
  196. type HisPatientTwo struct {
  197. ID int64 `gorm:"column:id" json:"id" form:"id"`
  198. Name string `gorm:"column:name" json:"name" form:"name"`
  199. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  200. Total float64 `gorm:"column:total" json:"total" form:"total"`
  201. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  202. Status int64 `gorm:"column:status" json:"status" form:"status"`
  203. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  204. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  205. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  206. Number string `gorm:"column:number" json:"number" form:"number"`
  207. }
  208. func (HisPatientTwo) TableName() string {
  209. return "his_patient"
  210. }
  211. type HisPrescriptionTwo struct {
  212. ID int64 `gorm:"column:id" json:"id" form:"id"`
  213. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  214. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  215. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  216. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  217. Status int64 `gorm:"column:status" json:"status" form:"status"`
  218. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  219. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  220. Number string `gorm:"column:number" json:"number" form:"number"`
  221. Type int64 `gorm:"column:type" json:"type" form:"type"`
  222. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  223. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  224. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  225. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  226. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  227. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  228. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  229. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  230. }
  231. func (HisPrescriptionTwo) TableName() string {
  232. return "his_prescription"
  233. }
  234. func GetNewHisPatientList(org_id int64, record_date int64) (patients []*PatientTwo, err error) {
  235. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  236. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  237. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  238. return db.Preload("HisPrescriptionTwo", "status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Where("user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  239. })
  240. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  241. return
  242. }
  243. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  244. db := readDb.Model(&PatientTwo{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  245. if sch_type != 0 {
  246. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  247. } else {
  248. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  249. }
  250. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  251. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  252. return
  253. }
  254. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  255. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  256. return
  257. }
  258. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  259. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  260. return
  261. }
  262. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  263. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  264. return
  265. }
  266. func GetHisPatientInfoThree(org_id int64, number string) (info models.HisPatient, err error) {
  267. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND number = ?", org_id, number).First(&info).Error
  268. return
  269. }
  270. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  271. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  272. return
  273. }
  274. func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  275. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  276. return
  277. }
  278. func GetNewHisHosptialRecordTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  279. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  280. return
  281. }
  282. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  283. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Count(&total).Error
  284. return
  285. }
  286. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  287. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  288. return
  289. }
  290. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  291. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  292. return
  293. }
  294. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  295. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  296. err = db.Find(&caseHistorys).Error
  297. return
  298. }
  299. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  300. likekey := "%" + keyword + "%"
  301. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  302. if startime > 0 {
  303. db = db.Where("record_date>=?", startime)
  304. }
  305. if endtime > 0 {
  306. db = db.Where("record_date<=?", endtime)
  307. }
  308. if len(keyword) > 0 {
  309. db = db.Where("template_name like ? ", likekey)
  310. }
  311. err = db.Find(&caseHistorys).Error
  312. return
  313. }
  314. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  315. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  316. return caseHistory, err
  317. }
  318. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  319. err = writeDb.Create(&template).Error
  320. return
  321. }
  322. func GetHisPatientCaseHistoryById(id int64) (*models.HisPatientCaseHistory, error) {
  323. history := models.HisPatientCaseHistory{}
  324. err := XTReadDB().Model(&history).Where("id = ? and status = 1", id).Find(&history).Error
  325. if err != nil {
  326. if err == gorm.ErrRecordNotFound {
  327. return nil, err
  328. } else {
  329. return nil, err
  330. }
  331. }
  332. return &history, nil
  333. }
  334. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  335. err := writeDb.Create(&caseHistory).Error
  336. return err
  337. }
  338. func UpdatePatientCaseHistory(id int64, his *models.HisPatientCaseHistory) error {
  339. err := XTWriteDB().Model(&his).Where("id = ? and status =1", id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.Pulse, "allergic_history": his.AllergicHistory, "diagnose": his.AllergicHistory, "sick": his.Sick, "remark": his.Remark, "doctor_advice": his.DoctorAdvice, "breathing": his.Breathing, "delivery_way": his.DeliveryWay, "diagnostic": his.Diagnostic, "family_history": his.FamilyHistory, "personal_history": his.PersonalHistory, "chief_conplaint": his.ChiefConplaint, "doctor": his.Doctor, "past_history": his.PastHistory, "history_of_present_illness": his.HistoryOfPresentIllness, "is_infect": his.IsInfect, "sick_date": his.SickDate, "symptom": his.Symptom, "sick_type": his.SickType, "blood_fat": his.BloodFat, "sbp": his.Sbp, "dbp": his.Dbp}).Error
  340. return err
  341. }
  342. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  343. tx := writeDb.Begin()
  344. if err = tx.Model(&models.HisPrescription{}).Save(prescription).Error; err != nil {
  345. tx.Rollback()
  346. return
  347. }
  348. tx.Commit()
  349. return
  350. }
  351. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  352. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  353. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  354. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  355. return
  356. }
  357. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  358. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  359. return
  360. }
  361. func DelelteProject(id int64, user_org_id int64) (err error) {
  362. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  363. return
  364. }
  365. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  366. err = readDb.Model(&models.HisPrescription{}).
  367. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  368. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  369. }).
  370. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  371. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  372. }).
  373. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  374. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  375. }).
  376. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  377. Find(&prescription).Error
  378. return
  379. }
  380. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  381. err = readDb.Model(&models.HisPrescription{}).
  382. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  383. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  384. }).
  385. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  386. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  387. }).
  388. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  389. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  390. }).
  391. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, his_patient_id, p_type).
  392. Find(&prescription).Error
  393. return
  394. }
  395. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  396. err = readDb.Model(&models.HisPrescription{}).
  397. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  398. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  399. }).
  400. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  401. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  402. }).
  403. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  404. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  405. }).
  406. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 AND his_patient_id = ? AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
  407. Find(&prescription).Error
  408. return
  409. }
  410. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  411. err = readDb.Model(&models.HisPrescription{}).
  412. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  413. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  414. }).
  415. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  416. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  417. }).
  418. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  419. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  420. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  421. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  422. }).
  423. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?) AND (his_patient_id = ? OR his_patient_id = 0)", org_id, record_date, patient_id, p_type, his_patient_id).
  424. Find(&prescription).Error
  425. return
  426. }
  427. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  428. err = readDb.Model(&models.HisPrescription{}).
  429. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  430. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  431. }).
  432. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  433. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  434. }).
  435. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  436. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  437. }).
  438. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  439. Find(&prescription).Error
  440. return
  441. }
  442. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  443. err = readDb.Model(&models.HisPrescription{}).
  444. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  445. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  446. }).
  447. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  448. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  449. }).
  450. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  451. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  452. }).
  453. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  454. Find(&prescription).Error
  455. return
  456. }
  457. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  458. err = readDb.Model(&models.HisPrescription{}).
  459. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  460. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  461. }).
  462. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  463. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  464. }).
  465. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  466. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  467. }).
  468. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  469. Find(&prescription).Error
  470. return
  471. }
  472. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  473. err = readDb.Model(&models.HisPrescription{}).
  474. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  475. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  476. }).
  477. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  478. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  479. }).
  480. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  481. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  482. }).
  483. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? ", org_id, start_date, end_date, patient_id, p_type).
  484. Find(&prescription).Error
  485. return
  486. }
  487. //未收费
  488. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  489. err = readDb.Model(&models.HisPrescription{}).
  490. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  491. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  492. }).
  493. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  494. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  495. }).
  496. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  497. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  498. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  499. return db.Where("status = 1 AND user_org_id = ?", org_id)
  500. }).
  501. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  502. Find(&prescription).Error
  503. return
  504. }
  505. //已收费
  506. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  507. err = readDb.Model(&models.HisPrescription{}).
  508. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  509. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  510. }).
  511. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  512. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  513. }).
  514. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  515. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  516. }).
  517. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  518. Find(&prescription).Error
  519. return
  520. }
  521. type OtherDrugWarehouseInfo struct {
  522. ID int64 `gorm:"column:id" json:"id" form:"id"`
  523. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  524. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  525. Status int64 `gorm:"column:status" json:"status" form:"status"`
  526. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  527. }
  528. func (OtherDrugWarehouseInfo) TableName() string {
  529. return "xt_drug_warehouse_info"
  530. }
  531. type VMDrugSalesReturnInfo struct {
  532. ID int64 `gorm:"column:id" json:"id" form:"id"`
  533. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  534. Count int64 `gorm:"column:count" json:"count" form:"count"`
  535. Status int64 `gorm:"column:status" json:"status" form:"status"`
  536. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  537. }
  538. func (VMDrugSalesReturnInfo) TableName() string {
  539. return "xt_drug_sales_return_info"
  540. }
  541. type VMDrugWarehouseOutInfo struct {
  542. ID int64 `gorm:"column:id" json:"id" form:"id"`
  543. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  544. Count int64 `gorm:"column:count" json:"count" form:"count"`
  545. Status int64 `gorm:"column:status" json:"status" form:"status"`
  546. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  547. }
  548. func (VMDrugWarehouseOutInfo) TableName() string {
  549. return "xt_drug_warehouse_out_info"
  550. }
  551. type VMDrugCancelStockInfo struct {
  552. ID int64 `gorm:"column:id" json:"id" form:"id"`
  553. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  554. Count int64 `gorm:"column:count" json:"count" form:"count"`
  555. Status int64 `gorm:"column:status" json:"status" form:"status"`
  556. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  557. }
  558. func (VMDrugCancelStockInfo) TableName() string {
  559. return "xt_drug_cancel_stock_info"
  560. }
  561. type BaseDrugLib struct {
  562. ID int64 `gorm:"column:id" json:"id" form:"id"`
  563. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  564. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  565. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  566. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  567. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  568. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  569. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  570. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  571. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  572. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  573. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  574. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  575. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  576. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  577. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  578. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  579. Dose float64 `gorm:"column:dose" json:"dose" form:"dose"`
  580. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  581. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  582. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  583. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  584. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  585. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  586. Number string `gorm:"column:number" json:"number" form:"number"`
  587. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  588. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  589. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  590. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  591. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  592. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  593. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  594. Code string `gorm:"column:code" json:"code" form:"code"`
  595. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  596. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  597. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  598. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  599. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  600. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  601. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  602. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  603. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  604. Label int64 `gorm:"column:label" json:"label" form:"label"`
  605. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  606. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  607. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  608. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  609. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  610. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  611. Status int64 `gorm:"column:status" json:"status" form:"status"`
  612. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  613. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  614. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  615. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  616. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  617. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  618. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  619. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  620. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  621. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  622. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  623. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  624. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  625. Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  626. Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  627. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  628. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  629. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  630. Total float64 `gorm:"column:total" json:"total" form:"total"`
  631. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  632. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  633. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  634. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  635. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  636. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  637. }
  638. func (BaseDrugLib) TableName() string {
  639. return "xt_base_drug"
  640. }
  641. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  642. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Find(&list).Error
  643. return
  644. }
  645. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  646. db := readDb.Model(&models.BaseDrugLib{}).Preload("Drugs", "status = 1 AND org_id = ? AND find_in_set('停用',drug_status) = 0", org_id).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Group("drug_name")
  647. err = db.Find(&drugs).Error
  648. return
  649. }
  650. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  651. if len(keyword) != 0 {
  652. key := "%" + keyword + "%"
  653. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ? ", org_id, key).Find(&list).Error
  654. } else {
  655. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  656. }
  657. return
  658. }
  659. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  660. err = writeDb.Create(&charge).Error
  661. return
  662. }
  663. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  664. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  665. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  666. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  667. return
  668. }
  669. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  670. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  671. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  672. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  673. return
  674. }
  675. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  676. tx := writeDb.Begin()
  677. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  678. tx.Rollback()
  679. return
  680. }
  681. tx.Commit()
  682. return
  683. }
  684. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  685. tx := writeDb.Begin()
  686. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  687. tx.Rollback()
  688. return
  689. }
  690. tx.Commit()
  691. return
  692. }
  693. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  694. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn, "mtime": time.Now().Unix()}).Error
  695. return
  696. }
  697. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  698. err := writeDb.Create(&patient).Error
  699. return err
  700. }
  701. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  702. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  703. return
  704. }
  705. func CreateOrder(order *models.HisOrder) (err error) {
  706. err = writeDb.Create(&order).Error
  707. return
  708. }
  709. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  710. err = writeDb.Create(&order).Error
  711. return
  712. }
  713. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  714. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).First(&info).Error
  715. return
  716. }
  717. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  718. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).First(&info).Error
  719. return
  720. }
  721. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  722. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
  723. return
  724. }
  725. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  726. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ?", org_id, record_date, patient_id).Order("record_date desc").First(&info).Error
  727. return
  728. }
  729. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  730. tx := writeDb.Begin()
  731. if err = tx.Model(&models.HisPrescription{}).Save(&info).Error; err != nil {
  732. tx.Rollback()
  733. return
  734. }
  735. tx.Commit()
  736. return
  737. }
  738. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string, p_type int64) (order []*models.HisOrder, err error, total int64) {
  739. offset := (page - 1) * limit
  740. db := readDb.Model(&models.HisOrder{})
  741. if doctor_id > 0 {
  742. db = db.Joins("join his_prescription_info as info on info.patient_id = his_order.patient_id AND info.record_date = his_order.settle_accounts_date AND info.doctor_id = ? AND info.user_org_id = ?", doctor_id, user_org_id)
  743. }
  744. if len(keywords) > 0 {
  745. keywords = "%" + keywords + "%"
  746. db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id AND patient.name like ? AND patient.user_org_id = ?", keywords, user_org_id)
  747. }
  748. if start_time != 0 {
  749. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  750. }
  751. if end_time != 0 {
  752. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  753. }
  754. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.p_type = ?", user_org_id, p_type)
  755. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  756. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  757. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  758. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  759. db = db.Preload("HisFundSettleListResult", "status = 1")
  760. db = db.Count(&total)
  761. err = db.Limit(limit).Offset(offset).Order("settle_accounts_date desc,ctime").Find(&order).Error
  762. return
  763. }
  764. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  765. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  766. return
  767. }
  768. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  769. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  770. return
  771. }
  772. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  773. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date = ?", user_org_id, id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  774. return
  775. }
  776. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  777. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  778. return
  779. }
  780. func UpDateHospitalHisPrescriptionInfoNumber(user_org_id int64, number string, start_time int64, end_time int64) (err error) {
  781. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date <= ? AND record_date >= ? ", user_org_id, end_time, start_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  782. return
  783. }
  784. type HisOrder struct {
  785. ID int64 `gorm:"column:id" json:"id" form:"id"`
  786. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  787. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  788. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  789. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  790. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  791. Status int64 `gorm:"column:status" json:"status" form:"status"`
  792. Number string `gorm:"column:number" json:"number" form:"number"`
  793. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  794. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  795. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  796. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  797. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  798. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  799. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  800. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  801. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  802. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  803. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  804. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  805. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  806. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  807. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  808. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  809. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  810. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  811. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  812. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  813. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  814. }
  815. func (HisOrder) TableName() string {
  816. return "his_order"
  817. }
  818. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  819. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  820. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  821. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  822. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  823. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  824. Order("ctime desc").
  825. Find(&order).Error
  826. return
  827. }
  828. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  829. err = readDb.Model(&models.HisPrescription{}).
  830. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  831. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  832. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  833. }).
  834. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  835. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  836. Find(&prescription).Error
  837. return
  838. }
  839. type HisPrescriptionInfo struct {
  840. ID int64 `gorm:"column:id" json:"id" form:"id"`
  841. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  842. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  843. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  844. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  845. Status int64 `gorm:"column:status" json:"status" form:"status"`
  846. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  847. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  848. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  849. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  850. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  851. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  852. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  853. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  854. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  855. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  856. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  857. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  858. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  859. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  860. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  861. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  862. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  863. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  864. }
  865. func (HisPrescriptionInfo) TableName() string {
  866. return "his_prescription_info"
  867. }
  868. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  869. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  870. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  871. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  872. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  873. Order("ctime desc").Find(&prescriptionOrder).Error
  874. return
  875. }
  876. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  877. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  878. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  879. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  880. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  881. return
  882. }
  883. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  884. err = readDb.Model(&models.HisPrescription{}).
  885. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  886. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  887. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  888. }).
  889. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  890. Find(&prescription).Error
  891. return
  892. }
  893. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  894. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  895. return
  896. }
  897. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  898. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  899. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  900. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  901. return
  902. }
  903. func UpdataHospitalOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  904. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  905. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  906. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  907. return
  908. }
  909. func UpdataOrderInfoStatus(id int64, number string, user_org_id int64) {
  910. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  911. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND user_org_id = ? AND order_number = ?", user_org_id, number).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  912. return
  913. }
  914. func SaveHisPatient(his models.HisPatient) (err error) {
  915. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", his.RecordDate, his.UserOrgId, his.ID).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  916. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  917. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  918. return
  919. }
  920. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  921. writeDb.Model(&models.HisPatient{}).Where("patient_id = ? AND status = 1 AND record_date =? AND user_org_id = ?", patient_id, record_time, org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  922. }
  923. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  924. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  925. return
  926. }
  927. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  928. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  929. First(&order).Error
  930. return
  931. }
  932. func UpDateOrder(order models.HisOrder) (err error) {
  933. err = writeDb.Save(&order).Error
  934. return
  935. }
  936. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  937. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
  938. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
  939. return
  940. }
  941. func CreateErrMsgLog(log *models.HisOrderError) {
  942. writeDb.Model(&models.HisOrderError{}).Create(&log)
  943. }
  944. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  945. err = readDb.Model(&models.VMHisPatient{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Count(&total).Error
  946. return
  947. }
  948. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  949. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  950. return
  951. }
  952. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  953. db := readDb.Model(&models.OutpatientServiceSick{})
  954. db = db.Where("user_org_id = ? AND status = 1", orgId)
  955. err = db.Order("ctime desc").Find(&list).Error
  956. return
  957. }
  958. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  959. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  960. db = db.Where("user_org_id = ? AND status = 1", orgId)
  961. err = db.Order("ctime desc").Find(&list).Error
  962. return
  963. }
  964. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  965. db := readDb.Model(&models.XtHisAddtionConfig{})
  966. db = db.Where("user_org_id = ? AND status = 1", orgId)
  967. err = db.Order("ctime desc").Find(&list).Error
  968. return
  969. }
  970. type XtHisOrder struct {
  971. ID int64 `gorm:"column:id" json:"id" form:"id"`
  972. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  973. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  974. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  975. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  976. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  977. Status int64 `gorm:"column:status" json:"status" form:"status"`
  978. Number string `gorm:"column:number" json:"number" form:"number"`
  979. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  980. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  981. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  982. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  983. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  984. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  985. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  986. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  987. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  988. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  989. }
  990. func (XtHisOrder) TableName() string {
  991. return "his_order"
  992. }
  993. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  994. err = readDb.Model(&models.HisPrescription{}).
  995. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  996. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  997. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  998. }).
  999. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1000. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  1001. Find(&prescription).Error
  1002. return
  1003. }
  1004. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  1005. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Find(&addition).Error
  1006. return
  1007. }
  1008. func DelelteAddition(id int64, user_org_id int64) (err error) {
  1009. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  1010. return
  1011. }
  1012. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  1013. offset := (page - 1) * limit
  1014. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("his_prescription_info.user_org_id = ? AND his_prescription_info.status = 1 AND his_prescription_info.record_date = ? AND his_prescription_info.p_type <> 1 ", org_id, record_date)
  1015. if len(keywords) > 0 {
  1016. keywords = "%" + keywords + "%"
  1017. db = db.Joins("JOIN xt_patients On his_prescription_info.patient_id = xt_patients.id AND xt_patients.name like ?", keywords)
  1018. }
  1019. db = db.Preload("Patients", "xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1020. db = db.Preload("HisPrescription", "his_prescription.user_org_id = ? AND his_prescription.status = 1 AND his_prescription.p_type <> 1", org_id)
  1021. db = db.Count(&total)
  1022. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1023. return
  1024. }
  1025. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  1026. offset := (page - 1) * limit
  1027. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  1028. if len(keywords) > 0 {
  1029. keywords = "%" + keywords + "%"
  1030. db = db.Joins("JOIN xt_patients as p On xt_schedule.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
  1031. db = db.Joins("JOIN his_prescription_info as info On xt_schedule.patient_id = info.patient_id AND info.user_org_id = ? AND info.record_date = ? AND info.prescription_number like ? AND info.p_type <> 1", org_id, record_date, keywords)
  1032. }
  1033. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1034. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1035. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1036. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1037. db = db.Count(&total)
  1038. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1039. return
  1040. }
  1041. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1042. patient := models.VMHisPatient{}
  1043. err := XTWriteDB().Model(&patient).Where("patient_id = ? and record_date = ? and user_org_id = ? and status = 1", patientid, recorddate, orgid).Updates(map[string]interface{}{"is_return": 3}).Error
  1044. return patient, err
  1045. }
  1046. type VMOtherHisPrescriptionInfo struct {
  1047. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1048. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1049. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1050. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1051. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1052. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1053. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1054. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1055. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1056. }
  1057. func (VMOtherHisPrescriptionInfo) TableName() string {
  1058. return "his_prescription_info"
  1059. }
  1060. type VMHisPrescription struct {
  1061. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1062. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1063. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1064. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1065. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1066. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1067. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1068. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1069. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1070. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1071. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1072. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1073. }
  1074. func (VMHisPrescription) TableName() string {
  1075. return "his_prescription"
  1076. }
  1077. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1078. if change_type == 1 { //根据日期取出上一方数据
  1079. var Id AdviceDate
  1080. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  1081. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1082. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1083. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1084. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1085. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1086. }).
  1087. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1088. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1089. })
  1090. }).Find(&advice).Error
  1091. } else if change_type == 2 {
  1092. var Id AdviceDate
  1093. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date > ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date desc").Scan(&Id).Error
  1094. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1095. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1096. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1097. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1098. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1099. }).
  1100. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1101. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1102. })
  1103. }).Find(&advice).Error
  1104. }
  1105. return
  1106. }
  1107. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1108. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ? AND p_type = ?", patient_id, org_id, start_time, end_time, p_type).
  1109. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1110. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1111. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1112. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1113. }).
  1114. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1115. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1116. })
  1117. }).Find(&advice).Error
  1118. return
  1119. }
  1120. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1121. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ?", patient_id, org_id, start_time, end_time).
  1122. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1123. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1124. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1125. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1126. }).
  1127. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1128. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1129. })
  1130. }).Find(&advice).Error
  1131. return
  1132. }
  1133. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1134. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1135. return
  1136. }
  1137. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1138. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1139. return
  1140. }
  1141. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1142. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? AND insutype = ? AND clr_type = ? ", org_id, end_time, start_time, insutype, clr_type).Find(&orders).Error
  1143. return
  1144. }
  1145. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1146. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? ", org_id, end_time, start_time).Find(&orders).Error
  1147. return
  1148. }
  1149. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1150. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1151. return
  1152. }
  1153. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1154. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1155. return
  1156. }
  1157. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1158. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1159. return
  1160. }
  1161. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1162. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1163. return
  1164. }
  1165. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1166. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1167. return
  1168. }
  1169. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1170. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1171. return
  1172. }
  1173. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1174. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1175. return
  1176. }
  1177. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1178. err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
  1179. return
  1180. }
  1181. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1182. var patient Patients
  1183. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1184. return patient, err
  1185. }
  1186. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1187. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1188. return
  1189. }
  1190. type VMHisProjectTeam struct {
  1191. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1192. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1193. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1194. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1195. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1196. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1197. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1198. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1199. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1200. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1201. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1202. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1203. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1204. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1205. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1206. }
  1207. func (VMHisProjectTeam) TableName() string {
  1208. return "xt_his_project_team"
  1209. }
  1210. type VMHisProject struct {
  1211. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1212. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1213. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1214. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1215. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1216. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1217. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1218. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1219. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1220. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1221. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1222. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1223. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1224. }
  1225. func (VMHisProject) TableName() string {
  1226. return "xt_his_project"
  1227. }
  1228. type VMItemProjectList struct {
  1229. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1230. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1231. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1232. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1233. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1234. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1235. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1236. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1237. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1238. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1239. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1240. }
  1241. func (VMItemProjectList) TableName() string {
  1242. return "xt_his_project_list"
  1243. }
  1244. type VMHisPrescriptionTwo struct {
  1245. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1246. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1247. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1248. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1249. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1250. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1251. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1252. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1253. }
  1254. func (VMHisPrescriptionTwo) TableName() string {
  1255. return "his_prescription"
  1256. }
  1257. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1258. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1259. for _, item := range project {
  1260. var project_item []*VMItemProjectList
  1261. ids := strings.Split(item.ItemId, ",")
  1262. XTReadDB().Model(&VMItemProjectList{}).Where("status = 1 AND id IN (?)", ids).Preload("VMHisProject", "status = 1 AND user_org_id = ?", orgid).Preload("GoodInfo", "status = 1 AND org_id = ?", orgid).Find(&project_item)
  1263. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1264. }
  1265. return
  1266. }
  1267. type HisDoctorAdviceInfo struct {
  1268. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1269. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1270. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1271. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1272. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1273. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1274. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1275. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1276. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1277. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1278. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1279. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1280. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1281. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1282. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1283. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1284. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1285. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1286. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1287. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1288. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1289. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1290. }
  1291. func (HisDoctorAdviceInfo) TableName() string {
  1292. return "his_doctor_advice_info"
  1293. }
  1294. type HisPrescriptionProject struct {
  1295. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1296. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1297. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1298. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1299. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1300. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1301. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1302. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1303. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1304. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1305. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1306. Count int64 `gorm:"column:count" json:"count" form:"count"`
  1307. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1308. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1309. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1310. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1311. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1312. Day string `gorm:"column:day" json:"day" form:"day"`
  1313. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1314. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1315. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1316. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1317. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1318. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1319. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1320. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1321. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1322. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1323. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1324. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1325. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1326. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1327. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1328. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1329. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1330. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1331. }
  1332. func (HisPrescriptionProject) TableName() string {
  1333. return "his_prescription_project"
  1334. }
  1335. type HisOrderInfo struct {
  1336. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1337. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1338. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1339. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1340. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1341. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1342. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1343. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1344. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1345. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1346. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1347. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1348. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1349. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1350. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1351. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1352. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1353. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1354. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1355. }
  1356. func (HisOrderInfo) TableName() string {
  1357. return "his_order_info"
  1358. }
  1359. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1360. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1361. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  1362. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1363. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  1364. }).Find(&order).Error
  1365. return
  1366. }
  1367. type MedicalInsuranceCostCompare struct {
  1368. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1369. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1370. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1371. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1372. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1373. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1374. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1375. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1376. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1377. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1378. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1379. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1380. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1381. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1382. }
  1383. func (MedicalInsuranceCostCompare) TableName() string {
  1384. return "medical_insurance_cost_compare"
  1385. }
  1386. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1387. offset := (page - 1) * limit
  1388. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1389. if len(keywords) == 0 {
  1390. db = db.Where("status=1")
  1391. if len(insutype) != 0 {
  1392. db = db.Where("insutype = ?", insutype)
  1393. }
  1394. if start_time != 0 {
  1395. db = db.Where("ctime >= ? ", start_time)
  1396. }
  1397. if end_time != 0 {
  1398. db = db.Where("ctime <= ? ", end_time)
  1399. }
  1400. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1401. } else {
  1402. keywords = "%" + keywords + "%"
  1403. db = db.Joins("join sgj_users.sgj_user_admin_role role on role.admin_user_id = medical_insurance_cost_compare.creator and role.user_name Like ?", keywords)
  1404. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1405. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1406. }
  1407. return
  1408. }
  1409. type TempPatients struct {
  1410. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1411. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1412. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1413. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1414. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1415. Name string `gorm:"column:name" json:"name" form:"name"`
  1416. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1417. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1418. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1419. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1420. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1421. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1422. }
  1423. func (TempPatients) TableName() string {
  1424. return "xt_patients"
  1425. }
  1426. type GdybPsnNcdsRecord struct {
  1427. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1428. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1429. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1430. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1431. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1432. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1433. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1434. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1435. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1436. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1437. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1438. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1439. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1440. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1441. }
  1442. func (GdybPsnNcdsRecord) TableName() string {
  1443. return "gdyb_psn_ncds_record"
  1444. }
  1445. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1446. offset := (page - 1) * limit
  1447. db := readDb.Model(&TempPatients{})
  1448. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1449. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1450. })
  1451. fmt.Println(is_cancel)
  1452. if len(keywords) == 0 {
  1453. if is_cancel == 1 {
  1454. db = db.Joins("JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND gdyb_psn_ncds_record.is_cancel = ?", is_cancel)
  1455. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1456. } else if is_cancel == 0 {
  1457. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1458. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1459. } else if is_cancel == 2 {
  1460. db = db.Joins("LEFT JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND (gdyb_psn_ncds_record.is_cancel <> 1 OR gdyb_psn_ncds_record.is_cancel is null)")
  1461. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1462. }
  1463. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1464. } else {
  1465. keywords = "%" + keywords + "%"
  1466. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1 AND xt_patients.name LIKE ?", orgID, keywords)
  1467. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1468. }
  1469. return
  1470. }
  1471. type CustomAccountFormData struct {
  1472. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1473. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1474. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1475. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1476. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1477. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1478. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1479. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1480. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1481. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1482. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1483. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1484. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1485. DiagnosisId string `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1486. DialysisCount int64 `gorm:"-"`
  1487. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1488. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1489. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1490. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1491. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1492. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1493. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1494. }
  1495. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string) (cus []*CustomAccountFormData, err error) {
  1496. err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay, o.hifmi_pay as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2 AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND insutype = ? Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
  1497. for _, item := range cus {
  1498. var total int64
  1499. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, end_time, start_time).Count(&total)
  1500. fmt.Println(total)
  1501. item.DialysisCount = total
  1502. fmt.Println(item.DialysisCount)
  1503. }
  1504. return
  1505. }
  1506. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1507. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1508. return
  1509. }
  1510. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order HisOrder, err error) {
  1511. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? ", user_org_id, patient_id, mdtrt_id).
  1512. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1513. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1514. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1515. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1516. Order("ctime desc").
  1517. Last(&order).Error
  1518. return
  1519. }
  1520. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1521. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? AND settle_accounts_date = ? ", user_org_id, patient_id, mdtrt_id, record_time).
  1522. Order("ctime desc").
  1523. Find(&order).Error
  1524. return
  1525. }
  1526. type NewCustomPatients struct {
  1527. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1528. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1529. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1530. Number string `gorm:"column:number" json:"number" form:"number"`
  1531. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1532. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1533. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  1534. }
  1535. func (NewCustomPatients) TableName() string {
  1536. return "his_patients"
  1537. }
  1538. type NewSZCustomPatients struct {
  1539. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1540. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1541. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1542. Number string `gorm:"column:number" json:"number" form:"number"`
  1543. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1544. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1545. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  1546. }
  1547. func (NewSZCustomPatients) TableName() string {
  1548. return "his_patients"
  1549. }
  1550. //
  1551. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  1552. // var tempPatients []*NewSZCustomPatients
  1553. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  1554. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1555. // return tempPatients, err
  1556. //}
  1557. type NewTempPatients struct {
  1558. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1559. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1560. Name string `gorm:"column:name" json:"name" form:"name"`
  1561. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1562. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1563. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  1564. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  1565. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  1566. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  1567. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  1568. }
  1569. func (NewTempPatients) TableName() string {
  1570. return "xt_patients"
  1571. }
  1572. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  1573. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1574. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1575. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1576. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1577. })
  1578. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  1579. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  1580. for _, item := range patients {
  1581. for _, sumItem := range item.HisPatient {
  1582. if len(sumItem.VMHisOrders) > 0 {
  1583. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1584. }
  1585. }
  1586. }
  1587. return
  1588. }
  1589. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1590. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1591. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1592. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ? ", org_id, record_date)
  1593. })
  1594. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <>", org_id, record_date)
  1595. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  1596. for _, item := range patients {
  1597. for _, sumItem := range item.HisPatient {
  1598. if len(sumItem.VMHisOrders) > 0 {
  1599. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1600. }
  1601. }
  1602. }
  1603. return
  1604. }
  1605. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  1606. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  1607. return
  1608. }
  1609. type CustomInComeStatistics struct {
  1610. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1611. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1612. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1613. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1614. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1615. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1616. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1617. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1618. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1619. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1620. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1621. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  1622. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  1623. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1624. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1625. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1626. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1627. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1628. }
  1629. func (CustomInComeStatistics) TableName() string {
  1630. return "his_order"
  1631. }
  1632. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  1633. offset := (page - 1) * limit
  1634. if len(keywords) != 0 {
  1635. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1636. } else {
  1637. if start_time != 0 && end_time != 0 {
  1638. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ?", org_id, start_time, end_time).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1639. } else {
  1640. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1641. }
  1642. }
  1643. return
  1644. }
  1645. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  1646. offset := (page - 1) * limit
  1647. if len(keywords) != 0 {
  1648. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1649. } else {
  1650. if start_time != 0 && end_time != 0 {
  1651. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ? ", org_id, start_time, end_time).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1652. } else {
  1653. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1654. }
  1655. }
  1656. return
  1657. }
  1658. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1659. // err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  1660. // return
  1661. //}
  1662. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  1663. err = writeDb.Create(&template).Error
  1664. return
  1665. }
  1666. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  1667. err = writeDb.Save(&s).Error
  1668. return
  1669. }
  1670. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  1671. err = writeDb.Save(&s).Error
  1672. return
  1673. }
  1674. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  1675. err = writeDb.Save(&project).Error
  1676. return
  1677. }
  1678. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  1679. err = readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ? AND status = 1", org_id, patient_id, sch_date).First(&sch).Error
  1680. return
  1681. }
  1682. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  1683. err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? AND status = 1 AND mode = ? AND patient_id = ?", org_id, mode_id, patient_id).Last(&prescription).Error
  1684. return
  1685. }
  1686. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  1687. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  1688. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  1689. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1690. }).
  1691. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  1692. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  1693. }).
  1694. Where("status = 1 AND p_template_id = ? ", template_id).
  1695. Find(&prescription).Error
  1696. return
  1697. }
  1698. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  1699. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND good_id = ?", orgID, patient_id, recordDate, good_id).First(&consumables).Error
  1700. return
  1701. }
  1702. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  1703. err = writeDb.Save(&consumables).Error
  1704. return
  1705. }
  1706. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  1707. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  1708. return
  1709. }
  1710. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  1711. redis := RedisClient()
  1712. defer redis.Close()
  1713. // cur_date := time.Now().Format("2006-01-02")
  1714. key := strconv.FormatInt(user_org_id, 10) + ":"+ strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_time, 10) + ":his_prescription_project"
  1715. his_prescription_project_str, _ := redis.Get(key).Result()
  1716. if len(his_prescription_project_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1717. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, patient_id, record_time).Find(&projects).Error
  1718. if err != nil {
  1719. if err == gorm.ErrRecordNotFound {
  1720. return nil, nil
  1721. } else {
  1722. return nil, err
  1723. }
  1724. } else {
  1725. if len(projects) > 0 {
  1726. //缓存数据
  1727. his_prescription_project_str, err := json.Marshal(projects)
  1728. if err == nil {
  1729. redis.Set(key, his_prescription_project_str, time.Second*60*60*18)
  1730. }
  1731. } else {
  1732. redis.Set(key, " ", time.Second*60*60*18)
  1733. }
  1734. return projects, nil
  1735. }
  1736. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1737. json.Unmarshal([]byte(his_prescription_project_str), &projects)
  1738. return projects, nil
  1739. }
  1740. }
  1741. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  1742. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  1743. return
  1744. }
  1745. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  1746. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  1747. return
  1748. }
  1749. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  1750. err = writeDb.Save(&good_info).Error
  1751. return
  1752. }
  1753. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  1754. err = readDb.Model(&models.HisPrescription{}).
  1755. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1756. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1757. }).
  1758. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1759. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1760. }).
  1761. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1762. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1763. }).
  1764. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status <> 2 ", org_id, start_date, end_date, patient_id, p_type).
  1765. Find(&prescription).Error
  1766. return
  1767. }
  1768. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  1769. err = readDb.Model(&models.HisPrescription{}).
  1770. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1771. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1772. }).
  1773. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1774. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1775. }).
  1776. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1777. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1778. }).
  1779. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status = 2 ", org_id, start_date, end_date, patient_id, p_type).
  1780. Find(&prescription).Error
  1781. return
  1782. }
  1783. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  1784. err = readDb.Model(&models.HisPrescription{}).
  1785. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1786. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1787. }).
  1788. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1789. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1790. }).
  1791. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1792. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1793. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  1794. return db.Where("status = 1 AND user_org_id = ?", org_id)
  1795. }).
  1796. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND order_status = 2 AND batch_number = ? AND p_type = ?", org_id, patient_id, order_number, p_type).
  1797. Find(&prescription).Error
  1798. return
  1799. }
  1800. //已收费
  1801. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  1802. err = readDb.Model(&models.HisPrescription{}).
  1803. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1804. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1805. }).
  1806. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1807. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1808. }).
  1809. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1810. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1811. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  1812. return db.Where("status = 1 AND user_org_id = ?", org_id)
  1813. }).
  1814. Where("user_org_id = ? AND status = 1 AND batch_number = ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, order_number, patient_id, p_type).
  1815. Find(&prescription).Error
  1816. return
  1817. }
  1818. func UpdataHisPateint(his *models.HisPatient) {
  1819. writeDb.Save(&his)
  1820. }
  1821. func SaveHisOrder(his *models.HisOrder) (err error) {
  1822. err = writeDb.Save(&his).Error
  1823. return
  1824. }
  1825. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1826. err = readDb.Model(&models.HisPrescription{}).
  1827. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1828. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1829. }).
  1830. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1831. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1832. }).
  1833. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1834. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1835. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  1836. return db.Where("status = 1 AND user_org_id = ?", org_id)
  1837. }).
  1838. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1839. Find(&prescription).Error
  1840. return
  1841. }
  1842. func GetNewAllUnChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1843. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1844. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1845. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ? AND order_status <> 2", org_id, record_date)
  1846. })
  1847. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  1848. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  1849. for _, item := range patients {
  1850. for _, sumItem := range item.HisPatient {
  1851. if len(sumItem.VMHisOrders) > 0 {
  1852. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1853. }
  1854. }
  1855. }
  1856. return
  1857. }
  1858. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1859. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 2 AND mdtrt_id = ?", org_id, patient_id, record_time, number).Count(&count).Error
  1860. return
  1861. }
  1862. func GetNewHisOrderList(org_id int64) (order []*models.NewHisOrder, err error) {
  1863. err = readDb.Model(&models.NewHisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Preload("HisPatient", "status = 1").Find(&order).Error
  1864. var numbers []string
  1865. for _, item := range order {
  1866. numbers = append(numbers, item.Number)
  1867. }
  1868. return
  1869. }
  1870. func GetNewHisOrderInfoList(order_numbers []string) (order []*models.VMHisOrderInfo, err error) {
  1871. err = readDb.Model(&models.VMHisOrderInfo{}).Where("status = 1 AND order_number in (?)", order_numbers).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1872. return db.Where("status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1")
  1873. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1874. return db.Where("status = 1 ").Preload("Drug", "status =1")
  1875. }).Find(&order).Error
  1876. return
  1877. }
  1878. func FindAllHisDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, drug_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1879. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_date > ? AND advice_date <= ? AND drug_id = ? ", orgId, patient_id, end, now, drug_id).Find(&advice).Error
  1880. return
  1881. }
  1882. func FindAllHisProjectByTime(now int64, end int64, patient_id int64, orgId int64, project_id int64) (project []*models.HisPrescriptionProject, err error) {
  1883. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date > ? AND record_date <= ? AND project_id = ? ", orgId, patient_id, end, now, project_id).Find(&project).Error
  1884. return
  1885. }