-
Notifications
You must be signed in to change notification settings - Fork 47
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
OpEx: Practitioners' email address, as defined in each of their cases #5574
Open
jimlerza
wants to merge
1
commit into
staging
Choose a base branch
from
opex-find-cases-in-which-a-practitioners-email-didnt-update
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// usage: | ||
// npx ts-node --transpile-only scripts/reports/practitioners-email-in-cases.ts 84c865f0-3867-40c8-aa31-f35c7e45998f | ||
|
||
import { | ||
ServerApplicationContext, | ||
createApplicationContext, | ||
} from '@web-api/applicationContext'; | ||
import { search } from '@web-api/persistence/elasticsearch/searchClient'; | ||
|
||
const practitionerId = process.argv[2]; | ||
if (!practitionerId) { | ||
console.log( | ||
'Usage: npx ts-node --transpile-only scripts/reports/practitioners-email-in-cases.ts <USER ID>', | ||
); | ||
process.exit(1); | ||
} | ||
|
||
const getUsersRole = async ({ | ||
applicationContext, | ||
userId, | ||
}: { | ||
applicationContext: ServerApplicationContext; | ||
userId: string; | ||
}): Promise<string | undefined> => { | ||
const { results } = await search({ | ||
applicationContext, | ||
searchParameters: { | ||
body: { | ||
from: 0, | ||
query: { | ||
bool: { | ||
must: [ | ||
{ | ||
term: { | ||
'pk.S': `user|${userId}`, | ||
}, | ||
}, | ||
{ | ||
term: { | ||
'sk.S': `user|${userId}`, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
size: 1, | ||
}, | ||
index: 'efcms-user', | ||
}, | ||
}); | ||
return results[0]?.role; | ||
}; | ||
|
||
const getPractitionersCases = async ({ | ||
applicationContext, | ||
role, | ||
userId, | ||
}: { | ||
applicationContext: ServerApplicationContext; | ||
role: string; | ||
userId: string; | ||
}): Promise<RawCase[]> => { | ||
const { results } = await search({ | ||
applicationContext, | ||
searchParameters: { | ||
body: { | ||
from: 0, | ||
query: { | ||
bool: { | ||
must: [ | ||
{ | ||
term: { | ||
[`${role}s.L.M.userId.S`]: userId, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
size: 10000, | ||
}, | ||
index: 'efcms-case', | ||
}, | ||
}); | ||
return results; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
(async () => { | ||
const applicationContext = createApplicationContext({}); | ||
const role = await getUsersRole({ | ||
applicationContext, | ||
userId: practitionerId, | ||
}); | ||
if (role !== 'irsPractitioner' && role !== 'privatePractitioner') { | ||
console.log(`Error: user is not a practitioner! User's role: ${role}`); | ||
return; | ||
} | ||
const practitionersCases: RawCase[] = await getPractitionersCases({ | ||
applicationContext, | ||
role, | ||
userId: practitionerId, | ||
}); | ||
const practitionersEmailInCases = {}; | ||
for (const practitionersCase of practitionersCases) { | ||
const practitionerObj = practitionersCase[`${role}s`]?.find( | ||
pract => pract.userId === practitionerId, | ||
); | ||
if (practitionerObj && practitionerObj.email) { | ||
practitionersEmailInCases[practitionersCase.docketNumber] = | ||
practitionerObj.email; | ||
} | ||
} | ||
console.log(practitionersEmailInCases); | ||
})(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it possible to have a duplicate docketNumber (e.g., maybe missing distinguishing suffixes)?
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.
Even for docket numbers that have suffixes, the
docketNumber.S
field will not contain the suffix. The suffix is stored separately in thedocketNumberSuffix.S
field and a composite of the docket number and suffix is stored asdocketNumberWithSuffix.S
for good measure.Because the docket number (without suffix) is used as the pk/sk for a case, there won't be duplicates.
If, however, it happens that the same practitioner can somehow be in a given case's
[irs|private]Practitioners
array twice, the.find()
a few lines above will settle for the first match it comes across.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.
Got it--great explanation, thank you!