陈少旭 2 ヶ月 前
コミット
c7257ffeab
共有2 個のファイルを変更した49 個の追加33 個の削除を含む
  1. 40 30
      controllers/inspection_api_controller.go
  2. 9 3
      service/inspection_service.go

+ 40 - 30
controllers/inspection_api_controller.go ファイルの表示

@@ -645,9 +645,11 @@ func (c *InspectionApiController) EditPatientInspection() {
645 645
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
646 646
 		return
647 647
 	}
648
-	inspMap := make(map[int64]*models.Inspection)
648
+	inspMap := make(map[string]models.Inspection)
649 649
 	for _, item := range insp {
650
-		inspMap[item.ID] = item
650
+		fmt.Println(item.ID)
651
+		a := strconv.FormatInt(item.ProjectId, 10) + "-" + strconv.FormatInt(item.ItemId, 10)
652
+		inspMap[a] = item
651 653
 	}
652 654
 
653 655
 	addinsp := make([]models.Inspection, 0)
@@ -657,32 +659,40 @@ func (c *InspectionApiController) EditPatientInspection() {
657 659
 
658 660
 	for _, item := range from.FormItem {
659 661
 		fmt.Println(item.ID)
660
-		if item.ID == 0 {
661
-			var inspection models.Inspection
662
-			inspection.OrgId = adminUserInfo.CurrentOrgId
663
-			inspection.PatientId = patient
664
-			inspection.ProjectId = from.ProjectId
665
-			inspection.ItemId = item.ItemId
666
-			inspection.ItemName = item.ItemName
667
-			inspection.ProjectName = item.ProjectName
668
-			inspection.InspectType = item.RangeType
669
-			inspection.InspectValue = item.Value
670
-			inspection.InspectDate = date
671
-			inspection.Status = 1
672
-			inspection.CreatedTime = time.Now().Unix()
673
-			inspection.UpdatedTime = time.Now().Unix()
674
-			addinsp = append(addinsp, inspection)
675
-		} else {
676
-			inspection := *inspMap[item.ID]
677
-			inspection.InspectValue = item.Value
678
-			inspection.InspectDate = date
679
-			inspection.UpdatedTime = time.Now().Unix()
680
-			editinsp = append(editinsp, inspection)
681
-			noMap = append(noMap, item.ID)
682
-		}
683 662
 
684
-	}
663
+		ref, _ := service.GetInspectionReferenceById(item.ItemId)
664
+		//if item.ID == 0 {
665
+		//	var inspection models.Inspection
666
+		//	inspection.OrgId = adminUserInfo.CurrentOrgId
667
+		//	inspection.PatientId = patient
668
+		//	inspection.ProjectId = from.ProjectId
669
+		//	inspection.ItemId = item.ItemId
670
+		//	inspection.ItemName = item.ItemName
671
+		//	inspection.ProjectName = item.ProjectName
672
+		//	inspection.InspectType = item.RangeType
673
+		//	inspection.InspectValue = item.Value
674
+		//	inspection.InspectDate = date
675
+		//	inspection.Status = 1
676
+		//	inspection.CreatedTime = time.Now().Unix()
677
+		//	inspection.UpdatedTime = time.Now().Unix()
678
+		//	addinsp = append(addinsp, inspection)
679
+		//} else {
680
+		//fmt.Println(item.ID)
681
+		a := strconv.FormatInt(item.ProjectId, 10) + "-" + strconv.FormatInt(ref.ItemId, 10)
682
+		fmt.Println(a)
683
+		fmt.Println(inspMap)
684
+
685
+		inspection := inspMap[a]
686
+		inspection.InspectValue = item.Value
687
+		inspection.InspectDate = date
688
+		inspection.UpdatedTime = time.Now().Unix()
689
+		editinsp = append(editinsp, inspection)
690
+		noMap = append(noMap, item.ID)
691
+		//}
685 692
 
693
+	}
694
+	//fmt.Println(editinsp)
695
+	//return
686 696
 	err = service.EditPatientInspection(addinsp, editinsp, noMap, patient, adminUserInfo.CurrentOrgId, from.ProjectId, date)
