Skip to content

Commit

Permalink
Merge branch 'P2-903-Tracking-of-outcomes-achievements-against-target…
Browse files Browse the repository at this point in the history
…s' of https://github.com/AllianceBioversityCIAT/onecgiar_pr into P2-903-Tracking-of-outcomes-achievements-against-targets
  • Loading branch information
xKeCo committed Dec 16, 2024
2 parents 09a6933 + 4139ee8 commit 1155a71
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,52 @@ export class ContributionToIndicatorResultsRepository extends Repository<Contrib
): Promise<ContributionToIndicatorResultsDto[]> {
const dataQuery = `
select main_ctir.id as contribution_id, main_ctir.is_active, main_r.id as result_id, main_r.result_code, main_r.title,
main_v.phase_name, main_v.id as version_id, main_rt.name as result_type, main_ci.official_code as result_submitter,
main_rs.status_name, date_format(main_r.created_date, '%Y-%m-%d') as created_date
from ${env.DB_TOC}.toc_results_indicators tri
right join ${env.DB_TOC}.toc_results indicator_outcome on tri.toc_results_id = indicator_outcome.id
right join ${env.DB_TOC}.toc_results outcomes on outcomes.toc_result_id = indicator_outcome.toc_result_id
right join ${env.DB_NAME}.results_toc_result rtr on rtr.toc_result_id = outcomes.id and rtr.is_active
left join ${env.DB_NAME}.contribution_to_indicators cti on
convert(cti.toc_result_id using utf8mb4) = convert(tri.toc_result_indicator_id using utf8mb4) and cti.is_active
left join ${env.DB_NAME}.result main_r on main_r.id = rtr.results_id and main_r.is_active
left join ${env.DB_NAME}.contribution_to_indicator_results main_ctir on main_ctir.result_id = main_r.id
and main_ctir.contribution_to_indicator_id = cti.id
left join ${env.DB_NAME}.\`version\` main_v on main_r.version_id = main_v.id
left join ${env.DB_NAME}.result_type main_rt on main_r.result_type_id = main_rt.id
left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id
and main_rbi.initiative_role_id = 1 and rtr.initiative_id = main_rbi.inititiative_id
left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id
left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id
where tri.toc_result_indicator_id = ? and tri.is_active and main_r.id is not null
main_v.phase_name, main_v.id as version_id, main_rt.name as result_type, main_ci.official_code as result_submitter,
main_rs.status_name, date_format(main_r.created_date, '%Y-%m-%d') as created_date, true as is_manually_mapped
from ${env.DB_TOC}.toc_results_indicators tri
right join ${env.DB_TOC}.toc_results indicator_outcome on tri.toc_results_id = indicator_outcome.id
right join ${env.DB_TOC}.toc_results outcomes on outcomes.toc_result_id = indicator_outcome.toc_result_id
right join ${env.DB_NAME}.results_toc_result rtr on rtr.toc_result_id = outcomes.id and rtr.is_active
left join ${env.DB_NAME}.contribution_to_indicators cti on
convert(cti.toc_result_id using utf8mb4) = convert(tri.toc_result_indicator_id using utf8mb4) and cti.is_active
left join ${env.DB_NAME}.result main_r on main_r.id = rtr.results_id and main_r.is_active
left join ${env.DB_NAME}.contribution_to_indicator_results main_ctir on main_ctir.result_id = main_r.id
and main_ctir.contribution_to_indicator_id = cti.id
left join ${env.DB_NAME}.\`version\` main_v on main_r.version_id = main_v.id
left join ${env.DB_NAME}.result_type main_rt on main_r.result_type_id = main_rt.id
left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id
and main_rbi.initiative_role_id = 1 and rtr.initiative_id = main_rbi.inititiative_id
left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id
left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id
where tri.toc_result_indicator_id = ? and tri.is_active and main_r.id is not null
union all
select main_ctir.id as contribution_id, main_ctir.is_active, main_r.id as result_id, main_r.result_code, main_r.title,
main_v.phase_name, main_v.id as version_id, main_rt.name as result_type, main_ci.official_code as result_submitter,
main_rs.status_name, date_format(main_r.created_date, '%Y-%m-%d') as created_date, false as is_manually_mapped
from ${env.DB_NAME}.contribution_to_indicator_results main_ctir
left join ${env.DB_NAME}.contribution_to_indicators cti on main_ctir.contribution_to_indicator_id = cti.id and cti.is_active
left join ${env.DB_NAME}.result main_r on main_r.id = main_ctir.result_id and main_r.is_active
left join ${env.DB_NAME}.\`version\` main_v on main_r.version_id = main_v.id
left join ${env.DB_NAME}.result_type main_rt on main_r.result_type_id = main_rt.id
left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id
and main_rbi.initiative_role_id = 1
left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id
left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id
where cti.toc_result_id = ? and main_ctir.result_id not in (
select rtr.results_id
from ${env.DB_NAME}.results_toc_result rtr
where rtr.is_active and rtr.toc_result_id in (
select outcomes.id
from ${env.DB_TOC}.toc_results_indicators tri
right join ${env.DB_TOC}.toc_results indicator_outcome on tri.toc_results_id = indicator_outcome.id
right join ${env.DB_TOC}.toc_results outcomes on outcomes.toc_result_id = indicator_outcome.toc_result_id
where convert(cti.toc_result_id using utf8mb4) = convert(tri.toc_result_indicator_id using utf8mb4) and tri.is_active
)
)
`;

return this.dataSource
.query(dataQuery, [tocId])
.query(dataQuery, [tocId, tocId])
.then((result) => result)
.catch((err) => {
throw this._handlersError.returnErrorRepository({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ export class ContributionToIndicatorsRepository extends Repository<ContributionT
"result_type", result_type,
"result_submitter", result_submitter,
"status_name", result_status,
"created_date", result_creation_date
"created_date", result_creation_date,
"is_manually_mapped", is_manually_mapped
))
from (
select main_ctir.id as contribution_id, main_ctir.is_active, main_r.id as result_id, main_r.result_code, main_r.title as result_title,
main_v.phase_name, main_v.id as phase_id, main_rt.name as result_type, main_ci.official_code as result_submitter,
main_rs.status_name as result_status, date_format(main_r.created_date, '%Y-%m-%d') as result_creation_date
main_rs.status_name as result_status, date_format(main_r.created_date, '%Y-%m-%d') as result_creation_date, true as is_manually_mapped
from ${env.DB_TOC}.toc_results_indicators tri
right join ${env.DB_TOC}.toc_results indicator_outcome on tri.toc_results_id = indicator_outcome.id
right join ${env.DB_TOC}.toc_results outcomes on outcomes.toc_result_id = indicator_outcome.toc_result_id
Expand All @@ -147,6 +148,30 @@ export class ContributionToIndicatorsRepository extends Repository<ContributionT
left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id
left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id
where tri.toc_result_indicator_id = ${tocId} and tri.is_active and main_r.id is not null
union all
select main_ctir.id as contribution_id, main_ctir.is_active, main_r.id as result_id, main_r.result_code, main_r.title as result_title,
main_v.phase_name, main_v.id as phase_id, main_rt.name as result_type, main_ci.official_code as result_submitter,
main_rs.status_name as result_status, date_format(main_r.created_date, '%Y-%m-%d') as result_creation_date, false as is_manually_mapped
from ${env.DB_NAME}.contribution_to_indicator_results main_ctir
left join ${env.DB_NAME}.contribution_to_indicators cti on main_ctir.contribution_to_indicator_id = cti.id and cti.is_active
left join ${env.DB_NAME}.result main_r on main_r.id = main_ctir.result_id and main_r.is_active
left join ${env.DB_NAME}.\`version\` main_v on main_r.version_id = main_v.id
left join ${env.DB_NAME}.result_type main_rt on main_r.result_type_id = main_rt.id
left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id
and main_rbi.initiative_role_id = 1
left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id
left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id
where convert(cti.toc_result_id using utf8mb4) = convert(${tocId} using utf8mb4) and main_ctir.result_id not in (
select rtr.results_id
from ${env.DB_NAME}.results_toc_result rtr
where rtr.is_active and rtr.toc_result_id in (
select outcomes.id
from ${env.DB_TOC}.toc_results_indicators tri
right join ${env.DB_TOC}.toc_results indicator_outcome on tri.toc_results_id = indicator_outcome.id
right join ${env.DB_TOC}.toc_results outcomes on outcomes.toc_result_id = indicator_outcome.toc_result_id
where convert(cti.toc_result_id using utf8mb4) = convert(tri.toc_result_indicator_id using utf8mb4) and tri.is_active
)
)
) inner_q
`;
}
Expand Down

0 comments on commit 1155a71

Please sign in to comment.