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 { Injectable, OnDestroy } from '@angular/core';
import deepDiff from 'return-deep-diff';
import { Subject } from 'rxjs/Subject';

@Injectable()
export class OhiLineAdjustmentService {


differences = new Subject();
firstClaimObject;
secondClaimObject;

fullObject1;
fullObject2;

samePdiLoaded: boolean;


constructor() { }


getInstance(instance) {
const myNewInstance = Object.assign({}, instance);
myNewInstance.billingInfoService = null;
if (this.firstClaimObject) {
this.secondClaimObject = myNewInstance;
this.fullObject2 = myNewInstance;
} else {
this.firstClaimObject = myNewInstance;
this.fullObject1 = myNewInstance;
}

if (this.secondClaimObject) {
this.compareServiceLine();
}
}






compareServiceLine() {
const obj1 = this.firstClaimObject.ohiSrvcLineAdjInfo;
const obj2 = this.secondClaimObject.ohiSrvcLineAdjInfo;

let ohiSrvcLineAdjInfoDiffs = deepDiff(obj1, obj2);

if (JSON.stringify(obj1) === JSON.stringify(obj2)) {
ohiSrvcLineAdjInfoDiffs = 'equal';
}


const answer = {};

obj1.map((o1, index) => {
obj2.map((o2) => {
if (o1.lineNumber === o2.lineNumber) {
const diffs = deepDiff(o1, o2);
if (diffs && o1.lineNumber) {
diffs['lineNumber'] = o1.lineNumber;
answer[o1.lineNumber] = diffs;
}
}
});
});



const objToBeDiffed1 = {};
const objToBeDiffed2 = {};


obj1.map((elem1, i1) => {
if (elem1['lineNumber']) {
let indexForWhileLoop = i1;
objToBeDiffed1[elem1['lineNumber']] = [];

while (obj1[indexForWhileLoop + 1] && obj1[indexForWhileLoop + 1]['lineNumber'] === null) {
objToBeDiffed1[elem1['lineNumber']].push(obj1[indexForWhileLoop + 1]);
indexForWhileLoop++;
}
}
obj2.map((elem2, i2) => {
if (elem2['lineNumber']) {
let indexForWhileLoop = i2;
objToBeDiffed2[elem2['lineNumber']] = [];

while (obj2[indexForWhileLoop + 1] && obj2[indexForWhileLoop + 1]['lineNumber'] === null) {
objToBeDiffed2[elem2['lineNumber']].push(obj2[indexForWhileLoop + 1]);
indexForWhileLoop++;
}
}
});
});

const rowsWithoutLineNumbersDiffs = deepDiff(objToBeDiffed1, objToBeDiffed2);

const arr = Object.keys(answer).map((k) => answer[k]);


// if the element of the array has a linenumber, splice the rows w/o lineNumbers after it
for (let i = 0; i < arr.length; i++) {
if ( rowsWithoutLineNumbersDiffs && arr && arr[i] && arr[i]['lineNumber'] ) {
rowsWithoutLineNumbersDiffs[arr[i]['lineNumber']].reverse().map((elem) => {
arr.splice(i + 1, 0, elem);
});
}
}
this.differences.next([answer, arr]);
}

}