Skip to content

Commit

Permalink
incorporated review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kanikasharma97 committed May 7, 2024
1 parent e50c425 commit 4db4e26
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/sap/fhir/model/r4/FHIRModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ sap.ui.define([
*/
FHIRModel.prototype.submitChanges =
function(sGroupId, fnSuccessCallback, fnErrorCallback) {
var removedResources = this.getRemovedResourcesObject();
var removedResources = this._getRemovedResourcesObject();
if (typeof sGroupId === "function") {
fnErrorCallback = fnSuccessCallback;
fnSuccessCallback = FHIRUtils.deepClone(sGroupId);
Expand Down Expand Up @@ -819,8 +819,10 @@ sap.ui.define([
* Iterates through the removed resources,
* retrieves corresponding resources from the model, and returns them.
* @returns {Array<object>} An array containing the removed resources.
* @private
* @since 2.3.8
*/
FHIRModel.prototype.getRemovedResourcesObject = function () {
FHIRModel.prototype._getRemovedResourcesObject = function () {
var resources = [];
for (var type in this.mRemovedResources) {
if (this.mRemovedResources.hasOwnProperty(type)) {
Expand Down
24 changes: 14 additions & 10 deletions src/sap/fhir/model/r4/FHIRUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,16 @@ sap.ui.define([

/**
* Extracts resource IDs from the error description in FHIR OperationOutcome.
* @param {Array<object>} operationOutcomes - The array of FHIR OperationOutcome objects.
* @param {Array<object>} aOperationOutcomes - The array of FHIR OperationOutcome objects.
* @returns {Array<string>} - An array containing the extracted resource IDs.
* @private
* @since 2.3.8
*/
FHIRUtils.getsIdFromOperationOutcome = function(operationOutcomes){
FHIRUtils.getsIdFromOperationOutcome = function(aOperationOutcomes){
var sIds = [];
for (var key in operationOutcomes) {
if (operationOutcomes.hasOwnProperty(key)) {
var operationOutcome = operationOutcomes[key];
for (var key in aOperationOutcomes) {
if (aOperationOutcomes.hasOwnProperty(key)) {
var operationOutcome = aOperationOutcomes[key];
var text = operationOutcome._aIssue[0].details.text;
var sId = text.match(/[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}/);
sIds.push(sId[0]);
Expand All @@ -738,15 +740,17 @@ sap.ui.define([

/**
* Filters an array of FHIR resources by their IDs, removing those that match the provided IDs.
* @param {Array<object>} resources - The array of FHIR resources to filter.
* @param {Array<string>} sIds - The array of resource IDs to exclude from the filtered result.
* @param {Array<object>} aResources - The array of FHIR resources to filter.
* @param {Array<string>} aSIds - The array of resource IDs to exclude from the filtered result.
* @returns {Array<object>} - The filtered array of FHIR resources.
* @private
* @since 2.3.8
*/
FHIRUtils.filterResourcesByIds = function(resources, sIds) {
FHIRUtils.filterResourcesByIds = function(aResources, aSIds) {
function isIdNotIncluded(obj) {
return !sIds.includes(obj.id);
return !aSIds.includes(obj.id);
}
return resources.filter(isIdNotIncluded);
return aResources.filter(isIdNotIncluded);
};

return FHIRUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"severity": "error",
"code": "conflict",
"details": {
"text": "Referenced resource exist 'e1692049-4bdc-4e40-abb5-4eae27ce0b8b' for resource 'RolePermission}'"
"text": "Referenced resource exist 'e1692049-4bdc-4e40-abb5-4eae27ce0b8b' for resource 'Patient}'"
},
"diagnostics": "Referenced resource exist 'e1692049-4bdc-4e40-abb5-4eae27ce0b8b' for resource 'RolePermission}'"
"diagnostics": "Referenced resource exist 'e1692049-4bdc-4e40-abb5-4eae27ce0b8b' for resource 'Patient}'"
}
],
"resourceType": "OperationOutcome",
Expand Down
8 changes: 4 additions & 4 deletions test/qunit/model/FHIRModel.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,13 +923,13 @@ sap.ui.define([
QUnit.test("Test delete containing successful entry and operation outcome", function (assert) {
var oJSONData = TestUtils.loadJSONFile("BundleWithDeleteSuccessAndFailureEntries");
var done = assert.async();
var sResId = this.oFhirModel.create("RolePermission", {
resourceType: "RolePermission",
var sResId = this.oFhirModel.create("Patient", {
resourceType: "Patient",
version: "1.0.0",
name: "PersonaRead"
name: "Billy"
}, "bundle");
this.oFhirModel.mChangedResources = {};
this.oFhirModel.remove(["/RolePermission/" + sResId], undefined, "bundle");
this.oFhirModel.remove(["/Patient/" + sResId], undefined, "bundle");
var fnErrorCallback = function (oMessage, aFHIRResource, aOperationOutcome) {
assert.strictEqual(aOperationOutcome.length, 1, "Bundle error callback contains the opertion outcome of the failed entry ");
done();
Expand Down
8 changes: 4 additions & 4 deletions test/qunit/model/FHIRModel.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1504,10 +1504,10 @@ sap.ui.define([
});

QUnit.test("Test getRemovedResourcesObject returning the correct value", function (assert) {
this.oFhirModel1.mRemovedResources = { RolePermission: ["RolePermission/123"] };
this.oFhirModel1.setProperty("/RolePermission/123", { id: 123, description: "this is a test object", resourceType: "RolePermission" });
var resources = this.oFhirModel1.getRemovedResourcesObject();
assert.deepEqual(resources, [{ id: 123, description: "this is a test object", resourceType: "RolePermission" }], "Correct resources returned");
this.oFhirModel1.mRemovedResources = { Patient: ["Patient/123"] };
this.oFhirModel1.setProperty("/Patient/123", { id: 123, description: "this is a test object", resourceType: "Patient" });
var resources = this.oFhirModel1._getRemovedResourcesObject();
assert.deepEqual(resources, [{ id: 123, description: "this is a test object", resourceType: "Patient" }], "Correct resources returned");
});

});
4 changes: 2 additions & 2 deletions test/qunit/model/FHIRUtils.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ sap.ui.define(["../utils/TestUtils", "sap/fhir/model/r4/FHIRUtils"], function(Te
"severity": "error",
"code": "conflict",
"details": {
"text": "Referenced resource exist '7b4abf15-8a93-4e11-8d85-96c945530d05' for resource 'RolePermission}'"
"text": "Referenced resource exist '7b4abf15-8a93-4e11-8d85-96c945530d05' for resource 'Patient}'"
},
"diagnostics": "Referenced resource exist '7b4abf15-8a93-4e11-8d85-96c945530d05' for resource 'RolePermission}'"
"diagnostics": "Referenced resource exist '7b4abf15-8a93-4e11-8d85-96c945530d05' for resource 'Patient}'"
}
]
}
Expand Down

0 comments on commit 4db4e26

Please sign in to comment.