cht-conf 4.1.2 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +2 -4
- package/src/fn/edit-contacts.js +70 -50
- package/src/fn/merge-contacts.js +69 -0
- package/src/fn/move-contacts.js +13 -236
- package/src/lib/hierarchy-operations/hierarchy-data-source.js +103 -0
- package/src/lib/hierarchy-operations/index.js +186 -0
- package/src/lib/hierarchy-operations/jsdocFolder.js +37 -0
- package/src/lib/hierarchy-operations/lineage-constraints.js +170 -0
- package/src/lib/hierarchy-operations/lineage-manipulation.js +63 -0
- package/src/lib/hierarchy-operations/replace-lineage.js +76 -0
- package/src/lib/lineage-constraints.js +0 -94
- package/src/lib/lineage-manipulation.js +0 -107
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/*
|
|
3
|
-
Given a doc, replace the lineage information therein with "replaceWith"
|
|
4
|
-
|
|
5
|
-
startingFromIdInLineage (optional) - Will result in a partial replacement of the lineage. Only the part of the lineage "after" the parent
|
|
6
|
-
with _id=startingFromIdInLineage will be replaced by "replaceWith"
|
|
7
|
-
*/
|
|
8
|
-
const replaceLineage = (doc, lineageAttributeName, replaceWith, startingFromIdInLineage) => {
|
|
9
|
-
const handleReplacement = (replaceInDoc, docAttr, replaceWith) => {
|
|
10
|
-
if (!replaceWith) {
|
|
11
|
-
const lineageWasDeleted = !!replaceInDoc[docAttr];
|
|
12
|
-
replaceInDoc[docAttr] = undefined;
|
|
13
|
-
return lineageWasDeleted;
|
|
14
|
-
} else if (replaceInDoc[docAttr]) {
|
|
15
|
-
replaceInDoc[docAttr]._id = replaceWith._id;
|
|
16
|
-
replaceInDoc[docAttr].parent = replaceWith.parent;
|
|
17
|
-
} else {
|
|
18
|
-
replaceInDoc[docAttr] = replaceWith;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return true;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// Replace the full lineage
|
|
25
|
-
if (!startingFromIdInLineage) {
|
|
26
|
-
return handleReplacement(doc, lineageAttributeName, replaceWith);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Replace part of a lineage
|
|
30
|
-
let currentParent = doc[lineageAttributeName];
|
|
31
|
-
while (currentParent) {
|
|
32
|
-
if (currentParent._id === startingFromIdInLineage) {
|
|
33
|
-
return handleReplacement(currentParent, 'parent', replaceWith);
|
|
34
|
-
}
|
|
35
|
-
currentParent = currentParent.parent;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return false;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
Function borrowed from shared-lib/lineage
|
|
43
|
-
*/
|
|
44
|
-
const minifyLineagesInDoc = doc => {
|
|
45
|
-
const minifyLineage = lineage => {
|
|
46
|
-
if (!lineage || !lineage._id) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const result = {
|
|
51
|
-
_id: lineage._id,
|
|
52
|
-
parent: minifyLineage(lineage.parent),
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return result;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
if (!doc) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if ('parent' in doc) {
|
|
63
|
-
doc.parent = minifyLineage(doc.parent);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if ('contact' in doc) {
|
|
67
|
-
doc.contact = minifyLineage(doc.contact);
|
|
68
|
-
if (doc.contact && !doc.contact.parent) delete doc.contact.parent; // for unit test clarity
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (doc.type === 'data_record') {
|
|
72
|
-
delete doc.patient;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const createLineageFromDoc = doc => {
|
|
77
|
-
if (!doc) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
_id: doc._id,
|
|
83
|
-
parent: doc.parent || undefined,
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/*
|
|
88
|
-
Given a lineage, return the ids therein
|
|
89
|
-
*/
|
|
90
|
-
const pluckIdsFromLineage = lineage => {
|
|
91
|
-
const result = [];
|
|
92
|
-
|
|
93
|
-
let current = lineage;
|
|
94
|
-
while (current) {
|
|
95
|
-
result.push(current._id);
|
|
96
|
-
current = current.parent;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
module.exports = {
|
|
103
|
-
createLineageFromDoc,
|
|
104
|
-
minifyLineagesInDoc,
|
|
105
|
-
pluckIdsFromLineage,
|
|
106
|
-
replaceLineage,
|
|
107
|
-
};
|