his_service.go 99KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  1. package service
  2. import (
  3. "fmt"
  4. "gdyb/models"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. type HisPatient struct {
  9. ID int64 `gorm:"column:id" json:"id" form:"id"`
  10. Name string `gorm:"column:name" json:"name" form:"name"`
  11. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  12. Total float64 `gorm:"column:total" json:"total" form:"total"`
  13. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  14. Status int64 `gorm:"column:status" json:"status" form:"status"`
  15. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  16. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  17. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  18. Number string `gorm:"column:number" json:"number" form:"number"`
  19. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  20. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  21. }
  22. func (HisPatient) TableName() string {
  23. return "his_patient"
  24. }
  25. type Schedule struct {
  26. ID int64 `gorm:"column:id" json:"id" form:"id"`
  27. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  28. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  29. Status int64 `gorm:"column:status" json:"status" form:"status"`
  30. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  31. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  32. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  33. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  34. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  35. }
  36. func (Schedule) TableName() string {
  37. return "xt_schedule"
  38. }
  39. type VMHisPrescriptionInfo struct {
  40. ID int64 `gorm:"column:id" json:"id" form:"id"`
  41. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  42. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  43. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  44. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  45. Status int64 `gorm:"column:status" json:"status" form:"status"`
  46. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  47. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  48. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  49. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  50. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  51. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  52. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  53. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  54. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  55. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  56. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  57. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  58. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  59. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  60. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  61. }
  62. func (VMHisPrescriptionInfo) TableName() string {
  63. return "his_prescription_info"
  64. }
  65. type Patients struct {
  66. ID int64 `gorm:"column:id" json:"id" form:"id"`
  67. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  68. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  69. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  70. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  71. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  72. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  73. Source int64 `gorm:"column:source" json:"source" form:"source"`
  74. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  75. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  76. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  77. Name string `gorm:"column:name" json:"name" form:"name"`
  78. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  79. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  80. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  81. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  82. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  83. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  84. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  85. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  86. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  87. Height int64 `gorm:"column:height" json:"height" form:"height"`
  88. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  89. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  90. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  91. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  92. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  93. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  94. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  95. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  96. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  97. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  98. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  99. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  100. Children int64 `gorm:"column:children" json:"children" form:"children"`
  101. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  102. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  103. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  104. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  105. PredialysisCondition string `gorm:"column:predialysis_condition" json:"predialysis_condition" form:"predialysis_condition"`
  106. PreHospitalDialysisFrequency string `gorm:"column:pre_hospital_dialysis_frequency" json:"pre_hospital_dialysis_frequency" form:"pre_hospital_dialysis_frequency"`
  107. PreHospitalDialysisTimes int64 `gorm:"column:pre_hospital_dialysis_times" json:"pre_hospital_dialysis_times" form:"pre_hospital_dialysis_times"`
  108. HospitalFirstDialysisDate int64 `gorm:"column:hospital_first_dialysis_date" json:"hospital_first_dialysis_date" form:"hospital_first_dialysis_date"`
  109. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  110. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  111. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  112. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  113. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  114. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  115. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  116. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  117. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  118. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  119. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  120. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  121. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains" form:"patient_complains"`
  122. PresentHistory string `gorm:"column:present_history" json:"present_history" form:"present_history"`
  123. PastHistory string `gorm:"column:past_history" json:"past_history" form:"past_history"`
  124. Temperature float64 `gorm:"column:temperature" json:"temperature" form:"temperature"`
  125. Pulse int64 `gorm:"column:pulse" json:"pulse" form:"pulse"`
  126. Respiratory int64 `gorm:"column:respiratory" json:"respiratory" form:"respiratory"`
  127. Sbp int64 `gorm:"column:sbp" json:"sbp" form:"sbp"`
  128. Dbp int64 `gorm:"column:dbp" json:"dbp" form:"dbp"`
  129. Status int64 `gorm:"column:status" json:"status" form:"status"`
  130. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  131. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  132. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  133. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  134. Age int64 `gorm:"column:age" json:"age" form:"age"`
  135. InfectiousNextRecordTime int64 `gorm:"column:infectious_next_record_time" json:"infectious_next_record_time" form:"infectious_next_record_time"`
  136. IsInfectious int64 `gorm:"column:is_infectious" json:"is_infectious" form:"is_infectious"`
  137. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind" form:"is_open_remind"`
  138. RemindCycle int64 `gorm:"column:remind_cycle" json:"remind_cycle" form:"remind_cycle"`
  139. ResponseResult string `gorm:"column:response_result" json:"response_result" form:"response_result"`
  140. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  141. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  142. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  143. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  144. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  145. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  146. IsExcelExport int64 `gorm:"column:is_excel_export" json:"is_excel_export" form:"is_excel_export"`
  147. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  148. OutReason string `gorm:"column:out_reason" json:"out_reason" form:"out_reason"`
  149. InsuplcAdmdvs string `gorm:"column:insuplc_admdvs" json:"insuplc_admdvs" form:"insuplc_admdvs"`
  150. }
  151. func (Patients) TableName() string {
  152. return "xt_patients"
  153. }
  154. type HisPrescription struct {
  155. ID int64 `gorm:"column:id" json:"id" form:"id"`
  156. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  157. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  158. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  159. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  160. Status int64 `gorm:"column:status" json:"status" form:"status"`
  161. }
  162. func (HisPrescription) TableName() string {
  163. return "his_prescription"
  164. }
  165. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
  166. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  167. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  168. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  169. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id).Find(&patients).Error
  170. return
  171. }
  172. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  173. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  174. return
  175. }
  176. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  177. 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
  178. return
  179. }
  180. func GetNewHisPatientInfo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  181. 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
  182. return
  183. }
  184. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  185. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  186. return
  187. }
  188. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  189. 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
  190. return
  191. }
  192. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  193. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  194. err = db.Find(&caseHistorys).Error
  195. return
  196. }
  197. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  198. likekey := "%" + keyword + "%"
  199. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  200. if startime > 0 {
  201. db = db.Where("record_date>=?", startime)
  202. }
  203. if endtime > 0 {
  204. db = db.Where("record_date<=?", endtime)
  205. }
  206. if len(keyword) > 0 {
  207. db = db.Where("template_name like ? ", likekey)
  208. }
  209. err = db.Find(&caseHistorys).Error
  210. return
  211. }
  212. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  213. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  214. return caseHistory, err
  215. }
  216. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  217. err = writeDb.Create(&template).Error
  218. return
  219. }
  220. func GetHisPatientCaseHistoryById(hispatientid int64) (*models.HisPatientCaseHistory, error) {
  221. history := models.HisPatientCaseHistory{}
  222. err := XTReadDB().Model(&history).Where("his_patient_id = ? and status = 1", hispatientid).Find(&history).Error
  223. if err != nil {
  224. if err == gorm.ErrRecordNotFound {
  225. return nil, err
  226. } else {
  227. return nil, err
  228. }
  229. }
  230. return &history, nil
  231. }
  232. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  233. err := writeDb.Create(&caseHistory).Error
  234. return err
  235. }
  236. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  237. err = writeDb.Save(&prescription).Error
  238. return
  239. }
  240. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  241. 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
  242. 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
  243. 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
  244. return
  245. }
  246. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  247. 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
  248. return
  249. }
  250. func DelelteProject(id int64, user_org_id int64) (err error) {
  251. 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
  252. return
  253. }
  254. func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  255. err = readDb.Model(&models.HisPrescription{}).
  256. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  257. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  258. }).
  259. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  260. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  261. }).
  262. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  263. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  264. }).
  265. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1", org_id, record_date, patient_id).
  266. Find(&prescription).Error
  267. return
  268. }
  269. func GetNewHisPrescription(org_id int64, his_patient_id int64, record_date int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  270. err = readDb.Model(&models.HisPrescription{}).
  271. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  272. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  273. }).
  274. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  275. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  276. }).
  277. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  278. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  279. }).
  280. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, reg_type).
  281. Find(&prescription).Error
  282. return
  283. }
  284. type OtherDrugWarehouseInfo struct {
  285. ID int64 `gorm:"column:id" json:"id" form:"id"`
  286. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  287. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  288. Status int64 `gorm:"column:status" json:"status" form:"status"`
  289. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  290. }
  291. func (OtherDrugWarehouseInfo) TableName() string {
  292. return "xt_drug_warehouse_info"
  293. }
  294. type VMDrugSalesReturnInfo struct {
  295. ID int64 `gorm:"column:id" json:"id" form:"id"`
  296. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  297. Count int64 `gorm:"column:count" json:"count" form:"count"`
  298. Status int64 `gorm:"column:status" json:"status" form:"status"`
  299. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  300. }
  301. func (VMDrugSalesReturnInfo) TableName() string {
  302. return "xt_drug_sales_return_info"
  303. }
  304. type VMDrugWarehouseOutInfo struct {
  305. ID int64 `gorm:"column:id" json:"id" form:"id"`
  306. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  307. Count int64 `gorm:"column:count" json:"count" form:"count"`
  308. Status int64 `gorm:"column:status" json:"status" form:"status"`
  309. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  310. }
  311. func (VMDrugWarehouseOutInfo) TableName() string {
  312. return "xt_drug_warehouse_out_info"
  313. }
  314. type VMDrugCancelStockInfo struct {
  315. ID int64 `gorm:"column:id" json:"id" form:"id"`
  316. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  317. Count int64 `gorm:"column:count" json:"count" form:"count"`
  318. Status int64 `gorm:"column:status" json:"status" form:"status"`
  319. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  320. }
  321. func (VMDrugCancelStockInfo) TableName() string {
  322. return "xt_drug_cancel_stock_info"
  323. }
  324. type BaseDrugLib struct {
  325. ID int64 `gorm:"column:id" json:"id" form:"id"`
  326. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  327. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  328. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  329. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  330. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  331. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  332. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  333. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  334. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  335. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  336. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  337. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  338. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  339. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  340. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  341. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  342. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  343. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  344. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  345. Number string `gorm:"column:number" json:"number" form:"number"`
  346. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  347. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  348. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  349. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  350. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  351. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  352. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  353. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  354. Code string `gorm:"column:code" json:"code" form:"code"`
  355. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  356. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  357. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  358. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  359. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  360. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  361. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  362. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  363. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  364. Label int64 `gorm:"column:label" json:"label" form:"label"`
  365. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  366. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  367. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  368. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  369. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  370. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  371. Status int64 `gorm:"column:status" json:"status" form:"status"`
  372. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  373. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  374. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  375. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  376. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  377. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  378. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  379. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  380. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  381. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  382. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  383. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  384. }
  385. func (BaseDrugLib) TableName() string {
  386. return "xt_base_drug"
  387. }
  388. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  389. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  390. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  391. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  392. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  393. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  394. return
  395. }
  396. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  397. err = writeDb.Create(&charge).Error
  398. return
  399. }
  400. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  401. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  402. 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")
  403. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  404. return
  405. }
  406. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  407. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  408. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  409. }).Where("org_id = ? AND status = 1 AND (user_type = 1 OR user_type = 2)", org_id).Find(&doctors).Error
  410. return
  411. }
  412. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  413. err = writeDb.Save(s).Error
  414. return
  415. }
  416. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  417. err = writeDb.Save(project).Error
  418. return
  419. }
  420. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  421. 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
  422. return
  423. }
  424. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  425. err := writeDb.Create(&patient).Error
  426. return err
  427. }
  428. func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  429. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  430. return
  431. }
  432. func GetNewVMHisPatientInfo(org_id int64, his_patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  433. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, his_patient_id).First(&info).Error
  434. return
  435. }
  436. func GetNewHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  437. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, id).First(&info).Error
  438. return
  439. }
  440. func GetHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  441. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  442. return
  443. }
  444. func CreateOrder(order *models.HisOrder) (err error) {
  445. err = writeDb.Create(&order).Error
  446. return
  447. }
  448. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  449. err = writeDb.Create(&order).Error
  450. return
  451. }
  452. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  453. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  454. return
  455. }
  456. func FindHisPatientPrescriptionInfo(org_id int64, his_patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  457. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ?", org_id, record_date, his_patient_id).First(&info).Error
  458. return
  459. }
  460. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  461. 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
  462. return
  463. }
  464. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  465. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, patient_id).Last(&info).Error
  466. return
  467. }
  468. func FindLastPatientPrescriptionInfoTwo1(org_id int64, patient_id int64) (info models.HisPrescriptionInfo, err error) {
  469. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? and p_type = 1", org_id, patient_id).Last(&info).Error
  470. return
  471. }
  472. func FindLastPatientPrescriptionInfoTwo2(org_id int64, patient_id int64,start_time string, end_time string) (info []models.HisPrescriptionInfo, err error) {
  473. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? and p_type = 1 and FROM_UNIXTIME(record_date) >= ? and FROM_UNIXTIME(record_date) <= ?", org_id, patient_id,start_time,end_time).Find(&info).Error
  474. return
  475. }
  476. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  477. err = writeDb.Save(&info).Error
  478. return
  479. }
  480. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string) (order []*models.HisOrder, err error, total int64) {
  481. offset := (page - 1) * limit
  482. db := readDb.Model(&models.HisOrder{})
  483. if doctor_id > 0 {
  484. 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)
  485. }
  486. if len(keywords) > 0 {
  487. keywords = "%" + keywords + "%"
  488. 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)
  489. }
  490. if start_time != 0 {
  491. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  492. }
  493. if end_time != 0 {
  494. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  495. }
  496. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ?", user_org_id)
  497. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  498. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  499. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  500. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  501. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  502. })
  503. db = db.Count(&total)
  504. err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
  505. return
  506. }
  507. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  508. 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
  509. return
  510. }
  511. func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
  512. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  513. return
  514. }
  515. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  516. 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": 2, "mtime": time.Now().Unix()}).Error
  517. return
  518. }
  519. func UpDateHisPrescriptionInfoNumber(user_org_id int64, his_patient_id int64, number string, record_time int64) (err error) {
  520. 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": 2, "mtime": time.Now().Unix()}).Error
  521. return
  522. }
  523. type HisOrder struct {
  524. ID int64 `gorm:"column:id" json:"id" form:"id"`
  525. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  526. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  527. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  528. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  529. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  530. Status int64 `gorm:"column:status" json:"status" form:"status"`
  531. Number string `gorm:"column:number" json:"number" form:"number"`
  532. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  533. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  534. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  535. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  536. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  537. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  538. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  539. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  540. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  541. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  542. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  543. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  544. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  545. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  546. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  547. SzChargeInfo string `gorm:"column:sz_charge_info" json:"sz_charge_info" form:"sz_charge_info"`
  548. SzProjectInfo string `gorm:"column:sz_project_info" json:"sz_project_info" form:"sz_project_info"`
  549. SzMedicineInsuranceInfo string `gorm:"column:sz_medicine_insurance_info" json:"sz_medicine_insurance_info" form:"sz_medicine_insurance_info"`
  550. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  551. OrgSetlNumber string `gorm:"column:org_setl_number" json:"org_setl_number" form:"org_setl_number"`
  552. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  553. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  554. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  555. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  556. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  557. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  558. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  559. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  560. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  561. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  562. }
  563. func (HisOrder) TableName() string {
  564. return "his_order"
  565. }
  566. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  567. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  568. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  569. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  570. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  571. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  572. Order("ctime desc").
  573. Find(&order).Error
  574. return
  575. }
  576. func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  577. err = readDb.Model(&models.HisPrescription{}).
  578. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  579. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  580. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  581. }).
  582. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  583. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
  584. Find(&prescription).Error
  585. return
  586. }
  587. type HisPrescriptionInfo struct {
  588. ID int64 `gorm:"column:id" json:"id" form:"id"`
  589. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  590. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  591. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  592. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  593. Status int64 `gorm:"column:status" json:"status" form:"status"`
  594. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  595. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  596. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  597. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  598. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  599. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  600. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  601. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  602. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  603. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  604. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  605. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  606. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  607. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  608. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  609. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  610. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  611. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  612. }
  613. func (HisPrescriptionInfo) TableName() string {
  614. return "his_prescription_info"
  615. }
  616. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  617. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  618. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  619. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  620. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  621. Order("ctime desc").Find(&prescriptionOrder).Error
  622. return
  623. }
  624. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  625. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ? ", id, org_id).
  626. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  627. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  628. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  629. return
  630. }
  631. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  632. err = readDb.Model(&models.HisPrescription{}).
  633. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  634. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  635. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  636. }).
  637. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  638. Find(&prescription).Error
  639. return
  640. }
  641. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  642. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  643. return
  644. }
  645. func UpdataOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  646. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  647. 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
  648. 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
  649. return
  650. }
  651. func UpdataOrderStatusThree(id int64, number string, user_org_id int64, log string, result string) (err error) {
  652. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  653. 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": 4, "mtime": time.Now().Unix()}).Error
  654. 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
  655. return
  656. }
  657. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  658. 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()})
  659. //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
  660. //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
  661. }
  662. func UpdataRegStatusTwo(his_patient_id int64, record_time int64, org_id int64) {
  663. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", record_time, org_id, his_patient_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  664. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  665. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  666. }
  667. func UpdataRegStatus2(id int64) error {
  668. err := writeDb.Model(&models.HisPatient{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  669. return err
  670. }
  671. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  672. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  673. return
  674. }
  675. func GetAdminUserInfo(org_id int64) (role models.UserAdminRole, err error) {
  676. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1", org_id).First(&role).Error
  677. return
  678. }
  679. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  680. err = readDb.Model(&HisOrder{}).Where("user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  681. First(&order).Error
  682. return
  683. }
  684. func UpDateOrder(order models.HisOrder) (err error) {
  685. err = writeDb.Save(&order).Error
  686. return
  687. }
  688. func UpDateOrderTwo(order *models.HisOrder) (err error) {
  689. err = writeDb.Save(&order).Error
  690. return
  691. }
  692. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  693. 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
  694. 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
  695. return
  696. }
  697. func CreateErrMsgLog(log *models.HisOrderError) {
  698. writeDb.Model(&models.HisOrderError{}).Create(&log)
  699. }
  700. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  701. 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
  702. return
  703. }
  704. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  705. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  706. return
  707. }
  708. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  709. db := readDb.Model(&models.OutpatientServiceSick{})
  710. db = db.Where("user_org_id = ? AND status = 1", orgId)
  711. err = db.Order("ctime desc").Find(&list).Error
  712. return
  713. }
  714. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  715. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  716. db = db.Where("user_org_id = ? AND status = 1", orgId)
  717. err = db.Order("ctime desc").Find(&list).Error
  718. return
  719. }
  720. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  721. db := readDb.Model(&models.XtHisAddtionConfig{})
  722. db = db.Where("user_org_id = ? AND status = 1", orgId)
  723. err = db.Order("ctime desc").Find(&list).Error
  724. return
  725. }
  726. type XtHisOrder struct {
  727. ID int64 `gorm:"column:id" json:"id" form:"id"`
  728. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  729. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  730. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  731. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  732. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  733. Status int64 `gorm:"column:status" json:"status" form:"status"`
  734. Number string `gorm:"column:number" json:"number" form:"number"`
  735. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  736. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  737. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  738. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  739. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  740. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  741. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  742. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  743. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  744. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  745. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  746. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  747. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  748. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  749. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  750. }
  751. func (XtHisOrder) TableName() string {
  752. return "his_order"
  753. }
  754. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  755. err = readDb.Model(&models.HisPrescription{}).
  756. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  757. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  758. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  759. }).
  760. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  761. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  762. Find(&prescription).Error
  763. return
  764. }
  765. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  766. 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
  767. return
  768. }
  769. func DelelteAddition(id int64, user_org_id int64) (err error) {
  770. 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
  771. return
  772. }
  773. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*Schedule, err error, total int64) {
  774. offset := (page - 1) * limit
  775. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  776. if len(keywords) > 0 {
  777. keywords = "%" + keywords + "%"
  778. 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)
  779. 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 ?", org_id, record_date, keywords)
  780. }
  781. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  782. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  783. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).
  784. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id)
  785. db = db.Count(&total)
  786. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  787. return
  788. }
  789. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  790. patient := models.VMHisPatient{}
  791. 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
  792. return patient, err
  793. }
  794. type VMOtherHisPrescriptionInfo struct {
  795. ID int64 `gorm:"column:id" json:"id" form:"id"`
  796. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  797. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  798. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  799. Status int64 `gorm:"column:status" json:"status" form:"status"`
  800. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  801. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  802. }
  803. func (VMOtherHisPrescriptionInfo) TableName() string {
  804. return "his_prescription_info"
  805. }
  806. type VMHisPrescription struct {
  807. ID int64 `gorm:"column:id" json:"id" form:"id"`
  808. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  809. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  810. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  811. Status int64 `gorm:"column:status" json:"status" form:"status"`
  812. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  813. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  814. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  815. Type int64 `gorm:"column:type" json:"type" form:"type"`
  816. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  817. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  818. }
  819. func (VMHisPrescription) TableName() string {
  820. return "his_prescription"
  821. }
  822. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  823. 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).
  824. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  825. return db.Where("status = 1 AND user_org_id = ?", org_id).
  826. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  827. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  828. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  829. })
  830. }).Find(&advice).Error
  831. return
  832. }
  833. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  834. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  835. return
  836. }
  837. func GetHisOrderByIDTwo(order_id int64) (order models.HisOrder, err error) {
  838. err = readDb.Model(&models.HisOrder{}).Preload("HisOrderInfo", "status = 1").Preload("HisPatient", "status = 1").Where("id = ? AND status = 1", order_id).First(&order).Error
  839. return
  840. }
  841. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  842. db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  843. return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  844. })
  845. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  846. return
  847. }
  848. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfo, err error) {
  849. db := readDb.Model(&models.HisOrderInfo{})
  850. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  851. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  852. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  853. })
  854. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  855. return
  856. }
  857. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfo, err error) {
  858. db := readDb.Model(&models.HisOrderInfo{})
  859. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  860. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  861. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  862. })
  863. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  864. return
  865. }
  866. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  867. db := readDb.Model(&models.HisOrder{})
  868. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  869. if len(clr_org) > 0 {
  870. db = db.Where("clr_optins = ?", clr_org)
  871. }
  872. if len(clr_type) > 0 {
  873. if mdtrtareaAdmvs == "150499" {
  874. if clr_type == "11" {
  875. db = db.Where("clr_type = ?", clr_type)
  876. }
  877. } else {
  878. db = db.Where("clr_type = ?", clr_type)
  879. }
  880. } else {
  881. db = db.Where("clr_type <> ?", "9903")
  882. }
  883. err = db.Find(&orders).Error
  884. return
  885. }
  886. func GetOrderByTimeFive(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  887. db := readDb.Model(&models.HisOrder{})
  888. db = db.Where("user_org_id = ? AND order_status = 3 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  889. if len(clr_org) > 0 {
  890. db = db.Where("clr_optins = ?", clr_org)
  891. }
  892. if len(clr_type) > 0 {
  893. if mdtrtareaAdmvs == "150499" {
  894. if clr_type == "11" {
  895. db = db.Where("clr_type = ?", clr_type)
  896. }
  897. } else {
  898. db = db.Where("clr_type = ?", clr_type)
  899. }
  900. }
  901. err = db.Find(&orders).Error
  902. return
  903. }
  904. func GetOrderByTimeFour(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  905. db := readDb.Model(&models.HisOrder{})
  906. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? ", org_id, end_time, start_time)
  907. err = db.Find(&orders).Error
  908. return
  909. }
  910. func GetOrderByTimeThree(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  911. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype).Find(&orders).Error
  912. return
  913. }
  914. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  915. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ?", org_id, end_time, start_time).Find(&orders).Error
  916. return
  917. }
  918. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  919. var patient models.Patients
  920. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  921. if err != nil {
  922. if err == gorm.ErrRecordNotFound {
  923. return nil, nil
  924. } else {
  925. return nil, err
  926. }
  927. }
  928. return &patient, nil
  929. }
  930. func FindDiagnoseById(id int64) (models.HisXtDiagnoseConfig, error) {
  931. dealer := models.HisXtDiagnoseConfig{}
  932. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ?", id).First(&dealer).Error
  933. return dealer, err
  934. }
  935. func FindDiagnoseByIdtwo(id string) (models.HisXtDiagnoseConfig, error) {
  936. dealer := models.HisXtDiagnoseConfig{}
  937. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ?", id).First(&dealer).Error
  938. return dealer, err
  939. }
  940. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  941. dealer := []*models.HisXtDiagnoseConfig{}
  942. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  943. return dealer, err
  944. }
  945. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  946. outPatient := &models.OutpatientServiceSick{}
  947. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  948. return outPatient, err
  949. }
  950. //
  951. //type MonthHisPrescription struct {
  952. // ID int64 `gorm:"column:id" json:"id" form:"id"`
  953. // UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  954. // RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  955. // PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  956. // HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  957. // Status int64 `gorm:"column:status" json:"status" form:"status"`
  958. // Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  959. // Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  960. // Number string `gorm:"column:number" json:"number" form:"number"`
  961. // Type int64 `gorm:"column:type" json:"type" form:"type"`
  962. // Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  963. // Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  964. // Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  965. // OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  966. // BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  967. // PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  968. // Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  969. // HisPatient models.VMHisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
  970. // HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  971. // HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  972. // HisAdditionalCharge []*models.HisAdditionalCharge `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
  973. // VMHisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  974. //}
  975. //
  976. //func (MonthHisPrescription) TableName() string {
  977. // return "his_prescription"
  978. //}
  979. func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  980. err = readDb.Model(&models.HisPrescription{}).
  981. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  982. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  983. }).
  984. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  985. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  986. }).
  987. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  988. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  989. }).
  990. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, reg_type).
  991. Find(&prescription).Error
  992. return
  993. }
  994. func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
  995. err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?) AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
  996. return
  997. }
  998. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  999. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1000. return
  1001. }
  1002. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1003. 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
  1004. return
  1005. }
  1006. func GetAppRole(orgID int64) (models.App_Role, error) {
  1007. var appRole models.App_Role
  1008. err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
  1009. return appRole, err
  1010. }
  1011. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1012. var patient Patients
  1013. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1014. return patient, err
  1015. }
  1016. func GetDrugList(orgID int64) (drug []*models.BaseDrugList, err error) {
  1017. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1018. table := XTReadDB().Table("xt_manufacturer as m")
  1019. fmt.Print(table)
  1020. if orgID > 0 {
  1021. db = db.Where("x.org_id = ? and x.id = 397", orgID)
  1022. }
  1023. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1024. return drug, err
  1025. }
  1026. func GetDrugDosageForm(orgid int64) (dataconfig []*models.XtDrugDataConfig, err error) {
  1027. err = XTReadDB().Where("(org_id = ? or org_id = 0) and parent_id = 4 and status = 1", orgid).Find(&dataconfig).Error
  1028. return dataconfig, err
  1029. }
  1030. func GetDoctorList(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1031. //err = UserReadDB().Model(&role).Where("org_id = ? and status = 1 and user_type = 2", orgid).Find(&role).Error
  1032. //return role, err
  1033. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1034. table := UserReadDB().Table("sgj_user_admin as a")
  1035. fmt.Println(table)
  1036. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1037. return role, err
  1038. }
  1039. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1040. err = readDb.Model(&models.HisPrescription{}).
  1041. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1042. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1043. }).
  1044. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1045. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1046. }).
  1047. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1048. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1049. }).
  1050. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1051. Find(&prescription).Error
  1052. return
  1053. }
  1054. func GetDoctorListTwo(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1055. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1 AND x.user_type = 2 AND x.org_id = ?", orgid)
  1056. //table := UserReadDB().Table("sgj_user_admin as a")
  1057. //fmt.Println(table)
  1058. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1059. return role, err
  1060. }
  1061. func GetRoleList(orgid int64) (role []*models.SgjUserRole, err error) {
  1062. err = UserReadDB().Model(&role).Where("org_id = ? and status =1", orgid).Find(&role).Error
  1063. return role, err
  1064. }
  1065. func GetDrugListByDetail(orgID int64, id int64) (drug []*models.BaseDrugList, err error) {
  1066. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1067. table := XTReadDB().Table("xt_manufacturer as m")
  1068. fmt.Print(table)
  1069. if orgID > 0 {
  1070. db = db.Where("x.org_id = ? and x.id = ?", orgID, id)
  1071. }
  1072. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1073. return drug, err
  1074. }
  1075. func GetGoodInformationList(orgid int64) (good []*models.GoodInformation, err error) {
  1076. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1077. table := XTReadDB().Table("xt_manufacturer as m")
  1078. fmt.Println(table)
  1079. if orgid > 0 {
  1080. db = db.Where("x.org_id = ?", orgid)
  1081. }
  1082. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1083. return good, err
  1084. }
  1085. func GetGoodListByDetail(orgid int64, id int64) (good []*models.GoodInformation, err error) {
  1086. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1087. table := XTReadDB().Table("xt_manufacturer as m")
  1088. fmt.Println(table)
  1089. if orgid > 0 {
  1090. db = db.Where("x.org_id = ? and x.id= ?", orgid, id)
  1091. }
  1092. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1093. return good, err
  1094. }
  1095. func GetDoctorListByDetail(orgid int64, id int64) (role []*models.SgjUserAdminRole, err error) {
  1096. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1097. table := UserReadDB().Table("sgj_user_admin as a")
  1098. fmt.Println(table)
  1099. if id > 0 {
  1100. db = db.Where("x.status = 1 and x.admin_user_id = ? and x.org_id = ?", id, orgid)
  1101. }
  1102. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1103. return role, err
  1104. }
  1105. func GetMyPorjecgList(orgid int64) (project []*models.MyHisProject, err error) {
  1106. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1107. return project, err
  1108. }
  1109. func GetMyPorjecgListDetail(orgid int64, id int64) (project []*models.MyHisProject, err error) {
  1110. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and id = ?", orgid, id).Find(&project).Error
  1111. return project, err
  1112. }
  1113. func GetBathchMyPorjecgList(idss []int64) (project []*models.MyHisProject, err error) {
  1114. db := XTReadDB().Table("xt_his_project")
  1115. if len(idss) == 1 {
  1116. err = db.Where("status = 1 and id = ?", idss[0]).Find(&project).Error
  1117. } else {
  1118. err = db.Where("status = 1 and id IN(?)", idss).Find(&project).Error
  1119. }
  1120. return project, err
  1121. }
  1122. func GetBathchMyPorjecgListtwo(org_id int64) (project []*models.MyHisProject, err error) {
  1123. db := XTReadDB().Table("xt_his_project")
  1124. err = db.Where("status = 1 and user_org_id = ?", org_id).Find(&project).Error
  1125. return project, err
  1126. }
  1127. func GetBatchDoctorList(idss []int64) (role []*models.SgjUserAdminRole, err error) {
  1128. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1129. table := UserReadDB().Table("sgj_user_admin as a")
  1130. fmt.Println(table)
  1131. if len(idss) == 1 {
  1132. db = db.Where("x.status = 1 and x.admin_user_id = ?", idss[0])
  1133. } else {
  1134. db = db.Where("x.status = 1 and x.admin_user_id IN(?)", idss)
  1135. }
  1136. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1137. return role, err
  1138. }
  1139. func GetAllPatient(org_id int64) (patients []*models.Patients, err error) {
  1140. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", org_id).Find(&patients).Error
  1141. return
  1142. }
  1143. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1144. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1145. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1146. return
  1147. }
  1148. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  1149. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date <= ? AND record_date >= ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1150. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1151. return
  1152. }
  1153. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1154. 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
  1155. return
  1156. }
  1157. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1158. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1159. return
  1160. }
  1161. func GetNewHisPrescriptionByNumber(number string) (pre models.HisPrescription, err error) {
  1162. err = readDb.Model(&models.HisPrescription{}).Where("batch_number = ? AND status = 1", number).First(&pre).Error
  1163. return
  1164. }
  1165. func CreateUploadRecord(result *models.HisFundSettleListResult) (err error) {
  1166. err = writeDb.Create(&result).Error
  1167. return
  1168. }
  1169. func GetUploadRecord(order_id int64) (result models.HisFundSettleListResult, err error) {
  1170. err = readDb.Model(&models.HisFundSettleListResult{}).Where("order_id = ? AND status = 1", order_id).First(result).Error
  1171. return
  1172. }
  1173. func UpdateRecord(result *models.HisFundSettleListResult) (err error) {
  1174. err = writeDb.Save(&result).Error
  1175. return
  1176. }
  1177. func GetDeviceNumberByID(bed_id int64, org_id int64) (device_number models.DeviceNumber, err error) {
  1178. err = readDb.Model(&models.DeviceNumber{}).Where("id = ? AND org_id = ?", bed_id, org_id).First(&device_number).Error
  1179. return
  1180. }
  1181. func UpdateHisPatientStatus(his *models.VMHisPatient) {
  1182. writeDb.Save(&his)
  1183. }
  1184. func GetLastHisOrder(org_id int64) (his models.HisOrder, err error) {
  1185. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code <> '' AND fa_piao_number <> ''", org_id).Last(&his).Error
  1186. return
  1187. }
  1188. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  1189. err = readDb.Model(&models.HisOrder{}).Select("max(convert(fa_piao_number,signed)) as fa_piao_number").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Find(&his).Error
  1190. return
  1191. }
  1192. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1193. 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
  1194. return
  1195. }
  1196. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1197. 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).
  1198. Order("ctime desc").
  1199. Find(&order).Error
  1200. return
  1201. }
  1202. func GetNewHisOrderThree(mdtrt_id string) (order HisOrder, err error) {
  1203. err = readDb.Model(&HisOrder{}).Where("status = 1 AND mdtrt_id=? ", mdtrt_id).First(&order).Error
  1204. return
  1205. }
  1206. func UpdateHisPatientThree(his *models.HisPatient) {
  1207. writeDb.Save(&his)
  1208. }
  1209. func GetNewHisPrescriptionTwo(org_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1210. err = readDb.Model(&models.HisPrescription{}).
  1211. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1212. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1213. }).
  1214. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1215. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1216. }).
  1217. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1218. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1219. }).
  1220. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, med_type).
  1221. Find(&prescription).Error
  1222. return
  1223. }
  1224. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_time int64, end_time int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1225. err = readDb.Model(&models.HisPrescription{}).
  1226. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1227. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1228. }).
  1229. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1230. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1231. }).
  1232. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1233. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1234. }).
  1235. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, med_type).
  1236. Find(&prescription).Error
  1237. return
  1238. }
  1239. func GetNewHisPatientInfoFour(org_id int64, id int64) (info models.HisPatient, err error) {
  1240. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  1241. return
  1242. }
  1243. func GetTodayHisOrder(org_id int64, patient_id int64, record_time int64, number string) (order models.HisOrder, err error) {
  1244. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 1 AND mdtrt_id = ?", org_id, patient_id, record_time, number).First(&order).Error
  1245. return
  1246. }
  1247. func GetLastFundList(org_id int64) (order models.HisFundSettleListResult, err error) {
  1248. err = readDb.Model(&models.HisFundSettleListResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Last(&order).Error
  1249. return
  1250. }
  1251. func GetOrderError(org_id int64) (order []*models.HisOrderError, err error) {
  1252. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 10106 ", org_id).Find(&order).Error
  1253. return
  1254. }
  1255. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1256. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 2 AND mdtrt_id = ?", org_id, patient_id, record_time, number).Count(&count).Error
  1257. return
  1258. }
  1259. func CreateHisPsn(psn *models.HisPsn) {
  1260. writeDb.Save(&psn)
  1261. }
  1262. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  1263. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1264. return
  1265. }
  1266. func GetPsnByPatientIdtWO(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1267. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ?", patient_id, record_date).Last(&psn).Error
  1268. return
  1269. }
  1270. //func GetPsnByPatientIdTwo(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1271. // err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ? AND stage = 1", patient_id, record_date).Last(&psn).Error
  1272. // return
  1273. //}
  1274. func GetPsnByPatientIdTwo(patient_id int64) (psn models.HisPsn, err error) {
  1275. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1276. return
  1277. }
  1278. func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
  1279. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2022-12-15 00:00:00'", org_id).Order("setl_time asc").Find(&his).Error
  1280. fmt.Println(err)
  1281. return
  1282. }
  1283. func GetAllHisOrderTwo(org_id int64) (his []*models.HisOrder, err error) {
  1284. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND id >= 247903", org_id).Order("setl_time asc").Find(&his).Error
  1285. fmt.Println(err)
  1286. return
  1287. }
  1288. func GetAllHisOrder10106(org_id int64) (his []*models.HisOrder, err error) {
  1289. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2023-08-01 00:00:00' AND setl_time <= '2023-08-31 23:59:00'").Order("setl_time asc").Find(&his).Error
  1290. fmt.Println(err)
  1291. return
  1292. }
  1293. func GetAllHisOrder10138() (his []*models.HisOrder, err error) {
  1294. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10138 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2023-06-01 00:00:00' AND setl_time <= '2023-06-30 23:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1295. fmt.Println(err)
  1296. return
  1297. }
  1298. func GetOrderError10138(org_id int64) (order []*models.HisOrderError, err error) {
  1299. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 10139000", org_id).Find(&order).Error
  1300. return
  1301. }
  1302. func GetAllHisOrder10278() (his []*models.HisOrder, err error) {
  1303. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10278 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2023-06-01 00:00:00'").Order("setl_time asc").Find(&his).Error
  1304. fmt.Println(err)
  1305. return
  1306. }
  1307. func GetAllHisOrder10265() (his []*models.HisOrder, err error) {
  1308. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2023-09-01 00:00:00'").Order("setl_time asc").Find(&his).Error
  1309. fmt.Println(err)
  1310. return
  1311. }
  1312. // func GetAllHisOrder2(org_id int64) (his []models.HisOrder, err error) {
  1313. // err = readDb.Model(&models.HisOrder{}).Where("id = 180753").Order("setl_time asc").First(&his).Error
  1314. // return
  1315. // }
  1316. func GetAllHisOrderErr10278() (his []*models.HisOrderError, err error) {
  1317. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = 10278 AND status = 1 AND stage = 10276").Find(&his).Error
  1318. return
  1319. }
  1320. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  1321. db := readDb.Model(&models.HisOrderInfo{})
  1322. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1323. return
  1324. }
  1325. func UpdataOrderStatusByNumber(number string) (err error) {
  1326. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND number = ?", number).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1327. return
  1328. }
  1329. func UpdataHospitalOrderStatus(number string, user_org_id int64) (err error) {
  1330. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND order_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
  1331. 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
  1332. 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
  1333. return
  1334. }
  1335. func GetHisFundSettleListResult(order_id int64) (result models.HisFundSettleListResult, err error) {
  1336. db := readDb.Model(&models.HisFundSettleListResult{})
  1337. err = db.Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1338. return
  1339. }
  1340. func SaveClearRecord(record *models.HisYidiClearRecord) {
  1341. writeDb.Save(&record)
  1342. }
  1343. func GetClearRecordById(id int64) (record models.HisYidiClearRecord, err error) {
  1344. err = readDb.Model(&models.HisYidiClearRecord{}).Where("id = ? AND status = 1").First(&record).Error
  1345. return
  1346. }
  1347. func UpdateOrder(order models.HisOrder) (err error) {
  1348. err = writeDb.Save(&order).Error
  1349. return
  1350. }
  1351. func UpdateOrderTwo(order models.NewHisOrder111) (err error) {
  1352. err = writeDb.Save(&order).Error
  1353. return
  1354. }
  1355. func GetNewHisPrescriptionTen(org_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  1356. err = readDb.Model(&models.HisPrescriptionTen{}).
  1357. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1358. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1359. }).
  1360. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1361. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1362. }).
  1363. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND p_type <> 1 ", org_id, record_date, his_patient_id).
  1364. Find(&prescription).Error
  1365. return
  1366. }
  1367. func GetHisOrderByIDTwo1111(order_id int64) (order models.NewHisOrder111, err error) {
  1368. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1369. return
  1370. }
  1371. func GetHisPrescriptionForMedType(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  1372. err = readDb.Model(&models.HisPrescription{}).
  1373. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1374. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1375. }).
  1376. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1377. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1378. }).
  1379. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1380. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  1381. }).
  1382. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 148801) or (user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 118801)", org_id, record_date, patient_id, org_id, record_date, patient_id).
  1383. Find(&prescription).Error
  1384. return
  1385. }
  1386. func GetOrderByTimeTen(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1387. err = readDb.Raw("select CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') END AS fund_key, his_order.insutype, '99' as `psn_type` , his_order.`med_type`, COUNT(DISTINCT his_order.`certno`) AS psn_cnt, count(*) as psn_time, sum(his_order.medfee_sumamt) as sumamt, sum(his_order.inscp_scp_amt) as amt, sum(his_order.fund_pay_sumamt) + sum(his_order.acct_pay) as fund FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 1 and his_order.order_status = 2 and his_order.setl_time >= ? and his_order.setl_time <= ? and his_order.setl_id <> '' GROUP BY fund_key", org_id, start_time+" 00:00:00", end_time+" 23:00:00").Scan(&orders).Error
  1388. return
  1389. }
  1390. func GetOrderByTimeTentwo(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1391. err = readDb.Raw("select CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') END AS fund_key, his_order.insutype, '99' as `psn_type` , his_order.`med_type`, COUNT(DISTINCT his_order.`certno`) AS psn_cnt, count(*) as psn_time, sum(his_order.medfee_sumamt) as sumamt, sum(his_order.inscp_scp_amt) as amt, sum(his_order.fund_pay_sumamt) + sum(his_order.acct_pay) as fund FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 0 and his_order.order_status = 3 and his_order.setl_time >= ? and his_order.setl_time <= ? and his_order.setl_id <> '' GROUP BY fund_key", org_id, start_time+" 00:00:00", end_time+" 23:00:00").Scan(&orders).Error
  1392. return
  1393. }
  1394. func GetOrderDetailByTimeTen(start_time string, end_time string, org_id int64, fund_key string) (fund []models.FundDetail, err error) {
  1395. err = readDb.Raw("SELECT CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') end AS fund_key, his_order.`setl_detail` FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 1 and his_order.order_status = 2 and his_order.setl_time >= ? and his_order.setl_time <= ? and CONCAT(his_order.insutype, '99', his_order.med_type, '555555') = ?", org_id, start_time+" 00:00:00", end_time+" 23:59:00", fund_key).Scan(&fund).Error
  1396. return
  1397. }
  1398. //
  1399. func Saveflow(flow models.HisPrescriptionFlow){
  1400. writeDb.Save(&flow)
  1401. }
  1402. func GetNewHisPrescriptionTenone(org_id int64,number string) (prescription []*models.HisPrescriptionTen, err error) {
  1403. err = readDb.Model(&models.HisPrescriptionTen{}).
  1404. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1405. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1406. }).
  1407. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1408. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1409. }).
  1410. Where("user_org_id = ? AND status = 1 AND batch_number = ? and order_status = 4 ", org_id, number).
  1411. Find(&prescription).Error
  1412. return
  1413. }