Bundled Exceptions

If HDR detects multiple validation errors during processing it returns them wrapped in a CommonException or a subclass of it. These validation errors may be accessed and inspected by calling getBundledExceptions() at the top-level exception.

Example 10-2 Bundled Exceptions

The following code sample illustrates how to handle bundled exceptions:

Observation focalAct = mActFactory.newObservation(ActMood.EVN,
  mDataTypeFactory.nullCD(NullFlavor.NI), 
  mDataTypeFactory.nullSET_II(NullFlavor.NI));
 
Observation obs = mActFactory.newObservation(ActMood.EVN, 
  mDataTypeFactory.nullCD(NullFlavor.NI), 
  mDataTypeFactory.nullSET_II(NullFlavor.NI));
obs.setStatusCode(mDataTypeFactory.newCS("INVALID_STATUS"));
obs.setMethodCode(mDataTypeFactory.newSET_CE(new CE[] {
  newCE("0251", "ObservationMethod"), 
  newCE("DoesNotExist", "ObservationMethod")}));
 
Observation obs2 = mActFactory.newObservation(ActMood.EVN, 
  mDataTypeFactory.nullCD(NullFlavor.NI), 
  mDataTypeFactory.nullSET_II(NullFlavor.NI));
obs2.setStatusCode(mDataTypeFactory.newCS("A_DIFFERENT_STATUS"));
 
ControlAct controlAct = mActFactory.newControlActEvent(
  mDataTypeFactory.nullCD(NullFlavor.NI), 
  mDataTypeFactory.nullSET_II(NullFlavor.NI));
 
cact.addOBActRelationship(ActRelationshipType.SUBJ, focal);
focalAct.addOBActRelationship(ActRelationshipType.COMP, obs);
focalAct.addOBActRelationship(ActRelationshipType.COMP, obs2);
 
try
{
  mRimService.submit(controlAct);
}
catch (CommonException e)
{
  StringBuffer sb = new StringBuffer();
  addExceptionDetailToBuffer(sb, e, 0);
  System.out.println(sb.toString());
}

Example 10-3 Helper Methods to Print Details of the Exception Bundle

The following code is a sample method that shows how to get exception details from bundled exceptions:

private StringBuffer addExceptionDetailToBuffer(StringBuffer sb,
            CommonException e, int indent) {
        sb.append(getIndentString(indent));
        sb.append(e.getClass().getName());
        sb.append(" ").append(e.getExceptionCode());
        sb.append(" ").append(e.getMessage());
        sb.append("\n");
 
        CommonException[] bundle = e.getBundledExceptions();
        for (int i = 0; i < bundle.length; i++) {
            sb = addExceptionDetailToBuffer(sb, bundle[i], indent + 1);
        }
 
        return sb;
    }

The following is the printed description of the exception bundle obtained from this call to RimService.submit(ControlAct):

[java] oracle.hsgbu.hdr.fwk.base.common.HDRRimException CTB_FK_MLTPL_VALIDATION_XCPTNS Multiple errors occurred processing request. [java] oracle.hsgbu.hdr.hl7.common.RimCodedAttributeException CTB_CORE_ETS_MEM_CODE_INVALID Concept code not found in concept list. [java] oracle.hsgbu.hdr.hl7.common.RimCodedAttributeException CTB_CORE_UNKNOWN_CODE Concept Code was not found for provided Code System. [java] oracle.hsgbu.hdr.hl7.common.RimCodedAttributeException CTB_CORE_ETS_MEM_CODE_INVALID Concept code not found in concept list. [java] oracle.hsgbu.hdr.hl7.rim.types.exception.common.RimDataTypeException HDR_CORE_GTS_PARSER Invalid syntax encounterd when parsing CE literal: '''ObservationMethod''';' Unexpected character O encountered at position 0 in OID literal string "ObservationMethod".