Example: Implementing a Dynamic Selection Query

Step 1: Create a new UIM that contains the required selection criteria.

This screen allows the audit coordinator to enter selection criteria relating to the dynamic query.

Figure 1. UIM to allow the audit coordinator to enter selection criteria
<PAGE
  PAGE_ID="exampleSelectionCriteria"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="file://Curam/UIMSchema.xsd"
>

  <PAGE_TITLE>
    <CONNECT
      <SOURCE
        NAME="TEXT"
        PROPERTY="PageTitle.Title"
      />
    </CONNECT>
  </PAGE_TITLE>

  <SERVER_INTERFACE
    CLASS="ExampleFacade"
    NAME="ACTION"
    OPERATION="validateCustomCriteria"
    PHASE="ACTION"
  />

  <PAGE_PARAMETER NAME="auditPlanID"/>
  <PAGE_PARAMETER NAME="queryID"/>

  <ACTION_SET
    ALIGNMENT="CENTER"
    TOP="false"
  >
    <ACTION_CONTROL 
      LABEL="ActionControl.Label.Cancel" 
      ALIGNMENT="LEFT"/>
    
    <ACTION_CONTROL
      DEFAULT="true"
      IMAGE="NextButton"
      LABEL="ActionControl.Label.Next"
      TYPE="SUBMIT"
    >
      <LINK
        SAVE_LINK="false"
        DISMISS_MODAL="false"
        PAGE_ID="exampleSelectAmount"
      >
        <CONNECT>
          <SOURCE
            NAME="PAGE"
            PROPERTY="auditPlanID"
          />
          <TARGET
            NAME="PAGE"
            PROPERTY="auditPlanID"
          />
        </CONNECT>
        <CONNECT>
          <SOURCE
            NAME="ACTION"
            PROPERTY="result$status"
          />
          <TARGET
            NAME="PAGE"
            PROPERTY="status"
          />
        </CONNECT>
        <CONNECT>
          <SOURCE
            NAME="PAGE"
            PROPERTY="queryID"
          />
          <TARGET
            NAME="PAGE"
            PROPERTY="queryID"
          />
        </CONNECT>
      </LINK>
    </ACTION_CONTROL>
  </ACTION_SET>

  <CLUSTER LABEL_WIDTH="30">
    <FIELD
      LABEL="Field.Label.Status"
      USE_BLANK="true"
      USE_DEFAULT="false">
      <CONNECT>
        <TARGET
          NAME="ACTION"
          PROPERTY="key$status"
        />
      </CONNECT>
    </FIELD>
  </CLUSTER>
  </PAGE>

Step 2: If required, create a screen to allow the audit coordinator enter the number of cases to audit.

Figure 2. UIM to allow the audit coordinator choose how much of the generated case sample to audit
<PAGE
  PAGE_ID="exampleSelectAmount"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="file://Curam/UIMSchema.xsd"
>

  <PAGE_TITLE>
    <CONNECT>
      <SOURCE
        NAME="TEXT"
        PROPERTY="PageTitle.Title"
      />
    </CONNECT>
  </PAGE_TITLE>

  <SERVER_INTERFACE
    CLASS="ExampleFacade"
    NAME="ACTION"
    OPERATION="validateNumberOfCases"
    PHASE="ACTION"
  />

  <PAGE_PARAMETER NAME="auditPlanID"/>
  <PAGE_PARAMETER NAME="status"/>
  <PAGE_PARAMETER NAME="queryID"/>

  <CLUSTER
    DESCRIPTION="Cluster.Description.Text"
    LABEL_WIDTH="30">
    
    <FIELD LABEL="Field.Label.Number">
      <CONNECT>
        <TARGET
          NAME="ACTION"
          PROPERTY="key$numberOfCases"
        />
      </CONNECT>
    </FIELD>
  </CLUSTER>


  <ACTION_SET
    TOP="false"
  >
    <ACTION_CONTROL 
    LABEL="ActionControl.Label.Cancel" 
    ALIGNMENT="LEFT"/>
    <ACTION_CONTROL
      DEFAULT="true"
      IMAGE="NextButton"
      LABEL="ActionControl.Label.Next"
      TYPE="SUBMIT"
    >
      <LINK
        SAVE_LINK="false"
        DISMISS_MODAL="false"
        PAGE_ID="exampleConfigureAlgorithm"
      >
        <CONNECT>
          <SOURCE
            NAME="PAGE"
            PROPERTY="auditPlanID"
          />
          <TARGET
            NAME="PAGE"
            PROPERTY="auditPlanID"
          />
        </CONNECT>
        <CONNECT>
          <SOURCE
            NAME="PAGE"
            PROPERTY="status"
          />
          <TARGET
            NAME="PAGE"
            PROPERTY="status"
          />
        </CONNECT>
        <CONNECT>
          <SOURCE
            NAME="ACTION"
            PROPERTY="result$numberOfCases"
          />
          <TARGET
            NAME="PAGE"
            PROPERTY="numberOfCases"
          />
        </CONNECT>
        <CONNECT>
          <SOURCE
            NAME="PAGE"
            PROPERTY="queryID"
          />
          <TARGET
            NAME="PAGE"
            PROPERTY="queryID"
          />
        </CONNECT>
      </LINK>
    </ACTION_CONTROL>
  </ACTION_SET>
</PAGE>

If required, create a screen to allow the audit coordinator enter algorithm parameters.

Figure 3. UIM to allow the audit coordinator to specify configurable parameters for the algorithm
<PAGE
  PAGE_ID="exampleConfigureAlgorithm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="file://Curam/UIMSchema.xsd"