687 697
 	if err != nil {
688 698
 		utils.ErrorLog("%v", err)
@@ -894,7 +904,7 @@ func (c *InspectionApiController) GetAllPatientInspection() {
894 904
 
895 905
 	switch upload_type {
896 906
 	case 1:
897
-		var inspections []*models.Inspection
907
+		var inspections []models.Inspection
898 908
 
899 909
 		for _, item := range ids {
900 910
 			id, _ := strconv.ParseInt(item, 10, 64)
@@ -933,7 +943,7 @@ func (c *InspectionApiController) GetAllPatientInspection() {
933 943
 
934 944
 		break
935 945
 	case 3:
936
-		var inspections []*models.Inspection
946
+		var inspections []models.Inspection
937 947
 
938 948
 		for _, item := range ids {
939 949
 			id, _ := strconv.ParseInt(item, 10, 64)
@@ -992,7 +1002,7 @@ func (c *InspectionApiController) GetAllPatientInspection() {
992 1002
 
993 1003
 		break
994 1004
 	case 6:
995
-		var inspections []*models.Inspection
1005
+		var inspections []models.Inspection
996 1006
 
997 1007
 		for _, item := range ids {
998 1008
 			id, _ := strconv.ParseInt(item, 10, 64)
@@ -1015,7 +1025,7 @@ func (c *InspectionApiController) GetAllPatientInspection() {
1015 1025
 
1016 1026
 		break
1017 1027
 	case 7:
1018
-		var inspections []*models.Inspection
1028
+		var inspections []models.Inspection
1019 1029
 
1020 1030
 		for _, item := range ids {
1021 1031
 			id, _ := strconv.ParseInt(item, 10, 64)

+ 9 - 3
service/inspection_service.go ファイルの表示

@@ -33,7 +33,7 @@ func GetPatientInspectionProjectCount(orgId, patientId int64) (projectCounts []*
33 33
 	return
34 34
 }
35 35
 
36
-func GetPatientInspectionByDate(orgId, patientId, date, projectId int64) (inspections []*models.Inspection, err error) {
36
+func GetPatientInspectionByDate(orgId, patientId, date, projectId int64) (inspections []models.Inspection, err error) {
37 37
 	err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id =? and inspect_date =? and status=1", patientId, orgId, projectId, date).Order("created_time desc").Find(&inspections).Error
38 38
 	return
39 39
 }
@@ -153,7 +153,7 @@ func DeletePatientInspection(orgId, patientId, projectId, date int64) (err error
153 153
 	return
154 154
 }
155 155
 
156
-func GetPatientInspections(orgId, patientId, projectId, page int64) (inspections []*models.Inspection, total int64, date int64, err error) {
156
+func GetPatientInspections(orgId, patientId, projectId, page int64) (inspections []models.Inspection, total int64, date int64, err error) {
157 157
 	var projectCount models.UserInspectionProjectCount
158 158
 	err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Order("inspect_date desc").Scan(&projectCount).Error
159 159
 	if err != nil {
@@ -218,7 +218,7 @@ func GetCheckRemindRecordTime(orgId int64, patientId int64, project_id int64) (r
218 218
 	return
219 219
 }
220 220
 
221
-func GetAllPatientInspection(orgId, patientId, page int64, projectId int64, start_time int64, end_time int64) (inspections []*models.Inspection, date int64, err error) {
221
+func GetAllPatientInspection(orgId, patientId, page int64, projectId int64, start_time int64, end_time int64) (inspections []models.Inspection, date int64, err error) {
222 222
 
223 223
 	//var projectCount models.UserInspectionProjectCount
224 224
 	//err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id in (?)  and status=1", patientId, orgId,projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Scan(&projectCount).Error
@@ -263,6 +263,12 @@ func GetInspectionReferenceByOrgId(orgid int64) (insepciton []*models.XtInspecti
263 263
 	return insepciton, err
264 264
 }
265 265
 
266
+func GetInspectionReferenceById(id int64) (insepciton models.XtInspectionReference, err error) {
267
+
268
+	err = readDb.Model(&insepciton).Where("id = ?", id).First(&insepciton).Error
269
+	return insepciton, err
270
+}
271
+
266 272
 func GetInspectionReferenceTwo(project_id int64) (reference []*models.InspectionReference, err error) {
267 273
 	err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and status = 1", project_id).Order("project_id").Find(&reference).Error
268 274
 	return