11 HDR Exception Handling

HDR provides a hierarchy of exception classes, which allow users to distinguish between validation errors and system errors (For example, locking errors, session timeout errors, and unexpected errors). All exception classes extend from the CommonException class.

To obtain information about as many issues as possible, exceptions may be received as a bundle with each child exception representing a different issue.

HDR translates server-side root cause exception to equivalent CommonException in the client-side EJB exception.

Note:

The mapping between the server-side exception to the equivalent client ETSException or its subclass is mentioned in the ExceptionConversionRules.txt file (available at <HDR_HOME>/hdr_exploded_app/oracle/apps/ctb/fwk/ex/server/ExceptionConversionRules.txt).

The code samples below help you to manage the following scenarios:

Optimistic Locking Exceptions

If HDR receives an OptimisticLockException from the underlying JPA framework, it wraps the exception in oracle.hsgbu.hdr.base.persist.exception.CorePersistenceException with error code HDR_OBJECT_ALREADY_MODIFIED_ERROR. The client application should attempt to query again if necessary and resubmit updates to HDR.

Example 11-1 Optimistic Locking Exception

The following code sample illustrates an optimistic locking exception:

// create an Act
SET_II actId = dataTypeFactory.newSET_II("9.989898.5.6.100", "OBS1001", true);
Act act = actFactory.newObservation(ActMood.EVN, null, actId);
ControlAct controlAct = actFactory.newControlActEvent(
  dataTypeFactory.nullCD(NullFlavor.NI), dataTypeFactory.nullSET_II(NullFlavor.NI));
controlAct.addOBActRelationship(ActRelationshipType.SUBJ, act);
rimService().submit(controlAct); 
 
// retrieve two copies of the Act
Act retrievedAct1 = retrieveAct(actId);
Act retrievedAct2 = retrieveAct(actId);
 
// update the Act
ControlAct controlAct2 = actFactory.newControlActEvent(
  dataTypeFactory.nullCD(NullFlavor.NI), dataTypeFactory.nullSET_II(NullFlavor.NI));
controlAct2.addOBActRelationship(ActRelationshipType.SUBJ, (Act)retrievedAct1.createNewVersion());
rimService().submit(controlAct2); 
 
// try updating the same Act with the other retrieved copy
ControlAct controlAct3 = actFactory.newControlActEvent(
  dataTypeFactory.nullCD(NullFlavor.NI), dataTypeFactory.nullSET_II(NullFlavor.NI));
controlAct3.addOBActRelationship(ActRelationshipType.SUBJ, (Act)retrievedAct2.createNewVersion());
try
{ 
  rimService.submit(controlAct3);
}
catch (CTBLockingException e)
{
  // One or more objects in the submission 
  // are locked by another process.
  //
  // Requery if necessary, and resubmit 
  // updates to HDR.
  //
  // In this case, we know the object is 
  // the Observation which was queried and
  // versioned, but this can be verified by
  // inspecting the Exception
 
  Act requeriedAct = retrieveAct(actId);
  ControlAct newControlAct = actFactory.newControlActEvent(
    dataTypeFactory.nullCD(NullFlavor.NI), dataTypeFactory.nullSET_II(NullFlavor.NI));
  newControlAct.addOBActRelationship(ActRelationshipType.SUBJ, (Act)requeriedAct.createNewVersion());
  rimService.submit(newControlAct);
}

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 11-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 11-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".