function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Krishna Sahu 1Krishna Sahu 1 

Would it we possible that someone can help me to write test class on that

public class BodyMapController {
    private static Map<String, String> getBodyParts()
    { 
        Map<String, String> mapPicklistKeyToValue = new Map<String, String>();
        for(EventWrapper.PicklistWrapper objPicklist : PatientJourneyUtil.pickListValueDynamically(new Patient_Log__c(), 'primary_area_front__c'))
        {
            mapPicklistKeyToValue.put(objPicklist.value.replaceAll(' ', ''), objPicklist.value);
        }
        for(EventWrapper.PicklistWrapper objPicklist : PatientJourneyUtil.pickListValueDynamically(new Patient_Log__c(), 'primary_area_back__c'))
        {
            mapPicklistKeyToValue.put(objPicklist.value.replaceAll(' ', ''), objPicklist.value);
        }
        return mapPicklistKeyToValue;
    }

    @AuraEnabled
    public static String savePatientLogs( String patientId,
                                        String listPrimaryFrontBodyParts,
                                        String listPrimaryBackBodyParts,
                                        String listSecondaryFrontBodyParts,
                                        String listSecondaryBackBodyParts,
                                        String listTertiaryFrontBodyParts,
                                        String listTertiaryBackBodyParts,
                                        String intensity,
                                        String frequency,
                                        String sensation)
    {
        Map<String, String> mapPicklistKeyToValue = BodyMapController.getBodyParts();
        List<String> lstPrimaryFrontBodyParts = new List<String>();
        System.debug('listPrimaryFrontBodyParts'+listPrimaryFrontBodyParts);
        for(String bodyPart : (List<String>)JSON.deserialize(listPrimaryFrontBodyParts, List<String>.class))
        {
            lstPrimaryFrontBodyParts.add(mapPicklistKeyToValue.get(bodyPart));
        }
        List<String> lstPrimaryBackBodyParts = new List<String>();
        for(String bodyPart : (List<String>)JSON.deserialize(listPrimaryBackBodyParts,  List<String>.class))
        {
            lstPrimaryBackBodyParts.add(mapPicklistKeyToValue.get(bodyPart));
        }
        List<String> lstSecondaryFrontBodyParts = new List<String>();
        for(String bodyPart : (List<String>)JSON.deserialize(listSecondaryFrontBodyParts,  List<String>.class))
        {
            lstSecondaryFrontBodyParts.add(mapPicklistKeyToValue.get(bodyPart));
        }
        List<String> lstSecondaryBackBodyParts = new List<String>();
        for(String bodyPart : (List<String>)JSON.deserialize(listSecondaryBackBodyParts,  List<String>.class))
        {
            lstSecondaryBackBodyParts.add(mapPicklistKeyToValue.get(bodyPart));
        }
        List<String> lstTertiaryFrontBodyParts = new List<String>();
        for(String bodyPart : (List<String>)JSON.deserialize(listTertiaryFrontBodyParts,  List<String>.class))
        {
            lstTertiaryFrontBodyParts.add(mapPicklistKeyToValue.get(bodyPart));
        }
        List<String> lstTertiaryBackBodyParts = new List<String>();
        for(String bodyPart : (List<String>)JSON.deserialize(listTertiaryBackBodyParts,  List<String>.class))
        {
            lstTertiaryBackBodyParts.add(mapPicklistKeyToValue.get(bodyPart));
        }
        //Name, sensation__c,frequency__c, pain_Intensity__c,
        Patient_Log__c objPatientLog = new Patient_Log__c(patient__c = patientId,
        Log_Type__c = 'Healthcloud',
                                                          primary_area_front__c = String.join(lstPrimaryFrontBodyParts, ';'),
                                                          secondary_area_front__c = String.join(lstSecondaryFrontBodyParts, ';'),
                                                          tertiary_area_front__c = String.join(lstTertiaryFrontBodyParts, ';'), 
                                                          primary_area_back__c = String.join(lstPrimaryBackBodyParts, ';'), 
                                                          secondary_area_back__c = String.join(lstSecondaryBackBodyParts, ';'), 
                                                          tertiary_area_back__c = String.join(lstTertiaryBackBodyParts, ';'));
        insert objPatientLog;
        return objPatientLog.Id;
    }