>

  <PAGE_TITLE>
    <CONNECT>
      <SOURCE
        NAME="TEXT"
        PROPERTY="PageTitle.Title"
      />
    </CONNECT>
  </PAGE_TITLE>

  <SERVER_INTERFACE
    CLASS="ExampleFacade"
    NAME="ACTION"
    OPERATION="generateExampleCaseList"
    PHASE="ACTION"
  />

  <PAGE_PARAMETER NAME="auditPlanID"/>
  <PAGE_PARAMETER NAME="status"/>
  <PAGE_PARAMETER NAME="numberOfCases"/>
  <PAGE_PARAMETER NAME="queryID"/>

  <CONNECT>
    <SOURCE
      NAME="PAGE"
      PROPERTY="auditPlanID"
    />
    <TARGET
      NAME="ACTION"
      PROPERTY="key$auditPlanID"
    />
  </CONNECT>
  <CONNECT>
    <SOURCE
      NAME="PAGE"
      PROPERTY="status"
    />
    <TARGET
      NAME="ACTION"
      PROPERTY="key$status"
    />
  </CONNECT>
  <CONNECT>
    <SOURCE
      NAME="PAGE"
      PROPERTY="numberOfCases"
    />
    <TARGET
      NAME="ACTION"
      PROPERTY="key$numberOfCases"
    />
  </CONNECT>
  <CONNECT>
    <SOURCE
      NAME="PAGE"
      PROPERTY="queryID"
    />
    <TARGET
      NAME="ACTION"
      PROPERTY="key$selectionQueryID"
    />
  </CONNECT>

  <CLUSTER LABEL_WIDTH="30">
    <FIELD LABEL="Field.Label.Interval">
      <CONNECT>
        <TARGET
          NAME="ACTION"
          PROPERTY="key$interval"
        />
      </CONNECT>
    </FIELD>
  </CLUSTER>


  <ACTION_SET
    TOP="false"
  >
    <ACTION_CONTROL 
    LABEL="ActionControl.Label.Cancel" 
    ALIGNMENT="LEFT"/>
    <ACTION_CONTROL
      IMAGE="FinishButton"
      LABEL="ActionControl.Label.Finish"
      TYPE="SUBMIT"
    />
  </ACTION_SET>
</PAGE>

Step 3: Create the necessary struct to cater for the selection criteria.

This struct contains all selection criteria available for the selection query along with any other required parameters.

ExampleSelectionCriteria

Step 4: Create and implement a new façade method that is responsible for generating the list of cases for audit.

This method uses the Case Audit Query Management API to execute the dynamic query, using the supplied selection criteria. This returns the list of cases matching the selection criteria. The relevant algorithm is then invoked to filter the case list. Finally, case audit records are created for each case in the remaining list.

Figure 4. Generating the list of cases for audit
// Inject the map
  @Inject
  private Map<SAMPLINGSTRATEGYEntry, SamplingStrategy> 
    samplingStrategies;

  /**
   * Generates the sample list of cases for audit based on the 
   * supplied selection criteria. This method filters the list 
   * using the algorithm associated with the case type for this 
   * audit plan. The number of cases returned in the list is also 
   * restricted by the number of cases specified by the user.
   *
   * @param key The selection criteria, selection query 
   *            identifier, the audit plan identifier, 
   *            the number of cases to generate and any 
   *            algorithm parameters.
   * 
   * @throws AppException
   * @throws InformationalException
   */
  public void generateExampleCaseList(
    ExampleSelectionCriteria key)
    throws AppException, InformationalException {
    
    AuditPlan auditPlan = auditPlanDAO.get(key.auditPlanID);
    
    CaseAuditQueryManagement caseAuditQueryManagement = 
      new CaseAuditQueryManagement();
    
    // Add all selection criteria to the map
    HashMap<String, String> parameterMap = 
      new HashMap<String, String>();
    parameterMap.put(":statusCode", key.status);
    
    // Call the Case Audit Query Management API 
    // to run the selection query
    List<curam.piwrapper.caseheader.impl.CaseHeader> caseList =
      caseAuditQueryManagement.runDynamicQueryCaseSearch(
        key.selectionQueryID, parameterMap);
    
    // Get the algorithm/sampling strategy configured 
    // for this case type
    final SamplingStrategy samplingStrategy = 
      samplingStrategies.get(
        auditPlan.getAuditCaseConfig().getAuditAlgorithm());

    List<Long> caseIDList = new ArrayList<Long>();

    for (CaseHeader caseHeader : caseList) {
      caseIDList.add(caseHeader.getID());
    }

    // Set up the algorithm parameters
    Map<String, Object> params = new TreeMap<String, Object>();
    params.put("n", new Integer(key.interval));

    // Invoke algorithm to generate case sample, 
    // passing in the list of cases,
    // the number of cases to return and the algorithm parameters
    List<Long> caseIDs = samplingStrategy.getRandomSample(
      caseIDList, key.numberOfCases, params);

    curam.core.facade.intf.CaseAudit caseAuditObj =
      curam.core.facade.fact.CaseAuditFactory.newInstance();

    // for each case, create a case audit
    for (int i = 0; i < caseIDs.size(); i++) {

      CaseAuditDetails caseAuditDetails = new CaseAuditDetails();
      caseAuditDetails.dtls.auditPlanID = key.auditPlanID;
      caseAuditDetails.dtls.caseID = caseIDs.get(i);
      caseAuditObj.createCaseAudit(caseAuditDetails);
    }

  }

Step 5: The systems administrator must create, validate and publish a new Selection Query with the SQL required to retrieve the relevant data and the selection criteria associated with it.

Important: Appropriate database indexing should be provided for any custom dynamic selection queries. Also, if a significant case load is expected to be returned from the selection query, it would be advisable to consider using Deferred Processing to generate the random sample of cases. For more information on Deferred Processing, please see the Cúram Server Developer Guide.