@csmart/ngc-smart-victim 1.18.14 → 1.18.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. package/karma.conf.js +32 -0
  2. package/ng-package.json +7 -0
  3. package/package.json +4 -21
  4. package/src/lib/caseNote/caseNote.component.css +22 -0
  5. package/src/lib/caseNote/caseNote.component.html +188 -0
  6. package/src/lib/caseNote/caseNote.component.ts +265 -0
  7. package/src/lib/common-dialog/common-dialog.component.css +10 -0
  8. package/src/lib/common-dialog/common-dialog.component.html +23 -0
  9. package/src/lib/common-dialog/common-dialog.component.spec.ts +25 -0
  10. package/src/lib/common-dialog/common-dialog.component.ts +21 -0
  11. package/src/lib/common-dialog/common-dialog.module.ts +22 -0
  12. package/src/lib/common-dialog/common-dialog.service.ts +35 -0
  13. package/src/lib/contact/contact.component.css +22 -0
  14. package/src/lib/contact/contact.component.html +124 -0
  15. package/src/lib/contact/contact.component.ts +176 -0
  16. package/src/lib/email-notification.service.ts +42 -0
  17. package/src/lib/email.services.ts +51 -0
  18. package/src/lib/http.service.ts +34 -0
  19. package/src/lib/intake.service.ts +82 -0
  20. package/src/lib/loader.service.ts +11 -0
  21. package/src/lib/safetyPlan/serviceProvider.component.ts +94 -0
  22. package/src/lib/safetyPlan/victimSafetyPlan.component.css +27 -0
  23. package/src/lib/safetyPlan/victimSafetyPlan.component.html +85 -0
  24. package/src/lib/safetyPlan/victimSafetyPlan.component.ts +178 -0
  25. package/src/lib/safetyPlan/victimSafetyPlanDetail.component.html +234 -0
  26. package/src/lib/safetyPlan/victimSafetyPlanDetail.component.ts +492 -0
  27. package/src/lib/shared/app.shared.module.ts +111 -0
  28. package/src/lib/shared/validators/date.validator.ts +73 -0
  29. package/src/lib/shared/validators/index.ts +1 -0
  30. package/src/lib/smart-victim-delete-confirm.component.ts +35 -0
  31. package/src/lib/smart-victim-detail/smart-victim-detail.component.css +43 -0
  32. package/src/lib/smart-victim-detail/smart-victim-detail.component.html +876 -0
  33. package/src/lib/smart-victim-detail/smart-victim-detail.component.spec.ts +25 -0
  34. package/src/lib/smart-victim-detail/smart-victim-detail.component.ts +1459 -0
  35. package/src/lib/smart-victim.component.css +245 -0
  36. package/src/lib/smart-victim.component.html +132 -0
  37. package/src/lib/smart-victim.component.spec.ts +25 -0
  38. package/src/lib/smart-victim.component.ts +334 -0
  39. package/src/lib/smart-victim.model.ts +312 -0
  40. package/src/lib/smart-victim.module.ts +110 -0
  41. package/src/lib/smart-victim.service.spec.ts +12 -0
  42. package/src/lib/smart-victim.service.ts +576 -0
  43. package/src/lib/victim-routing.module.ts +36 -0
  44. package/{lib/victimSearch/VictimSearchFilter.d.ts → src/lib/victimSearch/VictimSearchFilter.ts} +9 -7
  45. package/src/lib/victimSearch/victimSearchForm.component.html +35 -0
  46. package/src/lib/victimSearch/victimSearchForm.component.ts +41 -0
  47. package/{public-api.d.ts → src/public-api.ts} +12 -7
  48. package/src/test.ts +16 -0
  49. package/tsconfig.lib.json +36 -0
  50. package/tsconfig.spec.json +17 -0
  51. package/tslint.json +17 -0
  52. package/esm2022/csmart-ngc-smart-victim.mjs +0 -5
  53. package/esm2022/lib/caseNote/caseNote.component.mjs +0 -194
  54. package/esm2022/lib/common-dialog/common-dialog.component.mjs +0 -23
  55. package/esm2022/lib/common-dialog/common-dialog.module.mjs +0 -34
  56. package/esm2022/lib/common-dialog/common-dialog.service.mjs +0 -33
  57. package/esm2022/lib/contact/contact.component.mjs +0 -140
  58. package/esm2022/lib/email.services.mjs +0 -42
  59. package/esm2022/lib/intake.service.mjs +0 -57
  60. package/esm2022/lib/safetyPlan/serviceProvider.component.mjs +0 -99
  61. package/esm2022/lib/safetyPlan/victimSafetyPlan.component.mjs +0 -116
  62. package/esm2022/lib/safetyPlan/victimSafetyPlanDetail.component.mjs +0 -340
  63. package/esm2022/lib/shared/app.shared.module.mjs +0 -215
  64. package/esm2022/lib/shared/validators/date.validator.mjs +0 -59
  65. package/esm2022/lib/shared/validators/index.mjs +0 -2
  66. package/esm2022/lib/smart-victim-delete-confirm.component.mjs +0 -44
  67. package/esm2022/lib/smart-victim-detail/smart-victim-detail.component.mjs +0 -1155
  68. package/esm2022/lib/smart-victim.component.mjs +0 -317
  69. package/esm2022/lib/smart-victim.model.mjs +0 -142
  70. package/esm2022/lib/smart-victim.module.mjs +0 -128
  71. package/esm2022/lib/smart-victim.service.mjs +0 -370
  72. package/esm2022/lib/victim-routing.module.mjs +0 -41
  73. package/esm2022/lib/victimSearch/VictimSearchFilter.mjs +0 -3
  74. package/esm2022/lib/victimSearch/victimSearchForm.component.mjs +0 -38
  75. package/esm2022/public-api.mjs +0 -11
  76. package/fesm2022/csmart-ngc-smart-victim.mjs +0 -3342
  77. package/fesm2022/csmart-ngc-smart-victim.mjs.map +0 -1
  78. package/index.d.ts +0 -5
  79. package/lib/caseNote/caseNote.component.d.ts +0 -51
  80. package/lib/common-dialog/common-dialog.component.d.ts +0 -14
  81. package/lib/common-dialog/common-dialog.module.d.ts +0 -8
  82. package/lib/common-dialog/common-dialog.service.d.ts +0 -11
  83. package/lib/contact/contact.component.d.ts +0 -40
  84. package/lib/email.services.d.ts +0 -11
  85. package/lib/intake.service.d.ts +0 -57
  86. package/lib/safetyPlan/serviceProvider.component.d.ts +0 -19
  87. package/lib/safetyPlan/victimSafetyPlan.component.d.ts +0 -54
  88. package/lib/safetyPlan/victimSafetyPlanDetail.component.d.ts +0 -62
  89. package/lib/shared/app.shared.module.d.ts +0 -33
  90. package/lib/shared/validators/date.validator.d.ts +0 -9
  91. package/lib/shared/validators/index.d.ts +0 -1
  92. package/lib/smart-victim-delete-confirm.component.d.ts +0 -12
  93. package/lib/smart-victim-detail/smart-victim-detail.component.d.ts +0 -129
  94. package/lib/smart-victim.component.d.ts +0 -69
  95. package/lib/smart-victim.model.d.ts +0 -211
  96. package/lib/smart-victim.module.d.ts +0 -49
  97. package/lib/smart-victim.service.d.ts +0 -71
  98. package/lib/victim-routing.module.d.ts +0 -7
  99. package/lib/victimSearch/victimSearchForm.component.d.ts +0 -14
