Skip to content

Sample Process Module

Mads Hansen edited this page Jun 8, 2017 · 2 revisions

The PROCESS-MODULE is the property name used to designate the XQuery or JavaScript module used by the PROCESS-TASK. Typical tasks performed by the PROCESS-MODULE are to transform data or generate a report. Below is an example of each task using XQuery.

The following generates a report:

xquery version "1.0-ml";
import module namespace l-app-policy = "http://www.marklogic.com/ps/lib/l-app-policy" 
   at "/lib/l-app-policy.xqy";
      
declare namespace pb = "http://persistence.base.organization.gov";
declare namespace p = "http://persistence.ffe.organization.gov";
declare namespace b = "http://base.persistence.base.organization.gov";

declare variable $URI as xs:string external;  (: The value for this variable is passed in by CORB :)

let $doc := fn:doc($URI)
let $origAppId := $doc/p:financialPlanPolicy/p:originatingFinancialPlanIdentifier/text()
let $version := $doc/p:financialPlanPolicy/b:versionInformation/pb:versionNumber/text()  
let $ptn := $doc/p:financialPlanPolicy/p:policyTrackingNumber/text()
let $creationDate := fn:tokenize($doc/p:financialPlanPolicy/p:financialPlanPolicyCreationDateTime, "-")[1]
let $app := 
    if ($creationDate eq "2014") then 
        l-app-policy:getLinkedApplicationVersionFromPolicy($doc/p:financialPlanPolicy) 
    else ()
for $appMember in $app/p:applicationMember   
let $recordedFinancialAdviseUsage :=
      $appMember/p:recordedFinancialAdviseUsage/p:definingFinancialUseType/pb:referenceTypeCode/text()
let $missingDate := 
    if (fn:not($appMember/p:hedgeFundAccount/p:lastInvestmentDate) or 
          fn:empty($appMember/ p:hedgeFundAccount/p:lastInvestmentDate /text())) then 
      fn:true() 
    else 
      fn:false()
(: Note the string returned to CORB has two values separated by a comma 
 : which is then written to file by the ExportToFileTask 
 :) 
return 
  if ($recordedFinancialAdviseUsage eq "1" and $missingDate) then 
    fn:concat( $origAppId, ",", $ptn) 
  else ()

The following adds a node to certain documents:

xquery version "1.0-ml";
import module namespace audit = "http://ffx.ffe.gov/lib/util/audit" at "/lib/util/audit/audit.xqy";
 
declare namespace p = "http://persistence.organization.gov";

declare variable $URI as xs:string external := "/DE/gov/ffe/InsurancePlanPolicy/1151837.xml";

declare variable $DEBUG := fn:true();
declare variable $collectionName := "FFM3453_MissingSingleRelationships";

let $candidatePolicy := fn:doc($URI)/p:insurancePlanPolicy
let $subscriber := $candidatePolicy/p:coveredInsuredMember[fn:matches(./p:subscriberIndicator, "true")]
let $count := fn:count($subscriber)
return 
  if ($count eq 1) then
    let $insertionPoint :=
      if (fn:exists($subscriber/p:identifingTobaccoUseType)) then
          $subscriber/p:identifingTobaccoUseType
      else
        $subscriber/p:subscriberIndicator
    let $selfReferenceBlock :=
        element p:definingMemberAssocationTypeToSubscriber {
          element pb:referenceTypeCode { 1 },
          element pb:referenceTypeName { "ApplicationMemberAssociationReasonType" }
        }
    return
      if ($DEBUG) then
        ("ADD", $insertionPoint, $selfReferenceBlock)
      else (
        xdmp:node-insert-after( $insertionPoint, $selfReferenceBlock ),
        audit:audit($collectionName, $URI, $audit:CHANGE-TYPE-ADD, $insertionPoint, $selfReferenceBlock)
      )
  else ()