Skip to content

Commit

Permalink
#141: allow * as message type for checking auditability and response …
Browse files Browse the repository at this point in the history
…continuation in Hl7v2 transactions
  • Loading branch information
ohr committed Feb 22, 2017
1 parent a039baa commit ce2d238
Showing 1 changed file with 24 additions and 17 deletions.
Expand Up @@ -219,11 +219,13 @@ private static Map<String, Definition> createDefinitionsMap(
* Returns <code>true</code> when request messages of the given type are auditable.
*/
public boolean isAuditable(String messageType) {
Definition definition = definitions.get(true).get(messageType);
if (definition == null) {
throw new IllegalArgumentException("Unknown message type " + messageType);
try {
Definition definition = getDefinitionForMessageType(messageType, true);
return definition.auditable;
} catch (Hl7v2AcceptanceException e) {
throw new IllegalArgumentException(e);
}
return definition.auditable;

}


Expand All @@ -236,11 +238,12 @@ public boolean isAuditable(String messageType) {
* structure -- segments DSC, QAK.
*/
public boolean isContinuable(String messageType) {
Definition definition = definitions.get(true).get(messageType);
if (definition == null) {
throw new IllegalArgumentException("Unknown message type " + messageType);
try {
Definition definition = getDefinitionForMessageType(messageType, true);
return definition.responseContinuable;
} catch (Hl7v2AcceptanceException e) {
throw new IllegalArgumentException(e);
}
return definition.responseContinuable;
}


Expand Down Expand Up @@ -339,15 +342,7 @@ public void checkMessageAcceptance(
{
checkMessageVersion(version);

Definition definition = definitions.get(isRequest).get(messageType);

if (definition == null) {
definition = definitions.get(isRequest).get("*");
if (definition == null) {
throw new Hl7v2AcceptanceException("Invalid message type " + messageType + ", must be one of " +
join(definitions.get(isRequest).keySet()), ErrorCode.UNSUPPORTED_MESSAGE_TYPE);
}
}
Definition definition = getDefinitionForMessageType(messageType, isRequest);

if (! definition.isAllowedTriggerEvent(triggerEvent)) {
throw new Hl7v2AcceptanceException("Invalid trigger event " + triggerEvent + ", must be one of " +
Expand Down Expand Up @@ -383,6 +378,18 @@ public void checkMessageAcceptance(
}
}

private Definition getDefinitionForMessageType(String messageType, boolean isRequest) throws Hl7v2AcceptanceException {
Definition definition = definitions.get(isRequest).get(messageType);
if (definition == null) {
definition = definitions.get(isRequest).get("*");
if (definition == null) {
throw new Hl7v2AcceptanceException("Invalid message type " + messageType + ", must be one of " +
join(definitions.get(isRequest).keySet()), ErrorCode.UNSUPPORTED_MESSAGE_TYPE);
}
}
return definition;
}

private void checkMessageVersion(String version) throws Hl7v2AcceptanceException {
Version messageVersion = Version.versionOf(version);
if (! ArrayUtils.contains(hl7Versions, messageVersion)) {
Expand Down

0 comments on commit ce2d238

Please sign in to comment.