Skip to content

Commit

Permalink
HLM-6407 adding changes for facility template
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyanka-eGov committed Jul 23, 2024
1 parent 2e8be47 commit 15ca588
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 16 deletions.
28 changes: 26 additions & 2 deletions utilities/project-factory/src/server/api/campaignApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import createAndSearch from '../config/createAndSearch';
import { getDataFromSheet, generateActivityMessage, throwError, translateSchema, replicateRequest } from "../utils/genericUtils";
import { immediateValidationForTargetSheet, validateSheetData, validateTargetSheetData } from '../validators/campaignValidators';
import { callMdmsTypeSchema, getCampaignNumber } from "./genericApis";
import { boundaryBulkUpload, convertToTypeData, generateHierarchy, generateProcessedFileAndPersist, getBoundaryOnWhichWeSplit, getLocalizedName, reorderBoundariesOfDataAndValidate } from "../utils/campaignUtils";
import { boundaryBulkUpload, convertToTypeData, generateHierarchy, generateProcessedFileAndPersist, getBoundaryOnWhichWeSplit, getLocalizedName, reorderBoundariesOfDataAndValidate, checkIfSourceIsMicroplan } from "../utils/campaignUtils";
const _ = require('lodash');
import { produceModifiedMessages } from "../kafka/Listener";
import { createDataService } from "../service/dataManageService";
Expand Down Expand Up @@ -843,7 +843,31 @@ async function processCreate(request: any, localizationMap?: any) {
boundaryBulkUpload(request, localizationMap);
}
else {
const createAndSearchConfig = createAndSearch[type]
const source = request?.body?.ResourceDetails?.additionalDetails?.source;
// console.log(`Source is MICROPLAN -->`, source);
let createAndSearchConfig: any;
createAndSearchConfig = createAndSearch[type];

if (checkIfSourceIsMicroplan(source)) {
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignType = responseFromCampaignSearch?.CampaignDetails[0]?.projectType;
logger.info(`Data create Source is MICROPLAN --> ${source}`);
if (
createAndSearchConfig &&
createAndSearchConfig.parseArrayConfig &&
createAndSearchConfig.parseArrayConfig.parseLogic
) {
createAndSearchConfig.parseArrayConfig.parseLogic = createAndSearchConfig.parseArrayConfig.parseLogic.map(
(item: any) => {
if (item.sheetColumn === "E") {
item.sheetColumnName += `_${campaignType}`;
}
return item;
}
);
}
}

const dataFromSheet = await getDataFromSheet(request, request?.body?.ResourceDetails?.fileStoreId, request?.body?.ResourceDetails?.tenantId, createAndSearchConfig, undefined, localizationMap)
let schema: any;
if (type == "facility") {
Expand Down
7 changes: 5 additions & 2 deletions utilities/project-factory/src/server/api/genericApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,17 +1205,20 @@ async function callMdmsTypeSchema(
request: any,
tenantId: string,
type: any,
campaignType = "all"
campaignType: string = "all",
additionalParam?: string
) {
const { RequestInfo = {} } = request?.body || {};
const schemaCode = additionalParam && additionalParam.trim() !== "" ? additionalParam : "HCM-ADMIN-CONSOLE.adminSchema";

const requestBody = {
RequestInfo,
MdmsCriteria: {
tenantId: tenantId,
uniqueIdentifiers: [
`${type}.${campaignType}`
],
schemaCode: "HCM-ADMIN-CONSOLE.adminSchema"
schemaCode: schemaCode
}
};
const url = config.host.mdmsV2 + config.paths.mdms_v2_search;
Expand Down
132 changes: 132 additions & 0 deletions utilities/project-factory/src/server/config/createAndSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,138 @@ const createAndSearch: any = {
searchPath: "Facilities"
}
},
"facilityMicroplan": {
requiresToSearchFromSheet: [
{
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CODE",
searchPath: "Facility.id"
}
],
boundaryValidation: {
column: "HCM_ADMIN_CONSOLE_BOUNDARY_CODE_MANDATORY"
},
sheetSchema: {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "FacilityTemplateSchema",
"type": "object",
"properties": {
"Facility Name": {
"type": "string",
"maxLength": 2000,
"minLength": 1
},
"Facility Type": {
// "type": "string",
"enum": ["Warehouse", "Health Facility", "Storing Resource"]
},
"Facility Status": {
// "type": "string",
"enum": ["Temporary", "Permanent"]
},
"Capacity": {
"type": "number",
"minimum": 1,
"maximum": 100000000
}
},
"required": [
"Facility Name",
"Facility Type",
"Facility Status",
"Capacity"
],
"unique": [
"Facility Name"
]
},
uniqueIdentifier: "id",
uniqueIdentifierColumn: "A",
activeColumn: "F",
activeColumnName: "HCM_ADMIN_CONSOLE_FACILITY_USAGE",
uniqueIdentifierColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CODE",
matchEachKey: true,
parseArrayConfig: {
sheetName: "HCM_ADMIN_CONSOLE_FACILITIES",
parseLogic: [
{
sheetColumn: "A",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CODE",
resultantPath: "id",
type: "string"
},
{
sheetColumn: "B",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_NAME_MICROPLAN",
resultantPath: "name",
type: "string"
},
{
sheetColumn: "C",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_TYPE_MICROPLAN",
resultantPath: "usage",
type: "string"
},
{
sheetColumn: "D",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_STATUS_MICROPLAN",
resultantPath: "isPermanent",
type: "boolean",
conversionCondition: {
"Permanent": "true",
"Temporary": ""
}
},
{
sheetColumn: "E",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CAPACITY_MICROPLAN",
resultantPath: "storageCapacity",
type: "number"
},
{
sheetColumn: "J",
sheetColumnName: "HCM_ADMIN_CONSOLE_RESIDING_BOUNDARY_CODE_MICROPLAN"
}
],
tenantId: {
getValueViaPath: "ResourceDetails.tenantId",
resultantPath: "tenantId"
}
},
createBulkDetails: {
limit: 50,
createPath: "Facilities",
url: config.host.facilityHost + "facility/v1/bulk/_create"
},
searchDetails: {
searchElements: [
{
keyPath: "tenantId",
getValueViaPath: "ResourceDetails.tenantId",
isInParams: true,
isInBody: false,
},
{
keyPath: "Facility",
isInParams: false,
isInBody: true,
}
],
searchLimit: {
keyPath: "limit",
value: "200",
isInParams: true,
isInBody: false,
},
searchOffset: {
keyPath: "offset",
value: "0",
isInParams: true,
isInBody: false,
},
url: config.host.facilityHost + "facility/v1/_search",
searchPath: "Facilities"
}
},
"boundary": {
parseArrayConfig: {
sheetName: "HCM_ADMIN_CONSOLE_BOUNDARY_CODE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const createRequestSchema = {
"properties": {
"type": {
"type": "string",
"enum": ["boundary", "facility", "user", "boundaryWithTarget"]
"enum": ["boundary", "facility", "user", "boundaryWithTarget","facilityMicroplan"]
},
"tenantId": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions utilities/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ async function appendSheetsToWorkbook(request: any, boundaryData: any[], differe
const [mainSheetData, uniqueDistrictsForMainSheet, districtLevelRowBoundaryCodeMap] = createBoundaryDataMainSheet(request, boundaryData, differentTabsBasedOnLevel, hierarchy, localizationMap)
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0];
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject);
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject?.additionalDetails?.source);
if (!(isSourceMicroplan)) {
const mainSheet = workbook.addWorksheet(getLocalizedName(getBoundaryTabName(), localizationMap));
const columnWidths = Array(12).fill(30);
Expand Down Expand Up @@ -1777,7 +1777,7 @@ const getConfigurableColumnHeadersBasedOnCampaignType = async (request: any, loc
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0];
let campaignType = campaignObject?.projectType;
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject);
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject?.additionalDetails?.source);
campaignType = (isSourceMicroplan) ? `${config?.prefixForMicroplanCampaigns}-${campaignType}` : campaignType;
const mdmsResponse = await callMdmsTypeSchema(request, request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId, request?.query?.type || request?.body?.ResourceDetails?.type, campaignType)
if (!mdmsResponse || mdmsResponse?.columns.length === 0) {
Expand Down Expand Up @@ -1838,8 +1838,8 @@ async function getBoundaryOnWhichWeSplit(request: any) {
}


function checkIfSourceIsMicroplan(campaignObject: any): boolean {
return campaignObject?.additionalDetails?.source === 'microplan';
function checkIfSourceIsMicroplan(inputString: any): boolean {
return inputString === 'microplan';
}


Expand Down
35 changes: 28 additions & 7 deletions utilities/project-factory/src/server/utils/genericUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,18 +465,24 @@ function setDropdownFromSchema(request: any, schema: any, localizationMap?: { [k
async function createFacilitySheet(request: any, allFacilities: any[], localizationMap?: { [key: string]: string }) {
const tenantId = request?.query?.tenantId;
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const isSourceMicroplan = checkIfSourceIsMicroplan(responseFromCampaignSearch?.CampaignDetails?.[0]);
let schema: any;
const isSourceMicroplan = checkIfSourceIsMicroplan(responseFromCampaignSearch?.CampaignDetails?.[0]?.additionalDetails?.source);
let schema;
if (isSourceMicroplan) {
schema = await callMdmsTypeSchema(request, tenantId, "facility", "microplan");
schema = await callMdmsTypeSchema(request, tenantId, "facility", "microplan", "HCM-ADMIN-CONSOLE.adminSchemaMicroplan");
} else {
schema = await callMdmsTypeSchema(request, tenantId, "facility");
schema = await callMdmsTypeSchema(request, tenantId, "facility", "all");
}
const keys = schema?.columns;
setDropdownFromSchema(request, schema, localizationMap);
const headers = ["HCM_ADMIN_CONSOLE_FACILITY_CODE", ...keys]
const localizedHeaders = getLocalizedHeaders(headers, localizationMap);
let localizedHeaders;
if (isSourceMicroplan) {
localizedHeaders = getLocalizedHeadersForMicroplan(responseFromCampaignSearch, headers, localizationMap);

}
else {
localizedHeaders = getLocalizedHeaders(headers, localizationMap);
}
const facilities = allFacilities.map((facility: any) => {
return [
facility?.id,
Expand Down Expand Up @@ -575,6 +581,21 @@ function getLocalizedHeaders(headers: any, localizationMap?: { [key: string]: st
return messages;
}

function getLocalizedHeadersForMicroplan(responseFromCampaignSearch: any, headers: any, localizationMap?: { [key: string]: string }) {

const projectType = responseFromCampaignSearch?.CampaignDetails?.[0]?.projectType;

headers = headers.map((header: string) => {
if (header === 'HCM_ADMIN_CONSOLE_FACILITY_CAPACITY_MICROPLAN') {
return `${header}_${projectType}`;
}
return header;
});

const messages = headers.map((header: any) => (localizationMap ? localizationMap[header] || header : header));
return messages;
}



function modifyRequestForLocalisation(request: any, tenantId: string) {
Expand Down Expand Up @@ -1085,7 +1106,7 @@ function getDifferentDistrictTabs(boundaryData: any, differentTabsBasedOnLevel:
async function getConfigurableColumnHeadersFromSchemaForTargetSheet(request: any, hierarchy: any, boundaryData: any, differentTabsBasedOnLevel: any, campaignObject: any, localizationMap?: any) {
const districtIndex = hierarchy.indexOf(differentTabsBasedOnLevel);
let headers: any;
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject);
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject?.additionalDetails?.source);
if (isSourceMicroplan) {
logger.info(`Source is Microplan.`);
headers = getLocalizedHeaders(hierarchy, localizationMap);
Expand All @@ -1104,7 +1125,7 @@ async function getMdmsDataBasedOnCampaignType(request: any, localizationMap?: an
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0];
let campaignType = campaignObject.projectType;
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject);
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject?.additionalDetails?.source);
campaignType = (isSourceMicroplan) ? `${config?.prefixForMicroplanCampaigns}-${campaignType}` : campaignType;
const mdmsResponse = await callMdmsTypeSchema(request, request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId, request?.query?.type || request?.body?.ResourceDetails?.type, campaignType)
return mdmsResponse;
Expand Down

0 comments on commit 15ca588

Please sign in to comment.