From 569fe9c755329c455da11657b3309bfd2efd88ad Mon Sep 17 00:00:00 2001
From: Seamus Lee <seamus.lee@jmaconsulting.biz>
Date: Thu, 14 May 2020 23:47:03 -0400
Subject: [PATCH 1/2] Fix error retriving primary contact details based on
 logged in user

---
 .../Form/ProviderApplicationConfirm.php       | 25 +++++++++++--------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/CRM/Aoservicelisting/Form/ProviderApplicationConfirm.php b/CRM/Aoservicelisting/Form/ProviderApplicationConfirm.php
index f060fea..06af51a 100644
--- a/CRM/Aoservicelisting/Form/ProviderApplicationConfirm.php
+++ b/CRM/Aoservicelisting/Form/ProviderApplicationConfirm.php
@@ -354,22 +354,25 @@ class CRM_Aoservicelisting_Form_ProviderApplicationConfirm extends CRM_Aoservice
       ];
       if (!empty($this->_loggedInContactID)) {
         $primaryParams['contact_id'] = $this->_loggedInContactID;
-        $primaryContact = civicrm_api3('Contact', 'getsingle', [
+        $primaryContact = civicrm_api3('Contact', 'get', [
           'id' => $this->_loggedInContactID,
           'contact_type' => 'Individual',
           'contact_sub_type' => PRIMARY_CONTACT_SUBTYPE,
           'return' => ['first_name', 'last_name', 'email'],
         ]);
-        if ($primaryContact['first_name'] != $primaryParams['first_name'] &&
-          $primaryContact['last_name'] != $primaryParams['last_name'] &&
-          $primaryContact['email'] != $primaryParams['email']
-        ) {
-          civicrm_api3('Relationship', 'get', [
-            'contact_id_a' => $this->_loggedInContactID,
-            'contact_id_b' => $organization['id'],
-            'relationship_type_id' => PRIMARY_CONTACT_REL,
-            'api.relationship.delete' => '$value.id',
-          ]);
+        if (!empty($primaryContact['values'])) {
+          $primaryContact = $primaryContact['values'][$primaryContact['id']];
+          if ($primaryContact['first_name'] != $primaryParams['first_name'] &&
+            $primaryContact['last_name'] != $primaryParams['last_name'] &&
+            $primaryContact['email'] != $primaryParams['email']
+          ) {
+            civicrm_api3('Relationship', 'get', [
+              'contact_id_a' => $this->_loggedInContactID,
+              'contact_id_b' => $organization['id'],
+              'relationship_type_id' => PRIMARY_CONTACT_REL,
+              'api.relationship.delete' => '$value.id',
+            ]);
+          }
         }
       }
       else {
-- 
GitLab


From db8b38fa4dc315fac49394ed17e73996c2f35c53 Mon Sep 17 00:00:00 2001
From: Seamus Lee <seamus.lee@jmaconsulting.biz>
Date: Fri, 15 May 2020 00:02:02 -0400
Subject: [PATCH 2/2] Ensure that if we find a match for the primary contact in
 either regulated staff or aba staff then the corret subtype is set

---
 .../Form/ProviderApplicationConfirm.php              | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/CRM/Aoservicelisting/Form/ProviderApplicationConfirm.php b/CRM/Aoservicelisting/Form/ProviderApplicationConfirm.php
index 06af51a..57f5ace 100644
--- a/CRM/Aoservicelisting/Form/ProviderApplicationConfirm.php
+++ b/CRM/Aoservicelisting/Form/ProviderApplicationConfirm.php
@@ -266,6 +266,12 @@ class CRM_Aoservicelisting_Form_ProviderApplicationConfirm extends CRM_Aoservice
           if ($values['primary_first_name'] == $values['staff_first_name'][$rowNumber] &&
             $values['primary_last_name'] == $values['staff_last_name'][$rowNumber]
           ) {
+            // Ensure that contact is set to the correct subtype.
+            civicrm_api3('Contact', 'create', [
+              'contact_type' => 'Individual',
+              'contact_sub_type' => PRIMARY_CONTACT_SUBTYPE,
+              'id' => $abaMember['id'],
+            ]);
             E::createRelationship($staffMember['id'], $organization['id'], PRIMARY_CONTACT_REL);
             E::createPhone($staffMember['id'], CRM_Utils_Array::value('phone-Primary-6', $values));
             $primaryContactFound = TRUE;
@@ -317,6 +323,12 @@ class CRM_Aoservicelisting_Form_ProviderApplicationConfirm extends CRM_Aoservice
           if ($values['primary_first_name'] == $values['aba_first_name'][$key] &&
             $values['primary_last_name'] == $values['aba_last_name'][$key]
           ) {
+            // Ensure that contact is set to the correct subtype.
+            civicrm_api3('Contact', 'create', [
+              'contact_type' => 'Individual',
+              'contact_sub_type' => PRIMARY_CONTACT_SUBTYPE,
+              'id' => $abaMember['id'],
+            ]);
             E::createRelationship($abaMember['id'], $organization['id'], PRIMARY_CONTACT_REL);
             E::createPhone($abaMember['id'], CRM_Utils_Array::value('phone-Primary-6', $values));
             $primaryContactFound = TRUE;
-- 
GitLab