Skip to content

Commit

Permalink
fix: CE-1339 Linking to child complaint (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarlett-Truong authored Jan 10, 2025
1 parent 801ece5 commit 4c0e47e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions backend/src/v1/case_file/case_file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ export class CaseFileService {
linkComplaintsAndRunQuery = async (token: string, model: CaseFileDto, assessmentInput: any, query: string) => {
let returnValue;
const dateLinkCreated = new Date();
const complaintBeingLinkedId = assessmentInput.leadIdentifier;
const linkingToComplaintId = assessmentInput.assessmentDetails.actionLinkedComplaintIdentifier;
const complaintBeingLinkedId = assessmentInput.leadIdentifier; //child complaint (A)
let linkingToComplaintId = assessmentInput.assessmentDetails.actionLinkedComplaintIdentifier; //parent complaint (B)
const queryRunner = this.dataSource.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const idir = getIdirFromRequest(this.request);
// If actionLinkedComplaintIdentifier is present the link must be created in the database
if (assessmentInput.assessmentDetails.actionLinkedComplaintIdentifier) {
if (linkingToComplaintId) {
// When linking complaint "A" to complant "B", if "A" is already linked to "B" then the link is not created.
const existingLink = await this._linkedComplaintXrefRepository.findOne({
relations: { linked_complaint_identifier: true, complaint_identifier: true },
Expand Down Expand Up @@ -139,6 +139,21 @@ export class CaseFileService {
await queryRunner.manager.save(linkString);
});
}

// check if complaint "B" has linked with (is a child of) other complaints
const existingLinkOfParentComplaint = await this._linkedComplaintXrefRepository.findOne({
relations: { linked_complaint_identifier: true, complaint_identifier: true },
where: {
linked_complaint_identifier: { complaint_identifier: linkingToComplaintId },
active_ind: true,
},
});

//if complaint "B" is a child of complaint "C" -> link "A" directly to "C" (linkingToComplaintId now is "C")
if (existingLinkOfParentComplaint?.complaint_identifier?.complaint_identifier) {
linkingToComplaintId = existingLinkOfParentComplaint?.complaint_identifier?.complaint_identifier;
}

// Create the new link between the complaints
let newLink = new CreateLinkedComplaintXrefDto();
newLink = {
Expand Down

0 comments on commit 4c0e47e

Please sign in to comment.