|
3 | 3 | from cc_common.config import config, logger |
4 | 4 | from cc_common.exceptions import CCInternalException |
5 | 5 | from custom_resource_handler import CustomResourceHandler, CustomResourceResponse |
6 | | -from opensearch_client import OpenSearchClient |
7 | | - |
8 | | -# Initial index version for new deployments |
9 | | -INITIAL_INDEX_VERSION = 'v1' |
| 6 | +from opensearch_client import INITIAL_INDEX_VERSION, OpenSearchClient |
10 | 7 |
|
11 | 8 | # Readiness check configuration |
12 | 9 | # OpenSearch domains may take time to become responsive after CloudFormation reports them as created. |
@@ -53,8 +50,7 @@ def on_create(self, properties: dict) -> CustomResourceResponse | None: |
53 | 50 | index_name = f'compact_{compact}_providers_{INITIAL_INDEX_VERSION}' |
54 | 51 | # Create alias name (e.g., compact_cosm_providers) |
55 | 52 | alias_name = f'compact_{compact}_providers' |
56 | | - self._create_provider_index_with_alias( |
57 | | - client=client, |
| 53 | + client.create_provider_index_with_alias( |
58 | 54 | index_name=index_name, |
59 | 55 | alias_name=alias_name, |
60 | 56 | number_of_shards=number_of_shards, |
@@ -144,215 +140,5 @@ def _wait_for_domain_ready(self) -> OpenSearchClient: |
144 | 140 | f'Last error: {last_exception}' |
145 | 141 | ) |
146 | 142 |
|
147 | | - def _create_provider_index_with_alias( |
148 | | - self, |
149 | | - client: OpenSearchClient, |
150 | | - index_name: str, |
151 | | - alias_name: str, |
152 | | - number_of_shards: int, |
153 | | - number_of_replicas: int, |
154 | | - ) -> None: |
155 | | - """ |
156 | | - Create the provider index and alias in OpenSearch if they don't exist. |
157 | | -
|
158 | | - :param client: The OpenSearch client |
159 | | - :param index_name: The versioned index name (e.g., compact_cosm_providers_v1) |
160 | | - :param alias_name: The alias name (e.g., compact_cosm_providers) |
161 | | - :param number_of_shards: Number of primary shards for the index |
162 | | - :param number_of_replicas: Number of replica shards for the index |
163 | | - """ |
164 | | - # Check if the alias already exists (meaning an index version is already set up) |
165 | | - if client.alias_exists(alias_name): |
166 | | - logger.info(f"Alias '{alias_name}' already exists. Skipping index and alias creation.") |
167 | | - return |
168 | | - |
169 | | - # Check if the index already exists (edge case: index exists but alias doesn't) |
170 | | - if client.index_exists(index_name): |
171 | | - logger.info(f"Index '{index_name}' already exists. Creating alias only.") |
172 | | - client.create_alias(index_name, alias_name) |
173 | | - logger.info(f"Alias '{alias_name}' -> '{index_name}' created successfully.") |
174 | | - return |
175 | | - |
176 | | - # Create the index with the specified configuration |
177 | | - logger.info(f"Creating index '{index_name}'...") |
178 | | - index_mapping = self._get_provider_index_mapping(number_of_shards, number_of_replicas) |
179 | | - client.create_index(index_name, index_mapping) |
180 | | - logger.info(f"Index '{index_name}' created successfully.") |
181 | | - |
182 | | - # Create the alias pointing to the new index |
183 | | - logger.info(f"Creating alias '{alias_name}' -> '{index_name}'...") |
184 | | - client.create_alias(index_name, alias_name) |
185 | | - logger.info(f"Alias '{alias_name}' -> '{index_name}' created successfully.") |
186 | | - |
187 | | - def _get_provider_index_mapping(self, number_of_shards: int, number_of_replicas: int) -> dict: |
188 | | - """ |
189 | | - Define the index mapping for provider documents. |
190 | | -
|
191 | | - :param number_of_shards: Number of primary shards for the index |
192 | | - :param number_of_replicas: Number of replica shards for the index |
193 | | - :return: The index mapping dictionary |
194 | | - """ |
195 | | - # Nested schema for AdverseAction |
196 | | - adverse_action_properties = { |
197 | | - 'type': {'type': 'keyword'}, |
198 | | - 'adverseActionId': {'type': 'keyword'}, |
199 | | - 'compact': {'type': 'keyword'}, |
200 | | - 'jurisdiction': {'type': 'keyword'}, |
201 | | - 'providerId': {'type': 'keyword'}, |
202 | | - 'licenseType': {'type': 'keyword'}, |
203 | | - 'licenseTypeAbbreviation': {'type': 'keyword'}, |
204 | | - 'actionAgainst': {'type': 'keyword'}, |
205 | | - 'effectiveStartDate': {'type': 'date'}, |
206 | | - 'creationDate': {'type': 'date'}, |
207 | | - 'effectiveLiftDate': {'type': 'date'}, |
208 | | - 'dateOfUpdate': {'type': 'date'}, |
209 | | - 'encumbranceType': {'type': 'keyword'}, |
210 | | - 'clinicalPrivilegeActionCategories': {'type': 'keyword'}, |
211 | | - 'clinicalPrivilegeActionCategory': {'type': 'keyword'}, |
212 | | - 'submittingUser': {'type': 'keyword'}, |
213 | | - 'liftingUser': {'type': 'keyword'}, |
214 | | - } |
215 | | - |
216 | | - # Nested schema for Investigation |
217 | | - investigation_properties = { |
218 | | - 'type': {'type': 'keyword'}, |
219 | | - 'investigationId': {'type': 'keyword'}, |
220 | | - 'compact': {'type': 'keyword'}, |
221 | | - 'jurisdiction': {'type': 'keyword'}, |
222 | | - 'licenseType': {'type': 'keyword'}, |
223 | | - 'status': {'type': 'keyword'}, |
224 | | - 'dateOfUpdate': {'type': 'date'}, |
225 | | - } |
226 | | - |
227 | | - # Nested schema for License |
228 | | - license_properties = { |
229 | | - 'providerId': {'type': 'keyword'}, |
230 | | - 'type': {'type': 'keyword'}, |
231 | | - 'dateOfUpdate': {'type': 'date'}, |
232 | | - 'compact': {'type': 'keyword'}, |
233 | | - 'jurisdiction': {'type': 'keyword'}, |
234 | | - 'licenseType': {'type': 'keyword'}, |
235 | | - 'licenseStatusName': {'type': 'keyword'}, |
236 | | - 'licenseStatus': {'type': 'keyword'}, |
237 | | - 'jurisdictionUploadedLicenseStatus': {'type': 'keyword'}, |
238 | | - 'compactEligibility': {'type': 'keyword'}, |
239 | | - 'jurisdictionUploadedCompactEligibility': {'type': 'keyword'}, |
240 | | - 'licenseNumber': {'type': 'keyword'}, |
241 | | - 'givenName': { |
242 | | - 'type': 'text', |
243 | | - 'analyzer': 'custom_ascii_analyzer', |
244 | | - 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}, |
245 | | - }, |
246 | | - 'middleName': { |
247 | | - 'type': 'text', |
248 | | - 'analyzer': 'custom_ascii_analyzer', |
249 | | - 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}, |
250 | | - }, |
251 | | - 'familyName': { |
252 | | - 'type': 'text', |
253 | | - 'analyzer': 'custom_ascii_analyzer', |
254 | | - 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}, |
255 | | - }, |
256 | | - 'suffix': {'type': 'keyword'}, |
257 | | - 'dateOfIssuance': {'type': 'date'}, |
258 | | - 'dateOfRenewal': {'type': 'date'}, |
259 | | - 'dateOfExpiration': {'type': 'date'}, |
260 | | - 'dateOfBirth': {'type': 'date'}, |
261 | | - 'homeAddressStreet1': {'type': 'text'}, |
262 | | - 'homeAddressStreet2': {'type': 'text'}, |
263 | | - 'homeAddressCity': { |
264 | | - 'type': 'text', |
265 | | - 'analyzer': 'custom_ascii_analyzer', |
266 | | - 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}, |
267 | | - }, |
268 | | - 'homeAddressState': {'type': 'keyword'}, |
269 | | - 'homeAddressPostalCode': {'type': 'keyword'}, |
270 | | - 'emailAddress': {'type': 'keyword'}, |
271 | | - 'phoneNumber': {'type': 'keyword'}, |
272 | | - 'adverseActions': {'type': 'nested', 'properties': adverse_action_properties}, |
273 | | - 'investigations': {'type': 'nested', 'properties': investigation_properties}, |
274 | | - 'investigationStatus': {'type': 'keyword'}, |
275 | | - } |
276 | | - |
277 | | - # Nested schema for Privilege |
278 | | - privilege_properties = { |
279 | | - 'type': {'type': 'keyword'}, |
280 | | - 'providerId': {'type': 'keyword'}, |
281 | | - 'compact': {'type': 'keyword'}, |
282 | | - 'jurisdiction': {'type': 'keyword'}, |
283 | | - 'licenseJurisdiction': {'type': 'keyword'}, |
284 | | - 'licenseType': {'type': 'keyword'}, |
285 | | - 'dateOfIssuance': {'type': 'date'}, |
286 | | - 'dateOfRenewal': {'type': 'date'}, |
287 | | - 'dateOfExpiration': {'type': 'date'}, |
288 | | - 'dateOfUpdate': {'type': 'date'}, |
289 | | - 'adverseActions': {'type': 'nested', 'properties': adverse_action_properties}, |
290 | | - 'investigations': {'type': 'nested', 'properties': investigation_properties}, |
291 | | - 'administratorSetStatus': {'type': 'keyword'}, |
292 | | - 'compactTransactionId': {'type': 'keyword'}, |
293 | | - 'privilegeId': {'type': 'keyword'}, |
294 | | - 'status': {'type': 'keyword'}, |
295 | | - 'investigationStatus': {'type': 'keyword'}, |
296 | | - } |
297 | | - |
298 | | - return { |
299 | | - 'settings': { |
300 | | - 'index': { |
301 | | - 'number_of_shards': number_of_shards, |
302 | | - 'number_of_replicas': number_of_replicas, |
303 | | - }, |
304 | | - 'analysis': { |
305 | | - # this custom analyzer is recommended by Opensearch when you have international character |
306 | | - # sets, and you want to support searching by their closest ASCII equivalents. |
307 | | - # See https://docs.opensearch.org/latest/analyzers/token-filters/asciifolding/ |
308 | | - 'filter': {'custom_ascii_folding': {'type': 'asciifolding', 'preserve_original': True}}, |
309 | | - 'analyzer': { |
310 | | - 'custom_ascii_analyzer': { |
311 | | - 'type': 'custom', |
312 | | - 'tokenizer': 'standard', |
313 | | - 'filter': ['lowercase', 'custom_ascii_folding'], |
314 | | - } |
315 | | - }, |
316 | | - }, |
317 | | - }, |
318 | | - 'mappings': { |
319 | | - 'properties': { |
320 | | - # Top-level provider fields |
321 | | - 'providerId': {'type': 'keyword'}, |
322 | | - 'type': {'type': 'keyword'}, |
323 | | - 'dateOfUpdate': {'type': 'date'}, |
324 | | - 'compact': {'type': 'keyword'}, |
325 | | - 'licenseJurisdiction': {'type': 'keyword'}, |
326 | | - 'licenseStatus': {'type': 'keyword'}, |
327 | | - 'compactEligibility': {'type': 'keyword'}, |
328 | | - 'givenName': { |
329 | | - 'type': 'text', |
330 | | - 'analyzer': 'custom_ascii_analyzer', |
331 | | - 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}, |
332 | | - }, |
333 | | - 'middleName': { |
334 | | - 'type': 'text', |
335 | | - 'analyzer': 'custom_ascii_analyzer', |
336 | | - 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}, |
337 | | - }, |
338 | | - 'familyName': { |
339 | | - 'type': 'text', |
340 | | - 'analyzer': 'custom_ascii_analyzer', |
341 | | - 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}, |
342 | | - }, |
343 | | - 'suffix': {'type': 'keyword'}, |
344 | | - 'dateOfExpiration': {'type': 'date'}, |
345 | | - 'jurisdictionUploadedLicenseStatus': {'type': 'keyword'}, |
346 | | - 'jurisdictionUploadedCompactEligibility': {'type': 'keyword'}, |
347 | | - 'providerFamGivMid': {'type': 'keyword'}, |
348 | | - 'providerDateOfUpdate': {'type': 'date'}, |
349 | | - 'birthMonthDay': {'type': 'keyword'}, |
350 | | - # Nested arrays |
351 | | - 'licenses': {'type': 'nested', 'properties': license_properties}, |
352 | | - 'privileges': {'type': 'nested', 'properties': privilege_properties}, |
353 | | - } |
354 | | - }, |
355 | | - } |
356 | | - |
357 | 143 |
|
358 | 144 | on_event = OpenSearchIndexManager('opensearch-index-manager') |
0 commit comments