diff --git a/src/migration/1738896328079-add_viewProfileEvaulation.ts b/src/migration/1738896328079-add_viewProfileEvaulation.ts new file mode 100644 index 00000000..c5ce6afa --- /dev/null +++ b/src/migration/1738896328079-add_viewProfileEvaulation.ts @@ -0,0 +1,112 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddViewProfileEvaulation1738896328079 implements MigrationInterface { + name = 'AddViewProfileEvaulation1738896328079' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_director","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_director\``); + await queryRunner.query(`CREATE VIEW \`view_profile_evaluation\` AS SELECT + \`profileId\`, \`period\`, \`year\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result + FROM \`profileAssessment\` + WHERE \`period\` Is not null + GROUP BY \`profileId\`, \`period\`, \`year\` + ORDER BY \`year\` desc , \`period\` asc +`); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_profile_evaluation","SELECT \n `profileId`, `period`, `year`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result\n FROM `profileAssessment` \n WHERE `period` Is not null\n GROUP BY `profileId`, `period`, `year`\n ORDER BY `year` desc , `period` asc"]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_profile_evaluation","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_profile_evaluation\``); + await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT + \`profile\`.\`id\` AS \`Id\`, + \`profile\`.\`prefix\` AS \`prefix\`, + \`profile\`.\`firstName\` AS \`firstName\`, + \`profile\`.\`lastName\` AS \`lastName\`, + \`profile\`.\`citizenId\` AS \`citizenId\`, + \`profile\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRoot\`.\`orgRootShortName\` + WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1\`.\`orgChild1ShortName\` + WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2\`.\`orgChild2ShortName\` + WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3\`.\`orgChild3ShortName\` + ELSE \`orgChild4\`.\`orgChild4ShortName\` + END), + \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`posType\`.\`posTypeName\` AS \`posType\`, + \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, + \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`orgChild1\`.\`isOfficer\` AS \`isOfficer\`, + \`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`, + \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`posMaster\`.\`id\`, \`profile\`.\`id\`) AS \`key\`, + ( + SELECT \`actFullNameId\` + FROM \`view_director_acting\` AS \`acting\` + WHERE \`acting\`.\`Id\` = \`posMaster\`.\`current_holderId\` + AND \`acting\`.\`orgRootId\` = \`posMaster\`.\`orgRootId\` + AND ( + (\`acting\`.\`orgChild1Id\` IS NULL AND \`posMaster\`.\`orgChild1Id\` IS NULL) + OR (\`acting\`.\`orgChild1Id\` = \`posMaster\`.\`orgChild1Id\`) + ) + AND ( + (\`acting\`.\`orgChild2Id\` IS NULL AND \`posMaster\`.\`orgChild2Id\` IS NULL) + OR (\`acting\`.\`orgChild2Id\` = \`posMaster\`.\`orgChild2Id\`) + ) + AND ( + (\`acting\`.\`orgChild3Id\` IS NULL AND \`posMaster\`.\`orgChild3Id\` IS NULL) + OR (\`acting\`.\`orgChild3Id\` = \`posMaster\`.\`orgChild3Id\`) + ) + AND ( + (\`acting\`.\`orgChild4Id\` IS NULL AND \`posMaster\`.\`orgChild4Id\` IS NULL) + OR (\`acting\`.\`orgChild4Id\` = \`posMaster\`.\`orgChild4Id\`) + ) + ) AS \`actFullNameId\`, + ( + SELECT \`actFullName\` + FROM \`view_director_acting\` AS \`acting\` + WHERE \`acting\`.\`Id\` = \`posMaster\`.\`current_holderId\` + AND \`acting\`.\`orgRootId\` = \`posMaster\`.\`orgRootId\` + AND ( + (\`acting\`.\`orgChild1Id\` IS NULL AND \`posMaster\`.\`orgChild1Id\` IS NULL) + OR (\`acting\`.\`orgChild1Id\` = \`posMaster\`.\`orgChild1Id\`) + ) + AND ( + (\`acting\`.\`orgChild2Id\` IS NULL AND \`posMaster\`.\`orgChild2Id\` IS NULL) + OR (\`acting\`.\`orgChild2Id\` = \`posMaster\`.\`orgChild2Id\`) + ) + AND ( + (\`acting\`.\`orgChild3Id\` IS NULL AND \`posMaster\`.\`orgChild3Id\` IS NULL) + OR (\`acting\`.\`orgChild3Id\` = \`posMaster\`.\`orgChild3Id\`) + ) + AND ( + (\`acting\`.\`orgChild4Id\` IS NULL AND \`posMaster\`.\`orgChild4Id\` IS NULL) + OR (\`acting\`.\`orgChild4Id\` = \`posMaster\`.\`orgChild4Id\`) + ) + ) AS \`actFullName\` + + FROM + ((((((((((\`posMaster\` + JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) + LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) + LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) + LEFT JOIN \`orgChild2\` ON ((\`posMaster\`.\`orgChild2Id\` = \`orgChild2\`.\`id\`))) + LEFT JOIN \`orgChild3\` ON ((\`posMaster\`.\`orgChild3Id\` = \`orgChild3\`.\`id\`))) + LEFT JOIN \`orgChild4\` ON ((\`posMaster\`.\`orgChild4Id\` = \`orgChild4\`.\`id\`))) + JOIN \`posLevel\` ON ((\`profile\`.\`posLevelId\` = \`posLevel\`.\`id\`))) + JOIN \`posType\` ON ((\`profile\`.\`posTypeId\` = \`posType\`.\`id\`))) + LEFT JOIN \`position\` ON ((\`posMaster\`.\`id\` = \`position\`.\`posMasterId\`))) + LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) + WHERE + (\`position\`.\`positionIsSelected\` = TRUE)`); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_director","SELECT \n `profile`.`id` AS `Id`,\n `profile`.`prefix` AS `prefix`,\n `profile`.`firstName` AS `firstName`,\n `profile`.`lastName` AS `lastName`,\n `profile`.`citizenId` AS `citizenId`,\n `profile`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`posMaster`.`orgChild1Id` IS NULL) THEN `orgRoot`.`orgRootShortName`\n WHEN (`posMaster`.`orgChild2Id` IS NULL) THEN `orgChild1`.`orgChild1ShortName`\n WHEN (`posMaster`.`orgChild3Id` IS NULL) THEN `orgChild2`.`orgChild2ShortName`\n WHEN (`posMaster`.`orgChild4Id` IS NULL) THEN `orgChild3`.`orgChild3ShortName`\n ELSE `orgChild4`.`orgChild4ShortName`\n END),\n `posMaster`.`posMasterNo`) AS `posNo`,\n `posMaster`.`isDirector` AS `isDirector`,\n `posLevel`.`posLevelName` AS `posLevel`,\n `posType`.`posTypeName` AS `posType`,\n `posExecutive`.`posExecutiveName` AS `posExecutiveName`,\n `orgRoot`.`isDeputy` AS `isDeputy`,\n `orgChild1`.`isOfficer` AS `isOfficer`,\n `posMaster`.`orgRevisionId` AS `orgRevisionId`,\n `posMaster`.`orgRootId` AS `orgRootId`,\n `posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`posMaster`.`id`, `profile`.`id`) AS `key`,\n (\n SELECT `actFullNameId` \n FROM `view_director_acting` AS `acting`\n WHERE `acting`.`Id` = `posMaster`.`current_holderId` \n AND `acting`.`orgRootId` = `posMaster`.`orgRootId` \n AND (\n (`acting`.`orgChild1Id` IS NULL AND `posMaster`.`orgChild1Id` IS NULL) \n OR (`acting`.`orgChild1Id` = `posMaster`.`orgChild1Id`)\n ) \n AND (\n (`acting`.`orgChild2Id` IS NULL AND `posMaster`.`orgChild2Id` IS NULL) \n OR (`acting`.`orgChild2Id` = `posMaster`.`orgChild2Id`)\n ) \n AND (\n (`acting`.`orgChild3Id` IS NULL AND `posMaster`.`orgChild3Id` IS NULL) \n OR (`acting`.`orgChild3Id` = `posMaster`.`orgChild3Id`)\n ) \n AND (\n (`acting`.`orgChild4Id` IS NULL AND `posMaster`.`orgChild4Id` IS NULL) \n OR (`acting`.`orgChild4Id` = `posMaster`.`orgChild4Id`)\n )\n ) AS `actFullNameId`,\n (\n SELECT `actFullName` \n FROM `view_director_acting` AS `acting`\n WHERE `acting`.`Id` = `posMaster`.`current_holderId` \n AND `acting`.`orgRootId` = `posMaster`.`orgRootId` \n AND (\n (`acting`.`orgChild1Id` IS NULL AND `posMaster`.`orgChild1Id` IS NULL) \n OR (`acting`.`orgChild1Id` = `posMaster`.`orgChild1Id`)\n ) \n AND (\n (`acting`.`orgChild2Id` IS NULL AND `posMaster`.`orgChild2Id` IS NULL) \n OR (`acting`.`orgChild2Id` = `posMaster`.`orgChild2Id`)\n ) \n AND (\n (`acting`.`orgChild3Id` IS NULL AND `posMaster`.`orgChild3Id` IS NULL) \n OR (`acting`.`orgChild3Id` = `posMaster`.`orgChild3Id`)\n ) \n AND (\n (`acting`.`orgChild4Id` IS NULL AND `posMaster`.`orgChild4Id` IS NULL) \n OR (`acting`.`orgChild4Id` = `posMaster`.`orgChild4Id`)\n )\n ) AS `actFullName`\n \n FROM\n ((((((((((`posMaster`\n JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`)))\n LEFT JOIN `orgRoot` ON ((`posMaster`.`orgRootId` = `orgRoot`.`id`)))\n LEFT JOIN `orgChild1` ON ((`posMaster`.`orgChild1Id` = `orgChild1`.`id`)))\n LEFT JOIN `orgChild2` ON ((`posMaster`.`orgChild2Id` = `orgChild2`.`id`)))\n LEFT JOIN `orgChild3` ON ((`posMaster`.`orgChild3Id` = `orgChild3`.`id`)))\n LEFT JOIN `orgChild4` ON ((`posMaster`.`orgChild4Id` = `orgChild4`.`id`)))\n JOIN `posLevel` ON ((`profile`.`posLevelId` = `posLevel`.`id`)))\n JOIN `posType` ON ((`profile`.`posTypeId` = `posType`.`id`)))\n LEFT JOIN `position` ON ((`posMaster`.`id` = `position`.`posMasterId`)))\n LEFT JOIN `posExecutive` ON ((`position`.`posExecutiveId` = `posExecutive`.`id`)))\n WHERE\n (`position`.`positionIsSelected` = TRUE)"]); + } + +}