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' into dev
  • Loading branch information
xKeCo committed Dec 13, 2024
2 parents 64d0f72 + f43a037 commit dbae833
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,9 @@ export class ContributionToIndicatorResultsRepository extends Repository<Contrib
tocId: string,
): 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 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,
(
select json_arrayagg(json_object(
"contribution_id", linked_ctir.id,
"is_active", linked_ctir.is_active,
"result_id", linked_r.id,
"result_code", linked_r.result_code,
"result_title", linked_r.title,
"phase_name", linked_v.phase_name,
"phase_id", linked_v.id,
"result_type", linked_rt.name,
"result_submitter", linked_ci.official_code,
"result_status", linked_rs.status_name,
"result_creation_date", date_format(linked_r.created_date, '%Y-%m-%d')
))
from ${env.DB_NAME}.linked_result lr
left join ${env.DB_NAME}.result linked_r on linked_r.id = lr.linked_results_id and linked_r.is_active
left join ${env.DB_NAME}.contribution_to_indicator_results linked_ctir on linked_ctir.result_id = linked_r.id
and linked_ctir.contribution_to_indicator_id = cti.id
left join ${env.DB_NAME}.\`version\` linked_v on linked_r.version_id = linked_v.id
left join ${env.DB_NAME}.result_type linked_rt on linked_r.result_type_id = linked_rt.id
left join ${env.DB_NAME}.results_by_inititiative linked_rbi on linked_rbi.result_id = linked_r.id and linked_rbi.initiative_role_id = 1
left join ${env.DB_NAME}.clarisa_initiatives linked_ci on linked_ci.id = linked_rbi.inititiative_id
left join ${env.DB_NAME}.result_status linked_rs on linked_rs.result_status_id = linked_r.status_id
where lr.origin_result_id = main_r.id and lr.is_active and linked_r.id is not null
group by main_r.id
) as linked_results
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,18 @@ export class ContributionToIndicatorsRepository extends Repository<ContributionT
"is_active", is_active,
"result_id", result_id,
"result_code", result_code,
"result_title", result_title,
"title", result_title,
"phase_name", phase_name,
"phase_id", phase_id,
"version_id", phase_id,
"result_type", result_type,
"result_submitter", result_submitter,
"result_status", result_status,
"result_creation_date", result_creation_date,
"original_linked_result_code", original_linked_result_code,
"original_linked_result_phase", original_linked_result_phase
"status_name", result_status,
"created_date", result_creation_date
))
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,
null as original_linked_result_code, null as original_linked_result_phase
main_rs.status_name as result_status, date_format(main_r.created_date, '%Y-%m-%d') as result_creation_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
Expand All @@ -150,33 +147,6 @@ 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 linked_ctir.id as contribution_id, linked_ctir.is_active as is_active, linked_r.id as result_id,
linked_r.result_code as result_code, linked_r.title as result_title, linked_v.phase_name as phase_name,
linked_v.id as phase_id, linked_rt.name as result_type, linked_ci.official_code as result_submitter,
linked_rs.status_name as result_status, date_format(linked_r.created_date, '%Y-%m-%d') as result_creation_date,
original_results.result_code as original_linked_result_code, original_results.phase_id as original_linked_result_phase
from (
select main_r.id as result_id, main_r.result_code, main_r.version_id as phase_id
from ${env.DB_TOC}.toc_results_indicators tri
right join ${env.DB_TOC}.toc_results outcomes on tri.toc_results_id = outcomes.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}.result main_r on main_r.id = rtr.results_id and main_r.is_active
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
where tri.toc_result_indicator_id = ${tocId} and tri.is_active
) as original_results
left join ${env.DB_NAME}.linked_result lr on lr.is_active and lr.origin_result_id = original_results.result_id
left join ${env.DB_NAME}.result linked_r on linked_r.id = lr.linked_results_id and linked_r.is_active
left join ${env.DB_NAME}.contribution_to_indicator_results linked_ctir on linked_ctir.result_id = linked_r.id
left join ${env.DB_NAME}.\`version\` linked_v on linked_r.version_id = linked_v.id
left join ${env.DB_NAME}.result_type linked_rt on linked_r.result_type_id = linked_rt.id
left join ${env.DB_NAME}.results_by_inititiative linked_rbi on linked_rbi.result_id = linked_r.id and linked_rbi.initiative_role_id = 1
left join ${env.DB_NAME}.clarisa_initiatives linked_ci on linked_ci.id = linked_rbi.inititiative_id
left join ${env.DB_NAME}.result_status linked_rs on linked_rs.result_status_id = linked_r.status_id
where linked_r.id is not null
) inner_q
`;
}
Expand Down

0 comments on commit dbae833

Please sign in to comment.