Skip to content
New issue

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

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

Already on GitHub? # to your account

Feat/#1186 disable cross field validation for survival time #1214

Merged

Conversation

ciaranschutte
Copy link
Contributor

@ciaranschutte ciaranschutte commented Nov 6, 2024

Link to Issue

icgc-argo/roadmap#1186

Description

disables time conflict validation on follow_up, specimen and treatment if exception exists

Checklist

Type of Change

  • Bug
  • Refactor
  • New Feature
  • Release Candidate

Checklist before requesting review:

  • Check branch (code change PRs go to develop not master)
  • Check copyrights for new files
  • Manual testing
  • Regression tests completed and passing (double check number of tests).
  • Spelling has been checked.
  • Updated swagger docs accordingly (check it's still valid)
  • Set validationDependency in meta tag for Argo Dictionary fields used in code

Comment on lines 348 to 378
export const checkForExceptions = async (
record: DeepReadonly<SubmittedClinicalRecord>,
field: string,
schema: string,
): Promise<boolean> => {
const programId = record['program_id'] as string;

const programAdditionalSearchParams = {
exceptions: { requested_core_field: field },
};

const entityAdditionalSearchParams = {
[`${schema}.requested_core_field`]: field,
};

// retrieve submitted exceptions for program id (both program level and entity level)
const programException = await programExceptionRepository.find(
programId,
programAdditionalSearchParams,
);
const entityException = await entityExceptionRepository.find(
programId,
entityAdditionalSearchParams,
);

return notEmpty(programException) || notEmpty(entityException);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if program or entity exception exists

@@ -24,13 +24,82 @@ import {
SubmissionValidationOutput,
DonorVitalStatusValues,
} from '../submission-entities';
import { ClinicalEntitySchemaNames, FollowupFieldsEnum } from '../../common-model/entities';
import {
Copy link
Contributor Author

@ciaranschutte ciaranschutte Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes here mirror changes to other validation files.
big diff hash because I moved an inline function out of a function body for consistency

@ciaranschutte
Copy link
Contributor Author

CI failing due to tests. #1216 should fix it.

Copy link
Member

@joneubank joneubank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are my comments about the types used in the code provided, this is mostly about having your functions be more strict/opinionated about their interface/parameters.

@@ -66,6 +66,8 @@ const EntityExceptionModel =
mongoose.models.EntityException ||
mongoose.model<EntityException>('EntityException', entityExceptionSchema);

type OptionalSearchParams = Record<string, string>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this type alias? This is used in only one place, so we could just write Record<string, string> inline.

Comment on lines 43 to 47
type OptionalSearchParams = {
exceptions: Partial<{
requested_core_field: string;
}>;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again this is only used in one place, why not declare it inline?

The use of Partial could be smart if we expect this to expand, but maybe it would be simpler to just make this:

optionalSearchParams?: { requested_core_field?: string }

Since we don't currently need the extra layer in the object and there is only 1 property.

This comment is really similar to the comment on the repo's find function, where what is important is the interface that we export. This interface as written looks like it is trying to match the shape of data from another source, instead of requesting only data that is meaningful to this function's context.

Comment on lines 110 to 111
async find(
programId: string,
optionalSearchParams?: OptionalSearchParams,
): Promise<EntityException | null> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optionalSearchParams parameter, being a record of any strings, is very loose for this interface - there is no structure or guidance for what a caller should be sending here.

Reading through your implementation, you are directly sending the properties from this object into the mongo search query. That means the caller, coming from outside the repo file, needs to know about the structure of the repo for these queries to be useful.

I would consider thinking about what parameters a developer might want to send here and how to ensure that those values will always result in a valid query into the database. For our current task, this might be a field like requested_core_field?: string

src/submission/exceptions/exceptions.ts Show resolved Hide resolved
Comment on lines 348 to 351
export const checkForExceptions = async (
record: DeepReadonly<SubmittedClinicalRecord>,
field: string,
schema: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because both field and schema just accept a string, there is a possibility of a developer mixing up the order of these. It may be helpful to make this function take an object with named properties as an input. This will also improve readability when calling this function.

Compare for example:

// not clear that the arguments are in the wrong order
checkForExceptions(myTreatmentRecord, 'treatment', 'treatment_type');

// vs:
checkForExceptions({ record: myTreatmentRecord, schema: 'treatment', field: 'treatment_type' });

@joneubank
Copy link
Member

joneubank commented Nov 15, 2024

I am proposing a change to the expected behaviour detailed in the ticket. Instead of having our cross file validations check for the survival_time exception, we should just check if there is a survival_time value. If there is no value, then we don't apply the checks (they would always fail). If there is no value and also no exception, then the validation would fail in the donor entity validation, so we don't need to worry about that in the time interval cross validations.

I'll add a comment to the issue to the same effect and create a new PR into this branch with the proposed changes.

@ciaranschutte
Copy link
Contributor Author

tested locally.

@justincorrigible justincorrigible changed the title Feat/#1186 disable cross file for surivival time Feat/#1186 disable cross field validation for survival time Nov 18, 2024
@ciaranschutte ciaranschutte force-pushed the feat/#1186_disable_cross_file_for_surivival_time branch from 8e1859d to ceb65c0 Compare November 18, 2024 16:45
errors.push(
buildSubmissionError(
submittedRecord,
DataValidationErrors.NOT_ENOUGH_INFO_TO_VALIDATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source of testing errors -- this is removed and not replaced elsewhere. The tests are looking for the NOT_ENOUGH_INFO_TO_VALIDATE error and it's not found.

@ciaranschutte
Copy link
Contributor Author

@joneubank please see updated unit tests. I believe these updates match what we discussed in so far as the interval checks are on donor schema itself.

@ciaranschutte ciaranschutte merged commit c4aa428 into develop Nov 18, 2024
2 checks passed
@ciaranschutte ciaranschutte deleted the feat/#1186_disable_cross_file_for_surivival_time branch November 18, 2024 21:32
@ciaranschutte ciaranschutte mentioned this pull request Nov 18, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants