Skip to content

Commit

Permalink
chore(elastic-upgrade): import from right file, simplify conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
makelicious committed Jul 17, 2024
1 parent 7dd9e81 commit 4aa6ab1
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 30 deletions.
4 changes: 2 additions & 2 deletions packages/search/src/elasticsearch/dbhelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export const updateComposition = async (
)
} catch (e) {
logger.error(`updateComposition: error: ${e}`)
}

return
return
}
}

export const searchByCompositionId = async (
Expand Down
4 changes: 2 additions & 2 deletions packages/search/src/features/fhir/fhir-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import {
SavedComposition,
SavedLocation,
SavedTask,
TaskHistory
TaskHistory,
SearchDocument
} from '@opencrvs/commons/types'
import { FHIR_URL } from '@search/constants'
import { SearchDocument } from '@search/elasticsearch/utils'
import { logger } from '@opencrvs/commons'
import fetch from 'node-fetch'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { updateComposition } from '@search/elasticsearch/dbhelper'
import {
getUser,
IAssignment,
SearchDocument,
IUserModelData,
NAME_EN
} from '@search/elasticsearch/utils'
Expand All @@ -25,7 +24,8 @@ import {
getTaskFromSavedBundle,
LAST_USER_EXTENSION_URL,
resourceIdentifierToUUID,
SavedBundle
SavedBundle,
SearchDocument
} from '@opencrvs/commons/types'

export async function updateEventToAddAssignment(requestBundle: Hapi.Request) {
Expand Down
4 changes: 1 addition & 3 deletions packages/search/src/features/registration/birth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export const composeDocument = (
compositionId: composition.id,
event: EVENT.BIRTH,
createdAt:
(existingDocument &&
existingDocument.body.hits.hits.length > 0 &&
existingDocument.body.hits.hits[0]?._source?.createdAt) ||
existingDocument?.body?.hits?.hits?.[0]?._source?.createdAt ||
Date.now().toString(),
modifiedAt: Date.now().toString(),
operationHistories: composeOperationHistories(record) as IOperationHistory[]
Expand Down
12 changes: 5 additions & 7 deletions packages/search/src/features/registration/death/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import {
import {
composeOperationHistories,
createStatusHistory,
EVENT,
DeathDocument,
IOperationHistory,
NAME_EN,
REJECTED_STATUS,
composeAssignment
} from '@search/elasticsearch/utils'
import {
Expand All @@ -43,7 +40,10 @@ import {
resourceIdentifierToUUID,
findFirstTaskHistory,
getInformantType,
ValidRecord
ValidRecord,
REJECTED_STATUS,
IOperationHistory,
EVENT
} from '@opencrvs/commons/types'
import { findAssignment } from '@opencrvs/commons/assignment'
import { findPatientPrimaryIdentifier } from '@search/features/search/utils'
Expand All @@ -66,9 +66,7 @@ export const composeDocument = (
compositionId: composition.id,
event: EVENT.DEATH,
createdAt:
(existingDocument &&
existingDocument.body.hits.hits.length > 0 &&
existingDocument.body.hits.hits[0]?._source?.createdAt) ||
existingDocument?.body?.hits?.hits?.[0]?._source?.createdAt ||
Date.now().toString(),
operationHistories: composeOperationHistories(bundle) as IOperationHistory[]
}
Expand Down
14 changes: 6 additions & 8 deletions packages/search/src/features/registration/marriage/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ import {
} from '@search/elasticsearch/dbhelper'
import {
createStatusHistory,
EVENT,
SearchDocument,
MarriageDocument,
IOperationHistory,
NAME_EN,
REJECTED_STATUS,
composeOperationHistories,
composeAssignment
} from '@search/elasticsearch/utils'
Expand All @@ -45,7 +41,11 @@ import {
SavedRelatedPerson,
findFirstTaskHistory,
getInformantType,
ValidRecord
ValidRecord,
EVENT,
SearchDocument,
IOperationHistory,
REJECTED_STATUS
} from '@opencrvs/commons/types'
import { findAssignment } from '@opencrvs/commons/assignment'
import { findPatientPrimaryIdentifier } from '@search/features/search/utils'
Expand All @@ -66,9 +66,7 @@ export const composeDocument = (
compositionId: composition.id,
event: EVENT.MARRIAGE,
createdAt:
(existingDocument &&
existingDocument.body.hits.hits.length > 0 &&
existingDocument.body.hits.hits[0]?._source?.createdAt) ||
existingDocument?.body?.hits?.hits?.[0]?._source?.createdAt ||
Date.now().toString(),
operationHistories: composeOperationHistories(bundle) as IOperationHistory[]
}
Expand Down
8 changes: 6 additions & 2 deletions packages/search/src/features/reindex/reindex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { EVENT_TYPE, ValidRecord } from '@opencrvs/commons/types'
import {
EVENT_TYPE,
ValidRecord,
SearchDocument
} from '@opencrvs/commons/types'
import { OPENCRVS_INDEX_NAME } from '@search/constants'
import { client } from '@search/elasticsearch/client'
import { BirthDocument, SearchDocument } from '@search/elasticsearch/utils'
import { BirthDocument } from '@search/elasticsearch/utils'
import { streamAllRecords } from '@search/features/records/service'
import { composeDocument as composeBirthDocument } from '@search/features/registration/birth/service'
import { composeDocument as composeDeathDocument } from '@search/features/registration/death/service'
Expand Down
6 changes: 2 additions & 4 deletions packages/search/src/features/search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import {
findPatientIdentifier,
Patient,
SUPPORTED_PATIENT_IDENTIFIER_CODES
} from '@opencrvs/commons/types'
import {
SUPPORTED_PATIENT_IDENTIFIER_CODES,
CERTIFIED_STATUS,
REGISTERED_STATUS
} from '@search/elasticsearch/utils'
} from '@opencrvs/commons/types'
import { IAdvancedSearchParam } from '@search/features/search/types'
import { transformDeprecatedParamsToSupported } from './deprecation-support'
import { resolveLocationChildren } from './location'
Expand Down

0 comments on commit 4aa6ab1

Please sign in to comment.