Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

import { Component, OnInit, Inject, AfterViewInit, OnDestroy, ChangeDetectorRef } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { FormBuilder, FormGroup } from '@angular/forms';
import { CodeModel } from '../rfai-admin.model';
import { RfaiAdminService } from '../rfai-admin.service';
import { Router } from '@angular/router';
import { DOCUMENT } from '@angular/platform-browser';
import { CanDeactivateGuard, CanComponentDeactivate } from '../../../shared/guards/can-deactivate-gaurd';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { serviceDateValidatorOpt$ } from '../../../shared/validators';

const empty = val => val === null || val === ''; //
@Component({
selector: 'app-submission-codes',
templateUrl: './submission-codes.component.html',
styleUrls: ['./submission-codes.component.scss']
})
export class SubmissionCodesComponent
implements OnInit, OnDestroy, CanComponentDeactivate, AfterViewInit {
subscription: Subscription = new Subscription();
healthCodes: CodeModel[] = [];
healthCodesAccSwitch = false;
loincCodes: CodeModel[] = [];
loincCodesAccSwitch = false;
loincModCodes: CodeModel[] = [];
loincModCodesAccSwitch = false;
newCode: CodeModel = new CodeModel();
tempCodeObj: CodeModel = new CodeModel();
tempNewCodeObj: CodeModel = new CodeModel();
codeModalForm: FormGroup;
codeModalClosed = true;
addCodeClicked = false;
successMsg = '';
errorMsg = '';
errorStatus = false;
successStatus = false;
confirmModalClosed = true;
confirmType = 'code';
modalErrorCode = false;
modalErrorDesc = false;
currentDate: Date;
dateRangeError = false;
startEndDateFlag = false;
changesSaved = false;
currentCodeFullName: string;
discardChangesModalClosed = true;
discardChangesSubject: Subject<boolean> = new Subject<boolean>();
tabIdx = '0';
constructor(
@Inject(DOCUMENT) private document,
private rfaiAdminService: RfaiAdminService,
private canDeactivateGuard: CanDeactivateGuard,
private fb: FormBuilder,
private router: Router,
private changeDetectorRef: ChangeDetectorRef
) {}
ngOnInit() {
this.getCodes();
this.formInit();
}
ngAfterViewInit() {
this.subscription.add(this.codeModalForm.controls['endDate'].valueChanges.subscribe(v => {
if (this.codeModalForm.get('startDate').valid &&
this.codeModalForm.get('endDate').value &&
this.codeModalForm.get('endDate').value.length === 10 &&
this.codeModalForm.get('startDate').value &&
this.codeModalForm.get('startDate').value.length === 10
) {
this.datesValidator();
}
}));
this.subscription.add(this.codeModalForm.controls['startDate'].valueChanges.subscribe(v => {
if (this.codeModalForm.get('startDate').valid &&
this.codeModalForm.get('endDate').valid &&
this.codeModalForm.get('endDate').value &&
this.codeModalForm.get('endDate').value.length === 10 &&
this.codeModalForm.get('startDate').value &&
this.codeModalForm.get('startDate').value.length === 10
) {
this.datesValidator();
}
}));
}

formInit() {
this.codeModalForm = this.fb.group({
codeNumber: this.tempNewCodeObj.stcCd,
codeDescription: this.tempNewCodeObj.stcCdDesc,
level: this.tempNewCodeObj.level,
startDate: ['', [serviceDateValidatorOpt$]],
endDate: ['', [serviceDateValidatorOpt$]]
});
}
getCodes() {
this.subscription.add(
this.rfaiAdminService.getHccscCode().subscribe(
data => {
this.healthCodes = data;
this.healthCodes.forEach(healthCode => {
healthCode.archiveImg = '../../assets/images/ic_archive_red_24.svg';
healthCode.editTableImg =
'../../assets/images/ic_edit_table_blue_24.svg';
});
},
error => {
console.log('getHccscCode() error', error);
}
)
);

this.subscription.add(
this.rfaiAdminService.getLoincCodes().subscribe(
data => {
this.loincCodes = data[0].claimList;
data[0].lineList = data[0].lineList.filter(
code => code.level !== 'Both'
);
this.loincCodes = this.loincCodes.concat(data[0].lineList);
this.loincCodes.forEach(lionCode => {
lionCode.archiveImg = '../../assets/images/ic_archive_red_24.svg';
lionCode.editTableImg =
'../../assets/images/ic_edit_table_blue_24.svg';
});
},
error => {
console.log('getLoincCodes() error', error);
}
)
);

this.subscription.add(
this.rfaiAdminService.getLoincModifierCodes().subscribe(
data => {
this.loincModCodes = data;
this.loincModCodes.forEach(loincModCode => {
(loincModCode.archiveImg =
'../../assets/images/ic_archive_red_24.svg'),
(loincModCode.editTableImg =
'../../assets/images/ic_edit_table_blue_24.svg');
});
},
error => {
console.log('getLoincModifierCodes() error', error);
}
)
);
}

addCode(currentCodeFullName: string) {
this.document.body.style.overflow = 'visible';
this.modalErrorCode = false;
this.modalErrorDesc = false;
this.currentDate = new Date();
const tempStart = new Date(
this.codeModalForm.get('startDate').value
);
const tempEnd = new Date(
this.codeModalForm.get('endDate').value
);
tempStart.setHours(0, 0, 0, 0);
tempEnd.setHours(0, 0, 0, 0);
this.currentDate.setHours(0, 0, 0, 0);
if (
this.currentDate < tempStart &&
this.codeModalForm.get('startDate').value &&
!this.codeModalForm.get('startDate').value
) {
this.tempNewCodeObj.flag = false;
} else if (
this.currentDate > tempEnd &&
this.codeModalForm.get('endDate').value &&
!this.codeModalForm.get('startDate').value
) {
this.tempNewCodeObj.flag = false;
} else if (this.currentDate >= tempStart && this.currentDate <= tempEnd) {
this.tempNewCodeObj.flag = true;
} else if (
!this.codeModalForm.get('startDate').value &&
this.currentDate <= tempEnd
) {
this.tempNewCodeObj.flag = true;
} else if (
!this.codeModalForm.get('endDate').value &&
this.currentDate >= tempStart
) {
this.tempNewCodeObj.flag = true;
} else if (
(this.currentDate > tempStart && this.currentDate > tempEnd) ||
(this.currentDate < tempStart && this.currentDate < tempEnd)
) {
this.tempNewCodeObj.flag = false;
} else if (
!this.codeModalForm.get('startDate').value &&
!this.codeModalForm.get('endDate').value
) {
this.tempNewCodeObj.flag = true;
}
this.tempNewCodeObj.startDate = this.codeModalForm.get('startDate').value;
this.tempNewCodeObj.endDate = this.codeModalForm.get('endDate').value;
if (this.tempNewCodeObj.stcCd && this.tempNewCodeObj.stcCdDesc) {
this.tempNewCodeObj.editedOrNewFlag = true;
this.canDeactivateGuard.setCanLogout(false);

switch (currentCodeFullName) {
case 'Health Care Claim Status Category Code': {
this.healthCodes.push(this.tempNewCodeObj);
this.healthCodesAccSwitch = true;
break;
}
case 'LOINC Code': {
this.loincCodes.push(this.tempNewCodeObj);
this.loincCodesAccSwitch = true;
break;
}
case 'LOINC Modifier Code': {
this.loincModCodes.push(this.tempNewCodeObj);
this.loincModCodesAccSwitch = true;
break;
}
}
this.newCode = new CodeModel();
this.tempNewCodeObj = new CodeModel();
this.codeModalClosed = true;
this.tabIdx = '0';
this.rfaiAdminService.setTabIdx(this.tabIdx);

this.modalErrorCode = false;
this.modalErrorDesc = false;
} else {
this.tempNewCodeObj.stcCd
? (this.modalErrorDesc = true)
: (this.modalErrorCode = true);
this.tempNewCodeObj.stcCdDesc
? (this.modalErrorCode = true)
: (this.modalErrorDesc = true);
}
}

editCode(
newCode: CodeModel,
oldCode: CodeModel,
currentCodeFullName: string
) {
this.document.body.style.overflow = 'visible';
newCode.editedOrNewFlag = true;
this.modalErrorDesc = false;
this.modalErrorCode = false;
this.currentDate = new Date();

const tempStart = new Date(
this.codeModalForm.get('startDate').value
);
const tempEnd = new Date(
this.codeModalForm.get('endDate').value
);

tempStart.setHours(0, 0, 0, 0);
tempEnd.setHours(0, 0, 0, 0);
this.currentDate.setHours(0, 0, 0, 0);
if (
this.currentDate < tempStart &&
this.codeModalForm.get('startDate').value &&
!this.codeModalForm.get('endDate').value
) {
this.tempNewCodeObj.flag = false;
} else if (
this.currentDate > tempEnd &&
this.codeModalForm.get('endDate').value &&
!this.codeModalForm.get('startDate').value
) {
this.tempNewCodeObj.flag = false;
} else if (this.currentDate >= tempStart && this.currentDate <= tempEnd) {
this.tempNewCodeObj.flag = true;
} else if (
!this.codeModalForm.get('startDate').value &&
this.currentDate <= tempEnd
) {
this.tempNewCodeObj.flag = true;
} else if (
!this.codeModalForm.get('endDate').value &&
this.currentDate >= tempStart
) {
this.tempNewCodeObj.flag = true;
} else if (
(this.currentDate > tempStart && this.currentDate > tempEnd) ||
(this.currentDate < tempStart && this.currentDate < tempEnd)
) {
this.tempNewCodeObj.flag = false;
} else if (
!this.codeModalForm.get('startDate').value &&
!this.codeModalForm.get('endDate').value
) {
this.tempNewCodeObj.flag = true;
}
newCode.startDate = this.codeModalForm.get('startDate').value;
newCode.endDate = this.codeModalForm.get('endDate').value;
if (newCode.stcCd && newCode.stcCdDesc) {
this.codeModalClosed = true;
this.tabIdx = '0';
this.rfaiAdminService.setTabIdx(this.tabIdx);

newCode.editedOrNewFlag = true;
this.canDeactivateGuard.setCanLogout(false);
this.changesSaved = false;
switch (currentCodeFullName) {
case 'Health Care Claim Status Category Code': {
const indexElement = this.healthCodes.findIndex(
code => code.cd === oldCode.cd
);
if (indexElement > -1) {
this.healthCodes[indexElement] = newCode;
}
break;
}
case 'LOINC Code': {
const indexElement = this.loincCodes.findIndex(
code => code.cd === oldCode.cd
);
if (indexElement > -1) {
this.loincCodes[indexElement] = newCode;
}
break;
}
case 'LOINC Modifier Code': {
const indexElement = this.loincModCodes.findIndex(
code => code.cd === oldCode.cd
);
if (indexElement > -1) {
this.loincModCodes[indexElement] = newCode;
}
break;
}
}
} else {
newCode.stcCd
? (this.modalErrorDesc = true)
: (this.modalErrorCode = true);
newCode.stcCdDesc
? (this.modalErrorCode = true)
: (this.modalErrorDesc = true);
}
}

openAddCodeModal(currentCodeName: string) {
this.addCodeClicked = true;
if (currentCodeName === 'HCCS') {
this.currentCodeFullName = 'Health Care Claim Status Category Code';
}
if (currentCodeName === 'LOINC') {
this.currentCodeFullName = 'LOINC Code';
}
if (currentCodeName === 'LOINCMod') {
this.currentCodeFullName = 'LOINC Modifier Code';
}
this.codeModalForm
.get('startDate')
.setValue(this.newCode.startDate);
this.codeModalForm
.get('endDate')
.setValue(this.newCode.endDate);
this.onCodeModalOpenCommon();
}

openEditCodeModal(codeObj: CodeModel, currentCodeName: string) {
this.addCodeClicked = false;
this.modalErrorCode = false;
this.modalErrorDesc = false;
this.codeModalForm
.get('startDate')
.setValue(codeObj.startDate);
this.codeModalForm
.get('endDate')
.setValue(codeObj.endDate);
this.onCodeModalOpenCommon();
this.tempNewCodeObj = { ...codeObj };
this.tempCodeObj = { ...codeObj };
if (currentCodeName === 'HCCS') {
this.currentCodeFullName = 'Health Care Claim Status Category Code';
}
if (currentCodeName === 'LOINC') {
this.currentCodeFullName = 'LOINC Code';
}
if (currentCodeName === 'LOINCMod') {
this.currentCodeFullName = 'LOINC Modifier Code';
}
}

onCodeModalOpenCommon() {
this.document.body.style.overflow = 'hidden';
this.codeModalClosed = false;
this.tabIdx = '-1';
this.rfaiAdminService.setTabIdx(this.tabIdx);
this.tempNewCodeObj = new CodeModel();
this.dateRangeError = false;
this.startEndDateFlag = false;
}

onCodeModalClose() {
this.document.body.style.overflow = 'visible';
this.codeModalForm.reset({
codeNumber: '',
codeDescription: '',
level: '',
startDate: ''
});
this.codeModalClosed = true;
this.tabIdx = '0';
this.rfaiAdminService.setTabIdx(this.tabIdx);
this.addCodeClicked = false;
this.modalErrorCode = false;
this.modalErrorDesc = false;
this.dateRangeError = false;
this.startEndDateFlag = false;
}

submitCodeInfo(): void {
this.changesSaved = true;
this.router.navigate(['rfaiAdmin']);
const requestBody = {
hccList: this.healthCodes.filter(code => code.editedOrNewFlag),
loincList: this.loincCodes.filter(code => code.editedOrNewFlag),
loincModList: this.loincModCodes.filter(code => code.editedOrNewFlag)
};
const someArchived =
requestBody.hccList.some(code => code.archive) ||
requestBody.loincList.some(code => code.archive) ||
requestBody.loincModList.some(code => code.archive);
if (someArchived && this.confirmModalClosed) {
this.openConfirmationModal('code');
return;
}
this.subscription.add(
this.rfaiAdminService.postCodes(requestBody).subscribe(
data => {
// Show success message
this.successMsg = 'Updated Codes successfully.';
this.successStatus = true;
this.rfaiAdminService.setStatus(true, this.successStatus);
this.rfaiAdminService.setMsg(true, this.successMsg);
this.rfaiAdminService.setStatus(false, this.errorStatus);
this.rfaiAdminService.setMsg(false, '');
window.scrollTo(0, 0);
this.errorStatus = false; // suppress error message
this.getCodes(); // refresh codes
// turn off success message later
setTimeout(() => {
this.successStatus = false;
this.rfaiAdminService.setStatus(true, this.successStatus);
this.rfaiAdminService.setMsg(true, '');
}, 8000);
this.confirmModalClosed = true; // let non-modal forms run again
},
error => {
this.confirmModalClosed = true;
this.errorStatus = true;
this.errorMsg = error.error.message;
this.successStatus = false;
this.rfaiAdminService.setStatus(true, this.successStatus);
this.rfaiAdminService.setStatus(false, this.errorStatus);
this.rfaiAdminService.setMsg(false, this.errorMsg);
this.changesSaved = false;
setTimeout(() => {
this.errorStatus = false;
this.rfaiAdminService.setStatus(false, this.errorStatus);
this.rfaiAdminService.setMsg(false, '');
}, 8000);
}
)
);
}
openConfirmationModal(type: string) {
this.confirmType = type;
this.confirmModalClosed = false;
this.tabIdx = '-1';
this.rfaiAdminService.setTabIdx(this.tabIdx);
}

closeConfirmationModal() {
// callback from app-modal
this.confirmModalClosed = true;
this.tabIdx = '0';
this.rfaiAdminService.setTabIdx(this.tabIdx);
}
resetCodeInfo() {
this.changesSaved = false;
this.codeModalClosed = true;
this.tabIdx = '0';
this.rfaiAdminService.setTabIdx(this.tabIdx);
this.addCodeClicked = false;
this.confirmType = 'code';
this.startEndDateFlag = false;
this.getCodes();
}

setEditOrNewFlag(code: CodeModel) {
if (!code.editedOrNewFlag) {
code.editedOrNewFlag = true;
} else {
code.editedOrNewFlag = false;
}
}

datesValidator() {
if (
this.codeModalForm.get('startDate').value.length === 10 &&
this.codeModalForm.get('endDate').value.length === 10
) {
const fromDate = new Date(
this.codeModalForm.get('startDate').value
);
const toDate = new Date(
this.codeModalForm.get('endDate').value
);
if (toDate.valueOf() < fromDate.valueOf()) {
this.dateRangeError = true;
this.codeModalForm.get('startDate').setValue('');
this.codeModalForm.get('endDate').setValue('');
this.changeDetectorRef.detectChanges();
} else {
this.dateRangeError = false;
}
}
}

archive(code: CodeModel) {
if (code.archive) {
code.archive = false;
code.editedOrNewFlag = false;
code.archiveImg = '../../assets/images/ic_archive_red_24.svg';
code.editTableImg = '../../assets/images/ic_edit_table_blue_24.svg';
} else {
code.archive = true;
code.editedOrNewFlag = true;
code.archiveImg = '../../assets/images/ic_archive_white_24.svg';
code.editTableImg = '../../assets/images/ic_edit_table_white_24.svg';
}

if (this.healthCodes.some(data => data.editedOrNewFlag === true)) {
this.canDeactivateGuard.setCanLogout(false);
this.changesSaved = false;
}
if (this.loincCodes.some(data => data.editedOrNewFlag === true)) {
this.canDeactivateGuard.setCanLogout(false);
this.changesSaved = false;
}
if (this.loincModCodes.some(data => data.editedOrNewFlag === true)) {
this.canDeactivateGuard.setCanLogout(false);
this.changesSaved = false;
}
}

checkToDisable(startDateT, endDateT, temp) {
// determine if a code is disabled because it is not in a given date range.
// If start and end are on the same day, only an instant (0,0,0,0) is OK
// If you want a code to be valid today, start today and end tomorrow.

if (empty(startDateT) && empty(endDateT)) {
return false; // no restriction
}
const tempStart = new Date(startDateT);
tempStart.setHours(0, 0, 0, 0);
const tempEnd = new Date(endDateT);
tempEnd.setHours(0, 0, 0, 0);
this.currentDate = new Date();
this.currentDate.setHours(0, 0, 0, 0);
if (empty(startDateT) && this.currentDate <= tempEnd) {
return false; // no start, before end
} else if (tempStart <= this.currentDate && empty(endDateT)) {
return false; // started, no end
} else if (tempStart <= this.currentDate && this.currentDate <= tempEnd) {
return false; // strictly between start and end
}
return true; // out of range
}

canDeactivate(): Observable<boolean> | boolean {
if (
this.healthCodes.some(code => code.editedOrNewFlag) ||
this.loincCodes.some(code => code.editedOrNewFlag) ||
this.loincModCodes.some(code => code.editedOrNewFlag)
) {
if (!this.changesSaved) {
this.canDeactivateGuard.setCanLogout(false);
return this.openDiscardChangesModal();
} else {
return true;
}
} else {
return true;
}
}
closeDiscardChangesModal() {
this.discardChangesModalClosed = true;
this.tabIdx = '0';
this.rfaiAdminService.setTabIdx(this.tabIdx);
}
openDiscardChangesModal(): Observable<boolean> {
setTimeout(() => {
if (!this.discardChangesModalClosed) {
this.discardChangesModalClosed = true; // stop showing the message
this.tabIdx = '0';
this.rfaiAdminService.setTabIdx(this.tabIdx);

this.discardChangesSubject.next(false);
}
}, 30000);
this.discardChangesModalClosed = false;
this.tabIdx = '-1';
this.rfaiAdminService.setTabIdx(this.tabIdx);

return this.discardChangesSubject.asObservable();
}
action(value: boolean) {
this.discardChangesSubject.next(value);
this.canDeactivateGuard.setCanLogout(value);
this.closeDiscardChangesModal();
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}