Skip to content

Commit

Permalink
Error handling on segment.getComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
maur1th committed Feb 5, 2016
1 parent 68a4680 commit a362dea
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/hl7/segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ segment.prototype.getField = function(index) {
}

segment.prototype.getComponent = function(fieldIndex, componentIndex) {
return this.fields[fieldIndex - 1].value[0][componentIndex - 1].value[0];
var field = this.getField(fieldIndex);
if (field && field[componentIndex - 1]) {
return field[componentIndex - 1].value[0];
} else {
return '';
}
}

segment.prototype.toString = function(delimiters) {
Expand Down

0 comments on commit a362dea

Please sign in to comment.