Skip to content

Commit 1eae023

Browse files
committed
initial commit
1 parent 0663668 commit 1eae023

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

src/lib/api.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ const api = {
242242
if (cache.has('compressibleTypes')) {
243243
return cache.get('compressibleTypes');
244244
}
245-
const resp = await request.get({ url: configUrl, json: true });
246-
const compressibleTypes = resp.compressible_types.split(',').map(s=>s.trim());
245+
const resp = await request.get({url: configUrl, json: true});
246+
const compressibleTypes = resp.compressible_types.split(',').map(s => s.trim());
247247
cache.set('compressibleTypes', compressibleTypes);
248248
return compressibleTypes;
249249
} catch (e) {
@@ -254,7 +254,9 @@ const api = {
254254
}
255255
return [];
256256
}
257-
}
257+
},
258+
259+
request
258260
};
259261

260262
Object.entries(api)

src/lib/hierarchy-operations/delete-hierarchy.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ const DataSource = require('./hierarchy-data-source');
22
const JsDocs = require('./jsdocFolder');
33
const lineageConstraints = require('./lineage-constraints');
44
const { trace, info } = require('../log');
5+
const requestsApi = require('../api');
56

67
const prettyPrintDocument = doc => `'${doc.name}' (${doc._id})`;
78
async function deleteHierarchy(db, options, sourceIds) {
89
JsDocs.prepareFolder(options);
10+
const api = requestsApi();
911

1012
const sourceDocs = await DataSource.getContactsByIds(db, sourceIds);
1113
const constraints = await lineageConstraints(db, options);
@@ -18,7 +20,7 @@ async function deleteHierarchy(db, options, sourceIds) {
1820
for (const descendant of descendantsAndSelf) {
1921
const toDeleteUsers = options.disableUsers && constraints.isPlace(descendant);
2022
JsDocs.deleteDoc(options, descendant, toDeleteUsers);
21-
affectedReportCount += await deleteReportsForContact(db, options, descendant);
23+
affectedReportCount += await deleteReportsForContact(api, options, descendant);
2224
}
2325

2426
const affectedContactCount = descendantsAndSelf.length;
@@ -27,11 +29,11 @@ async function deleteHierarchy(db, options, sourceIds) {
2729
}
2830
}
2931

30-
async function deleteReportsForContact(db, options, contact) {
32+
async function deleteReportsForContact(api, options, contact) {
3133
let skip = 0;
3234
let reportBatch;
3335
do {
34-
reportBatch = await DataSource.getReportsForContacts(db, [], contact._id, skip);
36+
reportBatch = await DataSource.getReportsForContacts(api, [], contact._id, skip);
3537

3638
for (const report of reportBatch) {
3739
JsDocs.deleteDoc(options, report);

src/lib/hierarchy-operations/hierarchy-data-source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function getContactWithDescendants(db, contactId) {
5454
.filter(doc => doc && doc.type !== 'tombstone');
5555
}
5656

57-
async function getReportsForContacts(db, createdByIds, createdAtId, skip) {
57+
async function getReportsForContacts(api, createdByIds, createdAtId, skip) {
5858
const createdByKeys = createdByIds.map(id => [`contact:${id}`]);
5959
const createdAtKeys = createdAtId ? [
6060
[`patient_id:${createdAtId}`],

src/lib/hierarchy-operations/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ const JsDocs = require('./jsdocFolder');
44
const lineageManipulation = require('./lineage-manipulation');
55
const LineageConstraints = require('./lineage-constraints');
66
const { trace, info } = require('../log');
7+
const requestsApi = require('../../lib/api');
78

89
async function moveHierarchy(db, options, sourceIds, destinationId) {
910
JsDocs.prepareFolder(options);
11+
const api = requestsApi();
1012
trace(`Fetching contact details: ${destinationId}`);
1113
const constraints = await LineageConstraints(db, options);
1214
const destinationDoc = await DataSource.getContact(db, destinationId);
@@ -44,7 +46,7 @@ async function moveHierarchy(db, options, sourceIds, destinationId) {
4446

4547
minifyLineageAndWriteToDisk(options, [...updatedDescendants, ...updatedAncestors]);
4648

47-
const movedReportsCount = await updateReports(db, options, moveContext);
49+
const movedReportsCount = await updateReports(api, options, moveContext);
4850
trace(`${movedReportsCount} report(s) created by these affected contact(s) will be updated`);
4951

5052
affectedContactCount += updatedDescendants.length + updatedAncestors.length;
@@ -56,15 +58,15 @@ async function moveHierarchy(db, options, sourceIds, destinationId) {
5658
info(`Staged changes to lineage information for ${affectedContactCount} contact(s) and ${affectedReportCount} report(s).`);
5759
}
5860

59-
async function updateReports(db, options, moveContext) {
61+
async function updateReports(api, options, moveContext) {
6062
const descendantIds = moveContext.descendantsAndSelf.map(contact => contact._id);
6163

6264
let skip = 0;
6365
let reportDocsBatch;
6466
do {
6567
info(`Processing ${skip} to ${skip + DataSource.BATCH_SIZE} report docs`);
6668
const createdAtId = options.merge && moveContext.sourceId;
67-
reportDocsBatch = await DataSource.getReportsForContacts(db, descendantIds, createdAtId, skip);
69+
reportDocsBatch = await DataSource.getReportsForContacts(api, descendantIds, createdAtId, skip);
6870

6971
const lineageUpdates = replaceLineageOfReportCreator(reportDocsBatch, moveContext);
7072
const reassignUpdates = reassignReports(reportDocsBatch, moveContext);

0 commit comments

Comments
 (0)