Browse Source

医保对接

csx 4 years ago
parent
commit
5891737e63

+ 20 - 3
controllers/his_api_controller.go View File

@@ -1657,6 +1657,13 @@ func (c *HisApiController) GetHisOrderList() {
1657 1657
 	adminUser := c.GetAdminUserInfo()
1658 1658
 	org_id := adminUser.CurrentOrgId
1659 1659
 	order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords)
1660
+
1661
+	for _, item := range order {
1662
+		info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
1663
+		item.DoctorName = info.Doctor
1664
+		item.DepartmentName = info.XtHisDepartment.Name
1665
+	}
1666
+
1660 1667
 	if err == nil {
1661 1668
 		c.ServeSuccessJSON(map[string]interface{}{
1662 1669
 			"order": order,
@@ -1673,7 +1680,7 @@ func (c *HisApiController) GetHisOrder() {
1673 1680
 	number := c.GetString("number")
1674 1681
 	adminInfo := c.GetAdminUserInfo()
1675 1682
 	order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
1676
-	prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.SettleAccountsDate, order.Number)
1683
+	prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
1677 1684
 
1678 1685
 	if err == nil {
1679 1686
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -2031,6 +2038,10 @@ func (c *HisApiController) GetRegisterInfo() {
2031 2038
 	medical_expenses, _ := c.GetFloat("medical_expenses")
2032 2039
 	social_type, _ := c.GetInt64("social_type")
2033 2040
 
2041
+	diagnosis_id, _ := c.GetInt64("diagnosis")
2042
+	sick_type, _ := c.GetInt64("sick_type")
2043
+	reg_type := c.GetString("p_type")
2044
+
2034 2045
 	timeLayout := "2006-01-02"
2035 2046
 	loc, _ := time.LoadLocation("Local")
2036 2047
 	birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
@@ -2044,9 +2055,12 @@ func (c *HisApiController) GetRegisterInfo() {
2044 2055
 	recordDateTime := theTime.Unix()
2045 2056
 
2046 2057
 	adminInfo := c.GetAdminUserInfo()
2047
-
2058
+	tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
2059
+	if tempPatient.ID == 0 {
2060
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
2061
+		return
2062
+	}
2048 2063
 	var patient service.Patients
2049
-
2050 2064
 	if id == 0 {
2051 2065
 		patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
2052 2066
 
@@ -2099,6 +2113,9 @@ func (c *HisApiController) GetRegisterInfo() {
2099 2113
 			IdCardType:             id_card_type,
2100 2114
 			Departments:            department,
2101 2115
 			Doctor:                 doctor,
2116
+			PType:                  reg_type,
2117
+			Diagnosis:              diagnosis_id,
2118
+			SickType:               sick_type,
2102 2119
 		}
2103 2120
 		service.CreateHisPatient(&hisPatient)
2104 2121
 		c.ServeSuccessJSON(map[string]interface{}{

+ 59 - 84
controllers/his_project_api_controller.go View File

@@ -712,7 +712,10 @@ func (this *HisProjectApiController) SaveHisPatient() {
712 712
 	timeLayout := "2006-01-02"
713 713
 	loc, _ := time.LoadLocation("Local")
714 714
 	age, _ := this.GetInt64("age")
715
-	birthday := this.GetString("birthDay")
715
+	birthday := this.GetString("birthday")
716
+
717
+	patient_id, _ := this.GetInt64("id")
718
+
716 719
 	birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
717 720
 	birthUnix := birthdays.Unix()
718 721
 	certificates, _ := this.GetInt64("certificates")
@@ -722,19 +725,19 @@ func (this *HisProjectApiController) SaveHisPatient() {
722 725
 	cost_float, _ := strconv.ParseFloat(costs, 64)
723 726
 	department, _ := this.GetInt64("department")
724 727
 	doctor, _ := this.GetInt64("doctor")
725
-	medicalcare, _ := this.GetInt64("medicalCare")
726
-	idcard := this.GetString("idCard")
727
-	medicalExpenses, _ := this.GetInt64("medicalExpenses")
728
+	medicalcare, _ := this.GetInt64("medical_care")
729
+	idcard := this.GetString("id_card")
730
+	medicalExpenses, _ := this.GetInt64("medical_expenses")
728 731
 	medicalExpense := strconv.FormatInt(medicalExpenses, 10)
729 732
 	medicalExpense_float, _ := strconv.ParseFloat(medicalExpense, 64)
730
-	medicalinsurancecard := this.GetString("medicalInsuranceCard")
733
+	medicalinsurancecard := this.GetString("medical_insurance_card")
731 734
 
732 735
 	name := this.GetString("name")
733 736
 	register, _ := this.GetInt64("register")
734
-	registrationfee, _ := this.GetInt64("registrationFee")
737
+	registrationfee, _ := this.GetInt64("registration_fee")
735 738
 	registrationfees := strconv.FormatInt(registrationfee, 10)
736 739
 	registrationfees_float, _ := strconv.ParseFloat(registrationfees, 64)
737
-	settlementValue, _ := this.GetInt64("settlementValue")
740
+	settlementValue, _ := this.GetInt64("settlement_value")
738 741
 	sex, _ := this.GetInt64("sex")
739 742
 	total, _ := this.GetInt64("total")
740 743
 	totals := strconv.FormatInt(total, 10)
@@ -748,10 +751,44 @@ func (this *HisProjectApiController) SaveHisPatient() {
748 751
 	social_type, _ := this.GetInt64("social_type")
749 752
 	id_card_type, _ := this.GetInt64("id_card_type")
750 753
 
751
-	bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
752
-	if errcode == gorm.ErrRecordNotFound {
753
-		patient := models.XtHisPatient{
754
-			Age:                    age,
754
+	diagnosis_id, _ := this.GetInt64("diagnosis")
755
+	sick_type, _ := this.GetInt64("sick_type")
756
+	reg_type := this.GetString("p_type")
757
+
758
+	tempPatient, _ := service.GetPatientByIDCardAndName(idcard, adminUserInfo.CurrentOrgId, name)
759
+	if tempPatient.ID == 0 {
760
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
761
+		return
762
+	}
763
+
764
+	var patient service.Patients
765
+	if patient_id == 0 {
766
+		patient, _ = service.GetPatientByIDCard(idcard, adminUserInfo.CurrentOrgId)
767
+
768
+	} else {
769
+		patient, _ = service.GetPatientByIDTwo(adminUserInfo.CurrentOrgId, patient_id)
770
+
771
+	}
772
+
773
+	if patient.ID == 0 {
774
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
775
+		return
776
+	}
777
+	if len(patient.IdCardNo) == 0 {
778
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
779
+		return
780
+	}
781
+
782
+	timeStr := time.Now().Format("2006-01-02")
783
+	timeArr := strings.Split(timeStr, "-")
784
+	var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
785
+
786
+	his, err := service.GetHisPatientInfo(adminUserInfo.CurrentOrgId, patient.ID, recordDate.Unix())
787
+
788
+	var hisPatient models.XtHisPatient
789
+	if err == gorm.ErrRecordNotFound || his.ID == 0 {
790
+		hisPatient = models.XtHisPatient{
791
+			PatientId:              patient_id,
755 792
 			Birthday:               birthUnix,
756 793
 			IdType:                 certificates,
757 794
 			CostOfProduction:       cost_float,
@@ -764,6 +801,8 @@ func (this *HisProjectApiController) SaveHisPatient() {
764 801
 			TreatmentCost:          medicalExpense_float,
765 802
 			MedicalInsuranceNumber: medicalinsurancecard,
766 803
 			Name:                name,
804
+			Age:                 age,
805
+			Number:              str,
767 806
 			RegisterType:        register,
768 807
 			RegisterCost:        registrationfees_float,
769 808
 			BalanceAccountsType: settlementValue,
@@ -777,83 +816,19 @@ func (this *HisProjectApiController) SaveHisPatient() {
777 816
 			Phone:               phone,
778 817
 			SocialType:          social_type,
779 818
 			IdCardType:          id_card_type,
819
+			Diagnosis:           diagnosis_id,
820
+			PType:               reg_type,
821
+			SickType:            sick_type,
780 822
 		}
781
-
782
-		err := service.CreateHisPatient(&patient)
783
-		lastPatient, err := service.GetLastPatient(orgId)
784
-		timeStr := time.Now().Format("2006-01-02")
785
-		timeArr := strings.Split(timeStr, "-")
786
-		var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
787
-
788
-		hisPatient := models.HisPatient{
789
-			Number: str,
790
-		}
791
-		err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
792
-		fmt.Println("er", err)
793
-		if err != nil {
794
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
795
-			return
796
-		}
823
+		service.CreateHisPatient(&hisPatient)
797 824
 		this.ServeSuccessJSON(map[string]interface{}{
798
-			"patient": patient,
825
+			"his_info": hisPatient,
799 826
 		})
800
-	} else if errcode == nil {
801
-		patient := models.XtHisPatient{
802
-			Age:                    age,
803
-			Birthday:               birthUnix,
804
-			IdType:                 certificates,
805
-			CostOfProduction:       cost_float,
806
-			Departments:            department,
807
-			AdminUserId:            doctor,
808
-			MedicalTreatmentType:   medicalcare,
809
-			IdCardNo:               idcard,
810
-			IsNeedCostOfProduction: cost_checked,
811
-			TreatmentCost:          medicalExpense_float,
812
-			MedicalInsuranceNumber: medicalinsurancecard,
813
-			Name:                name,
814
-			RegisterType:        register,
815
-			RegisterCost:        registrationfees_float,
816
-			BalanceAccountsType: settlementValue,
817
-			Gender:              sex,
818
-			Total:               totals_float,
819
-			UserOrgId:           orgId,
820
-			PatientId:           bloodPatient.ID,
821
-			Ctime:               time.Now().Unix(),
822
-			Phone:               phone,
823
-			SocialType:          social_type,
824
-			IdCardType:          id_card_type,
825
-			RecordDate:          nowtime,
826
-			Status:              1,
827
-			IsReturn:            1,
828
-		}
829
-
830
-		//查询今日没有退号的患者是否已挂号
831
-		_, errcode := service.GetTodayHisPatient(nowtime, bloodPatient.ID, adminUserInfo.CurrentOrgId)
832
-		if errcode == gorm.ErrRecordNotFound {
833
-			err := service.CreateHisPatient(&patient)
834
-			lastPatient, err := service.GetLastPatient(orgId)
835
-			timeStr := time.Now().Format("2006-01-02")
836
-			timeArr := strings.Split(timeStr, "-")
837
-			var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
838
-
839
-			hisPatient := models.HisPatient{
840
-				Number: str,
841
-			}
842
-			err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
843
-			//fmt.Println("er", err)
844
-			if err != nil {
845
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
846
-				return
847
-			}
848
-			this.ServeSuccessJSON(map[string]interface{}{
849
-				"patient": patient,
850
-			})
851
-		} else if errcode == nil {
852
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
853
-			return
854
-		}
855
-
827
+	} else {
828
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisRegisterException)
829
+		return
856 830
 	}
831
+
857 832
 }
858 833
 
859 834
 func (this *HisProjectApiController) GetAllProjectTeam() {

+ 14 - 0
controllers/public_api_controller.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"os"
10 10
 	"path"
11 11
 	"runtime"
12
+	"strconv"
12 13
 	"strings"
13 14
 	"time"
14 15
 
@@ -29,6 +30,8 @@ func PublicApiRegistRouters() {
29 30
 	beego.Router("/api/public/handlecomdata", &PublicApiController{}, "get:HandleComData")
30 31
 	beego.Router("/hello", &PublicApiController{}, "get:HandleComData")
31 32
 
33
+	beego.Router("/handel", &PublicApiController{}, "get:HandleHIS")
34
+
32 35
 }
33 36
 
34 37
 func (c *PublicApiController) GetDoctorAdviceConfig() {
@@ -1633,3 +1636,14 @@ func (c *PublicApiController) HandleComData() {
1633 1636
 	}
1634 1637
 
1635 1638
 }
1639
+
1640
+func (c *PublicApiController) HandleHIS() {
1641
+	his, _ := service.GetAllHisInfo(9919)
1642
+	for _, item := range his {
1643
+		fsn := strings.Split(item.FeedetlSn, "-")
1644
+		item.FeedetlSn = fsn[0] + "-" + fsn[1] + "-" + strconv.FormatInt(item.ID, 10)
1645
+		fmt.Println(item.FeedetlSn)
1646
+		service.UpDateHis2(item)
1647
+	}
1648
+
1649
+}

+ 4 - 0
enums/error_code.go View File

@@ -224,6 +224,8 @@ const ( // ErrorCode
224 224
 	ErrorCodeCalOrderException = 20069
225 225
 
226 226
 	ErrorCodeHisRegisterException = 300001
227
+
228
+	ErrorCodeNoBloodPatientException = 300002
227 229
 )
228 230
 
229 231
 var ErrCodeMsgs = map[int]string{
@@ -438,6 +440,8 @@ var ErrCodeMsgs = map[int]string{
438 440
 	ErrorCodeCalOrderException: "结算失败",
439 441
 
440 442
 	ErrorCodeHisRegisterException: "一天只能挂一个号",
443
+
444
+	ErrorCodeNoBloodPatientException: "找不到该患者,请先在系统录入患者信息或检查患者身份证信息",
441 445
 }
442 446
 
443 447
 type SGJError struct {

+ 12 - 1
models/his_models.go View File

@@ -118,6 +118,9 @@ type HisPatient struct {
118 118
 	Phone                  string  `gorm:"column:phone" json:"phone" form:"phone"`
119 119
 	SocialType             int64   `gorm:"column:social_type" json:"social_type" form:"social_type"`
120 120
 	IdCardType             int64   `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
121
+	PType                  int64   `gorm:"column:p_type" json:"p_type" form:"p_type"`
122
+	Diagnosis              int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
123
+	SickType               int64   `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
121 124
 }
122 125
 
123 126
 func (HisPatient) TableName() string {
@@ -600,6 +603,9 @@ type XtHisPatient struct {
600 603
 	Phone                  string  `gorm:"column:phone" json:"phone" form:"phone"`
601 604
 	SocialType             int64   `gorm:"column:social_type" json:"social_type" form:"social_type"`
602 605
 	IdCardType             int64   `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
606
+	PType                  string  `gorm:"column:p_type" json:"p_type" form:"p_type"`
607
+	Diagnosis              int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
608
+	SickType               int64   `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
603 609
 }
604 610
 
605 611
 func (XtHisPatient) TableName() string {
@@ -675,6 +681,8 @@ type HisOrder struct {
675 681
 	FoundPrice            float64   `gorm:"column:found_price" json:"found_price" form:"found_price"`
676 682
 	MedicalInsurancePrice float64   `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
677 683
 	PrivatePrice          float64   `gorm:"column:private_price" json:"private_price" form:"private_price"`
684
+	DepartmentName        string    `gorm:"-" json:"department_name" form:"department_name"`
685
+	DoctorName            string    `gorm:"-" json:"doctor_name" form:"doctor_name"`
678 686
 
679 687
 	SettleType      int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
680 688
 	SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
@@ -683,7 +691,7 @@ type HisOrder struct {
683 691
 	HisOrderInfo        HisOrderInfo        `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
684 692
 	Patients            Patients            `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
685 693
 	HisPatient          HisPatient          `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
686
-	HisPrescriptionInfo HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
694
+	HisPrescriptionInfo HisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"p_info"`
687 695
 }
688 696
 
689 697
 func (HisOrder) TableName() string {
@@ -769,6 +777,9 @@ type VMHisPatient struct {
769 777
 	Iinfo                  string  `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
770 778
 	Idetinfo               string  `gorm:"column:idetinfo" json:"idetinfo" form:"idetinfo"`
771 779
 	IptOtpNo               string  `gorm:"column:ipt_otp_no" json:"ipt_otp_no" form:"ipt_otp_no"`
780
+	PType                  string  `gorm:"column:p_type" json:"p_type" form:"p_type"`
781
+	Diagnosis              int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
782
+	SickType               int64   `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
772 783
 }
773 784
 
774 785
 func (VMHisPatient) TableName() string {

+ 14 - 6
service/his_service.go View File

@@ -581,10 +581,8 @@ func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int6
581 581
 
582 582
 	db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
583 583
 		Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
584
-		Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
585
-		Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
586
-			return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
587
-		})
584
+		Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id)
585
+
588 586
 	db = db.Count(&total)
589 587
 	err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
590 588
 	return
@@ -650,14 +648,14 @@ func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisO
650 648
 	return
651 649
 }
652 650
 
653
-func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
651
+func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
654 652
 	err = readDb.Model(&models.HisPrescription{}).
655 653
 		Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
656 654
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
657 655
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
658 656
 		}).
659 657
 		Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
660
-		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
658
+		Where("user_org_id = ? AND status = 1  AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
661 659
 		Find(&prescription).Error
662 660
 	return
663 661
 }
@@ -998,6 +996,11 @@ func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients,
998 996
 	return
999 997
 }
1000 998
 
999
+func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
1000
+	err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
1001
+	return
1002
+}
1003
+
1001 1004
 func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
1002 1005
 	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
1003 1006
 	return
@@ -1008,3 +1011,8 @@ func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
1008 1011
 	err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
1009 1012
 	return patient, err
1010 1013
 }
1014
+
1015
+func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
1016
+	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
1017
+	return
1018
+}