Skip to content

Commit

Permalink
refactor: rename doc to result for consistency, remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Oct 10, 2023
1 parent e2b80dd commit 49855f8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
5 changes: 1 addition & 4 deletions api/FHIRApiService/services/base.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class BaseFhirApiService {
getResourceChangeFailureOperationOutcomeMsg(err) {
logger.error(err);

if (_.get(err, "resourceType", "") === "OperationOutcome")
return err;

let operationOutcomeMessage;
if (_.get(err, "message.code") === 11000) {
operationOutcomeMessage = {
Expand Down Expand Up @@ -100,7 +97,7 @@ class BaseFhirApiService {
if (this._pretty) xmlItem = xmlFormatter(xmlItem);
return this.response.status(code).send(xmlItem);
}

return this.response.status(code).send(item);
}

Expand Down
12 changes: 4 additions & 8 deletions api/FHIRApiService/services/bundle-operations.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,11 @@ class TransactionUpdateHandler extends BaseTransactionHandler {
let validation = await BaseFhirApiService.validateRequestResource(this.resource);
if (!validation.status) throw new FhirValidationError(validation.result);

let { code, doc } = await UpdateService.insertOrUpdateResource(this.resourceType, this.resource, getIdInFullUrl(this.fullUrl), this.transaction);
this.replaceIdInEntry(doc);
let { code, result } = await UpdateService.insertOrUpdateResource(this.resourceType, this.resource, getIdInFullUrl(this.fullUrl), this.transaction);
this.replaceIdInEntry(result);

if (_.get(doc, "resourceType") === "OperationOutcome" && code === 422) {
await this.transaction.abortTransaction();
throw new FhirValidationError(doc.result);
}
let reqBaseUrl = `${this.bundleOpService.request.protocol}://${this.bundleOpService.request.get('host')}/`;
let fullAbsoluteUrl = urlJoin(`/${process.env.FHIRSERVER_APIPATH}/${this.resourceType}/${getIdInFullUrl(this.fullUrl)}/_history/${doc.meta.versionId}`, reqBaseUrl);
let fullAbsoluteUrl = urlJoin(`/${process.env.FHIRSERVER_APIPATH}/${this.resourceType}/${getIdInFullUrl(this.fullUrl)}/_history/${result.meta.versionId}`, reqBaseUrl);
this.bundleOpService.bundleResponse.push({
response: {
status: code.toString(),
Expand All @@ -304,7 +300,7 @@ class TransactionUpdateHandler extends BaseTransactionHandler {
}
});

return { code, result: doc };
return { code, result };
}
}

Expand Down
7 changes: 4 additions & 3 deletions api/FHIRApiService/services/update.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class UpdateService extends BaseFhirApiService {
return await UpdateService.insertOrUpdateResource(this.resourceType, resourceClone, this.resourceId);

} catch (e) {
logger.error(`[Error: ${JSON.stringify(e)}] [Resource Type: ${this.resourceType}]`);
return {
status: false,
code: 500,
doc: e
result: e
};
}
}
Expand Down Expand Up @@ -82,7 +83,7 @@ class UpdateService extends BaseFhirApiService {
return {
status: true,
code: 200,
doc: newDoc.value.getFHIRField()
result: newDoc.value.getFHIRField()
};
}

Expand All @@ -94,7 +95,7 @@ class UpdateService extends BaseFhirApiService {
return {
status: true,
code: 201,
doc: doc.getFHIRField()
result: doc.getFHIRField()
};
}

Expand Down

0 comments on commit 49855f8

Please sign in to comment.