0% found this document useful (0 votes)
6 views10 pages

Query Manager

The QueryManager Apex class is designed to manage and execute various queries for Healthcloud users, retrieving data from multiple Salesforce objects. It includes methods for fetching orders, specimens, profiles, accounts, and other related records, with a focus on security and error logging. The class has undergone multiple updates to enhance its functionality and address user stories since its creation in January 2025.

Uploaded by

sauravgodbole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Query Manager

The QueryManager Apex class is designed to manage and execute various queries for Healthcloud users, retrieving data from multiple Salesforce objects. It includes methods for fetching orders, specimens, profiles, accounts, and other related records, with a focus on security and error logging. The class has undergone multiple updates to enhance its functionality and address user stories since its creation in January 2025.

Uploaded by

sauravgodbole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

/*

*
***********************************************************************************
*************************************************
* Apex Class Name : QueryManager
* Version : 2.1
* Created Date : 22-January-2025
* Function : This Query Manager class used to keep queries for Normal
Healthcloud Users and Guest users to fetch data from
different objects and return sObjects.
* Modification Log :
* --------------------------------------------------------------------------------
* User Story Date Description
* ---------------- ----------------------- ---------------------
* CDP-8317 22-January-2025 Initial version.
* CDP-8076 07-February-2025 Added getOrdersDetails method
to retrieve orderdetails based on OrderId.
* CDP-8742 10-February-2025 Changes done in
getOrdersDetails method to retrieve orderdetails based on OrderId.
* CDP-8744 11-February-2025 Added getOrderItemList and
getSpecimenOrderItemMappingList methods.
* CDP-8743 12-February-2025 Added getProfileList method to
retrive profiledetails based on profileid.
* CDP-6589 18-February-2025 Added
getSpecimenOrderItemMappingList method to retrive SpecimenOrderItem Mapping based
on testIds.
* CDP-9122 21-February-2025 Added getSpecimenList method
to retrieve specimenList based on specimenId.
* CDP-9379 25-February-2025 Added getAccountList,
getBillingInsauranceList, getUnknownAccount,getuserDetails method to retrieve
records.
* CDP-9637 26-February-2025 Added getCurrentOrder, method
to retrieve records.
* CDP-7307 5-March-2025 Added getProductRelation
method.
* CDP-6688 7-March-2025 Added getContentVersionList
method.
* CDP-9284 17-March-2025 Changes done in
getSpecimenOfOrderList method to hide Mobile Phlebotomy record.
* CDP-9651 19-March-2025 Changes done in getOrderList
for OrderType.
* CDP-10301 20-March-2025 Removed with SECURITY_ENFORCED
from soql query from
getOrderList,getProfileList,getuserDetails,getContentVersionList,getProductRelation
List methods as system field is fetched.
* CDP-9222 11-April-2025 Added getContentNoteList and
getContentDocumentLinkList method.
* CDP-9218 16-April-2025 Changes done in
getSpecimenOfOrderList,getSpecimenList method
* CDP-9296 16-April-2025 Added getTestReportMapping
method to fetch Test_Report_Mapping__c records.
* CDP-9219 25-April-2025 Updated getSpecimenList method
introduced Archive Retrieval Date and Archive Retrieval Time field
* CDP-11401 05-May-2025 Updated getuserDetails
method ,added input parameter to the method
* CDP-11295 07-May-2025 Added getOrderItemRecords
method, updated getOrderItemOfOrderList to fetch CaseNumber__c, CreateNewCase__c
fields.
* CDP-9302 08-May-2025 Updated
getOrderItemOfOrderList by adding IsAddOnTest__c field in query
*
***********************************************************************************
***************************************************
*/
public with sharing class QueryManager {
/**
* @param : Set<Id> orderIds
* @return : List<Specimen__c>
* @description : Fetch specimen records based on order id set.
**/
public static List<Specimen__c> getSpecimenOfOrderList(Set<Id> orderIds){
List<Specimen__c> specimenList = new List<Specimen__c>();
try{
specimenList = [SELECT
Id,name,SpecimenID__c,Physical_Specimen_ID__c,CollectionDate__c,CollectionTime__c,C
ollectionTimeZone__c, Received_Date__c,
Received_Time__c,Timezone__c, BodySite__c,
PrimarySite__c, Metastasis__c, SpecimenType__c ,
Cold_Ischemic_Duration_Mins__c ,Fixative__c,
Other_Fixative__c, Fixative_Unknown__c, Fixation_Duration_Hours__c,

Cold_Ischemic_Duration_Unknown__c,Fixation_Duration_Unknown__c,SpecimenTransport__c
,CreatedDate ,ArchiveRetrievalDate__c , ArchiveRetrievalTime__c FROM Specimen__c
WHERE Order__c IN: orderIds AND Type__c!
= :UTIL_Constants.SPECIMENTYPE_MPH WITH SECURITY_ENFORCED order by CreatedDate
DESC];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return specimenList;
}
/**
* @param : Set<Id> orderIds
* @return : List<Order>
* @description : Fetch order records based on order ids.
**/
public static List<Order> getOrderList(Set<Id> orderIds){
List<Order> orderList = new List<Order>();
try{
orderList = [SELECT Id, AC_QcSummary__c, Accession_Lab__c, Status,
CreatedBy.ProfileId, Patient__c, Fax_Number__c,
Verify_Fax_Number__c, Report_Recipient_Name__c,
Comments__c, NeoServe_Sync_Status__c, Narrative__c,Type, AccountId
FROM Order WHERE Id IN :orderIds];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return orderList;
}
/**
* @param : Set<Id> orderItemIds
* @return : List<Order>
* @description : Fetch order item records based on order item ids.
**/
public static List<OrderItem> getOrderItemOfOrderList(Set<Id> orderIds){
List<OrderItem> orderItemList = new List<OrderItem>();
try{
orderItemList = [SELECT
Id,Product2.Name,Test_Status__c,Lab_Assignment__c,TCP_Lab__c,TCA_Lab__c,Prior_Auth_
_c,IsAddOnTest__c,
Reflex_Comment__c, CaseNumber__c, CreateNewCase__c
FROM OrderItem where OrderId = : orderIds WITH SECURITY_ENFORCED ORDER BY
CreatedDate DESC];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return orderItemList;
}
/**
* @param : Set<Id> testIds
* @return : List<Specimen_OrderItem_Mapping__c>
* @description : Fetch specimen order item mapping based on test ids.
**/
public static List<Specimen_OrderItem_Mapping__c>
getSpecimenOrderItemMappingList(Set<Id> testIds){
List<Specimen_OrderItem_Mapping__c> specimenOrderItemMappingList = new
List<Specimen_OrderItem_Mapping__c>();
try{
specimenOrderItemMappingList = [Select
id,isActive__c,Order_Product__c,Specimen__c from Specimen_OrderItem_Mapping__c
where Order_Product__c IN: testIds and
isActive__c=true WITH SECURITY_ENFORCED];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return specimenOrderItemMappingList;
}

/**
* @param : Set<Id> testIds
* @return : List<Specimen_OrderItem_Mapping__c>
* @description : Fetch all specimen order item mapping based on test ids.
**/
public static List<Specimen_OrderItem_Mapping__c>
getAllSpecimenOrderItemMappingList(Set<Id> testIds){
List<Specimen_OrderItem_Mapping__c> specimenOrderItemMappingList = new
List<Specimen_OrderItem_Mapping__c>();
try{
specimenOrderItemMappingList = [Select
id,isActive__c,Order_Product__c,Specimen__c from Specimen_OrderItem_Mapping__c
where Order_Product__c IN: testIds WITH
SECURITY_ENFORCED];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return specimenOrderItemMappingList;
}

/**
* @param : Set<Id>ProfileIds
* @return : List<Profile>
* @description : Fetch Profile records based on Profile ids.
**/
public static List<Profile> getProfileList(Set<Id> profileIds){
List<Profile> profileRec = new List<Profile>();
try{
profileRec = [SELECT Id, Name FROM Profile WHERE Id IN :profileIds];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return profileRec;
}
/**
* @param : Set<Id>accountIds
* @return : List<Account>
* @description : Fetch Account records based on Account ids.
**/
public static List<Account> getAccountList(Set<Id> accountIds){
List<Account> accountRec = new List<Account>();
try{
accountRec = [select Id, Client_Status__c, name,
Account_number__c ,Client_Special_Instructions__c,LastName,FirstName,MiddleName,DOB
__c,HealthCloudGA__MedicalRecordNumber__c,Gender__c from account where Id
IN :AccountIds WITH SECURITY_ENFORCED];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return accountRec;
}

/**
* @param : Set<Id> specimenIds
* @return : List<Specimen__c>
* @description : Fetch specimen records based on specimen ids.
**/
public static List<Specimen__c> getSpecimenList(Set<Id> specimenIds){
List<Specimen__c> specimenList = new List<Specimen__c>();
try{
specimenList = [SELECT Id, Name, Order__c,SpecimenID__c,
Physical_Specimen_ID__c, CollectionDate__c,
CollectionTime__c,CollectionTimeZone__c,
Received_Date__c, Received_Time__c,
Timezone__c,Primary_Body_Site__c,Metastasis__c, BodySite__c, SpecimenType__c
,SpecimenTransport__c,Cold_Ischemic_Duration_Mins__c,
Fixative__c, Other_Fixative__c, Fixation_Duration_Hours__c,
Cold_Ischemic_Duration_Unknown__c, Fixative_Unknown__c,
Fixation_Duration_Unknown__c,Block__c,Unstained_Slides_s__c,

Stained_Slides_s__c,H_E_Slide_s__c,Smear_Fixed__c,Smear_Stained__c,Smear_Unstained_
_c,

Smear_Unstained_Slides_s__c,Sodium_Heparin_Green_Top__c,EDTA_Purple_Top__c,Fixed_Ce
ll_Pellet__c,Streck_BCT_Speckled_Top__c,

Other__c,Specimen_Transport_Unknown__c,Quantity__c ,ArchiveRetrievalDate__c ,
ArchiveRetrievalTime__c
FROM Specimen__c WHERE Id IN:specimenIds WITH
SECURITY_ENFORCED ORDER BY createdDate DESC];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return specimenList;
}
/**
* @param : Set<Id>orderIds
* @return : List<Billing_Insurance__c>
* @description : Fetch Billing Insurance records based on order ids.
**/
public static List<Billing_Insurance__c> getBillingInsauranceList(Set<Id>
orderIds){
List<Billing_Insurance__c> billingInsauranceRec = new
List<Billing_Insurance__c>();
try{
billingInsauranceRec = [SELECT Id, Order__c, PatientStatus__c,
BillTo__c, DischargeDate__c,OtherFacilityName__c,

Other_Facility_Address__Street__s,Other_Facility_Address__City__s,Other_Facility_Ad
dress__StateCode__s,

Other_Facility_Address__PostalCode__s,Other_Facility_Address__CountryCode__s From
Billing_Insurance__c
WHERE Order__c =: orderIds WITH
SECURITY_ENFORCED Order By CreatedDate DESC LIMIT 1];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return billingInsauranceRec;
}
/**
* @param : Set<Id> NPINumber, Set<Id> cdpClinicalRecordTypeId
* @return : List<Contact>
* @description : Fetch Contact records based on NPI Number and Record Type
**/
public static List<Contact> getContactList(Set<Id> NPINumber, Set<Id>
cdpClinicalRecordTypeId){
List<Contact> contactList = new List<Contact>();
try{
contactList = [SELECT Id, Name, NPI__c, AccountId, RecordTypeId FROM
Contact WHERE NPI__c IN: NPINumber
AND RecordTypeId IN: cdpClinicalRecordTypeId WITH
SECURITY_ENFORCED ORDER BY CreatedDate DESC LIMIT 1];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return contactList;
}

/**
* @param : Set<Id> contactId, Set<Id> accountId
* @return : List<AccountContactRelation>
* @description : Fetch Account-Contact Relation records based on Contact,
Account Id
**/
public static List<AccountContactRelation> getACRList(Set<Id> contactId,
Set<Id> accountId){
List<AccountContactRelation> acrList = new List<AccountContactRelation>();
try{
acrList = [SELECT Id, ContactId, AccountId FROM AccountContactRelation
WHERE ContactId IN: contactId AND AccountId IN: accountId
WITH SECURITY_ENFORCED];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return acrList;
}

/**
* @param : None
* @return : List<NeoServe_NPI_Details__mdt>
* @description : Fetch NeoServe NPI Details custom metadata Records
**/
public static List<NeoServe_NPI_Details__mdt> getNeoServeCMDList(){
List<NeoServe_NPI_Details__mdt> neoServeCMDList = new
List<NeoServe_NPI_Details__mdt>();
try{
neoServeCMDList = [SELECT Id, FirstName__c, LastName__c, MiddleName__c,
City__c, NPI__c, PostalCode__c, State__c,
FirstLineAddress__c, SecondLineAddress__c,
NPILength__c, FirstNameLength__c,
LastNameLength__c, MiddleNameLength__c,
CityLength__c, PostalCodeLength__c, StreetLength__c
FROM NeoServe_NPI_Details__mdt WITH
SECURITY_ENFORCED LIMIT 1];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return neoServeCMDList;
}

/**
* @param : None
* @return : List<Account>
* @description : Fetch Unknown Account record
**/
public static List<Account> getUnknownAccount(){
List<Account> unknownAccount = new List<Account>();
try{
unknownAccount = [SELECT Id FROM Account WHERE Name = :
UTIL_Constants.UNKNOWN_CLIENT
AND RecordType.Name = :
UTIL_Constants.ACCOUNT_Approved_RT WITH SECURITY_ENFORCED LIMIT 1];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return unknownAccount;
}

/**
* @param : None
* @return : List<Pricebook2>
* @description : Fetch StandardPriceBook record
**/
public static Pricebook2 getStandardPriceBook(){
Pricebook2 StandardPriceBook = new Pricebook2();
try{
StandardPriceBook = [SELECT Id, IsActive FROM Pricebook2 WHERE
isStandard = true AND IsActive=true WITH SECURITY_ENFORCED LIMIT 1];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return StandardPriceBook;
}
/**
* @param : None
* @return : List<Account>
* @description : Fetch Unknown dummy client Account record
**/
public static List<Account> getUnknownDummyClientAccount(){
List<Account> unknownDummyClientAccount = new List<Account>();
try{
unknownDummyClientAccount = [SELECT Id FROM Account WHERE Name = :
UTIL_Constants.DUMMY_CLIENT AND RecordType.Name = :
UTIL_Constants.ACCOUNT_Approved_RT WITH SECURITY_ENFORCED LIMIT 1];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return unknownDummyClientAccount;
}
/**
* @param : Set<Id>codeBundleSetIdIds
* @return : List<CodeSetBundle>
* @description : FetchCodeSetBundle records based on codeBundleSet ids.
**/
public static List<CodeSetBundle> getCodeSetBundleList(Set<Id>
codeBundleSetIds){
List<CodeSetBundle> codeSetBundleRec = new List<CodeSetBundle>();
try{
codeSetBundleRec = [SELECT Id, Name, Code__c,CodeSet1Id,
CodeSet1.CodeDescription
FROM CodeSetBundle
WHERE Id IN:codeBundleSetIds WITH
SECURITY_ENFORCED];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return codeSetBundleRec;
}

/**
* @param : Set<Id> userIds
* @return : List<User>
* @description : Fetch current logged in User record
**/
public static List<User> getuserDetails(Set<Id> userIds){
List<User> userDetails = new List<User>();
try{
userDetails = [SELECT Id, Accession_Lab__c, isActive, Profile.Name From
User WHERE Id IN:userIds AND isActive = true LIMIT 1];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return userDetails;
}

/**
* @param : String orderNumber
* @return : Order
* @description : Fetch getCurrentOrder record on the basis of orderNumber
**/
public static Order getCurrentOrder(String orderNumber){
Order currentOrder = new Order();
try{
currentOrder = [SELECT Id FROM Order WHERE OrderNumber =: orderNumber
WITH SECURITY_ENFORCED LIMIT 1];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return currentOrder;
}

/**
* @param : Set<Id>productIds
* @return : List<Product_Relation__c>
* @description : Fetch Product_Relation__c records based on ids.
**/
public static List<Product_Relation__c> getProductRelationList(Set<Id>
productIds){
List<Product_Relation__c> productRelationRec = new
List<Product_Relation__c>();
try{
productRelationRec = [SELECT Id, Name, Parent_Product__c,
Child_Product__c, Child_Product__r.Name, Child_Product__r.IsActive,
Child_Product__r.Methodology__c, Child_Product__r.Id,
Child_Product__r.Product_Text_Description__c
FROM Product_Relation__c WHERE Parent_Product__c IN:productIds AND
Child_Product__r.IsActive = true WITH SECURITY_ENFORCED Order BY Name ASC];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return productRelationRec;
}
/**
* @param : Set<Id> documentIds
* @return : List<ContentVersion>
* @description : Fetch ContentVersion records based on order ids.
**/
public static List<ContentVersion> getContentVersionList(Set<Id> documentIds){
List<ContentVersion> contentVersionList = new List<ContentVersion>();
try{
contentVersionList = [SELECT
Id,Title,ContentSize,ContentUrl,PathOnClient,FileExtension,ContentDocumentId,FileTy
pe,CreatedDate,VersionNumber,CreatedBy.Profile.Name
FROM ContentVersion WHERE contentDocumentId
IN:documentIds ORDER by CreatedDate ASC];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return contentVersionList;
}
/**
* @param : Set<Id> orderId
* @return : List<ContentDocumentLink>
* @description : Fetch ContentDocumentLink records based on order ids.
**/
public static List<ContentDocumentLink> getContentDocumentLinkList(Set<Id>
orderIds){
List<ContentDocumentLink> contentDocumentLinkList = new
List<ContentDocumentLink>();
try{
contentDocumentLinkList = [SELECT Id, ContentDocumentId, LinkedEntityId
FROM ContentDocumentLink WHERE LinkedEntityId IN:orderIds WITH SECURITY_ENFORCED];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return contentDocumentLinkList;
}
/**
* @param : Set<Id> contentDocumentIds , Set<String> titles
* @return : List<ContentNote>
* @description : Fetch ContentNote records based on contentDocumentIds and
titles.
**/
public static List<ContentNote> getContentNoteList(Set<Id> contentDocumentIds ,
Set<String> titles){
List<ContentNote> contentNoteList = new List<ContentNote>();
try{
contentNoteList = [SELECT Id, Title, Content, ContentModifiedDate,
CreatedBy.Name FROM ContentNote WHERE Id IN :contentDocumentIds AND Title
IN :titles ORDER BY CreatedDate DESC];
}catch(Exception e){
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return contentNoteList;
}

/**
* @param : Set<Id> orderItemIds
* @return : List<Test_Report_Mapping__c>
* @description : Fetch Test_Report_Mapping__c records based on order Item Id
set.
**/
public static List<Test_Report_Mapping__c> getTestReportMapping(Set<Id>
orderItemIds){
List<Test_Report_Mapping__c> testReportMappingList = new
List<Test_Report_Mapping__c>();
try {
testReportMappingList = [SELECT Id, CaseNumber__c,
Is_Case_Number_data_from_Order_Sync__c, OrderId__c, Order_Product__c
FROM Test_Report_Mapping__c WHERE
Is_Case_Number_data_from_Order_Sync__c = TRUE
AND Order_Product__c IN: orderItemIds WITH
SECURITY_ENFORCED];
} catch(Exception e) {
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return testReportMappingList;
}

/**
* @param : Set<Id> orderItemIds
* @return : List<OrderItem>
* @description : Fetch OrderItem records based on order Item Id set.
**/
public static List<OrderItem> getOrderItemRecords(Set<Id> orderItemIds){
List<OrderItem> orderItemRec = new List<OrderItem>();
try {
orderItemRec = [SELECT Id, Test_Status__c, Lab_Assignment__c,
TCP_Lab__c, TCA_Lab__c, Prior_Auth__c, Reflex_Comment__c, CaseNumber__c,
CreateNewCase__c
FROM OrderItem WHERE Id IN: orderItemIds WITH
SECURITY_ENFORCED];
} catch(Exception e) {
new ErrorLoggingException().transactionType('ErrorLogging').log(e);
}
return orderItemRec;
}
}

You might also like