    @AuraEnabled (cacheable=true)
    public static List<PatientLogSelectionWrapper> getPatientLog(String patientId) {
        system.debug('patientId=>'+patientId);
        List<PatientLogSelectionWrapper> lstPatientLogSelectionWrappers = new List<PatientLogSelectionWrapper>();
        Integer counter = 0;
        for(Patient_Log__c objPatientLog : [SELECT Name, pain_details__c, Id,
                                                    pain_Intensity__c,source__c,Log_Type__c,
                                                    CreatedBy.Name,CreatedDate
                                            FROM Patient_Log__c 
                                            WHERE patient__c =: Id.valueOf(patientId)
                                            ORDER BY CreatedDate  asc])
        {
            PatientLogSelectionWrapper objPatientLogSelectionWrapper = new PatientLogSelectionWrapper(objPatientLog.Id,
                                                                            objPatientLog.Name,
                                                                            objPatientLog.pain_details__c,
                                                                            objPatientLog.pain_Intensity__c,
                                                                            objPatientLog.Log_Type__c,
                                                                            objPatientLog.createdBy.Name,
                                                                            objPatientLog.createdDate.date(),
                                                                            objPatientLog.createdDate.time(),
                                                                            objPatientLog.createdDate,
                                                                            counter == 0);
            lstPatientLogSelectionWrappers.add(objPatientLogSelectionWrapper);
            counter++;
        }
        system.debug('patientLogList=>'+lstPatientLogSelectionWrappers);
        return lstPatientLogSelectionWrappers;        
    }
    @AuraEnabled (cacheable=true)
    public static PatientLogWrapper getPatientLogDetails(String logId) {
        system.debug('logId==>'+logId);
        List<String> listFrontBodyPart = new List<String>();
        List<String> listBackBodyPart = new List<String>();
        List<Patient_Log__c> patientLogList = new List<Patient_Log__c>();
        {
            patientLogList= [SELECT Name, sensation__c,frequency__c, sleep__c, pain_details__c, pain_Intensity__c,source__c , Log_Type__c, mood__c,  primary_area_front__c,
                             secondary_area_front__c,tertiary_area_front__c, primary_area_back__c, secondary_area_back__c, tertiary_area_back__c, CreatedDate
                             FROM Patient_Log__c 
                             WHERE Id =: Id.valueOf(logId)
                            ];
        }
        if(patientLogList[0].primary_area_front__c != null ){
            listFrontBodyPart.addAll(patientLogList[0].primary_area_front__c.split(';'));
        }
        if(patientLogList[0].secondary_area_front__c != null ){
            listFrontBodyPart.addAll(patientLogList[0].secondary_area_front__c.split(';'));
        }
        if(patientLogList[0].tertiary_area_front__c != null ){
            listFrontBodyPart.addAll(patientLogList[0].tertiary_area_front__c.split(';'));
        }
        if(patientLogList[0].primary_area_back__c != null ){
            listBackBodyPart.addAll(patientLogList[0].primary_area_back__c.split(';'));
        }
        if(patientLogList[0].secondary_area_back__c != null ){
            listBackBodyPart.addAll(patientLogList[0].secondary_area_back__c.split(';'));
        }
        if(patientLogList[0].tertiary_area_back__c != null ){
            listBackBodyPart.addAll(patientLogList[0].tertiary_area_back__c.split(';'));
        }
        
        
        PatientLogWrapper pw =  new PatientLogWrapper(listFrontBodyPart, listBackBodyPart, patientLogList[0].pain_Intensity__c, patientLogList[0].frequency__c, patientLogList[0].sensation__c, patientLogList[0].CreatedDate);       
        system.debug('pwpwpw==>'+pw);
        return pw;
    }
    
