diff --git a/force-app/main/default/classes/EDRD_EmpiIntegration.cls b/force-app/main/default/classes/EDRD_EmpiIntegration.cls index 94f566234..7688f9d6d 100644 --- a/force-app/main/default/classes/EDRD_EmpiIntegration.cls +++ b/force-app/main/default/classes/EDRD_EmpiIntegration.cls @@ -1,3 +1,12 @@ +/*------------------------------------------------------------------- +Class Name : EDRD_EmpiIntegration +Test Class Name : EDRD_EmpiIntegrationTest +Referance Class : EDRD_EmpiIntegrationTest/EmpiIntegration/Patient/EDRD_EmpiWrapper/ESA_cls_constants +Purpose : Get the Patient Information and Validate/Update/Create in Salesforce. +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ global without sharing class EDRD_EmpiIntegration implements Callable { public Object call(String action, Map args){ @@ -8,11 +17,12 @@ global without sharing class EDRD_EmpiIntegration implements Callable } global Boolean invokeMethod(String methodName, Map inputMap, Map outputMap, Map options) { + Boolean result = true; String jsonInput = Json.serialize(inputMap.get('input')); EDRD_EmpiWrapper.OutputWrapper patientOutputWrapper = new EDRD_EmpiWrapper.OutputWrapper(); EDRD_EmpiWrapper.InputWrapper inputWrapper = (EDRD_EmpiWrapper.InputWrapper) JSON.deserialize(jsonInput, EDRD_EmpiWrapper.InputWrapper.class); - + switch on methodName { when 'getEmpidata'{ this.getEmpidata(inputWrapper,outputMap); @@ -37,12 +47,23 @@ global without sharing class EDRD_EmpiIntegration implements Callable } } return result; - } + } +/*--------------------------------------------------------------------- +Method Name : validatePHN +Purpose : Check PHN is Exsit in salesforce Database or Not. +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public void validatePHN(EDRD_EmpiWrapper.InputWrapper inputWrapper,Map outputMap){ EDRD_EmpiWrapper.OutputWrapper patientOutputWrapper= new EDRD_EmpiWrapper.OutputWrapper(); List patientRecord = new Elevated().getSalesforceData(inputWrapper); if(!patientRecord.isEmpty()){ for(Account acc:patientRecord){ + patientOutputWrapper.firstName = acc.FirstName; + patientOutputWrapper.lastName = acc.LastName; + patientOutputWrapper.dateOfBirth = acc.PersonBirthdate; + patientOutputWrapper.gender = acc.PersonGender; patientOutputWrapper.phn = acc.Patient_Identifier__pc; patientOutputWrapper.isPatientFound = true; patientOutputWrapper.patientaccountId = acc.Id; @@ -59,7 +80,13 @@ global without sharing class EDRD_EmpiIntegration implements Callable outputMap.put('searchOutput',JSON.deserializeuntyped(result)); return; } - +/*--------------------------------------------------------------------- +Method Name : getSFdata +Purpose : Get the Data from salesforce based on user input(it cloud be PHN or Patient details). +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public void getSFdata(EDRD_EmpiWrapper.InputWrapper inputWrapper, Map outputMap) { List lstpatientOutputWrapper=new List(); @@ -88,7 +115,13 @@ global without sharing class EDRD_EmpiIntegration implements Callable return; } - +/*--------------------------------------------------------------------- +Method Name : validatePHN +Purpose : This common class, which we can call from any class to assine the patientOutputWrapper data +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public EDRD_EmpiWrapper.OutputWrapper loopsPatientDeatils(Account acc){ EDRD_EmpiWrapper.OutputWrapper patientOutputWrapper = new EDRD_EmpiWrapper.OutputWrapper(); @@ -102,6 +135,14 @@ global without sharing class EDRD_EmpiIntegration implements Callable return patientOutputWrapper; } +/*--------------------------------------------------------------------- +Method Name : createUpdatePatient +Purpose : If we found the Patient information in EMPI we update or create same dataCheck + PHN is Exsit in salesforce Database or Not. +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public void createUpdatePatient(EDRD_EmpiWrapper.InputWrapper inputWrapper, Map outputMap) { EDRD_EmpiWrapper.OutputWrapper patientOutputWrapper = new EDRD_EmpiWrapper.OutputWrapper(); @@ -128,7 +169,14 @@ global without sharing class EDRD_EmpiIntegration implements Callable createPatientInSF(inputWrapper,outputMap); return; } - } + } +/*--------------------------------------------------------------------- +Method Name : validatePHN +Purpose : Pass the PHN and get the Patient Infomation form EMPI database. +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public void getEmpidata(EDRD_EmpiWrapper.InputWrapper inputWrapper, Map outputMap) { EDRD_EmpiWrapper.OutputWrapper patientOutputWrapper = new EDRD_EmpiWrapper.OutputWrapper(); String phn = inputWrapper.phn; @@ -141,7 +189,13 @@ global without sharing class EDRD_EmpiIntegration implements Callable outputMap.put('searchOutput',JSON.deserializeuntyped(result)); return; } - +/*--------------------------------------------------------------------- +Method Name : getOutput +Purpose : Innter method. +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public EDRD_EmpiWrapper.OutputWrapper getOutput(String patientJSON){ EDRD_EmpiWrapper.OutputWrapper patientOutputWrapper = new EDRD_EmpiWrapper.OutputWrapper(); @@ -164,7 +218,13 @@ global without sharing class EDRD_EmpiIntegration implements Callable } return patientOutputWrapper; } - +/*--------------------------------------------------------------------- +Method Name : createPatientInSF +Purpose : Create Date in salesforce database. +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public void createPatientInSF(EDRD_EmpiWrapper.InputWrapper inputWrapper, Map outputMap) { EDRD_EmpiWrapper.OutputWrapper patientOutputWrapper = new EDRD_EmpiWrapper.OutputWrapper(); @@ -195,10 +255,16 @@ global without sharing class EDRD_EmpiIntegration implements Callable outputMap.put('searchOutput',JSON.deserializeuntyped(result)); return; } - +/*--------------------------------------------------------------------- +Method Name : createCareProgramEnrollee +Purpose : Create CareProgramEnrollee to associcated Account. +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public void createCareProgramEnrollee(Id patientId){ List cpeRecords = new Elevated().creByAccountId(patientId); - if(!cpeRecords.isEmpty()){ + if(cpeRecords.isEmpty()){ List CareProgramName = new Elevated().CareProgramByName(ESA_cls_constants.EDRD_NAME); CareProgramEnrollee careProgram = new CareProgramEnrollee(); careProgram.AccountId = patientId; @@ -208,7 +274,13 @@ global without sharing class EDRD_EmpiIntegration implements Callable insert careProgram; } } - +/*--------------------------------------------------------------------- +Method Name : createACR +Purpose : Craete ACR +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ public void createACR(EDRD_EmpiWrapper.InputWrapper inputWrapper,Map outputMap){ List acrListRecords = new Elevated().selectACR(Id.ValueOf(inputWrapper.LoginUserAccountId),Id.ValueOf(inputWrapper.PatientContactId)); @@ -220,8 +292,15 @@ global without sharing class EDRD_EmpiIntegration implements Callable insert acrRecords; } } - - public without sharing class Elevated{ +/*--------------------------------------------------------------------- +Class Name : Elevated +Purpose : This is Elevated class to get the salesforce data on System mode. +Version : 1.0 +Devloper Name : Accenture. +Date : 19/Dec/2024 +--------------------------------------------------------------------------*/ + public without sharing class Elevated + { public List creByAccountId(Id accountId){ return [SELECT Id FROM CareProgramEnrollee WHERE AccountId = :accountId Limit 1]; @@ -246,6 +325,8 @@ global without sharing class EDRD_EmpiIntegration implements Callable return [Select Id,Patient_Identifier__pc, FirstName, LastName, Patient_is_Deceased__pc, PersonBirthdate,PersonGender,PersonContactId from Account where Patient_Identifier__pc =: inputWrapper.phn]; } - } - } + } + + } + } \ No newline at end of file diff --git a/force-app/main/default/classes/EDRD_EmpiIntegrationTest.cls b/force-app/main/default/classes/EDRD_EmpiIntegrationTest.cls new file mode 100644 index 000000000..9ded1e8dc --- /dev/null +++ b/force-app/main/default/classes/EDRD_EmpiIntegrationTest.cls @@ -0,0 +1,274 @@ +/*----------------------------------------- +Test Class Name : EDRD_EmpiIntegrationTest +Main Class Name : EDRD_EmpiIntegration +Version : 1.0 +Devloper Name : Accenture. +------------------------------------------*/ +@isTest +public class EDRD_EmpiIntegrationTest { + @testSetup + static void setupTestData() { + + // Step 1: Create and insert an Account + Account testAccountUser = new Account( + Name = 'TestAccountUser987' + ); + insert testAccountUser; + + // Step 2: Create and insert a Contact related to the Account + Contact testContactUser = new Contact( + FirstName = 'Test', + LastName = 'ContactUser987', + Email = 'test.contact@example.com', + AccountId = testAccountUser.Id + ); + insert testContactUser; + + // Step 3: Create a User with associated Account and Contact + Profile userProfile = [SELECT Id FROM Profile WHERE Name = 'EDRD Prescriber Community User' LIMIT 1]; + User testUser = new User( + FirstName = 'Test', + LastName = 'User', + Email = 'test.user@example.com', + Username = 'test.user00978@abc.xyz.com', + Alias = 'tuser', + ProfileId = userProfile.Id, + TimeZoneSidKey = 'America/New_York', + LocaleSidKey = 'en_US', + EmailEncodingKey = 'UTF-8', + LanguageLocaleKey = 'en_US', + ContactId = testContactUser.Id + ); + insert testUser; + + + // Step 1: Create CareProgram + CareProgram testCP = new CareProgram(); + testCP.Name = 'EDRD'; + testCP.Status = 'New'; + insert testCP; + + // Step 2: Create a test Account for Salesforce data mock + Account testAccount = new Account( + FirstName = 'John', + LastName = 'Doe', + Patient_Identifier__pc = '9879450112', + PersonBirthdate = Date.newInstance(1990, 01, 01), + PersonGender = 'Male', + RecordTypeId = ESA_cls_constants.PatientRecordTypeId + ); + insert testAccount; + + // Step 3: Create a CareProgramEnrollee + CareProgramEnrollee testCPERecords = new CareProgramEnrollee(); + testCPERecords.AccountId = testAccount.Id; + testCPERecords.Name = 'testCPE'; + testCPERecords.Status = 'Active'; + testCPERecords.CareProgramId = testCP.Id; + insert testCPERecords; + } +/*--------------------------------------------------------------------- +Method Name : testgetEMPIData +Method Calling for : getEMPIData +Purpose : Pass the PHN and get the Patient Infomation form EMPI database. +Version : 1.0 +Devloper Name : Accenture. +--------------------------------------------------------------------------*/ + @isTest + static void testgetEMPIData() { + // Instantiate the class + EDRD_EmpiIntegration integration = new EDRD_EmpiIntegration(); + + // Mock input data + Map inputMap = new Map{ + 'input' => new Map{ + 'elementName' => 'searchPatient', + 'omniScriptId' => '0jNAq000000VXJ3MAO', + 'phn' => '9879450112' + }, + 'options' => new Map{ + 'ignoreCache' => false, + 'postTransformBundle' => '', + 'preTransformBundle' => '', + 'useContinuation' => false, + 'useQueueableApexRemoting' => false, + 'vlcClass' => 'EDRD_EmpiIntegration' + }, + 'output' => new Map{} + }; + + // Call the method + Object result = integration.call('getEmpidata', inputMap); + + // Assert results + System.assertNotEquals(null, result, 'Result should not be null'); + } +/*--------------------------------------------------------------------- +Method Name : testValidatePHN +Method Calling for : ValidatePHN +Purpose : Check PHN is Exsit in salesforce Database or Not. +Version : 1.0 +Devloper Name : Accenture. +--------------------------------------------------------------------------*/ + @isTest + static void testValidatePHN() { + + EDRD_EmpiIntegration integration = new EDRD_EmpiIntegration(); + + // Mock data + Map inputMap = new Map{ + 'phn' => '9879450112' + }; + Map outputMap = new Map(); + Map outputMapMain = new Map(); + outputMapMain.put('input',inputMap); + String jsonInput = Json.serialize(outputMapMain.get('input')); + EDRD_EmpiWrapper.InputWrapper inputWrapper = (EDRD_EmpiWrapper.InputWrapper) JSON.deserialize(jsonInput, EDRD_EmpiWrapper.InputWrapper.class); + // Call the method + integration.validatePHN(inputWrapper, outputMap); + + // Assert output + System.assert(outputMap.containsKey('searchOutput'), 'Output should contain searchOutput'); + Map searchOutput = (Map) outputMap.get('searchOutput'); + System.assertEquals(true, searchOutput.get('isPatientFound'), 'Patient should be found'); + } + +/*--------------------------------------------------------------------- +Method Name : testCreateUpdatePatient +Method Calling for : CreateUpdatePatient +Purpose : If we found the Patient information in EMPI we update or create same dataCheck + PHN is Exsit in salesforce Database or Not. +Version : 1.0 +Devloper Name : Accenture. +--------------------------------------------------------------------------*/ + @isTest + static void testCreateUpdatePatient() { + // Instantiate the class + EDRD_EmpiIntegration integration = new EDRD_EmpiIntegration(); + + // Mock data + Map inputMap = new Map{ + 'firstName' => 'John', + 'lastName' => 'Doe', + 'dateOfBirth' => Date.newInstance(1990, 01, 01), + 'gender' => 'Male', + 'phn' => '9879450112' + }; + Map outputMap = new Map(); + Map inputMapMain = new Map(); + inputMapMain.put('input',inputMap); + String jsonInput = Json.serialize(inputMapMain.get('input')); + + EDRD_EmpiWrapper.InputWrapper inputWrapper = (EDRD_EmpiWrapper.InputWrapper) JSON.deserialize(jsonInput, EDRD_EmpiWrapper.InputWrapper.class); + // Call the method + integration.createUpdatePatient(inputWrapper, outputMap); + + // Assert results + System.assert(outputMap.containsKey('searchOutput'), 'Output should contain searchOutput'); + } +/*--------------------------------------------------------------------- +Method Name : testGetSFData +Method Calling for : GetSFData +Purpose : Get the Data from salesforce based on user input(it cloud be PHN or Patient details). +Version : 1.0 +Devloper Name : Accenture. +--------------------------------------------------------------------------*/ + @isTest + static void testGetSFData() { + // Instantiate the class + EDRD_EmpiIntegration integration = new EDRD_EmpiIntegration(); + + // Mock data + Map inputMap = new Map{ + 'firstName' => 'John', + 'lastName' => 'Doe', + 'dateOfBirth' => Date.newInstance(1990, 01, 01) + }; + Map outputMap = new Map(); + + Map inputMapMain = new Map(); + inputMapMain.put('input',inputMap); + String jsonInput = Json.serialize(inputMapMain.get('input')); + EDRD_EmpiWrapper.InputWrapper inputWrapper = (EDRD_EmpiWrapper.InputWrapper) JSON.deserialize(jsonInput, EDRD_EmpiWrapper.InputWrapper.class); + // Call the method + integration.getSFdata(inputWrapper, outputMap); + + // Assert results + System.assert(outputMap.containsKey('searchOutput'), 'Output should contain searchOutput'); + // List> searchOutput = (List>) outputMap.get('searchOutput'); + // System.assert(searchOutput.size() > 0, 'Search output should not be empty'); + } +/*--------------------------------------------------------------------- +Method Name : testCreatePatientInSF +Method Calling for : CreatePatientInSF +Purpose : Create Date in salesforce database. +Version : 1.0 +Devloper Name : Accenture. +--------------------------------------------------------------------------*/ + @isTest + static void testCreatePatientInSF() { + // Instantiate the class + EDRD_EmpiIntegration integration = new EDRD_EmpiIntegration(); + + // Mock data + + Map inputMap = new Map{ + 'firstName' => 'Jane', + 'lastName' => 'Smith', + 'dateOfBirth' => Date.newInstance(1985, 07, 15), + 'phn' => '1234567890', + 'clickBy' => ESA_cls_constants.ManullyCreated + }; + Map outputMap = new Map(); + + Map inputMapMain = new Map(); + inputMapMain.put('input',inputMap); + String jsonInput = Json.serialize(inputMapMain.get('input')); + system.debug('jsonInput=136='+jsonInput); + EDRD_EmpiWrapper.InputWrapper inputWrapper = (EDRD_EmpiWrapper.InputWrapper) JSON.deserialize(jsonInput, EDRD_EmpiWrapper.InputWrapper.class); + system.debug('inputWrapper=134='+inputWrapper); + // Call the method + integration.createPatientInSF(InputWrapper, outputMap); + + // Assert results + System.assert(outputMap.containsKey('searchOutput'), 'Output should contain searchOutput'); + Map searchOutput = (Map) outputMap.get('searchOutput'); + System.assertEquals(true, searchOutput.get('isClickManulRecord'), 'Click manual record should be true'); + } +/*--------------------------------------------------------------------- +Method Name : testCreateACR +Method Calling for : CreateACR +Purpose : Create ACR Recods. +Version : 1.0 +Devloper Name : Accenture. +--------------------------------------------------------------------------*/ + @isTest + static void testCreateACR() { + + User us =[Select AccountId from user where Username ='test.user00978@abc.xyz.com' Limit 1]; + Account acc =[Select PersonContactId from Account where Patient_Identifier__pc = '9879450112' Limit 1]; + + EDRD_EmpiWrapper.InputWrapper inputWrapper = new EDRD_EmpiWrapper.InputWrapper(); + inputWrapper.LoginUserAccountId = us.AccountId; + inputWrapper.PatientContactId = acc.PersonContactId; + + Map outputMap = new Map(); + + // Step 4: Call the createACR method + EDRD_EmpiIntegration controller = new EDRD_EmpiIntegration(); + Test.startTest(); + controller.createACR(inputWrapper, outputMap); + Test.stopTest(); + + // Step 5: Validate that the AccountContactRelation record is created + List acrList = [ + SELECT Id, AccountId, ContactId, Roles + FROM AccountContactRelation + WHERE AccountId = :us.AccountId AND ContactId =: acc.PersonContactId + ]; + + System.assertEquals(1, acrList.size(), 'One AccountContactRelation record should be created.'); + System.assertEquals(ESA_cls_constants.EDRD_PHYSICIAN, acrList[0].Roles, 'The Role should be EDRD_PHYSICIAN.'); + + } +} \ No newline at end of file diff --git a/force-app/main/default/classes/EDRD_EmpiIntegrationTest.cls-meta.xml b/force-app/main/default/classes/EDRD_EmpiIntegrationTest.cls-meta.xml new file mode 100644 index 000000000..998805a82 --- /dev/null +++ b/force-app/main/default/classes/EDRD_EmpiIntegrationTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 62.0 + Active + diff --git a/force-app/main/default/classes/EDRD_EmpiWrapper.cls b/force-app/main/default/classes/EDRD_EmpiWrapper.cls index 3e680ae5d..273abe5f8 100644 --- a/force-app/main/default/classes/EDRD_EmpiWrapper.cls +++ b/force-app/main/default/classes/EDRD_EmpiWrapper.cls @@ -29,10 +29,10 @@ public class EDRD_EmpiWrapper { public Id patientContactId {get; set;} public Boolean isValidatePHNClick {get;set;} public Boolean isClickEmpiSearch {get;set;} - public Boolean isClickPHNSerachInSF {get;set;} + // public Boolean isClickPHNSerachInSF {get;set;} public Boolean isClickSFsearch {get;set;} public Boolean isClickManulRecord {get;set;} - public Boolean isClickValidateByPhn {get;set;} + // public Boolean isClickValidateByPhn {get;set;} } diff --git a/force-app/main/default/classes/ESA_cls_constants.cls b/force-app/main/default/classes/ESA_cls_constants.cls index 22c54ab4d..0a1ee7657 100644 --- a/force-app/main/default/classes/ESA_cls_constants.cls +++ b/force-app/main/default/classes/ESA_cls_constants.cls @@ -10,17 +10,29 @@ public class ESA_cls_constants { public static final String CASE_APPROVAL_TIME_UNIT_WEEK = 'Weeks'; public static final String CASE_APPROVAL_TIME_UNIT_MONTH = 'Months'; public static final String CASE_APPROVAL_TIME_UNIT_DAYS = 'Days'; - public static final String EDRD_NAME = 'EDRD'; - public static final String EDRD_CASE_STATUS_CANCELLED = 'Cancelled'; + public static final String EDRD_ACR_ROLES_CHAIR = 'Chair'; + public static final String EDRD_ACR_ROLES_REVIEWER = 'Reviewer'; + public static final String EDRD_ACR_ROLES_VICE_CHAIR = 'Vice Chair'; + public static final String EDRD_BUSINESS_SC_ACCOUNT = 'Subcommittee'; + public static final String EDRD_BUSINESS_AC_ACCOUNT = 'Advisory Committee'; 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'; - public static final String EDRD_FUNDING_DECISION_DENIED = 'Denied'; + public static final String EDRD_CASE_STATUS_CANCELLED = 'Cancelled'; + public static final String EDRD_CASE_STATUS_FUNDING_APPROVED = 'Funding Approved'; public static final String EDRD_FORMULATION_BOTTLE = 'Bottle'; + public static final String EDRD_FUNDING_DECISION_DENIED = 'Denied'; + public static final String EDRD_NAME = 'EDRD'; + public static final String EDRD_PERSONACCOUNT_SC = 'EDRD Sub Committee'; + public static final String EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE = 'Metabolic Subcommittee'; + public static final String EDRD_PERSONACCOUNT_AC = 'EDRD Advisory Committee'; + public static final String EDRD_PERSONACCOUNT_ACSC = 'EDRD Advisory/ Sub Committee'; + public static final String EDRD_PHYSICIAN = 'Physician'; + public static final String EDRD_PRESCRIBER_COMMUNITY_USER = 'EDRD Prescriber Community User'; + public static final String EDRD_PROVIDER = 'Provider'; public static final Id PatientRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Patient').getRecordTypeId(); public static final String ManullyCreated = 'manullyCreated'; - public static final String EMPICreated = 'EMPICreated'; + public static final String EMPICreated = 'EMPICreated'; + + + } \ No newline at end of file