@@ -0,0 +1,1459 @@
1
+ import { Component, OnInit, OnChanges, Input, Output, EventEmitter, ViewChild } from '@angular/core';
2
+ import { UntypedFormBuilder, UntypedFormGroup, UntypedFormControl,Validators,ValidatorFn } from '@angular/forms';
3
+ import { MatRadioChange, MatRadioGroup } from '@angular/material/radio';
4
+ import { Victim,VictimDrugUse, Contact, VictimAdvocate,VictimGuardian,VictimWeaponUse,VictimSupport,VictimRelationship } from '../smart-victim.model';
5
+ import { NgcSmartVictimService } from '../smart-victim.service';
6
+ import { Router, ActivatedRoute } from '@angular/router';
7
+ import { CommonDialogService} from '.././common-dialog/common-dialog.service';
8
+ import { DatePipe, formatDate, Location} from '@angular/common';
9
+ import { coerceBooleanProperty}from'@angular/cdk/coercion';
10
+ import { MatTableDataSource} from '@angular/material/table';
11
+ import { AddressValidators, SmartAddressComponent } from '@csmart/ngc-smart-address';
12
+ import { MatDialog } from '@angular/material/dialog';
13
+ import { MatSnackBar } from '@angular/material/snack-bar';
14
+ import { MatInput } from '@angular/material/input';
15
+ import { MatSelect } from '@angular/material/select';
16
+
17
+ import {
18
+ AfterViewInit,
19
+ ChangeDetectorRef,
20
+ Inject,
21
+ } from '@angular/core';
22
+
23
+ import {
24
+ UntypedFormArray,
25
+ AbstractControl,
26
+ FormGroupDirective,
27
+ NgForm,
28
+ } from '@angular/forms';
29
+
30
+ import { BehaviorSubject, Observable } from 'rxjs';
31
+
32
+ import {
33
+ XdmService,
34
+ SelectedOffender,
35
+ SmartAuthService,
36
+ LoginStaff,
37
+ SmartAccessControlConfig,
38
+ AccessType,
39
+ } from '@csmart/ngc-smart-core';
40
+
41
+ import { map, withLatestFrom } from 'rxjs/operators';
42
+ import { SmartDeleteConfirmComponent } from '@csmart/smart-ui';
43
+ import { ErrorStateMatcher } from '@angular/material/core';
44
+ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
45
+
46
+
47
+
48
+ export interface BooleanFn {
49
+ (): boolean;
50
+ }
51
+ export interface StringFn {
52
+ (): string;
53
+ }
54
+
55
+ export function conditionalValidator(predicate: BooleanFn,
56
+ validator: ValidatorFn,
57
+ errorNamespace?: string): ValidatorFn {
58
+ return (formControl => {
59
+ if (!formControl.parent) {
60
+ return null;
61
+ }
62
+ let error = null;
63
+ if (predicate()) {
64
+ error = validator(formControl);
65
+ }
66
+ if (errorNamespace && error) {
67
+ const customError = {};
68
+ customError[errorNamespace] = error;
69
+ error = customError
70
+ }
71
+ return error;
72
+ })
73
+ }
74
+
75
+
76
+ export function stringConditionalValidator(predicate: StringFn,
77
+ validator: ValidatorFn,
78
+ errorNamespace?: string): ValidatorFn {
79
+ return (formControl => {
80
+ if (!formControl.parent) {
81
+ return null;
82
+ }
83
+ let error = null;
84
+ if (predicate()=='YS') {
85
+ error = validator(formControl);
86
+ }
87
+ if (errorNamespace && error) {
88
+ const customError = {};
89
+ customError[errorNamespace] = error;
90
+ error = customError
91
+ }
92
+ return error;
93
+ })
94
+ }
95
+
96
+ @Component({
97
+ selector: 'csmart-victim-detail',
98
+ templateUrl: './smart-victim-detail.component.html',
99
+ styleUrls: ['./smart-victim-detail.component.css'],
100
+ providers: [CommonDialogService]
101
+ })
102
+ export class SmartVictimDetailComponent implements OnInit, OnChanges {
103
+ @Input() victimDetail = <Victim>{};
104
+ @Input() staffId: number;
105
+ @Input() offenderId: number;
106
+ @Input() isIntake: boolean;
107
+
108
+ @Output() onSave = new EventEmitter();
109
+ @Output() onCancel = new EventEmitter();
110
+ @ViewChild("addressComponent") addressComponent: SmartAddressComponent;
111
+
112
+
113
+ victimId: number;
114
+ victimForm: UntypedFormGroup;
115
+
116
+ drugs: any;
117
+ victimSupportTypes: any;
118
+ prefixes: any;
119
+ //victim: Victim = <Victim>{};
120
+ suffixes: any;
121
+ relationshipTypes: any;
122
+ genders: any;
123
+ docketlist: any;
124
+ weaponTypes: any;
125
+ flagOption: any;
126
+ selectedWeaponTypes: any;
127
+ //selectedVictimSupportTypes: any;
128
+ selectedDrugs: any;
129
+ id: any;
130
+ hidden: boolean=true;
131
+ private sub: any;
132
+ victimAdvocate: VictimAdvocate = <VictimAdvocate>{};
133
+ victimGuardian: VictimGuardian = <VictimGuardian>{};
134
+ victimWeaponUse: VictimWeaponUse;
135
+ victimSupport: VictimSupport;
136
+ victimDrugUse: VictimDrugUse;
137
+ result: any;
138
+ editMode: any;
139
+ guardianTabFlag: boolean = false;
140
+ advocateTabFlag: boolean = false;
141
+ commonChildrenDivFlag: boolean = false;
142
+ cpoExpirationDivFlag : boolean = false;
143
+ supportInPlaceDivFlag: boolean = false;
144
+ weaponInvolvedDivFlag: boolean = false;
145
+ drugUseDivFlag: boolean = false;
146
+ showDelete: boolean = false;
147
+ addressId: number = 0;
148
+ advocateAddressId: number = 0;
149
+ guardianAddressId: number = 0;
150
+ datePipe = new DatePipe('en-US');
151
+ emailPattern = "^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$";
152
+ phoneNumber = "\\d{10}";
153
+ editVictim: Victim = <Victim>{};
154
+ victimAge: number;
155
+ otherWeaponFlag: boolean = false;
156
+ otherDrugFlag: boolean = false;
157
+
158
+ contactDataSource= new MatTableDataSource();
159
+ contactList: Contact[];
160
+ guardianPhoneExistFlag: boolean = false;
161
+ advocatePhoneExistFlag: boolean = false;
162
+ phoneValidationFlag: boolean = false;
163
+ guaridanNoPhoneChkFlag: boolean = true;
164
+ advocateNoPhoneChkFlag: boolean = true;
165
+
166
+ addressValidators: AddressValidators = {
167
+ street: [],
168
+ street2: [],
169
+ city: [],
170
+ stateCode: [],
171
+ zipCode: [],
172
+ psaCode: [],
173
+ };
174
+ homePhoneControl = new UntypedFormControl();
175
+ cellPhoneControl = new UntypedFormControl();
176
+ workPhoneControl = new UntypedFormControl();
177
+ guardianHomePhoneControl = new UntypedFormControl();
178
+ guardianCellPhoneControl = new UntypedFormControl();
179
+ guardianWorkPhoneControl = new UntypedFormControl();
180
+ advocateHomePhoneControl = new UntypedFormControl();
181
+ advocateCellPhoneControl = new UntypedFormControl();
182
+ advocateWorkPhoneControl = new UntypedFormControl();
183
+ emergencyContactPhoneControl = new UntypedFormControl();
184
+
185
+ constructor(
186
+ private location: Location,
187
+ private formBuilder: UntypedFormBuilder,
188
+ private dialog: MatDialog,
189
+ private route: ActivatedRoute,
190
+ private router: Router,
191
+ public snackBar: MatSnackBar,
192
+ private commonDialogService: CommonDialogService,
193
+ private victimService: NgcSmartVictimService,
194
+ private changeDetectorRefs: ChangeDetectorRef,
195
+
196
+ ) {
197
+ this.initForm();
198
+ }
199
+
200
+ private initForm() {
201
+
202
+ console.log('initForm in smart-victim-detail');
203
+
204
+ this.victimForm = this.formBuilder.group({
205
+ underSupervisionFlag: new UntypedFormControl('', Validators.compose([ Validators.required])),
206
+ victimRelationships:new UntypedFormControl('', Validators.compose([ Validators.required])),
207
+ lastName: new UntypedFormControl('', Validators.compose([ Validators.required])),
208
+ firstName: new UntypedFormControl('', Validators.compose([ Validators.required])),
209
+ middleName: new UntypedFormControl('', ),
210
+ prefixId: new UntypedFormControl('', ),
211
+ suffixId: new UntypedFormControl('', ),
212
+ genderCode:new UntypedFormControl('', ),
213
+ birthDate: new UntypedFormControl('', ),
214
+ homePhone: new UntypedFormControl('', ),
215
+ cellPhone: new UntypedFormControl('', ),
216
+ workPhone: new UntypedFormControl('', ),
217
+ email:new UntypedFormControl('', Validators.compose([Validators.pattern(this.emailPattern) ])),
218
+ minorFlag:new UntypedFormControl('', Validators.compose([ Validators.required])),
219
+ victimAdvocateFlag: new UntypedFormControl('', Validators.compose([ Validators.required])),
220
+ guardianLastName:new UntypedFormControl('', stringConditionalValidator(() => this.victimForm.get('minorFlag').value, Validators.required, 'illuminatiError') ),
221
+ guardianFirstName: new UntypedFormControl('', stringConditionalValidator(() => this.victimForm.get('minorFlag').value, Validators.required, 'illuminatiError')),
222
+ guardianPrefixId:new UntypedFormControl('', ),
223
+ guardianSuffixId: new UntypedFormControl('', ),
224
+ //guardianGender:new FormControl('', ),
225
+ guardianBirthDate: new UntypedFormControl('', ),
226
+ guardianNoPhoneFlag:new UntypedFormControl(true),
227
+
228
+ guardianHomePhone:new UntypedFormControl('',),
229
+ guardianCellPhone:new UntypedFormControl('',),
230
+ guardianWorkPhone:new UntypedFormControl('',),
231
+
232
+
233
+ guardianEmail:new UntypedFormControl('', Validators.compose([Validators.pattern(this.emailPattern) ])),
234
+ advocateNoPhoneFlag: new UntypedFormControl(true),
235
+
236
+
237
+ advocateWorkPhone:new UntypedFormControl('',),
238
+ advocateHomePhone:new UntypedFormControl('',),
239
+ advocateCellPhone: new UntypedFormControl('',),
240
+
241
+
242
+ advocateSuffixId:new UntypedFormControl('', ),
243
+ advocatePrefixId: new UntypedFormControl('', ),
244
+ advocateFirstName: new UntypedFormControl('', stringConditionalValidator(() => this.victimForm.get('victimAdvocateFlag').value, Validators.required, 'illuminatiError')),
245
+ advocateLastName: new UntypedFormControl('', stringConditionalValidator(() => this.victimForm.get('victimAdvocateFlag').value, Validators.required,'illuminatiError')),
246
+ advocateEmail: new UntypedFormControl('', Validators.compose([Validators.pattern(this.emailPattern) ])),
247
+ emergencyContact: new UntypedFormControl('', ),
248
+ emergencyContactPhone:new UntypedFormControl('',),
249
+ emergencyChildren: new UntypedFormControl('', ),
250
+ emergencyCpo: new UntypedFormControl('', ),
251
+ emergencyDrug:new UntypedFormControl('', ),
252
+ emergencySupport: new UntypedFormControl('', ),
253
+ emergencyWeapon: new UntypedFormControl('', ),
254
+ drug: new UntypedFormControl('', ),
255
+ weapon: new UntypedFormControl('', ),
256
+ support: new UntypedFormControl('', ),
257
+ commonChildrenFlag: new UntypedFormControl('', ),
258
+ commonChildrenNumber:new UntypedFormControl('', ),
259
+ cpoExpirationFlag: new UntypedFormControl('', ),
260
+ cpoExpirationDate: new UntypedFormControl('', ),
261
+ accessRisk:new UntypedFormControl('', ),
262
+ drugUseFlag:new UntypedFormControl('', ),
263
+ supportInPlaceFlag: new UntypedFormControl('', ),
264
+ weaponInvolvedFlag: new UntypedFormControl('', ),
265
+ otherWeapon: new UntypedFormControl('', ),
266
+ otherDrug: new UntypedFormControl('', ),
267
+ alcoholUseFlag:new UntypedFormControl('', ),
268
+ victimSupports:new UntypedFormControl('', ),
269
+ victimWeaponUses:new UntypedFormControl('', ),
270
+ victimDrugUses:new UntypedFormControl('', ),
271
+ allowCsosaContactFlag: new UntypedFormControl('', ),
272
+ liveWithOffenderFlag: new UntypedFormControl('', ),
273
+
274
+ });
275
+
276
+ this.victimForm.markAsPristine();
277
+ this.victimForm.markAsUntouched();
278
+
279
+ }
280
+
281
+ private _getVictim() {
282
+ // if (this.victimId === 0) {
283
+
284
+ // return;
285
+ // };
286
+
287
+ this.editMode = true;
288
+ this.victimId= 24401;
289
+
290
+
291
+
292
+ if (this.editMode == true) {
293
+ console.log('find victim id inside getVictim');
294
+ console.log(this.victimId);
295
+
296
+ if (this.victimId === undefined) {
297
+ this.sub = this.route.params.subscribe(params => {
298
+ this.victimId = params['victimId'];
299
+ console.log('my this.victimId');
300
+ console.log(this.victimId);
301
+ });
302
+ }
303
+
304
+ this.victimService.getVictim(this.victimId)
305
+ .subscribe((victim: Victim) => {
306
+ console.log('victim data 1');
307
+ console.log(victim);
308
+ this.editVictim = <Victim>victim;
309
+
310
+ var supportsData =[];
311
+ this.editVictim.victimSupports.forEach( t=>{supportsData.push(t.victimSupportTypeId); } )
312
+ const victimSupportsControl = this.victimForm.get('victimSupports');
313
+ victimSupportsControl.setValue(supportsData);
314
+
315
+
316
+ var relationshipsData =[];
317
+ this.editVictim.victimOffenderRelationships.forEach( t=>{relationshipsData.push(t.victimOffenderRelationshipTypeId); } )
318
+ const victimOffenderRelationshipControl = this.victimForm.get('victimRelationships');
319
+ victimOffenderRelationshipControl.setValue(relationshipsData);
320
+
321
+
322
+ var weaponUsesData =[];
323
+ var otherWeapon = "";
324
+ this.editVictim.victimWeaponUses.forEach( t=>{
325
+ weaponUsesData.push(t.weaponTypeId);
326
+ if (t.weaponTypeId == "OTHER"){
327
+ otherWeapon = t.otherWeapon;
328
+ this.otherWeaponFlag = true;
329
+ }
330
+
331
+ } )
332
+
333
+
334
+ const victimWeaponUsesControl = this.victimForm.get('victimWeaponUses');
335
+ victimWeaponUsesControl.setValue(weaponUsesData);
336
+
337
+ const otherWeaponControl = this.victimForm.get('otherWeapon');
338
+ otherWeaponControl.setValue(otherWeapon);
339
+
340
+ var drugUseData =[];
341
+ var otherDrug = "";
342
+
343
+ console.log('load this.editVictim.victimDrugUses');
344
+ console.log(this.editVictim.victimDrugUses);
345
+ this.editVictim.victimDrugUses.forEach( t=>{
346
+
347
+ if (t.drugTypeId === null){
348
+ otherDrug = t.otherDrug;
349
+ this.otherDrugFlag = true;
350
+ t.drugTypeId ='OTHER';
351
+ }
352
+ drugUseData.push(t.drugTypeId);
353
+
354
+ } )
355
+
356
+ console.log('this.editVictim.victimDrugUses after push');
357
+ console.log(drugUseData);
358
+
359
+
360
+ if (drugUseData){
361
+ const victimDrugUsesControl = this.victimForm.get('victimDrugUses');
362
+ victimDrugUsesControl.setValue(drugUseData);
363
+
364
+ }
365
+
366
+ if (otherDrug){
367
+ const otherDrugControl = this.victimForm.get('otherDrug');
368
+ otherDrugControl.setValue(otherDrug);
369
+ }
370
+
371
+ //contact
372
+ this.victimService.getContacts(this.victimId).subscribe(
373
+ contactList => {
374
+ console.log('contactList');
375
+ console.log(contactList);
376
+ this.contactList = contactList;
377
+ this.contactDataSource.data = this.contactList;
378
+ }
379
+ );
380
+
381
+ //no phone field
382
+
383
+ if ( this.editVictim.guardianNoPhoneFlag === false ){
384
+ this.victimForm.patchValue({guardianNoPhoneFlag: false});
385
+ }
386
+ if ( this.editVictim.advocateNoPhoneFlag === false ){
387
+ this.victimForm.patchValue({advocateNoPhoneFlag: false});
388
+ }
389
+
390
+ this.homePhoneControl.setValue(
391
+ !this.editVictim.homePhone ? "" : this.editVictim.homePhone
392
+ );
393
+
394
+ this.cellPhoneControl.setValue(
395
+ !this.editVictim.cellPhone ? "" : this.editVictim.cellPhone
396
+ );
397
+
398
+ this.workPhoneControl.setValue(
399
+ !this.editVictim.workPhone ? "" : this.editVictim.workPhone
400
+ );
401
+
402
+ this.guardianHomePhoneControl.setValue(
403
+ !this.editVictim.guardianHomePhone ? "" : this.editVictim.guardianHomePhone
404
+ );
405
+
406
+ this.guardianCellPhoneControl.setValue(
407
+ !this.editVictim.guardianCellPhone ? "" : this.editVictim.guardianCellPhone
408
+ );
409
+
410
+ this.guardianWorkPhoneControl.setValue(
411
+ !this.editVictim.guardianWorkPhone ? "" : this.editVictim.guardianWorkPhone
412
+ );
413
+
414
+
415
+ this.advocateHomePhoneControl.setValue(
416
+ !this.editVictim.advocateHomePhone ? "" : this.editVictim.advocateHomePhone
417
+ );
418
+
419
+ this.advocateCellPhoneControl.setValue(
420
+ !this.editVictim.advocateCellPhone ? "" : this.editVictim.advocateCellPhone
421
+ );
422
+
423
+ this.advocateWorkPhoneControl.setValue(
424
+ !this.editVictim.advocateWorkPhone ? "" : this.editVictim.advocateWorkPhone
425
+ );
426
+
427
+ this.emergencyContactPhoneControl .setValue(
428
+ !this.editVictim.emergencyContactPhone ? "" : this.editVictim.emergencyContactPhone
429
+ );
430
+
431
+ }, error => {
432
+ this.snackBar.open("Error occured while retriving Victim Information. Please try again.");
433
+ });
434
+ return;
435
+ } else {
436
+ //new
437
+
438
+ }
439
+ }
440
+
441
+ ngOnChanges() {
442
+
443
+ }
444
+
445
+ onClear() {
446
+ if (this.addressComponent) this.addressComponent.reset();
447
+ }
448
+
449
+ showAddress(value){
450
+
451
+ if (value.checked){
452
+
453
+ this.victimService.getCurrentHousing(this.offenderId).subscribe(
454
+ (item: any) => {
455
+ this.addressId = item.housing.addressId;
456
+ this.victimForm.patchValue({addressId: this.addressId})
457
+ })
458
+ }
459
+ else{
460
+ this.addressComponent.reset();
461
+ this.editVictim.allowCsosaContactFlag = false;
462
+ this.addressId = null;
463
+ }
464
+
465
+ }
466
+
467
+ onAddressChange(addressId) {
468
+ this.victimForm.patchValue({addressId: addressId})
469
+ this.addressId = addressId;
470
+ }
471
+ onGuardianAddressChange(MyGuardianAddressId) {
472
+ this.victimForm.patchValue({guardianAddressId: MyGuardianAddressId})
473
+ this.guardianAddressId = MyGuardianAddressId;
474
+ }
475
+ onAdvocateAddressChange(MyAdvocateAddressId) {
476
+ this.victimForm.patchValue({advocateAddressId: MyAdvocateAddressId})
477
+ this.advocateAddressId = MyAdvocateAddressId;
478
+ }
479
+ cancel() {
480
+ this.victimForm.reset();
481
+ }
482
+ ngOnInit() {
483
+ this.homePhoneControl.valueChanges.subscribe((hpn: string) => {
484
+ const newValue = hpn.replace(/\D/g, '');
485
+ this.editVictim.homePhone= newValue;
486
+ });
487
+
488
+ this.cellPhoneControl.valueChanges.subscribe((hpn: string) => {
489
+ const newValue = hpn.replace(/\D/g, '');
490
+ this.editVictim.cellPhone= newValue;
491
+ });
492
+
493
+
494
+ this.workPhoneControl.valueChanges.subscribe((hpn: string) => {
495
+ const newValue = hpn.replace(/\D/g, '');
496
+ this.editVictim.workPhone= newValue;
497
+ });
498
+
499
+
500
+ this.guardianHomePhoneControl.valueChanges.subscribe((hpn: string) => {
501
+ const newValue = hpn.replace(/\D/g, '');
502
+ this.editVictim.guardianHomePhone= newValue;
503
+ });
504
+
505
+
506
+ this.guardianCellPhoneControl.valueChanges.subscribe((hpn: string) => {
507
+ const newValue = hpn.replace(/\D/g, '');
508
+ this.editVictim.guardianCellPhone= newValue;
509
+ });
510
+
511
+ this.guardianWorkPhoneControl.valueChanges.subscribe((hpn: string) => {
512
+ const newValue = hpn.replace(/\D/g, '');
513
+ this.editVictim.guardianWorkPhone= newValue;
514
+ });
515
+
516
+ this.advocateHomePhoneControl.valueChanges.subscribe((hpn: string) => {
517
+ const newValue = hpn.replace(/\D/g, '');
518
+ this.editVictim.advocateHomePhone= newValue;
519
+ });
520
+
521
+ this.advocateCellPhoneControl.valueChanges.subscribe((hpn: string) => {
522
+ const newValue = hpn.replace(/\D/g, '');
523
+ this.editVictim.advocateCellPhone= newValue;
524
+ });
525
+
526
+ this.advocateWorkPhoneControl.valueChanges.subscribe((hpn: string) => {
527
+ const newValue = hpn.replace(/\D/g, '');
528
+ this.editVictim.advocateWorkPhone= newValue;
529
+ });
530
+
531
+ this.emergencyContactPhoneControl .valueChanges.subscribe((hpn: string) => {
532
+ const newValue = hpn.replace(/\D/g, '');
533
+ this.editVictim.emergencyContactPhone= newValue;
534
+ });
535
+
536
+ this.offenderId = 219151;
537
+ this.staffId = 2929;
538
+ console.log('show offenderId');
539
+ console.log(this.offenderId);
540
+ console.log('show staffId');
541
+ console.log(this.staffId);
542
+ console.log('show isIntake');
543
+ console.log(this.isIntake);
544
+
545
+ //required field
546
+ const requiredImplementation = {get:function():boolean{if(this._required){return this._required;}
547
+ if(this.ngControl&&this.ngControl.control&&this.ngControl.control.validator
548
+ ){const emptyValueControl=Object.assign({},
549
+ this.ngControl.control);(emptyValueControl as any).value=null;
550
+ return('required'in(this.ngControl.control.validator(emptyValueControl)||{}));}
551
+ return false;},set:function(value:boolean){this._required=coerceBooleanProperty(value);},};
552
+ Object.defineProperty(MatInput.prototype,'required',requiredImplementation,);
553
+ Object.defineProperty(MatSelect.prototype,'required',requiredImplementation,);
554
+ Object.defineProperty(MatRadioGroup.prototype,'required',requiredImplementation,);
555
+ //required field end
556
+
557
+
558
+
559
+
560
+ if (this.victimDetail!=null) {
561
+ // edit record
562
+ this.editMode = true;
563
+ this.showDelete= true;
564
+ this.victimId = this.victimDetail.victimId;
565
+ this.guardianTabFlag = this.victimDetail.minorFlag;
566
+
567
+ if (this.victimDetail.victimAdvocateFlag=='YS'){
568
+ this.advocateTabFlag = true;
569
+ }
570
+
571
+ if (this.otherWeaponFlag == true){
572
+ const otherWeaponControl = this.victimForm.get('otherWeapon');
573
+ otherWeaponControl.setValidators(Validators.required);
574
+ }
575
+
576
+ if (this.otherDrugFlag == true){
577
+ const otherDrugControl = this.victimForm.get('otherDrug');
578
+ otherDrugControl.setValidators(Validators.required);
579
+ }
580
+
581
+ this.cpoExpirationDivFlag =this.victimDetail.cpoExpirationFlag;
582
+ this.commonChildrenDivFlag = this.victimDetail.commonChildrenFlag;
583
+ this.supportInPlaceDivFlag= this.victimDetail.supportInPlaceFlag;
584
+ this.weaponInvolvedDivFlag= this.victimDetail.weaponInvolvedFlag;
585
+ this.drugUseDivFlag= this.victimDetail.drugUseFlag;
586
+ this.addressId = this.victimDetail.addressId;
587
+ this.guardianAddressId = this.victimDetail.guardianAddressId;
588
+ this.advocateAddressId = this.victimDetail.advocateAddressId;
589
+ this._getVictim();
590
+
591
+ } else {
592
+ //add new record
593
+ this.victimForm.patchValue({guardianNoPhoneFlag: true});
594
+ this.victimForm.patchValue({advocateNoPhoneFlag: true});
595
+ }
596
+
597
+ this.victimService.getFlagOptionYesNoUnknowns().subscribe(
598
+ (items: any) => {
599
+ this.flagOption = items;
600
+ }
601
+ );
602
+ this.victimService.getGenders().subscribe(
603
+ (items: any) => {
604
+ this.genders = items;
605
+ }
606
+ );
607
+ this.victimService.getPrefixes().subscribe(
608
+ (items: any) => {
609
+ this.prefixes = items;
610
+ }
611
+ );
612
+ this.victimService.getSuffixes().subscribe(
613
+ (items: any) => {
614
+ this.suffixes = items;
615
+ }
616
+ );
617
+ this.victimService.getRelationshipTypes().subscribe(
618
+ (items: any) => {
619
+
620
+ this.relationshipTypes = items.filter( (y) => ((y.relationshipCategoryId === 'ST' || y.relationshipCategoryId === 'FM' )
621
+ && y.relationship !== 'AY'
622
+ && y.relationship !== 'VT'
623
+ && y.relationship !== 'CME'
624
+ && y.relationship !== 'HH'
625
+ && y.relationship !== 'NC'
626
+ && y.relationship !== 'CL'
627
+ && y.relationship !== 'OP'
628
+
629
+ ));
630
+ }
631
+ );
632
+ this.victimService.getSupportTypes().subscribe(
633
+ (items: any) => {
634
+ this.victimSupportTypes = items;
635
+ }
636
+ );
637
+ this.victimService.getWeaponTypes().subscribe(
638
+ (items: any) => {
639
+ this.weaponTypes = items;
640
+ }
641
+ );
642
+ this.victimService.getDrugsTypes().subscribe(
643
+ (items: any) => {
644
+ console.log('drug lookup items');
645
+ console.log(items);
646
+ this.drugs = items;
647
+ this.drugs.push({drugTypeId: 'OTHER', name: 'Other'});
648
+ console.log(this.drugs);
649
+ }
650
+ );
651
+ // this.victimService.getDocketList(this.offenderId).subscribe(
652
+ // (items: any) => {
653
+ // this.docketlist = items;
654
+ // }
655
+ // );
656
+
657
+ this.victimForm.get('minorFlag').valueChanges
658
+ .subscribe(value => {
659
+ this.victimForm.get('guardianFirstName').updateValueAndValidity();
660
+ this.victimForm.get('guardianLastName').updateValueAndValidity();
661
+ this.victimForm.get('guardianWorkPhone').updateValueAndValidity();
662
+ this.victimForm.get('guardianHomePhone').updateValueAndValidity();
663
+ this.victimForm.get('guardianCellPhone').updateValueAndValidity();
664
+ });
665
+
666
+ this.victimForm.get('victimAdvocateFlag').valueChanges
667
+ .subscribe(value => {
668
+ this.victimForm.get('advocateFirstName').updateValueAndValidity();
669
+ this.victimForm.get('advocateLastName').updateValueAndValidity();
670
+ this.victimForm.get('advocateWorkPhone').updateValueAndValidity();
671
+ this.victimForm.get('advocateHomePhone').updateValueAndValidity();
672
+ this.victimForm.get('advocateCellPhone').updateValueAndValidity();
673
+ });
674
+
675
+ }
676
+
677
+ back(){
678
+ //this.onSave.emit(this.victimDetail);
679
+ this.router.navigate(['victimList']);
680
+ }
681
+
682
+ deleteVictim() {
683
+ this.commonDialogService
684
+ .confirm('', 'Do you want to delete this Victim?', 'Yes', 'No')
685
+ .subscribe(res => {this.result = res;
686
+ if (this.result) {
687
+ this.victimService.deleteVictims(this.victimDetail.victimId, this.staffId)
688
+ .subscribe(result => {
689
+ this.snackBar.open('Delete Successfully!', '', {
690
+ duration: 3000, });
691
+
692
+
693
+ }
694
+ );
695
+
696
+ // this.onSave.emit(this.victimDetail);
697
+ // this.router.navigate(['victim']);
698
+ setTimeout(()=>{
699
+ window.location.reload();
700
+ },1500);
701
+
702
+
703
+ }
704
+ });
705
+ }
706
+
707
+ radioMinorChange($event: MatRadioChange){
708
+ if ($event.value === true) {
709
+ this.guardianTabFlag = true;
710
+ }
711
+ else{
712
+ this.guardianTabFlag = false;
713
+ }
714
+
715
+ }
716
+
717
+ radioAdvocateChange($event: MatRadioChange){
718
+
719
+ const advocateLastNameControl = this.victimForm.get('advocateLastName');
720
+ const advocateFirstNameControl = this.victimForm.get('advocateFirstName');
721
+
722
+ if ($event.value === "YS") {
723
+ this.advocateTabFlag = true;
724
+ advocateLastNameControl.setValidators(Validators.required);
725
+ advocateFirstNameControl.setValidators(Validators.required);
726
+ }
727
+ else{
728
+ this.advocateTabFlag = false;
729
+ advocateLastNameControl.clearValidators();
730
+ advocateFirstNameControl.clearValidators();
731
+ }
732
+ advocateLastNameControl.updateValueAndValidity();
733
+ advocateFirstNameControl.updateValueAndValidity();
734
+
735
+ }
736
+
737
+ radioCicChange($event: MatRadioChange){
738
+ if ($event.value === true) {
739
+ this.commonChildrenDivFlag = true;
740
+ // requrie field
741
+ this.setValidators('commonChildren');
742
+ }
743
+ else{
744
+ this.commonChildrenDivFlag = false;
745
+ }
746
+ }
747
+
748
+ setValidators(type) {
749
+ if(type == 'commonChildren'){
750
+ this.victimForm.get('commonChildrenNumber').clearValidators();
751
+ this.victimForm.get('commonChildrenNumber').setValidators(Validators.required);
752
+ }
753
+ else if (type == 'cpo'){
754
+ this.victimForm.get('cpoExpirationDate').clearValidators();
755
+ this.victimForm.get('cpoExpirationDate').setValidators(Validators.required);
756
+
757
+ }
758
+ }
759
+ radioSupportChange($event: MatRadioChange){
760
+ if ($event.value === true) {
761
+ this.supportInPlaceDivFlag = true;
762
+ }
763
+ else{
764
+ this.supportInPlaceDivFlag = false;
765
+ }
766
+ }
767
+ radioWeaponChange($event: MatRadioChange){
768
+ if ($event.value === true) {
769
+ this.weaponInvolvedDivFlag = true;
770
+ }
771
+ else{
772
+ this.weaponInvolvedDivFlag = false;
773
+ }
774
+ }
775
+ radioDrugChange($event: MatRadioChange){
776
+ if ($event.value === true) {
777
+ this.drugUseDivFlag = true;
778
+ }
779
+ else{
780
+ this.drugUseDivFlag = false;
781
+ }
782
+ }
783
+
784
+ radioCpoChange($event: MatRadioChange){
785
+ if ($event.value === true) {
786
+ this.cpoExpirationDivFlag = true;
787
+ this.setValidators('cpo');
788
+ }
789
+ else{
790
+ this.cpoExpirationDivFlag = false;
791
+ }
792
+ }
793
+
794
+ handleDOBChange($event ){
795
+ var ageDifMs = Date.now() - $event.value;
796
+ var ageDate = new Date(ageDifMs);
797
+ if( Math.abs(ageDate.getUTCFullYear() - 1970) <= 18){
798
+
799
+ this.snackBar.open('Victim is a Minor. This information is a sensitive and should not be disclosed to any unauthorized parties. Contact the legal guardian.', '', {
800
+ duration: 6000,});
801
+ const minorControl = this.victimForm.get('minorFlag');
802
+ minorControl.setValue(true);
803
+ this.guardianTabFlag = true;
804
+ }
805
+
806
+ }
807
+ checkOtherWeapon(WeaponUse){
808
+
809
+ const otherWeaponControl = this.victimForm.get('otherWeapon');
810
+ if (WeaponUse.includes("OTHER")){
811
+ this.otherWeaponFlag = true;
812
+ otherWeaponControl.setValidators(Validators.required)
813
+
814
+ }else{
815
+ this.otherWeaponFlag = false;
816
+ otherWeaponControl.clearValidators();
817
+ }
818
+ otherWeaponControl.updateValueAndValidity();
819
+ }
820
+
821
+ checkOtherDrug(DrugUse){
822
+
823
+ const otherDrugControl = this.victimForm.get('otherDrug');
824
+ if (DrugUse.includes("OTHER")){
825
+ this.otherDrugFlag = true;
826
+ otherDrugControl.setValidators(Validators.required)
827
+
828
+
829
+ }else{
830
+ this.otherDrugFlag = false;
831
+ otherDrugControl.clearValidators();
832
+
833
+
834
+ }
835
+ otherDrugControl.updateValueAndValidity();
836
+ }
837
+
838
+ //#region "save victim"
839
+ saveVictim() {
840
+
841
+ //guardian phone logic
842
+ if (!this.victimForm.value.guardianNoPhoneFlag)
843
+ {
844
+ if (this.guardianHomePhoneControl.value){
845
+ if (this.guardianHomePhoneControl.value !== null){
846
+ if (this.guardianHomePhoneControl.value !== ""){
847
+ this.guardianPhoneExistFlag = true;
848
+ }
849
+ }
850
+ }
851
+
852
+
853
+
854
+ if (this.guardianWorkPhoneControl.value !== undefined){
855
+ if (this.guardianWorkPhoneControl.value !== null){
856
+ if (this.guardianWorkPhoneControl.value !== ""){
857
+ this.guardianPhoneExistFlag = true;
858
+ }
859
+ }
860
+ }
861
+
862
+
863
+ if (this.guardianCellPhoneControl.value){
864
+ if (this.guardianCellPhoneControl.value!== null){
865
+ if (this.guardianCellPhoneControl.value !== ""){
866
+ this.guardianPhoneExistFlag = true;
867
+ }
868
+ }
869
+ }
870
+
871
+ }
872
+
873
+ console.log('this.victimForm.value.guardianNoPhoneFlag');
874
+ console.log(this.victimForm.value.guardianNoPhoneFlag);
875
+ console.log('this.guardianPhoneExistFlag');
876
+ console.log(this.guardianPhoneExistFlag);
877
+
878
+
879
+ if (this.guardianPhoneExistFlag === false && this.victimForm.value.guardianNoPhoneFlag === false)
880
+ {
881
+ this.phoneValidationFlag = true;
882
+ this.commonDialogService
883
+ .warning('', 'Please check the guardian phone field. You have to fill one of the three phone fileds.', 'Ok')
884
+ .subscribe(res => {this.result = res;
885
+
886
+ });
887
+ }
888
+ console.log('this.phoneValidationFlag');
889
+ console.log(this.phoneValidationFlag);
890
+
891
+ //advocate phone logic
892
+ if (!this.victimForm.value.advocateNoPhoneFlag)
893
+ {
894
+ if (this.advocateHomePhoneControl.value){
895
+ if (this.advocateHomePhoneControl.value !== null){
896
+ if (this.advocateHomePhoneControl.value !== ""){
897
+ this.advocatePhoneExistFlag = true;
898
+ }
899
+ }
900
+ }
901
+
902
+
903
+
904
+ if (this.advocateWorkPhoneControl.value !== undefined){
905
+ if (this.advocateWorkPhoneControl.value !== null){
906
+ if (this.advocateWorkPhoneControl.value !== ""){
907
+ this.advocatePhoneExistFlag = true;
908
+ }
909
+ }
910
+ }
911
+
912
+
913
+ if (this.advocateCellPhoneControl.value){
914
+ if (this.advocateCellPhoneControl.value !== null){
915
+ if (this.advocateCellPhoneControl.value !== ""){
916
+ this.advocatePhoneExistFlag = true;
917
+ }
918
+ }
919
+ }
920
+
921
+ }
922
+
923
+ console.log('this.victimForm.value.advocateNoPhoneFlag');
924
+ console.log(this.victimForm.value.advocateNoPhoneFlag);
925
+ console.log('this.advocatePhoneExistFlag');
926
+ console.log(this.advocatePhoneExistFlag);
927
+
928
+ if(this.advocatePhoneExistFlag === false && this.victimForm.value.advocateNoPhoneFlag === false)
929
+ {
930
+
931
+ this.phoneValidationFlag = true;
932
+ this.commonDialogService
933
+ .warning('', 'Please check the advocate phone field. You have to fill one of the three phone fileds.', 'Ok')
934
+ .subscribe(res => {this.result = res;
935
+
936
+ });
937
+ }
938
+
939
+
940
+ if (this.homePhoneControl.value){
941
+ this.victimForm.value.homePhone = this.homePhoneControl.value.replace(/[()\s-]/g, '');
942
+ }
943
+ else{
944
+ this.victimForm.value.homePhone = null;
945
+ }
946
+
947
+ if (this.cellPhoneControl.value){
948
+ this.victimForm.value.cellPhone = this.cellPhoneControl.value.replace(/[()\s-]/g, '') ;
949
+ }
950
+ else{
951
+ this.victimForm.value.cellPhone = null;
952
+ }
953
+
954
+ if (this.workPhoneControl.value){
955
+ this.victimForm.value.workPhone = this.workPhoneControl.value.replace(/[()\s-]/g, '');
956
+ }
957
+ else{
958
+ this.victimForm.value.workPhone= null;
959
+ }
960
+
961
+ if (this.guardianHomePhoneControl.value){
962
+ this.victimForm.value.guardianHomePhone = this.guardianHomePhoneControl.value.replace(/[()\s-]/g, '');
963
+ }
964
+ else{
965
+ this.victimForm.value.guardianHomePhone = null;
966
+ }
967
+
968
+ if (this.guardianCellPhoneControl.value){
969
+ this.victimForm.value.guardianCellPhone = this.guardianCellPhoneControl.value.replace(/[()\s-]/g, '');
970
+ }
971
+ else{
972
+ this.victimForm.value.guardianCellPhone = null;
973
+ }
974
+
975
+ if (this.guardianWorkPhoneControl.value){
976
+ this.victimForm.value.guardianWorkPhone = this.guardianWorkPhoneControl.value.replace(/[()\s-]/g, '');
977
+ }
978
+ else{
979
+ this.victimForm.value.guardianWorkPhone = null;
980
+ }
981
+
982
+
983
+ if (this.advocateHomePhoneControl.value){
984
+ this.victimForm.value.advocateHomePhone = this.advocateHomePhoneControl.value.replace(/[()\s-]/g, '')
985
+ }
986
+ else{
987
+ this.victimForm.value.advocateHomePhone = null;
988
+ }
989
+
990
+ if (this.advocateCellPhoneControl.value){
991
+ this.victimForm.value.advocateCellPhone = this.advocateCellPhoneControl.value.replace(/[()\s-]/g, '')
992
+ }
993
+ else{
994
+ this.victimForm.value.advocateCellPhone = null;
995
+ }
996
+
997
+ if (this.advocateWorkPhoneControl.value){
998
+ this.victimForm.value.advocateWorkPhone = this.advocateWorkPhoneControl.value.replace(/[()\s-]/g, '')
999
+ }
1000
+ else{
1001
+ this.victimForm.value.advocateWorkPhone = null;
1002
+ }
1003
+
1004
+
1005
+ if (this.emergencyContactPhoneControl.value){
1006
+ this.victimForm.value.emergencyContactPhone = this.emergencyContactPhoneControl.value.replace(/[()\s-]/g, '')
1007
+ }else{
1008
+ this.victimForm.value.emergencyContactPhone = null;
1009
+ }
1010
+ //data process
1011
+
1012
+ console.log('this.phoneValidationFlag 1');
1013
+ console.log(this.phoneValidationFlag);
1014
+ if ( this.phoneValidationFlag === false){
1015
+ if (this.victimDetail === null){
1016
+
1017
+ //insert new victim
1018
+
1019
+
1020
+ var myVictimRelationships = [];
1021
+
1022
+ console.log('this.victimForm.value.victimRelationships'+this.victimForm.value.victimRelationships)
1023
+ if (this.victimForm.value.victimRelationships){
1024
+ console.log('this.victimForm.value.victimRelationships 1'+this.victimForm.value.victimRelationships)
1025
+
1026
+ this.victimForm.value.victimRelationships.forEach(element => {
1027
+ const victimRelationship= <VictimRelationship>{};
1028
+ victimRelationship.victimId= this.victimForm.value.victimId;
1029
+ victimRelationship.victimOffenderRelationshipTypeId= element;
1030
+ victimRelationship.modifiedBy= this.staffId;
1031
+ myVictimRelationships.push(victimRelationship);
1032
+ console.log('this.victimForm.value.victimRelationships 2'+this.victimForm.value.victimId)
1033
+ console.log('this.victimForm.value.victimRelationships 3'+this.staffId)
1034
+ console.log('this.victimForm.value.victimRelationships 4'+element)
1035
+
1036
+ });
1037
+ }
1038
+
1039
+ console.log('myVictimRelationships'+myVictimRelationships)
1040
+
1041
+ var myVictimSupports = [];
1042
+ if (this.victimForm.value.victimSupports){
1043
+ this.victimForm.value.victimSupports.forEach(element => {
1044
+ const victimSupport= <VictimSupport>{};
1045
+ victimSupport.victimId= this.victimForm.value.victimId;
1046
+ victimSupport.victimSupportTypeId= element;
1047
+ victimSupport.modifiedBy= this.staffId;
1048
+ myVictimSupports.push(victimSupport);
1049
+ });
1050
+ }
1051
+
1052
+
1053
+ var myVictimDrugUses = [];
1054
+ console.log('this.victimForm.value.victimDrugUses during save');
1055
+ console.log(this.victimForm.value.victimDrugUses);
1056
+ if (this.victimForm.value.victimDrugUses){
1057
+ this.victimForm.value.victimDrugUses.forEach(element => {
1058
+ const victimDrugUse = <VictimDrugUse>{};
1059
+ victimDrugUse.drugTypeId = element;
1060
+
1061
+ if (element ==="OTHER" || element === "" || element === null){
1062
+ victimDrugUse.drugTypeId = null;
1063
+ victimDrugUse.otherDrug = this.victimForm.value.otherDrug;
1064
+ }
1065
+ else{
1066
+ victimDrugUse.drugTypeId = element;
1067
+ victimDrugUse.otherDrug = null;
1068
+ }
1069
+
1070
+ victimDrugUse.modifiedBy = this.staffId;
1071
+ victimDrugUse.victimId = this.victimForm.value.victimId;
1072
+ myVictimDrugUses.push(victimDrugUse);
1073
+ });
1074
+ }
1075
+
1076
+ console.log('this.victimForm.value.victimDrugUses during save 1');
1077
+ console.log(this.victimForm.value.victimDrugUses);
1078
+
1079
+ var myVictimWeaponUses = [];
1080
+
1081
+ if (this.victimForm.value.victimWeaponUses){
1082
+ this.victimForm.value.victimWeaponUses.forEach(element => {
1083
+ const victimWeaponUse = <VictimWeaponUse>{};
1084
+ victimWeaponUse.victimId= this.victimForm.value.victimId;
1085
+ victimWeaponUse.weaponTypeId= element;
1086
+
1087
+ if (element =="OTHER"){
1088
+ victimWeaponUse.otherWeapon = this.victimForm.value.otherWeapon;
1089
+ }
1090
+ else{
1091
+ victimWeaponUse.otherWeapon = null;
1092
+ }
1093
+ victimWeaponUse.modifiedBy= this.staffId;
1094
+ myVictimWeaponUses.push(victimWeaponUse);
1095
+ });
1096
+ }
1097
+
1098
+ const newVictim = {
1099
+ victimId: 0,
1100
+ offenderId: this.offenderId,
1101
+ // victimOffenderRelationshipTypeId:
1102
+ // this.victimForm.value.victimOffenderRelationshipTypeId,
1103
+ lastName: this.victimForm.value.lastName,
1104
+ firstName: this.victimForm.value.firstName,
1105
+ middleName: this.victimForm.value.middleName
1106
+ ? this.victimForm.value.middleName
1107
+ : null,
1108
+ prefixId: this.victimForm.value.prefixId
1109
+ ? this.victimForm.value.prefixId
1110
+ : null,
1111
+ suffixId: this.victimForm.value.suffixId
1112
+ ? this.victimForm.value.suffixId
1113
+ : null,
1114
+ birthDate: this.victimForm.value.birthDate
1115
+ ? this.victimForm.value.birthDate
1116
+ : null,
1117
+ genderCode: this.victimForm.value.genderCode
1118
+ ? this.victimForm.value.genderCode
1119
+ : null,
1120
+ underSupervisionFlag: this.victimForm.value.underSupervisionFlag,
1121
+ minorFlag: this.victimForm.value.minorFlag,
1122
+ victimAdvocateFlag: this.victimForm.value.victimAdvocateFlag,
1123
+
1124
+ homePhone: this.victimForm.value.homePhone,
1125
+ workPhone: this.victimForm.value.workPhone,
1126
+ cellPhone: this.victimForm.value.cellPhone,
1127
+ email: this.victimForm.value.email ? this.victimForm.value.email : null,
1128
+ addressId: this.victimForm.value.addressId
1129
+ ? this.victimForm.value.addressId
1130
+ : 1,
1131
+ emergencyContact: this.victimForm.value.emergencyContact
1132
+ ? this.victimForm.value.emergencyContact
1133
+ : null,
1134
+ emergencyContactPhone: this.victimForm.value.emergencyContactPhone,
1135
+ commonChildrenFlag: this.victimForm.value.commonChildrenFlag,
1136
+ commonChildrenNumber: this.victimForm.value.commonChildrenNumber,
1137
+ cpoExpirationFlag: this.victimForm.value.cpoExpirationFlag,
1138
+ cpoExpirationDate: this.victimForm.value.cpoExpirationDate
1139
+ ? this.datePipe.transform(this.victimForm.value.cpoExpirationDate, "short")
1140
+ : null,
1141
+ supportInPlaceFlag: this.victimForm.value.supportInPlaceFlag,
1142
+ weaponInvolvedFlag: this.victimForm.value.weaponInvolvedFlag,
1143
+ drugUseFlag: this.victimForm.value.drugUseFlag,
1144
+ alcoholUseFlag: this.victimForm.value.alcoholUseFlag,
1145
+ accessRisk: this.victimForm.value.accessRisk,
1146
+ modifiedBy: this.staffId,
1147
+ vVictimAdvocate: null,
1148
+ vVictimGuardian: null,
1149
+ victimDrugUses: myVictimDrugUses,
1150
+ victimSupports: myVictimSupports,
1151
+ victimOffenderRelationships: myVictimRelationships,
1152
+ victimWeaponUses: myVictimWeaponUses,
1153
+
1154
+ advocateFirstName: null,
1155
+ advocateLastName: null,
1156
+ advocateEmail: null,
1157
+ advocatePrefixId: null,
1158
+ advocateSuffixId: null,
1159
+ advocateNoPhoneFlag: null,
1160
+ advocateHomePhone: null,
1161
+ advocateWorkPhone: null,
1162
+ advocateCellPhone: null,
1163
+ advocateAddressId: null,
1164
+ guardianFirstName: null,
1165
+ guardianLastName: null,
1166
+ guardianEmail: null,
1167
+ guardianPrefixId: null,
1168
+ guardianSuffixId: null,
1169
+ guardianNoPhoneFlag: null,
1170
+ guardianHomePhone: null,
1171
+ guardianWorkPhone: null,
1172
+ guardianCellPhone: null,
1173
+ guardianAddressId: null,
1174
+ guardianBirthDate: null,
1175
+ //relationship: null,
1176
+ //relationship: this.victimForm.value.victimOffenderRelationshipTypeId? this.victimForm.value.victimOffenderRelationshipTypeId : null,
1177
+ allowCsosaContactFlag: this.victimForm.value.allowCsosaContactFlag
1178
+ ? this.victimForm.value.allowCsosaContactFlag
1179
+ : null,
1180
+ liveWithOffenderFlag: this.victimForm.value.liveWithOffenderFlag
1181
+ ? this.victimForm.value.liveWithOffenderFlag
1182
+ : null,
1183
+ };
1184
+
1185
+ if (this.addressId == 0){
1186
+ newVictim.addressId = null;
1187
+ } else {
1188
+ newVictim.addressId = this.addressId;
1189
+ }
1190
+
1191
+ newVictim.advocateAddressId = this.advocateAddressId;
1192
+ newVictim.guardianAddressId = this.guardianAddressId;
1193
+
1194
+
1195
+ console.log('newVictim');
1196
+ console.log(newVictim);
1197
+ this.victimService.postVictims(newVictim).subscribe(
1198
+ (items: any) => {
1199
+
1200
+ const id = items ? items.victimId : '';
1201
+
1202
+ if (this.victimForm.value.victimAdvocateFlag == "YS"){
1203
+
1204
+ console.log('add advocate');
1205
+ const victimAdvocate: VictimAdvocate = {
1206
+ victimAdvocateId: id,
1207
+ lastName: this.victimForm.value.advocateLastName,
1208
+ firstName: this.victimForm.value.advocateFirstName,
1209
+ prefixId: this.victimForm.value.advocatePrefixId,
1210
+ suffixId: this.victimForm.value.advocateSuffixId,
1211
+ addressId: this.advocateAddressId ? this.advocateAddressId: null,
1212
+ noPhoneFlag: this.victimForm.value.advocateNoPhoneFlag ? this.victimForm.value.advocateNoPhoneFlag: null,
1213
+ homePhone: this.victimForm.value.advocateHomePhone,
1214
+ workPhone: this.victimForm.value.advocateWorkPhone,
1215
+ cellPhone: this.victimForm.value.advocateCellPhone,
1216
+ email: this.victimForm.value.advocateEmail,
1217
+ modifiedBy: this.staffId
1218
+ };
1219
+
1220
+ this.victimService.postVictimAdvocate(id, victimAdvocate).subscribe();
1221
+ }
1222
+
1223
+ if (this.victimForm.value.minorFlag == true){
1224
+ const victimGuardian: VictimGuardian = {
1225
+ victimGuardianId: id,
1226
+ lastName: this.victimForm.value.guardianLastName,
1227
+ firstName: this.victimForm.value.guardianFirstName,
1228
+ prefixId: this.victimForm.value.guardianPrefixId,
1229
+ suffixId: this.victimForm.value.guardianSuffixId,
1230
+ birthDate: this.victimForm.value.guardianBirthDate,
1231
+ addressId: this.guardianAddressId? this.guardianAddressId: null,
1232
+ noPhoneFlag: this.victimForm.value.guardianNoPhoneFlag? this.victimForm.value.guardianNoPhoneFlag: null,
1233
+ homePhone: this.victimForm.value.guardianHomePhone,
1234
+ workPhone: this.victimForm.value.guardianWorkPhone,
1235
+ cellPhone: this.victimForm.value.guardianCellPhone,
1236
+ email: this.victimForm.value.guardianEmail,
1237
+ modifiedBy: this.staffId
1238
+ };
1239
+ this.victimService.postVictimGuardian(id, victimGuardian).subscribe();
1240
+ }
1241
+
1242
+ this.snackBar.open('Add Victim Successfully!', '', {
1243
+ duration: 3000,
1244
+ });
1245
+ //insert new
1246
+ if (this.isIntake===true){
1247
+ this.router.navigate(['victimHome']);
1248
+ }
1249
+ else
1250
+ {
1251
+ this.router.navigate(['victimList']);
1252
+ }
1253
+ //this.onSave.emit(this.victimDetail);
1254
+
1255
+ }
1256
+ );
1257
+
1258
+ }
1259
+ else {
1260
+ //update victim
1261
+ this.victimDetail.underSupervisionFlag = this.victimForm.value.underSupervisionFlag;
1262
+ //this.victimDetail.victimOffenderRelationshipTypeId = this.victimForm.value.victimOffenderRelationshipTypeId;
1263
+ this.victimDetail.lastName = this.victimForm.value.lastName;
1264
+ this.victimDetail.firstName = this.victimForm.value.firstName;
1265
+ this.victimDetail.middleName = this.victimForm.value.middleName;
1266
+ this.victimDetail.prefixId = this.victimForm.value.prefixId ? this.victimForm.value.prefixId : null;
1267
+ this.victimDetail.suffixId = this.victimForm.value.suffixId ? this.victimForm.value.suffixId : null;
1268
+ this.victimDetail.birthDate = this.victimForm.value.birthDate;
1269
+ this.victimDetail.genderCode = this.victimForm.value.genderCode;
1270
+ this.victimDetail.minorFlag = this.victimForm.value.minorFlag;
1271
+ this.victimDetail.homePhone = this.victimForm.value.homePhone;
1272
+ this.victimDetail.workPhone = this.victimForm.value.workPhone;
1273
+ this.victimDetail.cellPhone = this.victimForm.value.cellPhone;
1274
+ this.victimDetail.email = this.victimForm.value.email;
1275
+ this.victimDetail.victimAdvocateFlag = this.victimForm.value.victimAdvocateFlag;
1276
+ this.victimDetail.emergencyContact = this.victimForm.value.emergencyContact;
1277
+ this.victimDetail.emergencyContactPhone = this.victimForm.value.emergencyContactPhone;
1278
+ this.victimDetail.commonChildrenFlag = this.victimForm.value.commonChildrenFlag;
1279
+ this.victimDetail.commonChildrenNumber = this.victimForm.value.commonChildrenNumber;
1280
+ this.victimDetail.cpoExpirationDate = this.victimForm.value.cpoExpirationDate;
1281
+ this.victimDetail.cpoExpirationFlag = this.victimForm.value.cpoExpirationFlag;
1282
+ this.victimDetail.supportInPlaceFlag = this.victimForm.value.supportInPlaceFlag;
1283
+ this.victimDetail.weaponInvolvedFlag = this.victimForm.value.weaponInvolvedFlag;
1284
+ this.victimDetail.drugUseFlag = this.victimForm.value.drugUseFlag;
1285
+ this.victimDetail.alcoholUseFlag = this.victimForm.value.alcoholUseFlag;
1286
+ this.victimDetail.accessRisk = this.victimForm.value.accessRisk;
1287
+ this.victimDetail.addressId = this.addressId;
1288
+ this.victimDetail.allowCsosaContactFlag = this.victimForm.value.allowCsosaContactFlag;
1289
+ this.victimDetail.liveWithOffenderFlag = this.victimForm.value.liveWithOffenderFlag;
1290
+
1291
+ this.victimDetail.victimSupports = [];
1292
+ this.victimForm.value.victimSupports.forEach(element => {
1293
+ const victimSupport= <VictimSupport>{};
1294
+ victimSupport.victimId= this.victimDetail.victimId;
1295
+ victimSupport.victimSupportTypeId= element;
1296
+ victimSupport.modifiedBy= this.staffId;
1297
+ this.victimDetail.victimSupports.push(victimSupport);
1298
+ });
1299
+
1300
+
1301
+ this.victimDetail.victimOffenderRelationships = [];
1302
+ this.victimForm.value.victimRelationships.forEach(element => {
1303
+ const victimRelationship= <VictimRelationship>{};
1304
+ victimRelationship.victimId= this.victimDetail.victimId;
1305
+ victimRelationship.victimOffenderRelationshipTypeId= element;
1306
+ victimRelationship.modifiedBy= this.staffId;
1307
+ this.victimDetail.victimOffenderRelationships.push(victimRelationship);
1308
+ });
1309
+
1310
+
1311
+ this.victimDetail.victimDrugUses = [];
1312
+
1313
+ this.victimForm.value.victimDrugUses.forEach(element => {
1314
+ const victimDrugUse = <VictimDrugUse>{};
1315
+ victimDrugUse.drugTypeId = element;
1316
+ console.log('this.victimForm.value.victimDrugUses before')
1317
+ console.log(this.victimForm.value.victimDrugUses)
1318
+
1319
+ if (element === "OTHER" || element === "" ){
1320
+ victimDrugUse.drugTypeId = null;
1321
+ victimDrugUse.otherDrug = this.victimForm.value.otherDrug;
1322
+ }
1323
+ else{
1324
+ victimDrugUse.drugTypeId = element;
1325
+ victimDrugUse.otherDrug = null;
1326
+ }
1327
+
1328
+ victimDrugUse.modifiedBy = this.staffId;
1329
+ victimDrugUse.victimId = this.victimDetail.victimId;
1330
+ this.victimDetail.victimDrugUses.push(victimDrugUse);
1331
+
1332
+ });
1333
+ this.victimForm.value.victimDrugUses.filter(word => ( !(word.drugTypeId === null && word.otherDrug === null) ));
1334
+
1335
+ this.victimDetail.victimWeaponUses = [];
1336
+ this.victimForm.value.victimWeaponUses.forEach(element => {
1337
+ const victimWeaponUse = <VictimWeaponUse>{};
1338
+ victimWeaponUse.victimId= this.victimDetail.victimId;
1339
+ victimWeaponUse.weaponTypeId= element;
1340
+
1341
+ if (element =="OTHER"){
1342
+ victimWeaponUse.otherWeapon=this.victimForm.value.otherWeapon;
1343
+ }
1344
+ else{
1345
+ victimWeaponUse.otherWeapon = null;
1346
+ }
1347
+
1348
+ victimWeaponUse.modifiedBy= this.staffId;
1349
+ this.victimDetail.victimWeaponUses.push(victimWeaponUse);
1350
+
1351
+ });
1352
+
1353
+ console.log('this.victimDetail before emit');
1354
+ console.log(this.victimDetail);
1355
+
1356
+
1357
+ this.victimService.putVictims(this.victimDetail.victimId,this.victimDetail).subscribe(
1358
+ (items: any) => {
1359
+ this.snackBar.open('Update Successfully!', '', {
1360
+ duration: 3000,
1361
+ });
1362
+ //Advocate section
1363
+ this.victimAdvocate.victimAdvocateId = this.victimDetail.victimId;
1364
+ this.victimAdvocate.lastName= this.victimForm.value.advocateLastName;
1365
+ this.victimAdvocate.firstName= this.victimForm.value.advocateFirstName;
1366
+ this.victimAdvocate.prefixId= this.victimForm.value.advocatePrefixId ? this.victimForm.value.advocatePrefixId : null;
1367
+ this.victimAdvocate.suffixId= this.victimForm.value.advocateSuffixId ? this.victimForm.value.advocateSuffixId : null;
1368
+ this.victimAdvocate.addressId= this.advocateAddressId ? this.advocateAddressId : null;
1369
+ this.victimAdvocate.noPhoneFlag= this.victimForm.value.advocateNoPhoneFlag? true: false;
1370
+ this.victimAdvocate.homePhone= this.victimForm.value.advocateHomePhone;
1371
+ this.victimAdvocate.workPhone= this.victimForm.value.advocateWorkPhone;
1372
+ this.victimAdvocate.cellPhone= this.victimForm.value.advocateCellPhone;
1373
+ this.victimAdvocate.email= this.victimForm.value.advocateEmail ? this.victimForm.value.advocateEmail : null;
1374
+ this.victimAdvocate.modifiedBy= this.staffId;
1375
+
1376
+ console.log('work on advocate part');
1377
+ if (this.victimDetail.victimAdvocateFlag=='YS')
1378
+ {
1379
+ console.log('work on advocate flag is YS ');
1380
+ if(this.victimDetail.advocateFirstName != null){
1381
+ console.log('check advocate fisrt name ');
1382
+ console.log(this.victimDetail.advocateFirstName);
1383
+ this.victimService.putVictimAdvocate(this.victimDetail.victimId,this.victimAdvocate).subscribe(
1384
+ resp=>{} );
1385
+ }
1386
+ else
1387
+ {
1388
+ console.log('add advocate');
1389
+ console.log(this.victimAdvocate);
1390
+ this.victimService.postVictimAdvocate(this.victimDetail.victimId, this.victimAdvocate).subscribe();
1391
+ }
1392
+ }
1393
+
1394
+ // guardian section
1395
+ this.victimGuardian.victimGuardianId = this.victimDetail.victimId;
1396
+ this.victimGuardian.lastName = this.victimForm.value.guardianLastName;
1397
+ this.victimGuardian.firstName = this.victimForm.value.guardianFirstName;
1398
+ this.victimGuardian.prefixId = this.victimForm.value.guardianPrefixId ? this.victimForm.value.guardianPrefixId : null;
1399
+ this.victimGuardian.suffixId = this.victimForm.value.guardianSuffixId ? this.victimForm.value.guardianSuffixId : null;
1400
+ this.victimGuardian.addressId = this.guardianAddressId ? this.guardianAddressId : null;
1401
+ this.victimGuardian.noPhoneFlag = this.victimForm.value.guardianNoPhoneFlag? true: false;
1402
+ this.victimGuardian.homePhone = this.victimForm.value.guardianHomePhone;
1403
+ this.victimGuardian.workPhone = this.victimForm.value.guardianWorkPhone;
1404
+ this.victimGuardian.cellPhone = this.victimForm.value.guardianCellPhone;
1405
+ this.victimGuardian.email = this.victimForm.value.guardianEmail ? this.victimForm.value.guardianEmail : null;
1406
+ this.victimGuardian.modifiedBy = this.staffId;
1407
+
1408
+ if (this.victimDetail.minorFlag == true)
1409
+ {
1410
+ if(this.victimDetail.guardianFirstName != null )
1411
+ this.victimService.putVictimGuardian(this.victimDetail.victimId,this.victimGuardian).subscribe(
1412
+ resp=>{
1413
+ }
1414
+ );
1415
+ else
1416
+ {
1417
+ console.log('add gurdian');
1418
+ console.log(this.victimGuardian);
1419
+ this.victimService.postVictimGuardian(this.victimDetail.victimId, this.victimGuardian).subscribe();
1420
+ }
1421
+
1422
+ }
1423
+ }
1424
+
1425
+ );
1426
+
1427
+ }
1428
+ }//end of this.phoneValidationFlag = false
1429
+
1430
+ console.log('this.victimDetail');
1431
+ console.log(this.victimDetail);
1432
+ this.onSave.emit(this.victimDetail);
1433
+ }
1434
+
1435
+ //#endregion "save victim"
1436
+ addContact(){
1437
+ this.router.navigate(['victimContact',this.victimId]);
1438
+ }
1439
+ formatLabel(value: number) {
1440
+ return value;
1441
+ }
1442
+
1443
+
1444
+
1445
+ update() {
1446
+ // this.task.update(task => {
1447
+ // if (index === undefined) {
1448
+ // task.completed = completed;
1449
+ // task.subtasks?.forEach(t => (t.completed = completed));
1450
+ // } else {
1451
+ // task.subtasks![index].completed = completed;
1452
+ // task.completed = task.subtasks?.every(t => t.completed) ?? true;
1453
+ // }
1454
+ // return {...task};
1455
+ // });
1456
+ }
1457
+
1458
+
1459
+ }