Skip to content

Commit

Permalink
Merge pull request #1350 from bcgov/EDRD-PH1_Sept24Release_defectsFix…
Browse files Browse the repository at this point in the history
…ingBranch

Adding NULL check for dataload
  • Loading branch information
deepakmulamalla authored Sep 24, 2024
2 parents cf82add + cb38717 commit a344f6b
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 37 deletions.
60 changes: 60 additions & 0 deletions dev-app-post/main/default/classes/UserTriggerHandlerTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**********************************************************************************************
* @Author: Accenture
* @Date: 24 Sept 2024
* @Description: The purpose of this class is to cover Code coverage of UserTriggerHandler
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description]
24Sept - EDRD-911 - Deepak - Added activateACROnEDRDPortalEnable_Test method
***********************************************************************************************/
@isTest
public class UserTriggerHandlerTest {

/**
* @author: Deepak
* @date: 24 Sept 2024
* @description: The purpose of this method is to cover Testcoverage of activateACROnAccportalEnable
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
@isTest
public static void activateACROnEDRDPortalEnable_Test(){
Account patientAcc1 = TestFactory.newPatient('Patient1');
insert patientAcc1;
Account providerAcc = TestFactory.newProvider('Provider Test');
insert providerAcc;

Id patientContactId = [SELECT Id FROM Contact Where accountId =: patientAcc1.Id].get(0).Id;
AccountContactRelation ACRObj = new AccountContactRelation();
ACRObj.AccountId = providerAcc.Id;
ACRObj.ContactId = patientContactId;
ACRObj.Roles = ESA_cls_constants.EDRD_PHYSICIAN;
ACRObj.IsActive = false;
ACRObj.Is_EDRD_Data_Migration__c = true;
insert ACRObj;

Profile profileObj = [SELECT Id FROM Profile WHERE Name =: ESA_cls_constants.EDRD_PRESCRIBER_COMMUNITY_USER LIMIT 1];
Id ContactId = [SELECT Id FROM Contact WHERE AccountID =: providerAcc.Id].get(0).Id;
User accCommunityUser = TestFactory.createCommunityUser(ContactId, profileObj.Id, 'Provider', 'Test');

Test.startTest();
insert accCommunityUser;
Test.stopTest();

List<User> communityUser = [SELECT Id FROM User WHERE Id =: accCommunityUser.Id LIMIT 1];

List<Account> accUser = [SELECT Id, IsCustomerPortal FROM Account WHERE Id =: providerAcc.Id LIMIT 1];

List<AccountContactRelation> aCRList = [SELECT Id, AccountId, ContactId, Roles, Is_EDRD_Data_Migration__c, IsActive
FROM AccountContactRelation
WHERE AccountID =: providerAcc.Id LIMIT 1];

List<AccountShare> accShareList1 = [SELECT Id, AccountId, UserOrGroupId, RowCause, AccountAccessLevel
FROM AccountShare WHERE AccountId =: patientAcc1.Id
AND UserOrGroupId =: accCommunityUser.Id LIMIT 1];

Assert.areEqual(accUser[0].IsCustomerPortal, True, 'Portal User should be Active');
Assert.areEqual(aCRList[0].isActive, True, 'ACR should be Active');
Assert.areEqual(accShareList1[0].AccountAccessLevel, 'Edit', 'AccountShare access level should be Edit');
Assert.areEqual(accShareList1.size(), 1, 'AccountShare should have been created for the Patient');
Assert.areNotEqual(accShareList1.isEmpty(), true, 'AccountShare list should not be empty');
Assert.areNotEqual(accShareList1[0].UserOrGroupId, null, 'UserOrGroupId should not be null');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public with sharing class AccountContactRelationTriggerHandler {
* @date: 21 Aug 2024
* @description: The purpose of this method is to share patient records with provider on ACR insert.
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
20Sept - EDRD-911 - Deepak - Adding NULL Check
*/
public static void createPatientShare(List<AccountContactRelation> aCRList){
Map<Id, Id> providerIdVsPatientId = new Map<Id, Id>();
Expand All @@ -19,32 +20,36 @@ public with sharing class AccountContactRelationTriggerHandler {
List<AccountShare> accShareListToInsert = new List<AccountShare>();

for(AccountContactRelation aCRObj : aCRList){
if(aCRObj.Is_Person_Account__c && !String.IsEmpty(aCRObj.Roles) && aCRObj.Roles.containsIgnoreCase('Physician')){
if(aCRObj.Is_Person_Account__c && !String.IsEmpty(aCRObj.Roles) && aCRObj.Roles.containsIgnoreCase(ESA_cls_constants.EDRD_PHYSICIAN) && !aCRObj.Is_EDRD_Data_Migration__c){
providerIdVsPatientId.put(aCrObj.AccountId , acrObj.ContactAccountId__c);
}
}

providerIdVsRec = new Map<Id, User>([SELECT Id, Contact.AccountId From User
WHERE contact.AccountId IN: providerIdVsPatientId.keySet()]);
if(!providerIdVsPatientId.isEmpty()){
providerIdVsRec = new Map<Id, User>([SELECT Id, Contact.AccountId FROM User
WHERE Contact.AccountId IN :providerIdVsPatientId.keySet()]);
}

for(User userObj : providerIdVsRec.values()){
if(!providerIdVsUserIdSet.containsKey(userObj.Contact.AccountId)){
providerIdVsUserIdSet.put(userObj.Contact.AccountId, new Set<Id>());
if(!providerIdVsRec.isEmpty()){
for(User userObj : providerIdVsRec.values()){
if(!providerIdVsUserIdSet.containsKey(userObj.Contact.AccountId)){
providerIdVsUserIdSet.put(userObj.Contact.AccountId, new Set<Id>());
}

providerIdVsUserIdSet.get(userObj.Contact.AccountId).add(userObj.Id);
}

providerIdVsUserIdSet.get(userObj.Contact.AccountId).add(userObj.Id);
}

for(Id providerId: providerIdVsPatientId.keySet()){
for(Id userId: providerIdVsUserIdSet.get(providerId)){
accShareListToInsert.add(new AccountShare(AccountId = providerIdVsPatientId.get(providerId),
AccountAccessLevel = 'Edit', UserOrGroupId = UserId,
OpportunityAccessLevel = 'None'));
for(Id providerId: providerIdVsPatientId.keySet()){
for(Id userId: providerIdVsUserIdSet.get(providerId)){
accShareListToInsert.add(new AccountShare(AccountId = providerIdVsPatientId.get(providerId),
AccountAccessLevel = 'Edit', UserOrGroupId = UserId,
OpportunityAccessLevel = 'None'));
}
}

if(!accShareListToInsert.isEmpty()){
AccountContactShareHelper.insertAccountShares(accShareListToInsert);
}
}

if(!accShareListToInsert.isEmpty()){
AccountContactShareHelper.insertAccountShares(accShareListToInsert);
}
}

Expand All @@ -57,14 +62,14 @@ public with sharing class AccountContactRelationTriggerHandler {
public static void removePatientShare(List<AccountContactRelation> aCRList){
Map<Id, Id> providerIdVsPatientId = new Map<Id, Id>();

for(AccountContactRelation aCRObj : aCRList){
if(aCRObj.Is_Person_Account__c && !String.IsEmpty(aCRObj.Roles) && aCRObj.Roles.containsIgnoreCase('Physician')){
providerIdVsPatientId.put(aCRObj.AccountId , aCRObj.ContactAccountId__c);
for(AccountContactRelation aCRObj: aCRList){
if(aCRObj.Is_Person_Account__c && !String.IsEmpty(aCRObj.Roles) && aCRObj.Roles.containsIgnoreCase(ESA_cls_constants.EDRD_PHYSICIAN)){
providerIdVsPatientId.put(aCRObj.AccountId, aCRObj.ContactAccountId__c);
}
}

if(!providerIdVsPatientId.isEmpty()){
List<AccountShare> accShareList = [SELECT Id FROM AccountShare WHERE AccountId IN :providerIdVsPatientId.values()
List<AccountShare> accShareList = [SELECT Id FROM AccountShare WHERE AccountId IN :providerIdVsPatientId.values()
AND UserOrGroupId IN
(SELECT Id FROM User WHERE Contact.AccountId IN :providerIdVsPatientId.keySet())];

Expand All @@ -80,19 +85,19 @@ public with sharing class AccountContactRelationTriggerHandler {
* @description: The purpose of this method is to update patient record shared with provider on ACR update.
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
public static void updatePatientShare(Map<Id,AccountContactRelation> oldACRMap, Map<Id,AccountContactRelation> newACRMap){
public static void updatePatientShare(Map<Id, AccountContactRelation> oldACRMap, Map<Id, AccountContactRelation> newACRMap){
Map<Id, Id> providerIdVsPatientId = new Map<Id, Id>();
List<AccountContactRelation> accShareListToInsert = new List<AccountContactRelation>();

for(AccountContactRelation aCRObj : newACRMap.values()){
if(aCRObj.Is_Person_Account__c && !String.IsEmpty(aCRObj.Roles) && aCRObj.Roles.containsIgnoreCase('Physician') && aCRObj.IsActive){
providerIdVsPatientId.put(aCRObj.AccountId , aCRObj.ContactAccountId__c);
if(aCRObj.Is_Person_Account__c && !String.IsEmpty(aCRObj.Roles) && aCRObj.Roles.containsIgnoreCase(ESA_cls_constants.EDRD_PHYSICIAN) && aCRObj.IsActive){
providerIdVsPatientId.put(aCRObj.AccountId, aCRObj.ContactAccountId__c);
accShareListToInsert.add(aCRObj);
}
}

if(!providerIdVsPatientId.isEmpty()){
List<AccountShare> accShareList = [SELECT Id FROM AccountShare WHERE AccountId IN :providerIdVsPatientId.values()
List<AccountShare> accShareList = [SELECT Id FROM AccountShare WHERE AccountId IN :providerIdVsPatientId.values()
AND UserOrGroupId IN
(SELECT Id FROM User WHERE Contact.AccountId IN :providerIdVsPatientId.keySet())];

Expand Down
16 changes: 8 additions & 8 deletions force-app/main/default/classes/AccountContactShareHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public without sharing class AccountContactShareHelper {
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
public static void insertAccountShares(List<AccountShare> accShareListToInsert) {
if (!accShareListToInsert.isEmpty()) {
try {
try {
if (!accShareListToInsert.isEmpty()) {
Database.insert(accShareListToInsert, true);
} catch (DmlException e) {
System.debug('Error inserting AccountShare records: ' + e.getMessage());
}
} catch (DmlException e) {
System.debug('Error inserting AccountShare records: ' + e.getMessage());
}
}

Expand All @@ -31,12 +31,12 @@ public without sharing class AccountContactShareHelper {
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
public static void deleteAccountShares(List<AccountShare> accShareList) {
if (!accShareList.isEmpty()) {
try {
try {
if (!accShareList.isEmpty()) {
Database.delete(accShareList, true);
} catch (DmlException e) {
System.debug('Error deleting AccountShare records: ' + e.getMessage());
}
} catch (DmlException e) {
System.debug('Error deleting AccountShare records: ' + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public with sharing class ESA_cls_accountTriggerHandler {
Set<Id> patientIdSet = new Set<Id>();
for(account patientRec: newAccountList){
Boolean isPatientDeceasedChange = (oldAccountMap.get(patientRec.Id).Patient_is_Deceased__pc != newAccountMap.get(patientRec.Id).Patient_is_Deceased__pc
&& !newAccountMap.get(patientRec.Id).Patient_is_Deceased__pc);
&& newAccountMap.get(patientRec.Id).Patient_is_Deceased__pc);

if(isPatientDeceasedChange){
patientIdSet.add(patientRec.Id);
Expand Down
4 changes: 4 additions & 0 deletions force-app/main/default/classes/ESA_cls_constants.cls
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ public class ESA_cls_constants {
public static final String EDRD_CASE_STATUS_CANCELLED = 'Cancelled';
public static final String EDRD_CASE_CLOSER_REASON_PATIENT_DECEASED = 'Patient Deceased';
public static final String EDRD_CASE_MOHFUNDING_DENIED = 'Denied';
public static final String EDRD_CASE_STATUS_FUNDING_APPROVED = 'Funding Approved';
public static final String EDRD_PROVIDER = 'Provider';
public static final String EDRD_PRESCRIBER_COMMUNITY_USER = 'EDRD Prescriber Community User';
public static final String EDRD_PHYSICIAN = 'Physician';
}
62 changes: 62 additions & 0 deletions force-app/main/default/classes/UserTriggerHandler.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**********************************************************************************************
* @Author: Accenture
* @Date: 24 Sept 2024
* @Description: The purpose of this class is to create methods which can be used by different trigger event
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description]
24Sept - EDRD-911 - Accenture - Added activateACROnEDRDPortalEnable method
***********************************************************************************************/
public with sharing class UserTriggerHandler {
public static Id eDRDPrescriberProfileId = [SELECT Id FROM Profile WHERE Name =: ESA_cls_constants.EDRD_PRESCRIBER_COMMUNITY_USER LIMIT 1].Id;
public static Id recordTypeProvider = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get(ESA_cls_constants.EDRD_PROVIDER).getRecordTypeId();

/**
* @author: Deepak
* @date: 24 Sept 2024
* @description: The purpose of this method is to activate EDRD related ACR on provider releated to user.
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
public static void activateACROnEDRDPortalEnable(List<User> newUserList){
try{
Set<Id> providerIdSet = new Set<Id>();
Set<Id> accProviderIdSet = new Set<Id>();
Set<Id> acrIdsToUpdate = new Set<Id>();
Map<Id, Contact> contactIdVsContactRec;

for(User userObj: newUserList){
if((userObj.ProfileId == eDRDPrescriberProfileId && userObj.IsPortalEnabled)){
providerIdSet.add(userObj.ContactId);
}
}

if(!providerIdSet.isEmpty()){
contactIdVsContactRec = new Map<Id, Contact>([SELECT Id, AccountId FROM Contact
WHERE ID IN: providerIdSet AND
Account.RecordTypeId =: recordTypeProvider]);
for(Contact conObj: contactIdVsContactRec.values()){
accProviderIdSet.add(conObj.accountId);
}
}

if(!accProviderIdSet.isEmpty()){
List<AccountContactRelation> aCRList = [SELECT Id, AccountId, ContactId, Roles, Is_EDRD_Data_Migration__c, IsActive
FROM AccountContactRelation
WHERE AccountID IN: accProviderIdSet AND IsActive = false
AND Is_EDRD_Data_Migration__c = true];

for(AccountContactRelation aCRObj : aCRList){
if(!String.isEmpty(aCRObj.Roles) && aCRObj.Roles.containsIgnoreCase(ESA_cls_constants.EDRD_PHYSICIAN)){
acrIdsToUpdate.add(aCRObj.Id);
}
}

if (!acrIdsToUpdate.isEmpty()) {
// Calling the future method to update ACR records in a separate transaction
UserTriggerHelper.updateACRRecords(acrIdsToUpdate);
}
}
}
catch(Exception ex){
System.debug('An unexpected error occurred: ' + ex.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
35 changes: 35 additions & 0 deletions force-app/main/default/classes/UserTriggerHelper.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**********************************************************************************************
* @Author: Accenture
* @Date: 24 Sept 2024
* @Description: The purpose of this helper class is to update ACR records on User trigger event
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description]
***********************************************************************************************/
public with sharing class UserTriggerHelper{

/**
* @author: Deepak
* @date: 24 Sept 2024
* @description: Update AccountContactRelation records in future method.
* @param Set<Id> acrIdsToUpdate: Set of ACR records to update.
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
@future
public static void updateACRRecords(Set<Id> acrIdsToUpdate){
try {
List<AccountContactRelation> aCRListToUpdate = [SELECT Id, IsActive, Is_EDRD_Data_Migration__c
FROM AccountContactRelation
WHERE Id IN :acrIdsToUpdate];

for(AccountContactRelation aCRObj : aCRListToUpdate){
aCRObj.IsActive = true;
aCRObj.Is_EDRD_Data_Migration__c = false;
}

if(!aCRListToUpdate.isEmpty()){
Database.update(aCRListToUpdate, true);
}
} catch(Exception ex){
System.debug('Error while updating ACR records: ' + ex.getMessage());
}
}
}
5 changes: 5 additions & 0 deletions force-app/main/default/classes/UserTriggerHelper.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Is_EDRD_Data_Migration__c</fullName>
<defaultValue>false</defaultValue>
<externalId>false</externalId>
<label>Is EDRD Data Migration</label>
<trackHistory>false</trackHistory>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
<field>AccountContactRelation.IsActive</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>AccountContactRelation.Is_EDRD_Data_Migration__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>AccountContactRelation.Is_Person_Account__c</field>
Expand Down Expand Up @@ -407,7 +412,7 @@
<field>Case.EDRD_Please_specify_other__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>Case.EDRD_RPH_Patient_Not_Meet_Criteria__c</field>
<readable>true</readable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@
<field>AccountContactRelation.IsActive</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>AccountContactRelation.Is_EDRD_Data_Migration__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>AccountContactRelation.Is_Person_Account__c</field>
Expand Down
Loading

0 comments on commit a344f6b

Please sign in to comment.