    @AuraEnabled (cacheable=true)
    public static comparisonWrapper getComparisonLogDetails(String logId1, String logId2, Boolean isFrontSide){
        system.debug('in getComparisonLogDetails logId1'+ logId1);
        system.debug('in getComparisonLogDetails logId2'+ logId2);
        List<PatientLogWrapper> listWrapper = new List<PatientLogWrapper>();
        List<String> commonBodyPart = new List<String>();
        List<String> listFrontBodyPart = new List<String>();
        List<String> listBackBodyPart = new List<String>();
        set<Id> setLogIds = new set<Id>();
        setLogIds.add(Id.valueof(logId1));
        setLogIds.add(Id.valueof(logId2));
        //List<String> listFields = new List<String>{'primary_area_front__c','secondary_area_front__c','tertiary_area_front__c','primary_area_back__c', 'secondary_area_back__c', 'tertiary_area_back__c'};
        List<String> listFields = new List<String>();
        if(isFrontSide){
            listFields.add('primary_area_front__c');
            listFields.add('secondary_area_front__c');
            listFields.add('tertiary_area_front__c');
        }else{
            listFields.add('primary_area_back__c');
            listFields.add('secondary_area_back__c');
            listFields.add('tertiary_area_back__c'); 
        }
           
            
        
        List<Patient_Log__c> listPatientLogs = [SELECT Name, sensation__c,frequency__c, sleep__c, pain_details__c, pain_Intensity__c,source__c , Log_Type__c, mood__c, 
                                                    primary_area_front__c, secondary_area_front__c,tertiary_area_front__c, primary_area_back__c, secondary_area_back__c, 
                                                    tertiary_area_back__c FROM Patient_Log__c  WHERE Id IN : setLogIds order by createdDate ASC];
        
        Patient_Log__c patientLog1 =  listPatientLogs[0];
        Patient_Log__c patientLog2 =  listPatientLogs[1];
        for(String field : listFields){
            set<String> setBodyParts1 = new set<String>();
            String bodyParts = String.valueof(patientLog1.get(field));
            if(!string.isEmpty(bodyParts)){
                setBodyParts1.addAll(bodyParts.split(';'));
            }
            set<String> setbodyParts2 = new set<String>();
            String bodyParts2 = String.valueof(patientLog2.get(field));
            if(!string.isEmpty(bodyParts2)){
                setbodyParts2.addAll(bodyParts2.split(';'));
            }
            if(setBodyParts1.size() > setbodyParts2.size()){
                for(String bpart : setBodyParts1){
                    if(setbodyParts2.contains(bpart)){
                        commonBodyPart.add(bpart);
                    }/*else if(bpart.startsWith('FRONT')){
listFrontBodyPart.add(bpart);
} else if(bpart.startsWith('BACK')){
listBackBodyPart.add(bpart);
}*/
                }
            }else{
                for(String bpart : setbodyParts2){
                    if(setBodyParts1.contains(bpart)){
                        commonBodyPart.add(bpart);
                    }/*else if(bpart.startsWith('FRONT')){
listFrontBodyPart.add(bpart);
} else if(bpart.startsWith('BACK')){
listBackBodyPart.add(bpart);
}*/
                }
            }
            
            
        }
        listWrapper.add(getPatientLogDetails(logId1));
        listWrapper.add(getPatientLogDetails(logId2));
        system.debug('commonBodyPart'+commonBodyPart);
        system.debug('listWrapper'+listWrapper);
        ComparisonWrapper cw = new ComparisonWrapper(listWrapper, commonBodyPart); 
        system.debug('ComparisonWrapper'+cw);
        return cw;
    }
    @AuraEnabled (cacheable=true)
    public static Account getPatientDetails(String patientId){
        List<Account> listPatients = new List<Account>();
        listPatients = [SELECT id, Name, journey_stage__c FROM Account WHERE ID =: Id.valueof(patientId)];
        return listPatients[0];
    }

    public class PatientLogSelectionWrapper
    {
        @AuraEnabled public String patientLogId             {get;set;} 
        @AuraEnabled public String patientLogName           {get;set;} 
        @AuraEnabled public String patientDetail            {get;set;}
        @AuraEnabled public String painIntensity            {get;set;}
        @AuraEnabled public String source                   {get;set;}
        @AuraEnabled public String createdBy                {get;set;}
        @AuraEnabled public Date createdDate                {get;set;}
        @AuraEnabled public Time createdTime                {get;set;}
        @AuraEnabled public DateTime createdDatetime        {get;set;}
        @AuraEnabled public Boolean isBaseline              {get;set;}

        public PatientLogSelectionWrapper(String patientLogId,
                                        String patientLogName,
                                        String patientDetail,
                                        String painIntensity,
                                        String source,
                                        String createdBy,
                                        Date createdDate,
                                        Time createdTime,
                                        DateTime createdDatetime,
                                        Boolean isBaseline)
        {
            this.patientLogId = patientLogId;
            this.patientLogName = patientLogName;
            this.patientDetail = patientDetail;
            this.painIntensity = painIntensity;
            this.source = source;
            this.createdBy = createdBy;
            this.createdDate = createdDate;
            this.createdTime = createdTime;
            this.createdDatetime = createdDatetime;
            this.isBaseline = isBaseline;
        }
    }
    
    public class PatientLogWrapper{
        @AuraEnabled public List<String> listFrontBodyPart {get;set;} 
        @AuraEnabled public List<String> listBackBodyPart {get;set;}
        @AuraEnabled public String painIntensity {get;set;}
        @AuraEnabled public  Decimal frequency {get;set;}
        @AuraEnabled public String sensation {get;set;}
        @AuraEnabled public Datetime createdDate {get;set;}
        
        PatientLogWrapper(List<String> listFrontBodyPart,List<String> listBackBodyPart, string painIntensity, Decimal frequency, String sensation, Datetime createdDate){
            //this.listBodyPart = new List<String>();
            this.listFrontBodyPart = listFrontBodyPart;
            this.listBackBodyPart = listBackBodyPart;
            this.painIntensity =painIntensity;
            this.frequency = frequency;
            this.sensation = sensation;
            this.createdDate = createdDate;
            
        }
        
    }
    
    public class ComparisonWrapper{
        @AuraEnabled public List<PatientLogWrapper> listWrappers {get;set;} 
        @AuraEnabled public List<String> commonBodyPart {get;set;} 
        
        ComparisonWrapper(List<PatientLogWrapper> listWrappers, List<String> commonBodyPart){
            this.listWrappers = listWrappers;
            this.commonBodyPart = commonBodyPart;
        }
        
    }
    
    
}
PriyaPriya (Salesforce Developers) 
Hey Krishna,

It will be difficult to write the test class for the community. But if you can provide the attempted code, then community can help you to fix the issue to increase the code coverage.

Thanks,
Priya Ranjan