diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 708b5fc0..87645e59 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -5278,15 +5278,15 @@ export class ProfileController extends Controller { "current_holders", "current_holders.orgRoot", "profileSalary", - "profileEducations" + "profileEducations", ], order: { // profileSalary: { // order: "DESC", // }, profileEducations: { - createdAt: "DESC" - } + createdAt: "DESC", + }, }, }); if (!profile) { @@ -5465,9 +5465,10 @@ export class ProfileController extends Controller { isPosmasterAct: data.length > 0, posmasterAct: data, salary: profile ? profile.amount : null, - education: profile && profile.profileEducations.length > 0 - ? `${profile.profileEducations[0].degree ?? ""}-${profile.profileEducations[0].field ?? ""}` - : "-" + education: + profile && profile.profileEducations.length > 0 + ? `${profile.profileEducations[0].degree ?? ""}-${profile.profileEducations[0].field ?? ""}` + : "-", }; if (_profile.child4Id != null) { @@ -7867,4 +7868,47 @@ export class ProfileController extends Controller { ]); return new HttpSuccess(); } + + /** + * API แก้ไขอีเมล + * + * @summary แก้ไขอีเมล (USER) + * + */ + @Get("keycloak/user") + async listUserKeycloak( + @Request() request: RequestWithUser, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query() keyword: string = "", + ) { + // sort by org + const [profiles, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.roleKeycloaks", "roleKeycloaks") + .where("profile.citizenId LIKE :citizenId", { + citizenId: `%${keyword}%`, + }) + .andWhere(keyword != null && keyword != "" ? `profile.citizenId like '%${keyword}%'` : "1=1") + .andWhere( + keyword != null && keyword != "" + ? `CONCAT(profile.prefix, profile.firstName," ",profile.lastName) like '%${keyword}%'` + : "1=1", + ) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const _profiles = profiles.map((_data) => ({ + id: _data.id, + firstname: _data.firstName, + lastname: _data.lastName, + email: _data.email, + username: _data.citizenId, + citizenId: _data.citizenId, + roles: _data.roleKeycloaks, + enabled: _data.isActive, + })); + + return new HttpSuccess({ data: _profiles, total }); + } } diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index ff23fe98..47c8342f 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany, JoinColumn, ManyToOne, Double } from "typeorm"; +import { Entity, Column, OneToMany, JoinColumn, ManyToOne, Double, ManyToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { PosMaster } from "./PosMaster"; import { PosLevel } from "./PosLevel"; @@ -35,6 +35,7 @@ import { DevelopmentRequest } from "./DevelopmentRequest"; import { StateOperatorUser } from "./StateOperatorUser"; import { StateUserComment } from "./StateUserComment"; import { CommandSign } from "./CommandSign"; +import { RoleKeycloak } from "./RoleKeycloak"; @Entity("profile") export class Profile extends EntityBase { @@ -174,6 +175,12 @@ export class Profile extends EntityBase { }) isLeave: boolean; + @Column({ + comment: "สถานะการใช้งาน", + default: true, + }) + isActive: boolean; + @Column({ nullable: true, comment: "เหตุผลเกษียณ", @@ -548,6 +555,9 @@ export class Profile extends EntityBase { @OneToMany(() => PermissionOrg, (permissionOrg) => permissionOrg.profileTree) permissionProfiles: PermissionOrg[]; + + @ManyToMany(() => RoleKeycloak, (roleKeycloak) => roleKeycloak.profiles) + roleKeycloaks: RoleKeycloak[]; } @Entity("profileHistory") diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 748d64c7..80288eec 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany, ManyToOne, Double } from "typeorm"; +import { Entity, Column, OneToMany, ManyToOne, Double, ManyToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { EmployeePosLevel } from "./EmployeePosLevel"; import { EmployeePosType } from "./EmployeePosType"; @@ -33,6 +33,7 @@ import { ProfileEmployeeEmployment } from "./ProfileEmployeeEmployment"; import { ProfileEdit } from "./ProfileEdit"; import { ProfileDevelopment } from "./ProfileDevelopment"; import { DevelopmentRequest } from "./DevelopmentRequest"; +import { RoleKeycloak } from "./RoleKeycloak"; @Entity("profileEmployee") export class ProfileEmployee extends EntityBase { @@ -192,6 +193,12 @@ export class ProfileEmployee extends EntityBase { }) isLeave: boolean; + @Column({ + comment: "สถานะการใช้งาน", + default: true, + }) + isActive: boolean; + @Column({ nullable: true, comment: "เหตุผลเกษียณ", @@ -801,6 +808,9 @@ export class ProfileEmployee extends EntityBase { default: null, }) dutyTimeEffectiveDate: Date; + + @ManyToMany(() => RoleKeycloak, (roleKeycloak) => roleKeycloak.profileEmployees) + roleKeycloaks: RoleKeycloak[]; } @Entity("profileEmployeeHistory") diff --git a/src/entities/RoleKeycloak.ts b/src/entities/RoleKeycloak.ts new file mode 100644 index 00000000..c1a9083b --- /dev/null +++ b/src/entities/RoleKeycloak.ts @@ -0,0 +1,21 @@ +import { Entity, Column, ManyToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Profile } from "./Profile"; +import { ProfileEmployee } from "./ProfileEmployee"; + +@Entity("roleKeycloak") +export class RoleKeycloak extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อ role", + length: 255, + default: null, + }) + name: string; + + @ManyToMany(() => Profile, (profile) => profile.roleKeycloaks) + profiles: Profile[]; + + @ManyToMany(() => ProfileEmployee, (profileEmployee) => profileEmployee.roleKeycloaks) + profileEmployees: ProfileEmployee[]; +} diff --git a/src/migration/1731311003025-update_table_profie_add_rolekeycloak.ts b/src/migration/1731311003025-update_table_profie_add_rolekeycloak.ts new file mode 100644 index 00000000..a4a392b0 --- /dev/null +++ b/src/migration/1731311003025-update_table_profie_add_rolekeycloak.ts @@ -0,0 +1,304 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableProfieAddRolekeycloak1731311003025 implements MigrationInterface { + name = 'UpdateTableProfieAddRolekeycloak1731311003025' + + 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_acting","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_director_acting\``); + 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(`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(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_director_acting","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_director_acting\``); + await queryRunner.query(`CREATE TABLE \`roleKeycloak\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'ชื่อ role', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 1`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 1`); + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 1`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 1`); + await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT + \`profileChild\`.\`id\` AS \`Id\`, + \`profileChild\`.\`prefix\` AS \`prefix\`, + \`profileChild\`.\`firstName\` AS \`firstName\`, + \`profileChild\`.\`lastName\` AS \`lastName\`, + \`profileChild\`.\`citizenId\` AS \`citizenId\`, + \`profileChild\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` + WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` + WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` + WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` + ELSE \`orgChild4Child\`.\`orgChild4ShortName\` + END), + \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, + \`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`posType\`.\`posTypeName\` AS \`posType\`, + \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, + \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`, + \`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`profile\`.\`prefix\`, + \`profile\`.\`firstName\`, + ' ', + \`profile\`.\`lastName\`) AS \`actFullName\` + FROM + ((((((((((((((\`posMasterAct\` + JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) + JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) + LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) + LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) + LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) + LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) + LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) + JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`))) + JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`))) + JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) + LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) + JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) + LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`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_acting","SELECT \n `profileChild`.`id` AS `Id`,\n `profileChild`.`prefix` AS `prefix`,\n `profileChild`.`firstName` AS `firstName`,\n `profileChild`.`lastName` AS `lastName`,\n `profileChild`.`citizenId` AS `citizenId`,\n `profileChild`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`posMaster`.`orgChild1Id` IS NULL) THEN `orgRootChild`.`orgRootShortName`\n WHEN (`posMaster`.`orgChild2Id` IS NULL) THEN `orgChild1Child`.`orgChild1ShortName`\n WHEN (`posMaster`.`orgChild3Id` IS NULL) THEN `orgChild2Child`.`orgChild2ShortName`\n WHEN (`posMaster`.`orgChild4Id` IS NULL) THEN `orgChild3Child`.`orgChild3ShortName`\n ELSE `orgChild4Child`.`orgChild4ShortName`\n END),\n `posMaster`.`posMasterNo`) AS `posNo`,\n `posMasterChild`.`isDirector` AS `isDirectorChild`,\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 `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`, `profileChild`.`id`) AS `key`,\n `profile`.`id` AS `actFullNameId`,\n CONCAT(`profile`.`prefix`,\n `profile`.`firstName`,\n ' ',\n `profile`.`lastName`) AS `actFullName`\n FROM\n ((((((((((((((`posMasterAct`\n JOIN `posMaster` `posMasterChild` ON ((`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`)))\n JOIN `profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`)))\n LEFT JOIN `orgRoot` `orgRootChild` ON ((`posMasterChild`.`orgRootId` = `orgRootChild`.`id`)))\n LEFT JOIN `orgChild1` `orgChild1Child` ON ((`posMasterChild`.`orgChild1Id` = `orgChild1Child`.`id`)))\n LEFT JOIN `orgChild2` `orgChild2Child` ON ((`posMasterChild`.`orgChild2Id` = `orgChild2Child`.`id`)))\n LEFT JOIN `orgChild3` `orgChild3Child` ON ((`posMasterChild`.`orgChild3Id` = `orgChild3Child`.`id`)))\n LEFT JOIN `orgChild4` `orgChild4Child` ON ((`posMasterChild`.`orgChild4Id` = `orgChild4Child`.`id`)))\n JOIN `posLevel` ON ((`profileChild`.`posLevelId` = `posLevel`.`id`)))\n JOIN `posType` ON ((`profileChild`.`posTypeId` = `posType`.`id`)))\n JOIN `posMaster` ON ((`posMasterAct`.`posMasterId` = `posMaster`.`id`)))\n LEFT JOIN `orgRoot` ON ((`posMaster`.`orgRootId` = `orgRoot`.`id`)))\n JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`)))\n LEFT JOIN `position` ON ((`posMasterChild`.`id` = `position`.`posMasterId`)))\n LEFT JOIN `posExecutive` ON ((`position`.`posExecutiveId` = `posExecutive`.`id`)))\n WHERE\n (`position`.`positionIsSelected` = TRUE)"]); + 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\`, + \`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\`, + NULL AS \`actFullNameId\`, + NULL 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 `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 NULL AS `actFullNameId`,\n NULL AS `actFullName`\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)"]); + } + + 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_director","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_director\``); + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_director_acting","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_director_acting\``); + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`isActive\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`isActive\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`isActive\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`isActive\``); + await queryRunner.query(`DROP TABLE \`roleKeycloak\``); + await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT + \`profileChild\`.\`id\` AS \`Id\`, + \`profileChild\`.\`prefix\` AS \`prefix\`, + \`profileChild\`.\`firstName\` AS \`firstName\`, + \`profileChild\`.\`lastName\` AS \`lastName\`, + \`profileChild\`.\`citizenId\` AS \`citizenId\`, + \`profileChild\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` + ELSE \`orgChild4Child\`.\`orgChild4ShortName\` + END), + \`bma_ehr_organization_demo\`.\`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`bma_ehr_organization_demo\`.\`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`bma_ehr_organization_demo\`.\`posType\`.\`posTypeName\` AS \`posType\`, + NULL AS \`posExecutiveName\`, + \`bma_ehr_organization_demo\`.\`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`, + \`profileChild\`.\`id\`) AS \`key\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`bma_ehr_organization_demo\`.\`profile\`.\`prefix\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`firstName\`, + ' ', + \`bma_ehr_organization_demo\`.\`profile\`.\`lastName\`) AS \`actFullName\` + FROM + ((((((((((((\`bma_ehr_organization_demo\`.\`posMasterAct\` + JOIN \`bma_ehr_organization_demo\`.\`posMaster\` \`posMasterChild\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`bma_ehr_organization_demo\`.\`posLevel\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`bma_ehr_organization_demo\`.\`posType\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posMaster\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterId\` = \`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgRoot\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` = \`bma_ehr_organization_demo\`.\`orgRoot\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`)))`); + 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_acting","SELECT \n `profileChild`.`id` AS `Id`,\n `profileChild`.`prefix` AS `prefix`,\n `profileChild`.`firstName` AS `firstName`,\n `profileChild`.`lastName` AS `lastName`,\n `profileChild`.`citizenId` AS `citizenId`,\n `profileChild`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` IS NULL) THEN `orgRootChild`.`orgRootShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` IS NULL) THEN `orgChild1Child`.`orgChild1ShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` IS NULL) THEN `orgChild2Child`.`orgChild2ShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` IS NULL) THEN `orgChild3Child`.`orgChild3ShortName`\n ELSE `orgChild4Child`.`orgChild4ShortName`\n END),\n `bma_ehr_organization_demo`.`posMaster`.`posMasterNo`) AS `posNo`,\n `posMasterChild`.`isDirector` AS `isDirectorChild`,\n `bma_ehr_organization_demo`.`posMaster`.`isDirector` AS `isDirector`,\n `bma_ehr_organization_demo`.`posLevel`.`posLevelName` AS `posLevel`,\n `bma_ehr_organization_demo`.`posType`.`posTypeName` AS `posType`,\n NULL AS `posExecutiveName`,\n `bma_ehr_organization_demo`.`orgRoot`.`isDeputy` AS `isDeputy`,\n `bma_ehr_organization_demo`.`posMaster`.`orgRootId` AS `orgRootId`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`bma_ehr_organization_demo`.`posMaster`.`id`,\n `profileChild`.`id`) AS `key`,\n `bma_ehr_organization_demo`.`profile`.`id` AS `actFullNameId`,\n CONCAT(`bma_ehr_organization_demo`.`profile`.`prefix`,\n `bma_ehr_organization_demo`.`profile`.`firstName`,\n ' ',\n `bma_ehr_organization_demo`.`profile`.`lastName`) AS `actFullName`\n FROM\n ((((((((((((`bma_ehr_organization_demo`.`posMasterAct`\n JOIN `bma_ehr_organization_demo`.`posMaster` `posMasterChild` ON ((`bma_ehr_organization_demo`.`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`)))\n JOIN `bma_ehr_organization_demo`.`profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgRoot` `orgRootChild` ON ((`posMasterChild`.`orgRootId` = `orgRootChild`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild1` `orgChild1Child` ON ((`posMasterChild`.`orgChild1Id` = `orgChild1Child`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild2` `orgChild2Child` ON ((`posMasterChild`.`orgChild2Id` = `orgChild2Child`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild3` `orgChild3Child` ON ((`posMasterChild`.`orgChild3Id` = `orgChild3Child`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild4` `orgChild4Child` ON ((`posMasterChild`.`orgChild4Id` = `orgChild4Child`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posLevel` ON ((`profileChild`.`posLevelId` = `bma_ehr_organization_demo`.`posLevel`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posType` ON ((`profileChild`.`posTypeId` = `bma_ehr_organization_demo`.`posType`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posMaster` ON ((`bma_ehr_organization_demo`.`posMasterAct`.`posMasterId` = `bma_ehr_organization_demo`.`posMaster`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgRoot` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgRootId` = `bma_ehr_organization_demo`.`orgRoot`.`id`)))\n JOIN `bma_ehr_organization_demo`.`profile` ON ((`bma_ehr_organization_demo`.`posMaster`.`current_holderId` = `bma_ehr_organization_demo`.`profile`.`id`)))"]); + await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT + \`bma_ehr_organization_demo\`.\`profile\`.\`id\` AS \`Id\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`prefix\` AS \`prefix\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`firstName\` AS \`firstName\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`lastName\` AS \`lastName\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`citizenId\` AS \`citizenId\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`bma_ehr_organization_demo\`.\`orgRoot\`.\`orgRootShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`bma_ehr_organization_demo\`.\`orgChild1\`.\`orgChild1ShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`bma_ehr_organization_demo\`.\`orgChild2\`.\`orgChild2ShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`bma_ehr_organization_demo\`.\`orgChild3\`.\`orgChild3ShortName\` + ELSE \`bma_ehr_organization_demo\`.\`orgChild4\`.\`orgChild4ShortName\` + END), + \`bma_ehr_organization_demo\`.\`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`bma_ehr_organization_demo\`.\`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`bma_ehr_organization_demo\`.\`posType\`.\`posTypeName\` AS \`posType\`, + NULL AS \`posExecutiveName\`, + \`bma_ehr_organization_demo\`.\`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`id\`) AS \`key\`, + NULL AS \`actFullNameId\`, + NULL AS \`actFullName\` + FROM + ((((((((\`bma_ehr_organization_demo\`.\`posMaster\` + JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgRoot\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` = \`bma_ehr_organization_demo\`.\`orgRoot\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild1\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` = \`bma_ehr_organization_demo\`.\`orgChild1\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild2\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` = \`bma_ehr_organization_demo\`.\`orgChild2\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild3\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` = \`bma_ehr_organization_demo\`.\`orgChild3\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild4\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` = \`bma_ehr_organization_demo\`.\`orgChild4\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posLevel\` ON ((\`bma_ehr_organization_demo\`.\`profile\`.\`posLevelId\` = \`bma_ehr_organization_demo\`.\`posLevel\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posType\` ON ((\`bma_ehr_organization_demo\`.\`profile\`.\`posTypeId\` = \`bma_ehr_organization_demo\`.\`posType\`.\`id\`)))`); + 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 `bma_ehr_organization_demo`.`profile`.`id` AS `Id`,\n `bma_ehr_organization_demo`.`profile`.`prefix` AS `prefix`,\n `bma_ehr_organization_demo`.`profile`.`firstName` AS `firstName`,\n `bma_ehr_organization_demo`.`profile`.`lastName` AS `lastName`,\n `bma_ehr_organization_demo`.`profile`.`citizenId` AS `citizenId`,\n `bma_ehr_organization_demo`.`profile`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` IS NULL) THEN `bma_ehr_organization_demo`.`orgRoot`.`orgRootShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` IS NULL) THEN `bma_ehr_organization_demo`.`orgChild1`.`orgChild1ShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` IS NULL) THEN `bma_ehr_organization_demo`.`orgChild2`.`orgChild2ShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` IS NULL) THEN `bma_ehr_organization_demo`.`orgChild3`.`orgChild3ShortName`\n ELSE `bma_ehr_organization_demo`.`orgChild4`.`orgChild4ShortName`\n END),\n `bma_ehr_organization_demo`.`posMaster`.`posMasterNo`) AS `posNo`,\n `bma_ehr_organization_demo`.`posMaster`.`isDirector` AS `isDirector`,\n `bma_ehr_organization_demo`.`posLevel`.`posLevelName` AS `posLevel`,\n `bma_ehr_organization_demo`.`posType`.`posTypeName` AS `posType`,\n NULL AS `posExecutiveName`,\n `bma_ehr_organization_demo`.`orgRoot`.`isDeputy` AS `isDeputy`,\n `bma_ehr_organization_demo`.`posMaster`.`orgRootId` AS `orgRootId`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`bma_ehr_organization_demo`.`posMaster`.`id`,\n `bma_ehr_organization_demo`.`profile`.`id`) AS `key`,\n NULL AS `actFullNameId`,\n NULL AS `actFullName`\n FROM\n ((((((((`bma_ehr_organization_demo`.`posMaster`\n JOIN `bma_ehr_organization_demo`.`profile` ON ((`bma_ehr_organization_demo`.`posMaster`.`current_holderId` = `bma_ehr_organization_demo`.`profile`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgRoot` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgRootId` = `bma_ehr_organization_demo`.`orgRoot`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild1` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` = `bma_ehr_organization_demo`.`orgChild1`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild2` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` = `bma_ehr_organization_demo`.`orgChild2`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild3` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` = `bma_ehr_organization_demo`.`orgChild3`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild4` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` = `bma_ehr_organization_demo`.`orgChild4`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posLevel` ON ((`bma_ehr_organization_demo`.`profile`.`posLevelId` = `bma_ehr_organization_demo`.`posLevel`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posType` ON ((`bma_ehr_organization_demo`.`profile`.`posTypeId` = `bma_ehr_organization_demo`.`posType`.`id`)))"]); + await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT + \`bma_ehr_organization_demo\`.\`profile\`.\`id\` AS \`Id\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`prefix\` AS \`prefix\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`firstName\` AS \`firstName\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`lastName\` AS \`lastName\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`citizenId\` AS \`citizenId\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`bma_ehr_organization_demo\`.\`orgRoot\`.\`orgRootShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`bma_ehr_organization_demo\`.\`orgChild1\`.\`orgChild1ShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`bma_ehr_organization_demo\`.\`orgChild2\`.\`orgChild2ShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`bma_ehr_organization_demo\`.\`orgChild3\`.\`orgChild3ShortName\` + ELSE \`bma_ehr_organization_demo\`.\`orgChild4\`.\`orgChild4ShortName\` + END), + \`bma_ehr_organization_demo\`.\`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`bma_ehr_organization_demo\`.\`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`bma_ehr_organization_demo\`.\`posType\`.\`posTypeName\` AS \`posType\`, + NULL AS \`posExecutiveName\`, + \`bma_ehr_organization_demo\`.\`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`id\`) AS \`key\`, + NULL AS \`actFullNameId\`, + NULL AS \`actFullName\` + FROM + ((((((((\`bma_ehr_organization_demo\`.\`posMaster\` + JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgRoot\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` = \`bma_ehr_organization_demo\`.\`orgRoot\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild1\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` = \`bma_ehr_organization_demo\`.\`orgChild1\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild2\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` = \`bma_ehr_organization_demo\`.\`orgChild2\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild3\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` = \`bma_ehr_organization_demo\`.\`orgChild3\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild4\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` = \`bma_ehr_organization_demo\`.\`orgChild4\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posLevel\` ON ((\`bma_ehr_organization_demo\`.\`profile\`.\`posLevelId\` = \`bma_ehr_organization_demo\`.\`posLevel\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posType\` ON ((\`bma_ehr_organization_demo\`.\`profile\`.\`posTypeId\` = \`bma_ehr_organization_demo\`.\`posType\`.\`id\`)))`); + 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 `bma_ehr_organization_demo`.`profile`.`id` AS `Id`,\n `bma_ehr_organization_demo`.`profile`.`prefix` AS `prefix`,\n `bma_ehr_organization_demo`.`profile`.`firstName` AS `firstName`,\n `bma_ehr_organization_demo`.`profile`.`lastName` AS `lastName`,\n `bma_ehr_organization_demo`.`profile`.`citizenId` AS `citizenId`,\n `bma_ehr_organization_demo`.`profile`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` IS NULL) THEN `bma_ehr_organization_demo`.`orgRoot`.`orgRootShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` IS NULL) THEN `bma_ehr_organization_demo`.`orgChild1`.`orgChild1ShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` IS NULL) THEN `bma_ehr_organization_demo`.`orgChild2`.`orgChild2ShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` IS NULL) THEN `bma_ehr_organization_demo`.`orgChild3`.`orgChild3ShortName`\n ELSE `bma_ehr_organization_demo`.`orgChild4`.`orgChild4ShortName`\n END),\n `bma_ehr_organization_demo`.`posMaster`.`posMasterNo`) AS `posNo`,\n `bma_ehr_organization_demo`.`posMaster`.`isDirector` AS `isDirector`,\n `bma_ehr_organization_demo`.`posLevel`.`posLevelName` AS `posLevel`,\n `bma_ehr_organization_demo`.`posType`.`posTypeName` AS `posType`,\n NULL AS `posExecutiveName`,\n `bma_ehr_organization_demo`.`orgRoot`.`isDeputy` AS `isDeputy`,\n `bma_ehr_organization_demo`.`posMaster`.`orgRootId` AS `orgRootId`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`bma_ehr_organization_demo`.`posMaster`.`id`,\n `bma_ehr_organization_demo`.`profile`.`id`) AS `key`,\n NULL AS `actFullNameId`,\n NULL AS `actFullName`\n FROM\n ((((((((`bma_ehr_organization_demo`.`posMaster`\n JOIN `bma_ehr_organization_demo`.`profile` ON ((`bma_ehr_organization_demo`.`posMaster`.`current_holderId` = `bma_ehr_organization_demo`.`profile`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgRoot` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgRootId` = `bma_ehr_organization_demo`.`orgRoot`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild1` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` = `bma_ehr_organization_demo`.`orgChild1`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild2` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` = `bma_ehr_organization_demo`.`orgChild2`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild3` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` = `bma_ehr_organization_demo`.`orgChild3`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild4` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` = `bma_ehr_organization_demo`.`orgChild4`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posLevel` ON ((`bma_ehr_organization_demo`.`profile`.`posLevelId` = `bma_ehr_organization_demo`.`posLevel`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posType` ON ((`bma_ehr_organization_demo`.`profile`.`posTypeId` = `bma_ehr_organization_demo`.`posType`.`id`)))"]); + await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT + \`profileChild\`.\`id\` AS \`Id\`, + \`profileChild\`.\`prefix\` AS \`prefix\`, + \`profileChild\`.\`firstName\` AS \`firstName\`, + \`profileChild\`.\`lastName\` AS \`lastName\`, + \`profileChild\`.\`citizenId\` AS \`citizenId\`, + \`profileChild\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` + WHEN (\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` + ELSE \`orgChild4Child\`.\`orgChild4ShortName\` + END), + \`bma_ehr_organization_demo\`.\`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`bma_ehr_organization_demo\`.\`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`bma_ehr_organization_demo\`.\`posType\`.\`posTypeName\` AS \`posType\`, + NULL AS \`posExecutiveName\`, + \`bma_ehr_organization_demo\`.\`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`bma_ehr_organization_demo\`.\`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`, + \`profileChild\`.\`id\`) AS \`key\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`bma_ehr_organization_demo\`.\`profile\`.\`prefix\`, + \`bma_ehr_organization_demo\`.\`profile\`.\`firstName\`, + ' ', + \`bma_ehr_organization_demo\`.\`profile\`.\`lastName\`) AS \`actFullName\` + FROM + ((((((((((((\`bma_ehr_organization_demo\`.\`posMasterAct\` + JOIN \`bma_ehr_organization_demo\`.\`posMaster\` \`posMasterChild\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`bma_ehr_organization_demo\`.\`posLevel\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`bma_ehr_organization_demo\`.\`posType\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`posMaster\` ON ((\`bma_ehr_organization_demo\`.\`posMasterAct\`.\`posMasterId\` = \`bma_ehr_organization_demo\`.\`posMaster\`.\`id\`))) + LEFT JOIN \`bma_ehr_organization_demo\`.\`orgRoot\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`orgRootId\` = \`bma_ehr_organization_demo\`.\`orgRoot\`.\`id\`))) + JOIN \`bma_ehr_organization_demo\`.\`profile\` ON ((\`bma_ehr_organization_demo\`.\`posMaster\`.\`current_holderId\` = \`bma_ehr_organization_demo\`.\`profile\`.\`id\`)))`); + 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_acting","SELECT \n `profileChild`.`id` AS `Id`,\n `profileChild`.`prefix` AS `prefix`,\n `profileChild`.`firstName` AS `firstName`,\n `profileChild`.`lastName` AS `lastName`,\n `profileChild`.`citizenId` AS `citizenId`,\n `profileChild`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` IS NULL) THEN `orgRootChild`.`orgRootShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` IS NULL) THEN `orgChild1Child`.`orgChild1ShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` IS NULL) THEN `orgChild2Child`.`orgChild2ShortName`\n WHEN (`bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` IS NULL) THEN `orgChild3Child`.`orgChild3ShortName`\n ELSE `orgChild4Child`.`orgChild4ShortName`\n END),\n `bma_ehr_organization_demo`.`posMaster`.`posMasterNo`) AS `posNo`,\n `posMasterChild`.`isDirector` AS `isDirectorChild`,\n `bma_ehr_organization_demo`.`posMaster`.`isDirector` AS `isDirector`,\n `bma_ehr_organization_demo`.`posLevel`.`posLevelName` AS `posLevel`,\n `bma_ehr_organization_demo`.`posType`.`posTypeName` AS `posType`,\n NULL AS `posExecutiveName`,\n `bma_ehr_organization_demo`.`orgRoot`.`isDeputy` AS `isDeputy`,\n `bma_ehr_organization_demo`.`posMaster`.`orgRootId` AS `orgRootId`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `bma_ehr_organization_demo`.`posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`bma_ehr_organization_demo`.`posMaster`.`id`,\n `profileChild`.`id`) AS `key`,\n `bma_ehr_organization_demo`.`profile`.`id` AS `actFullNameId`,\n CONCAT(`bma_ehr_organization_demo`.`profile`.`prefix`,\n `bma_ehr_organization_demo`.`profile`.`firstName`,\n ' ',\n `bma_ehr_organization_demo`.`profile`.`lastName`) AS `actFullName`\n FROM\n ((((((((((((`bma_ehr_organization_demo`.`posMasterAct`\n JOIN `bma_ehr_organization_demo`.`posMaster` `posMasterChild` ON ((`bma_ehr_organization_demo`.`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`)))\n JOIN `bma_ehr_organization_demo`.`profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgRoot` `orgRootChild` ON ((`posMasterChild`.`orgRootId` = `orgRootChild`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild1` `orgChild1Child` ON ((`posMasterChild`.`orgChild1Id` = `orgChild1Child`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild2` `orgChild2Child` ON ((`posMasterChild`.`orgChild2Id` = `orgChild2Child`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild3` `orgChild3Child` ON ((`posMasterChild`.`orgChild3Id` = `orgChild3Child`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgChild4` `orgChild4Child` ON ((`posMasterChild`.`orgChild4Id` = `orgChild4Child`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posLevel` ON ((`profileChild`.`posLevelId` = `bma_ehr_organization_demo`.`posLevel`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posType` ON ((`profileChild`.`posTypeId` = `bma_ehr_organization_demo`.`posType`.`id`)))\n JOIN `bma_ehr_organization_demo`.`posMaster` ON ((`bma_ehr_organization_demo`.`posMasterAct`.`posMasterId` = `bma_ehr_organization_demo`.`posMaster`.`id`)))\n LEFT JOIN `bma_ehr_organization_demo`.`orgRoot` ON ((`bma_ehr_organization_demo`.`posMaster`.`orgRootId` = `bma_ehr_organization_demo`.`orgRoot`.`id`)))\n JOIN `bma_ehr_organization_demo`.`profile` ON ((`bma_ehr_organization_demo`.`posMaster`.`current_holderId` = `bma_ehr_organization_demo`.`profile`.`id`)))"]); + } + +}