-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/#1186 disable cross field validation for survival time #1214
Conversation
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); | ||
}; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
CI failing due to tests. #1216 should fix it. |
There was a problem hiding this 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>; |
There was a problem hiding this comment.
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.
type OptionalSearchParams = { | ||
exceptions: Partial<{ | ||
requested_core_field: string; | ||
}>; | ||
}; |
There was a problem hiding this comment.
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.
async find( | ||
programId: string, | ||
optionalSearchParams?: OptionalSearchParams, | ||
): Promise<EntityException | null> { |
There was a problem hiding this comment.
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
export const checkForExceptions = async ( | ||
record: DeepReadonly<SubmittedClinicalRecord>, | ||
field: string, | ||
schema: string, |
There was a problem hiding this comment.
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' });
I am proposing a change to the expected behaviour detailed in the ticket. Instead of having our cross file validations check for the I'll add a comment to the issue to the same effect and create a new PR into this branch with the proposed changes. |
tested locally. |
8e1859d
to
ceb65c0
Compare
errors.push( | ||
buildSubmissionError( | ||
submittedRecord, | ||
DataValidationErrors.NOT_ENOUGH_INFO_TO_VALIDATE, |
There was a problem hiding this comment.
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.
@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. |
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
Checklist before requesting review:
develop
not master)validationDependency
in meta tag for Argo Dictionary fields used in code