Skip to content

Commit

Permalink
Merge pull request #600 from episphere/stage
Browse files Browse the repository at this point in the history
Stage -> Prod Sync (May 2024 Release)
  • Loading branch information
we-ai authored May 23, 2024
2 parents 86ffc73 + 64ed92e commit acfc01c
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 89 deletions.
2 changes: 1 addition & 1 deletion config/dev/cloudbuild2.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', 'getParticipants', '--trigger-http', '--runtime=${_RUNTIME}', '--source=${_SOURCE}', '--env-vars-file=config/dev/.env.yaml']
args: ['functions', 'deploy', 'getParticipants', '--trigger-http', '--runtime=${_RUNTIME}', '--memory=1024MB', '--source=${_SOURCE}', '--env-vars-file=config/dev/.env.yaml']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'add-iam-policy-binding', 'getParticipants', '--member=allUsers', '--role=${_ROLE}']
- name: 'gcr.io/cloud-builders/gcloud'
Expand Down
2 changes: 1 addition & 1 deletion config/prod/cloudbuild2.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', 'getParticipants', '--trigger-http', '--runtime=${_RUNTIME}', '--source=${_SOURCE}', '--env-vars-file=config/prod/.env.yaml']
args: ['functions', 'deploy', 'getParticipants', '--trigger-http', '--runtime=${_RUNTIME}', '--memory=1024MB', '--source=${_SOURCE}', '--env-vars-file=config/prod/.env.yaml']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'add-iam-policy-binding', 'getParticipants', '--member=allUsers', '--role=${_ROLE}']
- name: 'gcr.io/cloud-builders/gcloud'
Expand Down
4 changes: 3 additions & 1 deletion config/stage/.env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ TWILIO_MESSAGING_SERVICE_SID: projects/nih-nci-dceg-connect-stg-5519/secrets/twi
APP_REGISTRATION_TENANT_ID: projects/nih-nci-dceg-connect-stg-5519/secrets/app-registration-tenant-id/versions/1
APP_REGISTRATION_CLIENT_ID: projects/nih-nci-dceg-connect-stg-5519/secrets/app-registration-client-id/versions/1
APP_REGISTRATION_CLIENT_SECRET: projects/nih-nci-dceg-connect-stg-5519/secrets/app-registration-client-secret/versions/1
GITHUB_TOKEN: projects/nih-nci-dceg-connect-stg-5519/secrets/questionnaire-sha-tracking/versions/1
GITHUB_TOKEN: projects/nih-nci-dceg-connect-stg-5519/secrets/questionnaire-sha-tracking/versions/1
PROMIS_UOID: projects/nih-nci-dceg-connect-stg-5519/secrets/promis-uoid/versions/1
PROMIS_TOKEN: projects/nih-nci-dceg-connect-stg-5519/secrets/promis-token/versions/1
2 changes: 1 addition & 1 deletion config/stage/cloudbuild2.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', 'getParticipants', '--trigger-http', '--runtime=${_RUNTIME}', '--source=${_SOURCE}', '--env-vars-file=config/stage/.env.yaml']
args: ['functions', 'deploy', 'getParticipants', '--trigger-http', '--runtime=${_RUNTIME}', '--memory=1024MB', '--source=${_SOURCE}', '--env-vars-file=config/stage/.env.yaml']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'add-iam-policy-binding', 'getParticipants', '--member=allUsers', '--role=${_ROLE}']
- name: 'gcr.io/cloud-builders/gcloud'
Expand Down
140 changes: 79 additions & 61 deletions utils/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2400,77 +2400,95 @@ const confirmShipmentKit = async (shipmentData) => {

const storeKitReceipt = async (package) => {
try {
const kitSnapshot = await db.collection("kitAssembly").where('972453354', '==', package['972453354']).where('221592017', '==', 277438316).get();
if (kitSnapshot.size === 0) {
return false;
}
const kitDoc = kitSnapshot.docs[0];
const Connect_ID = kitDoc.data()['Connect_ID'];

const participantSnapshot = await db.collection("participants").where('173836415.266600170.319972665.687158491', '==', kitDoc.data()[687158491]).get();
const participantDoc = participantSnapshot.docs[0];
const participantDocData = participantSnapshot.docs[0].data();
let toReturn;
await db.runTransaction(async (transaction) => {
const kitSnapshot = await transaction.get(db.collection("kitAssembly").where('972453354', '==', package['972453354']).where('221592017', '==', 277438316));
if (kitSnapshot.size === 0) {
toReturn = false;
return;
}
const kitDoc = kitSnapshot.docs[0];
const kitData = kitDoc.data();
const Connect_ID = kitData['Connect_ID'];

const participantSnapshot = await transaction.get(db.collection("participants").where('173836415.266600170.319972665.687158491', '==', kitDoc.data()[687158491]));
const participantDoc = participantSnapshot.docs[0];
const participantDocData = participantSnapshot.docs[0].data();

const token = participantDocData['token'];
const uid = participantDocData['state']['uid'];
const site = participantDocData['827220437'];
const prefEmail = participantDocData['869588347'];
const ptName = participantDocData['153211406'] || participantDocData['399159511']
const surveyStatus = participantDocData['547363263']

const prevParticipantObject = participantDocData[173836415][266600170][319972665];
const collectionId = package['259846815']?.split(' ')[0];
const objectId = package['259846815']?.split(' ')[1];

if (objectId === undefined || collectionId === undefined) {
toReturn = { status: 'Check Collection ID' };
return;
}

const token = participantDocData['token'];
const uid = participantDocData['state']['uid'];
const site = participantDocData['827220437'];
const prefEmail = participantDocData['869588347'];
const ptName = participantDocData['153211406'] || participantDocData['399159511']
const surveyStatus = participantDocData['547363263']
// check the collection ID from the kitAssembly against the one from package and error if they don't match
if(kitData[fieldMapping.collectionCupId] !== package[fieldMapping.collectionCupId]) {
toReturn = { status: 'Collection Cup ID from tracking number does not match provided Collection Cup ID' };
return;
}

const prevParticipantObject = participantDocData[173836415][266600170][319972665];
const collectionId = package['259846815']?.split(' ')[0];
const objectId = package['259846815']?.split(' ')[1];

if (objectId === undefined || collectionId === undefined) {
return { status: 'Check Collection ID' }
}
const biospecPkg = {
'143615646': {
'593843561': 353358909,
'825582494': package['259846815'],
'826941471': package['826941471']
},
'260133861': package['260133861'],
'678166505': package['678166505'],
'820476880': collectionId,
'827220437': site,
'Connect_ID': Connect_ID,
'token': token,
'uid': uid
}

const biospecPkg = {
'143615646': {
'593843561': 353358909,
'825582494': package['259846815'],
'826941471': package['826941471']
},
'260133861': package['260133861'],
'678166505': package['678166505'],
'820476880': collectionId,
'827220437': site,
'Connect_ID': Connect_ID,
'token': token,
'uid': uid
}

await db.collection('biospecimen').add(biospecPkg);

await kitDoc.ref.update({
'137401245': package['137401245'] === true ? 353358909 : 104430631,
'221592017': 375535639,
'633640710': processPackageConditions(package['633640710']),
'755095663': package['755095663'],
'826941471': package['826941471']
});
// Create a reference to a document that doesn't exist yet with the given ID
const newDocRef = db.collection('biospecimen').doc(uid);

transaction.set(newDocRef, biospecPkg);

await participantDoc.ref.update({
'684635302': 353358909,
'254109640': 353358909,
'173836415.266600170.915179629': 103209024,
'173836415.266600170.448660695': package['678166505'],
'173836415.266600170.319972665': {
...prevParticipantObject,
transaction.update(kitDoc.ref, {
'137401245': package['137401245'] === true ? 353358909 : 104430631,
'221592017': 375535639,
'633640710': processPackageConditions(package['633640710']),
'755095663': package['755095663'],
'826941471': package['826941471']
}
});

transaction.update(participantDoc.ref, {
'684635302': 353358909,
'254109640': 353358909,
'173836415.266600170.915179629': 103209024,
'173836415.266600170.448660695': package['678166505'],
'173836415.266600170.319972665': {
...prevParticipantObject,
'221592017': 375535639,
'826941471': package['826941471']
}
});

toReturn = { status: true, Connect_ID, token, uid, prefEmail, ptName, surveyStatus };
return;
});

return { status: true, Connect_ID, token, uid, prefEmail, ptName, surveyStatus };
return toReturn;

}
catch (error) {
console.error(error);
return new Error(error);
}
}
catch (error) {
console.error(error);
return new Error(error);
}
}

const processPackageConditions = (pkgConditions) => {
const keys = [950521660, 545319575, 938338155, 205954477, 289239334, 992420392, 541085383, 427719697, 100618603];
Expand Down
42 changes: 24 additions & 18 deletions utils/promis.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const CryptoJS = require('crypto-js');

const generatePromisAuthToken = () => {
const generatePromisAuthToken = async () => {

/* temp revert of code
const { getSecret } = require('./shared');
*/

const uoid = '';
const token = '';
const uoid = await getSecret(process.env.PROMIS_UOID);
const token = await getSecret(process.env.PROMIS_TOKEN);

const encodedWord = CryptoJS.enc.Utf8.parse(uoid + ":" + token);
const encoded = CryptoJS.enc.Base64.stringify(encodedWord);
Expand All @@ -24,6 +22,7 @@ const processPromisResults = async (uid) => {

const forms = Object.keys(promisConfig);
const scoresPayload = {};
const scoresPromises = [];

for (let form of forms) {
const sourceQuestion = surveyResults[promisConfig[form].source];
Expand All @@ -44,34 +43,41 @@ const processPromisResults = async (uid) => {
}
}

const scores = await getScoringData(promisConfig[form].id, scoringData);

if (scores) {
scoresPayload[promisConfig[form].score] = parseInt(scores['T-Score']);
scoresPayload[promisConfig[form].error] = parseInt(scores['SError']);
}
scoresPromises.push(
getScoringData(promisConfig[form].id, scoringData).then(scores => {
if (scores) {
scoresPayload[promisConfig[form].score] = parseInt(scores['T-Score']);
scoresPayload[promisConfig[form].error] = parseInt(scores['SError']);
}
})
);
}
}

if (Object.keys(scoresPayload).length > 0) {
await updateSurvey(scoresPayload, collection, doc);
}
Promise.all(scoresPromises).then(async () => {
if (Object.keys(scoresPayload).length > 0) {
await updateSurvey(scoresPayload, collection, doc);
}
}).catch(error => {
console.error("Error in processing scoring data:", error);
});
}

const getScoringData = async (id, data) => {

const formData = new URLSearchParams();
const url = `https://www.assessmentcenter.net/ac_api/2013-01/Scores/`;
const url = `https://dcb-promis.cit.nih.gov/2013-01/Scores/${id}.json`;
const token = await generatePromisAuthToken();

Object.keys(data).forEach(key => {
formData.append(key, data[key]);
});

try {
const response = await fetch(`${url}${id}.json`, {
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": "Basic " + generatePromisAuthToken(),
"Authorization": `Basic ${token}`,
"Content-Type": "application/x-www-form-urlencoded"
},
body: formData.toString()
Expand All @@ -80,7 +86,7 @@ const getScoringData = async (id, data) => {
const scores = await response.json();

if (scores.ItemErrors) {
throw new Error('Errors in request data sent to PROMIS Scoring API', scores.ItemErrors);
throw new Error(`Errors in request data sent to PROMIS Scoring API: ${scores.ItemErrors}`);
}

return scores.Form[0];
Expand Down
12 changes: 6 additions & 6 deletions utils/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ const submit = async (res, data, uid) => {
if (moduleStatusConcepts[key] && data[key] === 231311385) {
moduleComplete = true;

/* temp revert of code
if (key === '320303124') {
calculateScores = true;
}
*/
}
})

Expand All @@ -75,12 +73,14 @@ const submit = async (res, data, uid) => {

await checkDerivedVariables(token, siteCode);

/* temp revert of code
if (calculateScores) {
const { processPromisResults } = require('./promis');
processPromisResults(uid);

//remove condition once implemented in dev tier
if(process.env.GCLOUD_PROJECT === 'nih-nci-dceg-connect-stg-5519' || process.env.GCLOUD_PROJECT === 'nih-nci-dceg-connect-prod-6d04') {
const { processPromisResults } = require('./promis');
processPromisResults(uid);
}
}
*/
}
}

Expand Down

0 comments on commit acfc01c

Please sign in to comment.