Explorar el Código

[add]

再婚や死別の対応
poohr hace 3 semanas
padre
commit
35148cd224

+ 10
- 0
src/app/models/marriage-relation.ts Ver fichero

@@ -0,0 +1,10 @@
1
+export interface MarriageRelation {
2
+  id: string;
3
+  dankaId: string;
4
+  person1Id: string;
5
+  person2Id: string;
6
+  status: 'current' | 'divorced' | 'widowed' | 'unknown';
7
+  startDate: string;
8
+  endDate: string;
9
+  note: string;
10
+}

+ 40
- 0
src/app/pages/danka-detail/danka-detail.ts Ver fichero

@@ -6,8 +6,10 @@ import { KakochoService } from '../../services/kakocho-service';
6 6
 import { Danka } from '../../models/danka';
7 7
 import { Family } from '../../models/family';
8 8
 import { Kakocho } from '../../models/kakocho';
9
+import { MarriageRelation } from '../../models/marriage-relation';
9 10
 import { AppHeader } from '../../share/header/app-header';
10 11
 import { AppSideMenu } from '../../share/side-menu/app-side-menu';
12
+import { MarriageRelationService } from '../../services/marriage-relation-service';
11 13
 
12 14
 @Component({
13 15
   selector: 'app-danka-detail',
@@ -19,6 +21,7 @@ export class DankaDetail {
19 21
   danka: Danka | undefined;
20 22
   families: Family[] = [];
21 23
   kakocholist: Kakocho[] = [];
24
+  marriageRelations: MarriageRelation[] = [];
22 25
   currentYear = new Date().getFullYear();
23 26
 
24 27
   selectedTab: 'basic' | 'family' | 'kakocho' | 'familyTree' = 'basic';
@@ -28,6 +31,7 @@ export class DankaDetail {
28 31
     private dankaService: DankaService,
29 32
     private familyService: FamilyService,
30 33
     private kakochoService: KakochoService,
34
+    private marriageRelationService: MarriageRelationService,
31 35
     private route: ActivatedRoute,
32 36
   ) {
33 37
     //遷移先からタブ情報を取得
@@ -43,6 +47,7 @@ export class DankaDetail {
43 47
     const id = this.route.snapshot.params['id'];
44 48
     if (id) {
45 49
       this.danka = this.dankaService.getDankaById(id);
50
+      this.marriageRelations = this.marriageRelationService.getMarriageRelationsByDankaId(id);
46 51
       this.families = this.familyService.getFamiliesByDankaId(id);
47 52
       this.selectedFamily = this.families[0];
48 53
       this.kakocholist = this.kakochoService.getKakochoByDankaId(id);
@@ -105,4 +110,39 @@ export class DankaDetail {
105 110
       (child) => child.fatherId === family.id || child.motherId === family.id,
106 111
     );
107 112
   }
113
+
114
+  getCurrentMarriage(family: Family): MarriageRelation | undefined {
115
+    return this.marriageRelations.find(
116
+      (relation) =>
117
+        relation.status === 'current' &&
118
+        (relation.person1Id === family.id || relation.person2Id === family.id),
119
+    );
120
+  }
121
+
122
+  getPastMarriages(family: Family): MarriageRelation[] {
123
+    return this.marriageRelations.filter(
124
+      (relation) =>
125
+        relation.status !== 'current' &&
126
+        (relation.person1Id === family.id || relation.person2Id === family.id),
127
+    );
128
+
129
+  }
130
+
131
+  getMarriagePartner(relation: MarriageRelation, family: Family): Family | undefined {
132
+    const partnerId = relation.person1Id === family.id ? relation.person2Id : relation.person1Id;
133
+    return this.getFamilyById(partnerId);
134
+  }
135
+
136
+  getMarriageStatusLabel(status: string): string {
137
+    if (status === 'current') {
138
+      return '現在の配偶者';
139
+    }
140
+    if (status === 'divorced') {
141
+      return '離婚';
142
+    }
143
+    if (status === 'widowed') {
144
+      return '死別';
145
+    }
146
+    return '不明';
147
+  }
108 148
 }

+ 16
- 0
src/app/services/marriage-relation-service.spec.ts Ver fichero

@@ -0,0 +1,16 @@
1
+import { TestBed } from '@angular/core/testing';
2
+
3
+import { MarriageRelationService } from './marriage-relation-service';
4
+
5
+describe('MarriageRelationService', () => {
6
+  let service: MarriageRelationService;
7
+
8
+  beforeEach(() => {
9
+    TestBed.configureTestingModule({});
10
+    service = TestBed.inject(MarriageRelationService);
11
+  });
12
+
13
+  it('should be created', () => {
14
+    expect(service).toBeTruthy();
15
+  });
16
+});

+ 125
- 0
src/app/services/marriage-relation-service.ts Ver fichero

@@ -0,0 +1,125 @@
1
+import { Injectable } from '@angular/core';
2
+import { MarriageRelation } from '../models/marriage-relation';
3
+
4
+@Injectable({
5
+  providedIn: 'root',
6
+})
7
+export class MarriageRelationService {
8
+  private marriageRelations: MarriageRelation[] = [
9
+    {
10
+      id: '1',
11
+      dankaId: '1',
12
+      person1Id: '2', // 太郎
13
+      person2Id: '8', // 花子
14
+      status: 'divorced',
15
+      startDate: '',
16
+      endDate: '',
17
+      note: '前妻',
18
+    },
19
+    {
20
+      id: '2',
21
+      dankaId: '1',
22
+      person1Id: '2', // 太郎
23
+      person2Id: '7', // 美咲
24
+      status: 'current',
25
+      startDate: '',
26
+      endDate: '',
27
+      note: '現在の配偶者',
28
+    },
29
+  ];
30
+
31
+  getMarriageRelationsByDankaId(dankaId: string): MarriageRelation[] {
32
+    return this.marriageRelations.filter((relation) => relation.dankaId === dankaId);
33
+  }
34
+
35
+  getMarriageRelationsByFamilyId(familyId: string): MarriageRelation[] {
36
+    return this.marriageRelations.filter(
37
+      (relation) => relation.person1Id === familyId || relation.person2Id === familyId,
38
+    );
39
+  }
40
+
41
+  getCurrentMarriageByFamilyId(familyId: string): MarriageRelation | undefined {
42
+    return this.marriageRelations.find(
43
+      (relation) =>
44
+        relation.status === 'current' &&
45
+        (relation.person1Id === familyId || relation.person2Id === familyId),
46
+    );
47
+  }
48
+
49
+  getPastMarriagesByFamilyId(familyId: string): MarriageRelation[] {
50
+    return this.marriageRelations.filter(
51
+      (relation) =>
52
+        relation.status !== 'current' &&
53
+        (relation.person1Id === familyId || relation.person2Id === familyId),
54
+    );
55
+  }
56
+
57
+  getMarriageRelationById(id: string): MarriageRelation | undefined {
58
+    return this.marriageRelations.find((relation) => relation.id === id);
59
+  }
60
+
61
+  validateMarriageRelation(data: MarriageRelation): string[] {
62
+    const errors: string[] = [];
63
+
64
+    if (!data.person1Id || !data.person2Id) {
65
+      errors.push('配偶関係の人物が選択されていません。');
66
+    }
67
+
68
+    if (data.person1Id === data.person2Id) {
69
+      errors.push('同じ人物同士を配偶関係に設定することはできません。');
70
+    }
71
+
72
+    const duplicate = this.marriageRelations.find(
73
+      (relation) =>
74
+        relation.id !== data.id &&
75
+        ((relation.person1Id === data.person1Id && relation.person2Id === data.person2Id) ||
76
+          (relation.person1Id === data.person2Id && relation.person2Id === data.person1Id)),
77
+    );
78
+
79
+    if (duplicate) {
80
+      errors.push('この2人の配偶関係はすでに登録されています。');
81
+    }
82
+
83
+    if (data.status === 'current') {
84
+      const currentConflict = this.marriageRelations.find(
85
+        (relation) =>
86
+          relation.id !== data.id &&
87
+          relation.status === 'current' &&
88
+          (relation.person1Id === data.person1Id ||
89
+            relation.person2Id === data.person1Id ||
90
+            relation.person1Id === data.person2Id ||
91
+            relation.person2Id === data.person2Id),
92
+      );
93
+
94
+      if (currentConflict) {
95
+        errors.push(
96
+          '現在の配偶者は1人までです。既存の配偶関係を離婚・死別などに変更してから登録してください。',
97
+        );
98
+      }
99
+    }
100
+
101
+    return errors;
102
+  }
103
+
104
+  saveMarriageRelation(data: MarriageRelation): string[] {
105
+    const errors = this.validateMarriageRelation(data);
106
+
107
+    if (errors.length > 0) {
108
+      return errors;
109
+    }
110
+
111
+    const index = this.marriageRelations.findIndex((relation) => relation.id === data.id);
112
+
113
+    if (index === -1) {
114
+      this.marriageRelations.push(data);
115
+    } else {
116
+      this.marriageRelations[index] = data;
117
+    }
118
+
119
+    return [];
120
+  }
121
+
122
+  deleteMarriageRelation(id: string): void {
123
+    this.marriageRelations = this.marriageRelations.filter((relation) => relation.id !== id);
124
+  }
125
+}

Loading…
Cancelar
Guardar