Sidebar
0 votes
441 views
by brandon-w-8204 (34.1k points)

1 Answer

0 votes

Here is a published function that can be used to get the Registry information from CPS.

function cemRetrieveConsentInfo(patientId,subscription,dbName,cpsVersion) {
   
   //Get PID
   var pid = '';
   var pidResult;
   if (StringUtils.equalsIgnoreCase(cpsVersion, 'EMR98')) {
      pidResult = qie.doQuery(dbName,
      "SELECT p.pid \n" +
         "   FROM PatientProfile p\n" +
         "   WHERE p.patientid = '" + patientId + "'");
      pid = pidResult.getNode("pid");
      if (pid.length() > 0 ) {
         messageCache.setValue('pid', pid);
      } else {
         throw 'Patient ID ' + patientId + ' not found in database';
      }
   } else if (StringUtils.equalsIgnoreCase(cpsVersion, 'CPS12')) {
      pidResult = qie.doQuery(dbName,
      "SELECT p.pid \n" +
         "   FROM Person p\n" +
         "   WHERE p.patientid = '" + patientId + "'");
      pid = pidResult.getNode("pid");
      if (pid.length() > 0 ) {
         messageCache.setValue('pid', pid);
      } else {
         throw 'Patient ID ' + patientId + ' not found in database';
      }
   } else {
      throw 'cpsVersion "' + cpsVersion + '" not valid. Expected values EMR98 and CPS12';
   }
   
   //Determine if registry/subcription exists
   var subscriptionInfo = qie.doQuery(
      dbName,
      "select CEM_SubscriptionID, RegistryOptInByDefault\n" +
         "from CEM_Subscription\n" +
         "where Name = '" + subscription + "'");
      qie.debug('subscriptionInfo.getRowCount(): ' + subscriptionInfo.getRowCount());
      if (subscriptionInfo.getRowCount() === 0) {
         throw 'Registry/Subscription "' + subscription + '" not found in dbName "' + dbName + '"';
      }
      
      var optInByDefault = subscriptionInfo.getNode('RegistryOptInByDefault');
      var subscriptionId = subscriptionInfo.getNode('CEM_SubscriptionID');
      
      //Get Patient Specific Record
      var patientRegistryInfo = qie.doQuery(
         dbName,
         "select OptOut, OptOutDate, OptInDate\n" +
            "from PatientRegistry pr\n" +
            "where pr.pid = " + pid);
         
         var consent = '';
         var consentDate = '';
         //Determine if optout or optin
         if (patientRegistryInfo.getRowCount() > 0) {
            if (StringUtils.equalsIgnoreCase(patientRegistryInfo.getNode('OptOut'), 'true')) {
               consent = 'N';
               consentDate = patientRegistryInfo.getNode('OptOutDate');
            } else if (StringUtils.equalsIgnoreCase(patientRegistryInfo.getNode('OptOut'), 'false')) {
               consent = 'Y';
               consentDate = patientRegistryInfo.getNode('OptInDate');
            }
         } else {
            if (StringUtils.equalsIgnoreCase(optInByDefault, 'Y')) {
               consent = 'Y';
               consentDate = '';
            } else {
               consent = 'N';
               consentDate = '';
            }
         }
         
         //Return Consent and Consent Date
         return [consent, consentDate];
}
 
This will return an array with the consent  and date.
 
Here is an example of calling the published function and getting the result.
var consentInfo = cemRetrieveConsentInfo(
   source.getNode('PID-3.1'),
   'Qvera Consent Test',
   messageCache.getValue('dbName'),
   'CPS12');
   
   qie.debug('consent: ' + consentInfo[0]);
   qie.debug('consentDate: ' + consentInfo[1]);

 

by brandon-w-8204 (34.1k points)
...