Skip to content

Commit

Permalink
feat: change unique way of bundle
Browse files Browse the repository at this point in the history
- Rule: FullUrl must be unique in a bundle,
or else entries with the same fullUrl must have different meta.versionId
(except in history bundles)
  • Loading branch information
Chinlinlee committed Oct 8, 2023
1 parent f09ca1f commit 6682fd3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion models/FHIR/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,18 @@ function createBundle(req, docs, count, skip, limit, resource, option) {
bundle.entry.push(entry);
}
}
bundle.entry = _.uniqBy(bundle.entry, "fullUrl");

if (type === "history") {
// entries with the same fullUrl must have different meta.versionId (except in history bundles)
bundle.entry = _.uniqWith(bundle.entry, (a , b) => {
return a.resource.id === b.resource.id &&
a.resource.meta.versionId === b.resource.meta.versionId;
});
} else {
// FullUrl must be unique in a bundle
bundle.entry = _.uniqBy(bundle.entry, "fullUrl");
}

if (bundle.entry.length == 0) {
delete bundle.entry;
}
Expand Down

0 comments on commit 6682fd3

Please sign in to comment.