-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmolecularqcs.js
80 lines (65 loc) · 2.55 KB
/
molecularqcs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
import bsi from './bsi/module.js';
import dynamo from './dynamo/module.js';
import got from 'got';
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
const secretClient = new SecretsManager();
var molecularqcsModule = (() => {
async function getCdrSecrets() {
return secretClient.getSecretValue({SecretId: process.env.CDR_SECRET});
}
async function createCdrRequest(molecularqc) {
let data = await getCdrSecrets();
var secrets = JSON.parse(data.SecretString);
const url = process.env.CDR_BASE_URL + 'molecularQCEvent/' + molecularqc.caseId;
let response = await got.post(url, {
json: molecularqc,
username: secrets.username,
password: secrets.password,
throwHttpErrors: false,
});
return response.statusCode;
}
return {
pullRecentChanges: async () => {
await bsi.login();
var lastUpdated = await dynamo.getLatest('Case');
var bsiCases = await bsi.cases.getUpdated(lastUpdated.lastModified);
for (let index = 0; index < bsiCases.length; index++) {
var molecularqc = await bsi.molecularqcs.get(bsiCases[index]);
await dynamo.molecularqcs.update(molecularqc);
}
await dynamo.updateLatest(lastUpdated);
await bsi.logoff();
},
sync: async (molecularqc) => {
console.log("Syncing " + molecularqc.caseId + " to CDR.");
var lastModified = molecularqc.lastModified;
delete molecularqc.lastModified;
var statusCode = await createCdrRequest(molecularqc);
console.log("Recording status code " + statusCode + ".");
await dynamo.molecularqcs.updateSync({
caseId: molecularqc.caseId,
lastModified: lastModified,
lastSynced: new Date().toISOString(),
syncResult: statusCode
});
},
dynamoToJson: (data) => {
return dynamo.toJson(data);
},
get: async (caseId) => {
return dynamo.molecularqcs.get(caseId);
},
getSync: async (caseId) => {
return dynamo.molecularqcs.getSync(caseId);
},
rebuild: async (caseId) => {
await bsi.login();
var molecularqc = await bsi.molecularqcs.get(caseId);
await dynamo.molecularqcs.update(molecularqc);
await bsi.logoff();
}
};
})();
export default molecularqcsModule;