Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CE-1339 Linking to child complaint #858

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading