his_service.go 125KB

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