Skip to content

Hl7 38 file handling #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion server/hl7/hl7.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ function parseFile(req, res, next) {
}).catch(err =>
next(new APIError(err, httpStatus.BAD_REQUEST))
).then((data) => {
if (!data.startsWith('MSH|')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach works since (I believe) all HL7 messages have to start with the message header (MSH)

throw new Error('Please upload a valid HL7 file');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an error here like this will cause the sever to return a 500. We can instead do this:
next(new APIError('Please upload a valid HL7 file', httpStatus.BAD_REQUEST)); - this will return a 400 Bad Request

}
req.user.files.unshift({ filename: req.file.path });
const newFile = req.user.files[0];
return Promise.all([data, newFile, req.user.save()]);
Expand All @@ -91,7 +94,6 @@ function parseFile(req, res, next) {
.then(() => res.status(201).send(`Successfully uploaded ${getFileName(req.user.files[0].filename)}`))
.catch(err => next(new APIError(err, httpStatus.INTERNAL_SERVER_ERROR)));
}

/**
* Get list of user files
* @returns {files[]}
Expand Down