Skip to content

Commit

Permalink
Merge branch 'console' into console-v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jagankumar-egov committed Dec 5, 2024
2 parents 1309e63 + c89e818 commit 85a20ca
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 138 deletions.
195 changes: 107 additions & 88 deletions health-services/project-factory/src/server/api/genericApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@ function getRawCellValue(cell: any) {
return cell.value.richText.map((rt: any) => rt.text).join('');
}
else if ('hyperlink' in cell.value) {
if(cell?.value?.text?.richText?.length > 0){
if (cell?.value?.text?.richText?.length > 0) {
return cell.value.text.richText.map((t: any) => t.text).join('');
}
else{
else {
return cell.value.text;
}
}
else if ('formula' in cell.value) {
// Get the result of the formula
return cell.value.result;
}
else if('sharedFormula' in cell.value){
else if ('sharedFormula' in cell.value) {
// Get the result of the shared formula
return cell.value.result;
}
Expand Down Expand Up @@ -844,65 +844,65 @@ async function getBoundarySheetData(
}
}

async function getConfigurableColumnHeadersBasedOnCampaignTypeForBoundaryManagement(request:any, localizationMap?: { [key: string]: string }) {
try {
const mdmsResponse = await callMdmsTypeSchema(
request,
request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId,
false,
request?.query?.type || request?.body?.ResourceDetails?.type,
"all"
);
if (!mdmsResponse || mdmsResponse?.columns.length === 0) {
logger.error(
`Campaign Type all has not any columns configured in schema`
);
throwError(
"COMMON",
400,
"SCHEMA_ERROR",
`Campaign Type all has not any columns configured in schema`
async function getConfigurableColumnHeadersBasedOnCampaignTypeForBoundaryManagement(request: any, localizationMap?: { [key: string]: string }) {
try {
const mdmsResponse = await callMdmsTypeSchema(
request,
request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId,
false,
request?.query?.type || request?.body?.ResourceDetails?.type,
"all"
);
}
// Extract columns from the response
const columnsForGivenCampaignId = mdmsResponse?.columns;
if (!mdmsResponse || mdmsResponse?.columns.length === 0) {
logger.error(
`Campaign Type all has not any columns configured in schema`
);
throwError(
"COMMON",
400,
"SCHEMA_ERROR",
`Campaign Type all has not any columns configured in schema`
);
}
// Extract columns from the response
const columnsForGivenCampaignId = mdmsResponse?.columns;

// Get localized headers based on the column names
const headerColumnsAfterHierarchy = getLocalizedHeaders(
columnsForGivenCampaignId,
localizationMap
);
if (
!headerColumnsAfterHierarchy.includes(
getLocalizedName(config.boundary.boundaryCode, localizationMap)
)
) {
logger.error(
`Column Headers of generated Boundary Template does not have ${getLocalizedName(
config.boundary.boundaryCode,
localizationMap
)} column`
// Get localized headers based on the column names
const headerColumnsAfterHierarchy = getLocalizedHeaders(
columnsForGivenCampaignId,
localizationMap
);
if (
!headerColumnsAfterHierarchy.includes(
getLocalizedName(config.boundary.boundaryCode, localizationMap)
)
) {
logger.error(
`Column Headers of generated Boundary Template does not have ${getLocalizedName(
config.boundary.boundaryCode,
localizationMap
)} column`
);
throwError(
"COMMON",
400,
"VALIDATION_ERROR",
`Column Headers of generated Boundary Template does not have ${getLocalizedName(
config.boundary.boundaryCode,
localizationMap
)} column`
);
}
return headerColumnsAfterHierarchy;
} catch (error: any) {
console.log(error);
throwError(
"COMMON",
"FILE",
400,
"VALIDATION_ERROR",
`Column Headers of generated Boundary Template does not have ${getLocalizedName(
config.boundary.boundaryCode,
localizationMap
)} column`
"FETCHING_COLUMN_ERROR",
"Error fetching column Headers From Schema (either boundary code column not found or given Campaign Type not found in schema) Check logs"
);
}
return headerColumnsAfterHierarchy;
} catch (error: any) {
console.log(error);
throwError(
"FILE",
400,
"FETCHING_COLUMN_ERROR",
"Error fetching column Headers From Schema (either boundary code column not found or given Campaign Type not found in schema) Check logs"
);
}
}
async function createStaff(resouceBody: any) {
// Create staff
Expand Down Expand Up @@ -985,44 +985,63 @@ async function createProjectFacility(resouceBody: any) {
}

// Helper function to create staff
const createStaffHelper = (resourceId: any, projectId: any, resouceBody: any, tenantId: any, startDate: any, endDate: any) => {
const ProjectStaff = {
tenantId: tenantId.split(".")?.[0],
projectId,
userId: resourceId,
startDate,
endDate,
};
const newResourceBody = { ...resouceBody, ProjectStaff };
return createStaff(newResourceBody);
const createProjectStaffHelper = (resourceId: any, projectId: any, resouceBody: any, tenantId: any, startDate: any, endDate: any) => {
try {
const ProjectStaff = {
tenantId: tenantId.split(".")?.[0],
projectId,
userId: resourceId,
startDate,
endDate,
};
const newResourceBody = { ...resouceBody, ProjectStaff };
return createStaff(newResourceBody);
} catch (error) {
// Log the error if the API call fails
logger.error(`Failed to create project staff for staffId ${resourceId}:`, error);
throw error; // Rethrow the error to propagate it
}
};

// Helper function to create project resource
const createProjectResourceHelper = (resourceId: any, projectId: any, resouceBody: any, tenantId: any, startDate: any, endDate: any) => {
const ProjectResource = {
tenantId: tenantId.split(".")?.[0],
projectId,
resource: {
productVariantId: resourceId,
type: "DRUG",
isBaseUnitVariant: false,
},
startDate,
endDate,
};
const newResourceBody = { ...resouceBody, ProjectResource };
return createProjectResource(newResourceBody);
try {
const ProjectResource = {
tenantId: tenantId.split(".")?.[0],
projectId,
resource: {
productVariantId: resourceId,
type: "DRUG",
isBaseUnitVariant: false,
},
startDate,
endDate,
};
const newResourceBody = { ...resouceBody, ProjectResource };
return createProjectResource(newResourceBody);
}
catch (error) {
// Log the error if the API call fails
logger.error(`Failed to create project resource for resourceId ${resourceId}:`, error);
throw error; // Rethrow the error to propagate it
}
};

// Helper function to create project facility
const createProjectFacilityHelper = (resourceId: any, projectId: any, resouceBody: any, tenantId: any) => {
const ProjectFacility = {
tenantId: tenantId.split(".")?.[0],
projectId,
facilityId: resourceId,
};
const newResourceBody = { ...resouceBody, ProjectFacility };
return createProjectFacility(newResourceBody);
const createProjectFacilityHelper = (resourceId: any, projectId: any, resouceBody: any, tenantId: any, startDate: any, endDate: any) => {
try {
const ProjectFacility = {
tenantId: tenantId.split(".")?.[0],
projectId,
facilityId: resourceId,
};
const newResourceBody = { ...resouceBody, ProjectFacility };
return createProjectFacility(newResourceBody);
} catch (error) {
// Log the error if the API call fails
logger.error(`Failed to create facility for facilityId ${resourceId}:`, error);
throw error; // Rethrow the error to propagate it
}
};


Expand Down Expand Up @@ -1059,7 +1078,7 @@ async function createRelatedEntity(
mappingArray.push(mappingObject)
}
}
const mappingObject: any = { mappingArray: mappingArray, CampaignDetails: CampaignDetails, RequestInfo: requestBody?.RequestInfo , parentCampaign: requestBody?.parentCampaign }
const mappingObject: any = { mappingArray: mappingArray, CampaignDetails: CampaignDetails, RequestInfo: requestBody?.RequestInfo, parentCampaign: requestBody?.parentCampaign }
await processMapping(mappingObject)
}

Expand Down Expand Up @@ -1466,7 +1485,7 @@ export {
getMDMSV1Data,
callMdmsTypeSchema,
getSheetDataFromWorksheet,
createStaffHelper,
createProjectStaffHelper,
createProjectFacilityHelper, createProjectResourceHelper,
createAndUploadJsonFile,
getConfigurableColumnHeadersBasedOnCampaignTypeForBoundaryManagement
Expand Down
7 changes: 2 additions & 5 deletions health-services/project-factory/src/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getDBSchemaName = (dbSchema = "") => {
}
// Configuration object containing various environment variables
const config = {
batchSize:100,
cacheTime: 300,
isProduction: process.env ? true : false,
token: "", // add default token if core services are not port forwarded
Expand All @@ -32,19 +33,15 @@ const config = {
boundaryCodeMandatory: 'HCM_ADMIN_CONSOLE_BOUNDARY_CODE_MANDATORY',
boundaryCodeOld: "HCM_ADMIN_CONSOLE_BOUNDARY_CODE_OLD",
boundaryTab: process.env.BOUNDARY_TAB_NAME || "HCM_ADMIN_CONSOLE_BOUNDARY_DATA",
// Default criteria for generating different tabs
generateDifferentTabsOnBasisOf: process.env.SPLIT_BOUNDARIES_ON || "ADMIN_DISTRITO",
// default configurable number of data of boundary type on which generate different tabs
numberOfBoundaryDataOnWhichWeSplit: process.env.SPLIT_BOUNDARIES_ON_LENGTH || "2",
boundaryRelationShipDelay: 3500
},
facility: {
facilityTab: process.env.FACILITY_TAB_NAME || "HCM_ADMIN_CONSOLE_FACILITIES",
facilitySchemaMasterName: process.env.FACILITY_SCHEMA_MASTER || "facilitySchema",
},
user: {
userTab: process.env.USER_TAB_NAME || "HCM_ADMIN_CONSOLE_USER_LIST",
userSchemaMasterName: process.env.USER_SCHEMA_MASTER || "userSchema",
userDefaultPassword: process.env.USER_DEFAULT_PASSWORD || "eGov@123",
userPasswordAutoGenerate: process.env.USER_PASSWORD_AUTO_GENERATE || "true",
mapUserViaCommonParent: process.env.MAP_USER_VIA_COMMON_PARENT || false,
Expand Down Expand Up @@ -167,7 +164,7 @@ const config = {
unfrozeTillRow: process.env.UNFROZE_TILL_ROW || "10000",
unfrozeTillColumn: process.env.UNFROZE_TILL_COLUMN || "50",
moduleName: process.env.MODULE_NAME || "HCM-ADMIN-CONSOLE",
readMeTab: "HCM_README_SHEETNAME",
readMeTab: process.env.READ_ME_TAB || "HCM_README_SHEETNAME",
userMainBoundary: "mz",
userMainBoundaryType: "Country",
idgen: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const downloadDataService = async (request: express.Request) => {
tenantId: request?.query?.tenantId,
forceUpdate: 'true',
hierarchyType: request?.query?.hierarchyType,
campaignId :request?.query?.campaignId,
campaignId: request?.query?.campaignId,
};
const newRequestToGenerate = replicateRequest(request, newRequestBody, params);
// Added auto generate since no previous generate request found
Expand All @@ -60,11 +60,11 @@ const downloadDataService = async (request: express.Request) => {
// Send response with resource details
if (resourceDetails != null && responseData != null && responseData.length > 0) {
responseData[0].additionalDetails = {
...responseData[0].additionalDetails,
...responseData[0].additionalDetails,
...resourceDetails.additionalDetails // Spread the properties of resourceDetails.additionalDetails
};
}

return responseData;
}

Expand Down Expand Up @@ -94,14 +94,14 @@ const getBoundaryDataService = async (
logger.info("NO CACHE FOUND :: REQUEST :: " + cacheKey);
}
const workbook = getNewExcelWorkbook();
const localizationMapHierarchy = hierarchyType && await getLocalizedMessagesHandler(request, request?.query?.tenantId, getLocalisationModuleName(hierarchyType),true);
const localizationMapHierarchy = hierarchyType && await getLocalizedMessagesHandler(request, request?.query?.tenantId, getLocalisationModuleName(hierarchyType), true);
const localizationMapModule = await getLocalizedMessagesHandler(request, request?.query?.tenantId);
const localizationMap = { ...localizationMapHierarchy, ...localizationMapModule };
// Retrieve boundary sheet data
const boundarySheetData: any = await getBoundarySheetData(request, localizationMap);
const localizedBoundaryTab = getLocalizedName(getBoundaryTabName(), localizationMap);
const boundarySheet = workbook.addWorksheet(localizedBoundaryTab);
addDataToSheet(request,boundarySheet, boundarySheetData, '93C47D', 40, true);
addDataToSheet(request, boundarySheet, boundarySheetData, '93C47D', 40, true);
const boundaryFileDetails: any = await createAndUploadFile(workbook, request);
// Return boundary file details
logger.info("RETURNS THE BOUNDARY RESPONSE");
Expand All @@ -120,7 +120,10 @@ const getBoundaryDataService = async (

const createDataService = async (request: any) => {

const localizationMap = await getLocalizedMessagesHandler(request, request?.body?.ResourceDetails?.tenantId);
const hierarchyType = request?.body?.ResourceDetails?.hierarchyType;
const localizationMapHierarchy = hierarchyType && await getLocalizedMessagesHandler(request, request?.body?.ResourceDetails?.tenantId, getLocalisationModuleName(hierarchyType), true);
const localizationMapModule = await getLocalizedMessagesHandler(request, request?.body?.ResourceDetails?.tenantId);
const localizationMap = { ...localizationMapHierarchy, ...localizationMapModule };
// Validate the create request
logger.info("Validating data create request")
await validateCreateRequest(request, localizationMap);
Expand Down
Loading

0 comments on commit 85a20ca

Please sign in to comment.