From f1993a41cc11fe77e89b2448af4141aa97394006 Mon Sep 17 00:00:00 2001 From: Pyry Rouvila Date: Fri, 4 Oct 2024 11:57:41 +0300 Subject: [PATCH 01/18] fix(header): advanced search button fixed and remove unused code (#7723) * fix(header): advanced search button fixed and remove unused code * fix: add missing goToSearchResult dispatch --- .../client/src/components/Header/Header.tsx | 44 ++++++------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/packages/client/src/components/Header/Header.tsx b/packages/client/src/components/Header/Header.tsx index 628b3fcb23..e8817bf478 100644 --- a/packages/client/src/components/Header/Header.tsx +++ b/packages/client/src/components/Header/Header.tsx @@ -13,20 +13,14 @@ import { constantsMessages } from '@client/i18n/messages' import { messages } from '@client/i18n/messages/views/header' import { Icon } from '@opencrvs/components/lib/Icon' import { - goBack, - goForward, goToEvents as goToEventsAction, - goToPerformanceHome, goToSearch, goToSearchResult, goToSettings, - goToTeamSearch, - goToTeamUserList, goToCreateNewUserWithLocationId, goToCreateNewUser, goToAdvancedSearch } from '@client/navigation' -import { redirectToAuthentication } from '@client/profile/profileActions' import { getUserDetails } from '@client/profile/profileSelectors' import { IStoreState } from '@client/store' import styled from 'styled-components' @@ -68,19 +62,12 @@ type IStateProps = { } type IDispatchProps = { - redirectToAuthentication: typeof redirectToAuthentication - goToSearchResult: typeof goToSearchResult goToEvents: typeof goToEventsAction goToSearch: typeof goToSearch - goToSettings: typeof goToSettings - goBack: typeof goBack - goForward: typeof goForward - goToPerformanceHomeAction: typeof goToPerformanceHome goToCreateNewUserWithLocationId: typeof goToCreateNewUserWithLocationId goToCreateNewUser: typeof goToCreateNewUser - goToTeamSearchAction: typeof goToTeamSearch - goToTeamUserListAction: typeof goToTeamUserList goToAdvancedSearch: typeof goToAdvancedSearch + goToSearchResult: typeof goToSearchResult setAdvancedSearchParam: typeof setAdvancedSearchParam } @@ -147,20 +134,23 @@ const USERS_WITHOUT_SEARCH = SYS_ADMIN_ROLES.concat( export const HeaderComponent = (props: IFullProps) => { const { location, - mapPerformanceClickHandler, - goToCreateNewUserWithLocationId, - changeTeamLocation, - goToCreateNewUser, userDetails, mobileSearchBar, - goToSearch, offlineData, className, intl, activeMenuItem, title, mobileRight, - goToEvents + goToSearch, + goToEvents, + goToCreateNewUserWithLocationId, + goToCreateNewUser, + goToAdvancedSearch, + goToSearchResult, + setAdvancedSearchParam, + mapPerformanceClickHandler, + changeTeamLocation } = props const getMobileHeaderActionProps = (activeMenuItem: ACTIVE_MENU_ITEM) => { @@ -365,9 +355,7 @@ export const HeaderComponent = (props: IFullProps) => { ? undefined : navigationList } - searchHandler={(text, type) => - props.goToSearchResult(text, type, isMobile) - } + searchHandler={(text, type) => goToSearchResult(text, type, isMobile)} /> ) } @@ -492,20 +480,14 @@ export const Header = connect( .map((field) => field.name) }), { - redirectToAuthentication, - goToSearchResult, goToSearch, goToSettings, - goBack, - goForward, goToEvents: goToEventsAction, - goToPerformanceHomeAction: goToPerformanceHome, goToCreateNewUserWithLocationId, goToCreateNewUser, - goToTeamSearchAction: goToTeamSearch, - goToTeamUserListAction: goToTeamUserList, goToAdvancedSearch: goToAdvancedSearch, - setAdvancedSearchParam: setAdvancedSearchParam + setAdvancedSearchParam: setAdvancedSearchParam, + goToSearchResult } )(injectIntl(withRouter(HeaderComponent))) From fb8659fc0f645a98dc39a35cc51cbe2192268e92 Mon Sep 17 00:00:00 2001 From: tahmidrahman-dsi Date: Fri, 4 Oct 2024 19:27:26 +0600 Subject: [PATCH 02/18] fix: label param in required error messages --- packages/client/src/views/RegisterForm/review/ReviewSection.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/views/RegisterForm/review/ReviewSection.tsx b/packages/client/src/views/RegisterForm/review/ReviewSection.tsx index 066e5ce651..0ed935b4b1 100644 --- a/packages/client/src/views/RegisterForm/review/ReviewSection.tsx +++ b/packages/client/src/views/RegisterForm/review/ReviewSection.tsx @@ -894,7 +894,7 @@ class ReviewSectionComp extends React.Component { {field.ignoreFieldLabelOnErrorMessage || (field.previewGroup && - this.props.intl.formatMessage(field.label) + ' ')} + this.props.intl.formatMessage(field.label, field.labelParam) + ' ')} {this.props.intl.formatMessage( errorsOnField.message, errorsOnField.props From b413289aab62035fd9e0909384e9d2f746c65c94 Mon Sep 17 00:00:00 2001 From: tahmidrahman-dsi Date: Mon, 7 Oct 2024 17:20:19 +0600 Subject: [PATCH 03/18] fix: condition to detect if informant type changed or not --- packages/client/src/views/RegisterForm/RegisterForm.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/client/src/views/RegisterForm/RegisterForm.tsx b/packages/client/src/views/RegisterForm/RegisterForm.tsx index 9adcb5957f..16164f06f8 100644 --- a/packages/client/src/views/RegisterForm/RegisterForm.tsx +++ b/packages/client/src/views/RegisterForm/RegisterForm.tsx @@ -705,7 +705,8 @@ class RegisterFormView extends React.Component { const { declaration } = this.props const informantTypeChanged = prevProps.declaration?.data?.informant?.informantType !== - declaration?.data?.informant?.informantType + declaration?.data?.informant?.informantType && + Boolean(declaration?.data?.informant?.informantType) // see https://github.com/opencrvs/opencrvs-core/issues/5820 if (informantTypeChanged) { From 4800d3638b90a2d9911ab8bd012df631b8150b9d Mon Sep 17 00:00:00 2001 From: tahmidrahman-dsi Date: Mon, 7 Oct 2024 17:48:19 +0600 Subject: [PATCH 04/18] fix: prevent extra space in person name in notification content --- packages/notification/src/features/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/notification/src/features/utils.ts b/packages/notification/src/features/utils.ts index 640a10d2f9..3012f8bb52 100644 --- a/packages/notification/src/features/utils.ts +++ b/packages/notification/src/features/utils.ts @@ -117,7 +117,7 @@ export function getPersonName( if (!name) { error(record, `name not found in patient resource for ${compositionCode}`) } - return [name.given?.join(' '), name.family].join(' ').trim() + return [name.given?.join(' ').trim(), name.family].join(' ').trim() } export function getRegistrationLocation( From fede7111c963f1d45acd94f17aa93a2879eb7407 Mon Sep 17 00:00:00 2001 From: tahmidrahman-dsi Date: Mon, 7 Oct 2024 18:34:22 +0600 Subject: [PATCH 05/18] fix: amend function slugify --- .github/workflows/trigger-e2e-environment.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/trigger-e2e-environment.yml b/.github/workflows/trigger-e2e-environment.yml index 151a22db08..dc83a559e1 100644 --- a/.github/workflows/trigger-e2e-environment.yml +++ b/.github/workflows/trigger-e2e-environment.yml @@ -79,7 +79,8 @@ jobs: .trim() .replace(/\s+/g, '-') .replace(/-+/g, '-') - .substr(0, 35); + .substr(0, 35) + .replace(/[^a-zA-Z0-9]+$/g, ''); } const result = await github.rest.repos.createDispatchEvent({ owner: 'opencrvs', From cd5d71f1fc0c36c1921b31184caafcb4c6ee389c Mon Sep 17 00:00:00 2001 From: tahmidrahman-dsi Date: Tue, 8 Oct 2024 11:50:38 +0600 Subject: [PATCH 06/18] fix: forward child/deceased name in birth/death rejection notification --- .../notification/src/features/sentForUpdates/handler.ts | 7 +++++-- packages/notification/src/features/utils.ts | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/notification/src/features/sentForUpdates/handler.ts b/packages/notification/src/features/sentForUpdates/handler.ts index c188e57375..99e87f8c15 100644 --- a/packages/notification/src/features/sentForUpdates/handler.ts +++ b/packages/notification/src/features/sentForUpdates/handler.ts @@ -14,6 +14,7 @@ import { sendNotification } from '@notification/features/sms/utils' import { messageKeys } from '@notification/i18n/messages' import { getOfficeName, + getPersonName, getRegistrationLocation } from '@notification/features/utils' import { @@ -41,7 +42,8 @@ export async function birthSentForUpdatesNotification( trackingId: getTrackingId(rejectedRecord), crvsOffice: getOfficeName(rejectedRecord), registrationLocation: getRegistrationLocation(rejectedRecord), - informantName: getInformantName(rejectedRecord) + informantName: getInformantName(rejectedRecord), + name: getPersonName(rejectedRecord, 'child') } ) return h.response().code(200) @@ -66,7 +68,8 @@ export async function deathSentForUpdatesNotification( trackingId: getTrackingId(rejectedRecord), crvsOffice: getOfficeName(rejectedRecord), registrationLocation: getRegistrationLocation(rejectedRecord), - informantName: getInformantName(rejectedRecord) + informantName: getInformantName(rejectedRecord), + name: getPersonName(rejectedRecord, 'deceased') } ) return h.response().code(200) diff --git a/packages/notification/src/features/utils.ts b/packages/notification/src/features/utils.ts index 3012f8bb52..84154448c6 100644 --- a/packages/notification/src/features/utils.ts +++ b/packages/notification/src/features/utils.ts @@ -51,7 +51,7 @@ export function getContactEmail( } function error( - record: ReadyForReviewRecord | RegisteredRecord, + record: ReadyForReviewRecord | RegisteredRecord | RejectedRecord, message: string ): never { const task = getTaskFromSavedBundle(record) @@ -97,7 +97,7 @@ export function getInformantName( } export function getPersonName( - record: ReadyForReviewRecord | RegisteredRecord, + record: ReadyForReviewRecord | RegisteredRecord | RejectedRecord, personType: 'deceased' | 'child' ) { const compositionCode: Extract< From 4dee840633dc11bdbae8409e3ee490eb94a9d348 Mon Sep 17 00:00:00 2001 From: tahmidrahman-dsi Date: Tue, 8 Oct 2024 11:51:38 +0600 Subject: [PATCH 07/18] chore: add a descriptive comment to use the trim when handling given name in notification --- packages/notification/src/features/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/notification/src/features/utils.ts b/packages/notification/src/features/utils.ts index 84154448c6..01bdfd8683 100644 --- a/packages/notification/src/features/utils.ts +++ b/packages/notification/src/features/utils.ts @@ -117,6 +117,7 @@ export function getPersonName( if (!name) { error(record, `name not found in patient resource for ${compositionCode}`) } + // the trim used in given name handles the case when a country does not have middlename return [name.given?.join(' ').trim(), name.family].join(' ').trim() } From c71656a7414fea12a8080b39a0c1e9e4f4b62765 Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 3 Oct 2024 16:56:29 +0300 Subject: [PATCH 08/18] fix(migration): add conditionality to type error. Fetch location when needed --- ...434-add_identifiers_DOB_gender_location.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts b/packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts index 1eff8ff225..c45dd91309 100644 --- a/packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts +++ b/packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts @@ -52,7 +52,8 @@ export const up = async (db: Db, client: MongoClient) => { const body = {} const compositionDoc = (await compositionCursor.next()) as unknown as fhir.Composition - await setInformantDeceasedAndLocationDetails(db, body, compositionDoc) + + await setInformantDeceasedAndLocationDetails(db, body, compositionDoc) // <-- this one throws the error } skip += limit processedDocCount += count @@ -157,16 +158,18 @@ async function setInformantDeceasedAndLocationDetails( ) if (encounterDoc.length > 0) { - const locationId = encounterDoc[0].location[0].location.reference.replace( - 'Location/', - '' - ) + const locationId = + encounterDoc[0]?.location?.[0]?.location?.reference?.replace( + 'Location/', + '' + ) + + const locationDoc = locationId + ? await getCollectionDocuments(db, COLLECTION_NAMES.LOCATION, [ + locationId + ]) + : [] - const locationDoc = await getCollectionDocuments( - db, - COLLECTION_NAMES.LOCATION, - [locationId] - ) if (locationDoc.length > 0) { const address: fhir.Address = locationDoc[0].address if (address) { From 4cfe1c05cb8508945bb70f4b1b3ea37b6f49ca94 Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 3 Oct 2024 17:33:46 +0300 Subject: [PATCH 09/18] fix(migration): add conditionality checks for hearth migrations --- ...0822085901-rejected-declarations-started-by.ts | 2 +- .../20221017133354-restore-supporting-document.ts | 2 +- ...31452-add_practioner_id_event_registrations.ts | 4 ++-- .../20221128065238-migrate-documents-to-minio.ts | 2 +- .../20230127063226-update-practitioner-role.ts | 4 ++-- ...28065851-change-certified-status-to-issused.ts | 2 +- .../20230602120944-populate-valid-locationid.ts | 15 ++++++++------- .../hearth/20231123125224-deceased-birth-date.ts | 2 +- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/migration/src/migrations/hearth/20220822085901-rejected-declarations-started-by.ts b/packages/migration/src/migrations/hearth/20220822085901-rejected-declarations-started-by.ts index 122f9cf994..4ed22d3533 100644 --- a/packages/migration/src/migrations/hearth/20220822085901-rejected-declarations-started-by.ts +++ b/packages/migration/src/migrations/hearth/20220822085901-rejected-declarations-started-by.ts @@ -79,7 +79,7 @@ async function getCompositionIdToStartedByMap( if (startedByMap.has(compositionId)) return startedByMap.set( compositionId, - extractId(task.extension[0].valueReference.reference) + extractId(task.extension[0]?.valueReference.reference) ) }) return startedByMap diff --git a/packages/migration/src/migrations/hearth/20221017133354-restore-supporting-document.ts b/packages/migration/src/migrations/hearth/20221017133354-restore-supporting-document.ts index 4cdb795998..932940a96a 100644 --- a/packages/migration/src/migrations/hearth/20221017133354-restore-supporting-document.ts +++ b/packages/migration/src/migrations/hearth/20221017133354-restore-supporting-document.ts @@ -56,7 +56,7 @@ export const up = async (db: Db, client: MongoClient) => { const immediatePrevComp = compositionHistory[correctionIndex - 1] const hasDocumentSection = immediatePrevComp?.section?.find( (section: fhir.CompositionSection) => - section?.code?.coding?.[0].code === 'supporting-documents' + section?.code?.coding?.[0]?.code === 'supporting-documents' ) if (hasDocumentSection) { await db diff --git a/packages/migration/src/migrations/hearth/20221031131452-add_practioner_id_event_registrations.ts b/packages/migration/src/migrations/hearth/20221031131452-add_practioner_id_event_registrations.ts index a684f35b27..8bbaf7ef61 100644 --- a/packages/migration/src/migrations/hearth/20221031131452-add_practioner_id_event_registrations.ts +++ b/packages/migration/src/migrations/hearth/20221031131452-add_practioner_id_event_registrations.ts @@ -52,7 +52,7 @@ async function migrateRegistrations(measurement: string, db: Db) { await writePoints(updatedPoints) - const startTime = registrations[0].time?.getNanoTime() + const startTime = registrations[0]?.time?.getNanoTime() const endTime = registrations[registrations.length - 1].time?.getNanoTime() const deleteQuery = `DELETE FROM ${measurement} WHERE registrarPractitionerId = '' AND time >= ${startTime} AND time <= ${endTime}` @@ -110,7 +110,7 @@ const getUpdatedPoints = async ( ) } - let id: string = '' + let id = '' if ( practitionerExtension && practitionerExtension.valueReference && diff --git a/packages/migration/src/migrations/hearth/20221128065238-migrate-documents-to-minio.ts b/packages/migration/src/migrations/hearth/20221128065238-migrate-documents-to-minio.ts index b7458dc9d3..cda35d1b7a 100644 --- a/packages/migration/src/migrations/hearth/20221128065238-migrate-documents-to-minio.ts +++ b/packages/migration/src/migrations/hearth/20221128065238-migrate-documents-to-minio.ts @@ -38,7 +38,7 @@ export const up = async (db: Db, client: MongoClient) => { ) while (await documentCursor.hasNext()) { const document = await documentCursor.next() - const fileData = document?.content[0].attachment.data + const fileData = document?.content[0]?.attachment?.data if (fileData && isBase64FileString(fileData)) { const refUrl = await uploadBase64ToMinio(fileData) if (refUrl) { diff --git a/packages/migration/src/migrations/hearth/20230127063226-update-practitioner-role.ts b/packages/migration/src/migrations/hearth/20230127063226-update-practitioner-role.ts index 6485a0a63c..dae1bbe667 100644 --- a/packages/migration/src/migrations/hearth/20230127063226-update-practitioner-role.ts +++ b/packages/migration/src/migrations/hearth/20230127063226-update-practitioner-role.ts @@ -105,8 +105,8 @@ export const up = async (db: Db, client: MongoClient) => { if (hasSystemTypes) { const typeCode = practitionerRole.code?.find( - (c) => c.coding?.[0].system === systemTypes - )?.coding?.[0].code + (c) => c.coding?.[0]?.system === systemTypes + )?.coding?.[0]?.code await db .collection('PractitionerRole') .updateOne( diff --git a/packages/migration/src/migrations/hearth/20230328065851-change-certified-status-to-issused.ts b/packages/migration/src/migrations/hearth/20230328065851-change-certified-status-to-issused.ts index 1b9b6863a7..734e357ad7 100644 --- a/packages/migration/src/migrations/hearth/20230328065851-change-certified-status-to-issused.ts +++ b/packages/migration/src/migrations/hearth/20230328065851-change-certified-status-to-issused.ts @@ -67,7 +67,7 @@ export const up = async (db: Db, client: MongoClient) => { const operationHistoriesData = searchResult && searchResult.body.hits.hits.length > 0 && - searchResult.body.hits.hits[0]._source?.operationHistories + searchResult.body.hits.hits?.[0]?._source?.operationHistories const lastOperationHistory = operationHistoriesData && operationHistoriesData.length > 0 && diff --git a/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts b/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts index 446d6bcf84..3aa2be2830 100644 --- a/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts +++ b/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts @@ -138,10 +138,11 @@ async function updateEventLocationIdOrJurisdictionIds(db: Db, elasticDoc: any) { ) if (encounterDoc.length > 0) { - const locationId = encounterDoc[0].location[0].location.reference.replace( - 'Location/', - '' - ) + const locationId = + encounterDoc[0]?.location?.[0]?.location?.reference?.replace( + 'Location/', + '' + ) const locationDoc = await getCollectionDocuments( db, @@ -150,10 +151,10 @@ async function updateEventLocationIdOrJurisdictionIds(db: Db, elasticDoc: any) { ) if (locationDoc.length > 0) { - if (locationDoc[0].type.coding[0].code === 'HEALTH_FACILITY') { - body.eventLocationId = locationDoc[0].id + if (locationDoc?.[0]?.type?.coding?.[0]?.code === 'HEALTH_FACILITY') { + body.eventLocationId = locationDoc[0]?.id } else { - const address = locationDoc[0].address + const address = locationDoc[0]?.address if (address) { const eventJurisdictionIds: string[] = [] address.state && eventJurisdictionIds.push(address.state) diff --git a/packages/migration/src/migrations/hearth/20231123125224-deceased-birth-date.ts b/packages/migration/src/migrations/hearth/20231123125224-deceased-birth-date.ts index a714d8a5be..1346ccb23a 100644 --- a/packages/migration/src/migrations/hearth/20231123125224-deceased-birth-date.ts +++ b/packages/migration/src/migrations/hearth/20231123125224-deceased-birth-date.ts @@ -50,7 +50,7 @@ export const up = async (db: Db, client: MongoClient) => { }) let processed = 0 for await (const patient of patientIterator) { - const age = parseInt(patient.extension[0].valueString, 10) + const age = parseInt(patient.extension?.[0]?.valueString, 10) const birthDate = subYears(new Date(patient.deceasedDateTime), age) db.collection('Patient').updateOne( { id: patient.id }, From 112bbafbffa9b3206f863fa9e357abfbadf41881 Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 3 Oct 2024 17:57:39 +0300 Subject: [PATCH 10/18] fix(migration): add missing conditional --- .../hearth/20221128065238-migrate-documents-to-minio.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/migration/src/migrations/hearth/20221128065238-migrate-documents-to-minio.ts b/packages/migration/src/migrations/hearth/20221128065238-migrate-documents-to-minio.ts index cda35d1b7a..64ce438df2 100644 --- a/packages/migration/src/migrations/hearth/20221128065238-migrate-documents-to-minio.ts +++ b/packages/migration/src/migrations/hearth/20221128065238-migrate-documents-to-minio.ts @@ -38,7 +38,7 @@ export const up = async (db: Db, client: MongoClient) => { ) while (await documentCursor.hasNext()) { const document = await documentCursor.next() - const fileData = document?.content[0]?.attachment?.data + const fileData = document?.content?.[0]?.attachment?.data if (fileData && isBase64FileString(fileData)) { const refUrl = await uploadBase64ToMinio(fileData) if (refUrl) { From f0738f0b1f824722c7ee3784351ff3cb801bc526 Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 4 Oct 2024 16:09:12 +0300 Subject: [PATCH 11/18] fix(migration): add fallback onError for daysInYear date --- .../hearth/20230221105416-create-performance-views.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts b/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts index 6ee5997a81..54b6a525fd 100644 --- a/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts +++ b/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts @@ -766,7 +766,9 @@ export const up = async (db: Db, client: MongoClient) => { $project: { _id: { $concat: [{ $toString: '$id' }, '_', '$daysInYear.date'] }, name: 1, - date: { $dateFromString: { dateString: '$daysInYear.date' } }, + date: { + $dateFromString: { dateString: '$daysInYear.date', onError: null } + }, estimatedNumberOfBirths: '$daysInYear.estimatedNumberOfBirths', event: 'Birth' } From 3f3c2466cdc0dd223f7aefd64bf7ae7217f9d25a Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 4 Oct 2024 16:44:21 +0300 Subject: [PATCH 12/18] fix(migration): add fallback to dates --- .../20230221105416-create-performance-views.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts b/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts index 54b6a525fd..cbd7e252ee 100644 --- a/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts +++ b/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts @@ -452,10 +452,16 @@ export const up = async (db: Db, client: MongoClient) => { districtName: '$district.name', stateName: '$state.name', createdAt: { - $dateFromString: { dateString: '$firstTask.lastModified' } + $dateFromString: { + dateString: '$firstTask.lastModified', + onError: new Date(0).toISOString() + } }, registeredAt: { - $dateFromString: { dateString: '$registerTask.lastModified' } + $dateFromString: { + dateString: '$registerTask.lastModified', + onError: new Date(0).toISOString() + } }, status: '$latestTask.businessStatus.coding.code', childsAgeInDaysAtDeclaration: 1, @@ -631,7 +637,10 @@ export const up = async (db: Db, client: MongoClient) => { stateName: '$state.name', event: 'Birth', createdAt: { - $dateFromString: { dateString: '$lastModified' } + $dateFromString: { + dateString: '$lastModified', + onError: new Date(0).toISOString() + } } } }, From c44afb0a8d3f2cd8d1ccf7d268046e179df4323c Mon Sep 17 00:00:00 2001 From: Markus Date: Mon, 7 Oct 2024 17:13:36 +0300 Subject: [PATCH 13/18] fix(migration): do not throw during onDrop event --- packages/search/src/features/reindex/reindex.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/search/src/features/reindex/reindex.ts b/packages/search/src/features/reindex/reindex.ts index 1ff823d8e3..f323ed1ee1 100644 --- a/packages/search/src/features/reindex/reindex.ts +++ b/packages/search/src/features/reindex/reindex.ts @@ -74,9 +74,7 @@ export const reindex = async () => { } }), onDrop(doc) { - throw new Error( - `Document ${doc.document.compositionId} couldn't be inserted` - ) + console.log('dropping id', doc.document.compositionId) } }, { From fea0749105e8cbf459e5cddaa3d2c893045f9440 Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 8 Oct 2024 10:42:43 +0300 Subject: [PATCH 14/18] fix(migration): log out dropped ids after stream end --- packages/search/src/features/reindex/reindex.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/search/src/features/reindex/reindex.ts b/packages/search/src/features/reindex/reindex.ts index f323ed1ee1..9e85cab640 100644 --- a/packages/search/src/features/reindex/reindex.ts +++ b/packages/search/src/features/reindex/reindex.ts @@ -62,6 +62,8 @@ export const reindex = async () => { } }) + const droppedCompositionIds: string[] = [] + await client.helpers.bulk( { retries: 3, @@ -74,13 +76,14 @@ export const reindex = async () => { } }), onDrop(doc) { - console.log('dropping id', doc.document.compositionId) + droppedCompositionIds.push(doc.document.compositionId) } }, { meta: true } ) + const t2 = performance.now() logger.info( `Finished reindexing to ${index} in ${((t2 - t1) / 1000).toFixed( @@ -88,6 +91,11 @@ export const reindex = async () => { )} seconds` ) + if (droppedCompositionIds.length) { + logger.warn(`Could not index ${droppedCompositionIds.length} document(s)`) + logger.warn(droppedCompositionIds.join(', ')) + } + return { index } } From 70abbbcf772274f2b3b204a4a38f1bf558a2154a Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 8 Oct 2024 11:02:23 +0300 Subject: [PATCH 15/18] fix(migration): clean up unneeded changes made during debugging --- ...92434-add_identifiers_DOB_gender_location.ts | 2 +- .../20230221105416-create-performance-views.ts | 17 ++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts b/packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts index c45dd91309..b8d7828dd6 100644 --- a/packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts +++ b/packages/migration/src/migrations/hearth/20221110092434-add_identifiers_DOB_gender_location.ts @@ -53,7 +53,7 @@ export const up = async (db: Db, client: MongoClient) => { const compositionDoc = (await compositionCursor.next()) as unknown as fhir.Composition - await setInformantDeceasedAndLocationDetails(db, body, compositionDoc) // <-- this one throws the error + await setInformantDeceasedAndLocationDetails(db, body, compositionDoc) } skip += limit processedDocCount += count diff --git a/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts b/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts index cbd7e252ee..415a783481 100644 --- a/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts +++ b/packages/migration/src/migrations/hearth/20230221105416-create-performance-views.ts @@ -452,16 +452,10 @@ export const up = async (db: Db, client: MongoClient) => { districtName: '$district.name', stateName: '$state.name', createdAt: { - $dateFromString: { - dateString: '$firstTask.lastModified', - onError: new Date(0).toISOString() - } + $dateFromString: { dateString: '$firstTask.lastModified' } }, registeredAt: { - $dateFromString: { - dateString: '$registerTask.lastModified', - onError: new Date(0).toISOString() - } + $dateFromString: { dateString: '$registerTask.lastModified' } }, status: '$latestTask.businessStatus.coding.code', childsAgeInDaysAtDeclaration: 1, @@ -637,10 +631,7 @@ export const up = async (db: Db, client: MongoClient) => { stateName: '$state.name', event: 'Birth', createdAt: { - $dateFromString: { - dateString: '$lastModified', - onError: new Date(0).toISOString() - } + $dateFromString: { dateString: '$lastModified' } } } }, @@ -776,7 +767,7 @@ export const up = async (db: Db, client: MongoClient) => { _id: { $concat: [{ $toString: '$id' }, '_', '$daysInYear.date'] }, name: 1, date: { - $dateFromString: { dateString: '$daysInYear.date', onError: null } + $dateFromString: { dateString: '$daysInYear.date' } }, estimatedNumberOfBirths: '$daysInYear.estimatedNumberOfBirths', event: 'Birth' From e5321e99f49a31b83e8855abfa05232169265f0c Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 8 Oct 2024 13:22:44 +0300 Subject: [PATCH 16/18] fix(migration): fetch location when id is found during population. Clean conditions --- ...30328065851-change-certified-status-to-issused.ts | 4 +--- .../20230602120944-populate-valid-locationid.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/migration/src/migrations/hearth/20230328065851-change-certified-status-to-issused.ts b/packages/migration/src/migrations/hearth/20230328065851-change-certified-status-to-issused.ts index 734e357ad7..202c5596da 100644 --- a/packages/migration/src/migrations/hearth/20230328065851-change-certified-status-to-issused.ts +++ b/packages/migration/src/migrations/hearth/20230328065851-change-certified-status-to-issused.ts @@ -65,9 +65,7 @@ export const up = async (db: Db, client: MongoClient) => { const searchResult = await searchByCompositionId(compositionId) const operationHistoriesData = - searchResult && - searchResult.body.hits.hits.length > 0 && - searchResult.body.hits.hits?.[0]?._source?.operationHistories + searchResult?.body?.hits?.hits?.[0]?._source?.operationHistories const lastOperationHistory = operationHistoriesData && operationHistoriesData.length > 0 && diff --git a/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts b/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts index 3aa2be2830..b750706757 100644 --- a/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts +++ b/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts @@ -144,14 +144,14 @@ async function updateEventLocationIdOrJurisdictionIds(db: Db, elasticDoc: any) { '' ) - const locationDoc = await getCollectionDocuments( - db, - COLLECTION_NAMES.LOCATION, - [locationId] - ) + const locationDoc = locationId + ? await getCollectionDocuments(db, COLLECTION_NAMES.LOCATION, [ + locationId + ]) + : [] if (locationDoc.length > 0) { - if (locationDoc?.[0]?.type?.coding?.[0]?.code === 'HEALTH_FACILITY') { + if (locationDoc[0].type?.coding?.[0]?.code === 'HEALTH_FACILITY') { body.eventLocationId = locationDoc[0]?.id } else { const address = locationDoc[0]?.address From fd1b46a1f3d0cf09bfc269e2726bf31f7ad6bdfe Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 8 Oct 2024 13:30:47 +0300 Subject: [PATCH 17/18] fix(migration): add variable to clarify code --- .../hearth/20230602120944-populate-valid-locationid.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts b/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts index b750706757..d7af4b0c25 100644 --- a/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts +++ b/packages/migration/src/migrations/hearth/20230602120944-populate-valid-locationid.ts @@ -151,10 +151,11 @@ async function updateEventLocationIdOrJurisdictionIds(db: Db, elasticDoc: any) { : [] if (locationDoc.length > 0) { - if (locationDoc[0].type?.coding?.[0]?.code === 'HEALTH_FACILITY') { - body.eventLocationId = locationDoc[0]?.id + const firstLocationDoc = locationDoc[0] + if (firstLocationDoc.type?.coding?.[0]?.code === 'HEALTH_FACILITY') { + body.eventLocationId = firstLocationDoc.id } else { - const address = locationDoc[0]?.address + const address = firstLocationDoc.address if (address) { const eventJurisdictionIds: string[] = [] address.state && eventJurisdictionIds.push(address.state) From 13a275430d92dff713fce862c9c650bc86e20a47 Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 8 Oct 2024 14:41:43 +0300 Subject: [PATCH 18/18] fix(migration): change logging level to error --- packages/search/src/features/reindex/reindex.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/search/src/features/reindex/reindex.ts b/packages/search/src/features/reindex/reindex.ts index 9e85cab640..e739632aaf 100644 --- a/packages/search/src/features/reindex/reindex.ts +++ b/packages/search/src/features/reindex/reindex.ts @@ -92,8 +92,8 @@ export const reindex = async () => { ) if (droppedCompositionIds.length) { - logger.warn(`Could not index ${droppedCompositionIds.length} document(s)`) - logger.warn(droppedCompositionIds.join(', ')) + logger.error(`Could not index ${droppedCompositionIds.length} document(s)`) + logger.error(droppedCompositionIds.join(', ')) } return { index }