Skip to content

Commit

Permalink
Merge pull request #398 from Enterprise-CMCS/master
Browse files Browse the repository at this point in the history
Release to val
  • Loading branch information
mdial89f authored Feb 21, 2024
2 parents e9ae481 + 7547805 commit 9d23c48
Show file tree
Hide file tree
Showing 88 changed files with 2,762 additions and 1,048 deletions.
20 changes: 0 additions & 20 deletions .codeclimate.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
STAGE_NAME: ${{ inputs.environment || (startsWith(github.event.ref, 'snyk-') && 'snyk' || github.event.ref) }}
permissions:
id-token: write
contents: read
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
39 changes: 31 additions & 8 deletions src/libs/opensearch-lib.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
Client,
Connection,
} from "@opensearch-project/opensearch";
import { Client, Connection } from "@opensearch-project/opensearch";
import { defaultProvider } from "@aws-sdk/credential-provider-node";
import * as aws4 from "aws4";
import axios from "axios";
import { aws4Interceptor } from "aws4-axios";
import { STSClient, AssumeRoleCommand } from "@aws-sdk/client-sts";
import { opensearch } from "shared-types";
import { errors as OpensearchErrors } from "@opensearch-project/opensearch";

let client: Client;

export async function getClient(host: string) {
Expand Down Expand Up @@ -43,6 +42,11 @@ export async function bulkUpdateData(
index: opensearch.Index,
arrayOfDocuments: any
) {
// Skip if no documents have been supplied
if (arrayOfDocuments.length === 0) {
console.log("No documents to update. Skipping bulk update operation.");
return;
}
client = client || (await getClient(host));
var response = await client.helpers.bulk({
datasource: arrayOfDocuments,
Expand All @@ -62,7 +66,18 @@ export async function bulkUpdateData(

export async function deleteIndex(host: string, index: opensearch.Index) {
client = client || (await getClient(host));
var response = await client.indices.delete({ index });
try {
await client.indices.delete({ index });
} catch (error) {
if (
error instanceof OpensearchErrors.ResponseError &&
error.message.includes("index_not_found_exception")
) {
console.log(`Index ${index} not found. Continuing...`);
} else {
throw error;
}
}
}

export async function mapRole(
Expand Down Expand Up @@ -111,7 +126,11 @@ export async function mapRole(
}
}

export async function search(host: string, index: opensearch.Index, query: any) {
export async function search(
host: string,
index: opensearch.Index,
query: any
) {
client = client || (await getClient(host));
try {
const response = await client.search({
Expand All @@ -124,7 +143,11 @@ export async function search(host: string, index: opensearch.Index, query: any)
}
}

export async function getItem(host: string, index: opensearch.Index, id: string) {
export async function getItem(
host: string,
index: opensearch.Index,
id: string
) {
client = client || (await getClient(host));
try {
const response = await client.get({ id, index });
Expand All @@ -139,7 +162,7 @@ export async function createIndex(host: string, index: opensearch.Index) {
client = client || (await getClient(host));
try {
const exists = await client.indices.exists({ index });
if(!!exists.body) return;
if (!!exists.body) return;

await client.indices.create({ index });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/shared-types/action-types/new-submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { attachmentSchema } from "../attachments";
// This is the event schema for ne submissions from our system
export const onemacSchema = z.object({
authority: z.string(),
seaActionType: z.string().optional(), // Used by waivers.
seaActionType: z.string().optional(), // Used by waivers and chip spas
origin: z.string(),
additionalInformation: z.string().nullable().default(null),
submitterName: z.string(),
Expand Down
15 changes: 15 additions & 0 deletions src/packages/shared-types/action-types/seatool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,25 @@ export const seatoolSchema = z.object({
.array(
z.object({
PLAN_TYPE_NAME: z.string(),
PLAN_TYPE_ID: z.number(),
})
)
.nonempty()
.nullable(),
STATE_PLAN_SERVICETYPES: z
.array(
z.object({
SERVICE_TYPE_ID: z.number(),
})
)
.nullable(),
STATE_PLAN_SERVICE_SUBTYPES: z
.array(
z.object({
SERVICE_SUBTYPE_ID: z.number(),
})
)
.nullable(),
STATE_PLAN: z.object({
SUBMISSION_DATE: z.number().nullable(),
PLAN_TYPE: z.number().nullable(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum PlanType {
export enum Authority {
MED_SPA = "medicaid spa",
CHIP_SPA = "chip spa",
WAIVER = "waiver",
Expand Down
4 changes: 4 additions & 0 deletions src/packages/shared-types/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export type RHFComponentMap = {
Checkbox: {
options: RHFOption[];
};
Upload: {
maxFiles?: number;
maxSize?: number;
};
FieldArray: {
appendText?: string;
};
Expand Down
4 changes: 3 additions & 1 deletion src/packages/shared-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export * as opensearch from "./opensearch";
export * from "./uploads";
export * from "./actions";
export * from "./attachments";
export * from "./planType";
export * from "./authority";
export * from "./action-types";
export * from "./forms";
export * from "./inputs";
export * from "./states";
export * from "./statusHelper";
export * from "./guides";
export * from "./lambda-events";
export * from "./seatool-authorities";
export * from "./seatool-tables";
2 changes: 1 addition & 1 deletion src/packages/shared-types/opensearch/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ export type ExportHeaderOptions<TData> = {
name: string;
};

export type Index = "main" | "seatool" | "changelog";
export type Index = "main" | "insights" | "changelog" | "types" | "subtypes";
2 changes: 2 additions & 0 deletions src/packages/shared-types/opensearch/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * as changelog from "./changelog";
export * as main from "./main";
export * as types from "./types";
export * as subtypes from "./subtypes";
export * from "./_";
7 changes: 6 additions & 1 deletion src/packages/shared-types/opensearch/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export type Document = z.infer<newSubmission.Schema> &
z.infer<withdrawRai.Schema> &
z.infer<withdrawPackage.Schema> &
z.infer<toggleWithdrawEnabled.Schema> &
z.infer<seatool.Schema> & {
z.infer<seatool.Schema> &
{
type: string | null, // added by the sink
subType: string | null, // added by the sink
} &
{
changelog?: Changelog[];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ export const transform = (id: string) => {
};

export type Schema = ReturnType<typeof transform>;
export const tombstone = (id:string) => {
return {
id,
additionalInformation: null,
raiWithdrawEnabled: null,
attachments: null,
submitterEmail: null,
submitterName: null,
};
};
66 changes: 58 additions & 8 deletions src/packages/shared-types/opensearch/main/transforms/seatool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import {
SeatoolOfficer,
} from "../../..";

import { PlanType } from "../../../planType";
import {
Authority,
SEATOOL_AUTHORITIES,
} from "shared-types";

type AuthorityType = "SPA" | "WAIVER" | "MEDICAID" | "CHIP";
type Flavor = "SPA" | "WAIVER" | "MEDICAID" | "CHIP";

const authorityLookup = (val: number | null): null | string => {
const flavorLookup = (val: number | null): null | string => {
if (!val) return null;

const lookup: Record<number, AuthorityType> = {
const lookup: Record<number, Flavor> = {
122: "WAIVER",
123: "WAIVER",
124: "CHIP",
Expand Down Expand Up @@ -120,6 +123,20 @@ const isInSecondClock = (
return false; // otherwise, we're not
};

const getAuthority = (
authorityId: number | undefined,
id: string | undefined
) => {
try {
if (!authorityId) return null;
return SEATOOL_AUTHORITIES[authorityId];
} catch (error) {
console.log(`SEATOOL AUTHORITY LOOKUP ERROR: ${id} ${authorityId}`);
console.log(error);
return null;
}
};

export const transform = (id: string) => {
return seatoolSchema.transform((data) => {
const { leadAnalystName, leadAnalystOfficerId } = getLeadAnalyst(data);
Expand All @@ -130,23 +147,28 @@ export const transform = (id: string) => {
(item) => item.SPW_STATUS_ID === data.STATE_PLAN.SPW_STATUS_ID
)?.SPW_STATUS_DESC || "Unknown";
const { stateStatus, cmsStatus } = getStatus(seatoolStatus);
const authorityId = data.PLAN_TYPES?.[0].PLAN_TYPE_ID;
const typeId = data.STATE_PLAN_SERVICETYPES?.[0]?.SERVICE_TYPE_ID;
const subTypeId = data.STATE_PLAN_SERVICE_SUBTYPES?.[0]?.SERVICE_SUBTYPE_ID;
return {
id,
flavor: flavorLookup(data.STATE_PLAN.PLAN_TYPE), // This is MEDICAID CHIP or WAIVER... our concept
actionType: data.ACTIONTYPES?.[0].ACTION_NAME,
actionTypeId: data.ACTIONTYPES?.[0].ACTION_ID,
approvedEffectiveDate: getDateStringOrNullFromEpoc(
data.STATE_PLAN.APPROVED_EFFECTIVE_DATE
),
authority: authorityLookup(data.STATE_PLAN.PLAN_TYPE),
changedDate: getDateStringOrNullFromEpoc(data.STATE_PLAN.CHANGED_DATE),
description: data.STATE_PLAN.SUMMARY_MEMO,
finalDispositionDate: getFinalDispositionDate(seatoolStatus, data),
leadAnalystOfficerId,
initialIntakeNeeded:
!leadAnalystName && seatoolStatus !== SEATOOL_STATUS.WITHDRAWN,
leadAnalystName,
planType: data.PLAN_TYPES?.[0].PLAN_TYPE_NAME as PlanType | null,
planTypeId: data.STATE_PLAN.PLAN_TYPE,
authorityId: authorityId || null,
authority: getAuthority(authorityId, id) as Authority | null,
typeId: typeId || null,
subTypeId: subTypeId || null,
proposedDate: getDateStringOrNullFromEpoc(data.STATE_PLAN.PROPOSED_DATE),
raiReceivedDate,
raiRequestedDate,
Expand All @@ -165,9 +187,37 @@ export const transform = (id: string) => {
raiReceivedDate,
raiWithdrawnDate,
seatoolStatus,
authorityLookup(data.STATE_PLAN.PLAN_TYPE)
flavorLookup(data.STATE_PLAN.PLAN_TYPE)
),
};
});
};
export type Schema = ReturnType<typeof transform>;
export const tombstone = (id: string) => {
return {
id,
flavor: null,
actionType: null,
actionTypeId: null,
approvedEffectiveDate: null,
changedDate: null,
description: null,
finalDispositionDate: null,
leadAnalystName: null,
leadAnalystOfficerId: null,
authority: null,
authorityId: null,
proposedDate: null,
raiReceivedDate: null,
raiRequestedDate: null,
raiWithdrawnDate: null,
reviewTeam: null,
state: null,
cmsStatus: null,
stateStatus: null,
seatoolStatus: null,
statusDate: null,
submissionDate: null,
subject: null,
};
};
25 changes: 25 additions & 0 deletions src/packages/shared-types/opensearch/subtypes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
Response as Res,
Hit,
Filterable as FIL,
QueryState,
AggQuery,
ExportHeaderOptions,
} from "./../_";
import { z } from "zod";
import { Type } from "./transforms";

export type Document = z.infer<Type.Schema>;

export type Response = Res<Document>;
export type ItemResult = Hit<Document> & {
found: boolean;
};

export type Field = keyof Document | `${keyof Document}.keyword`;
export type Filterable = FIL<Field>;
export type State = QueryState<Field>;
export type Aggs = AggQuery<Field>;
export type ExportHeader = ExportHeaderOptions<Document>;

export * from "./transforms";
15 changes: 15 additions & 0 deletions src/packages/shared-types/opensearch/subtypes/transforms/Type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { seaSubtypeSchema } from "../../..";

export const transform = () => {
return seaSubtypeSchema.transform((data) => {
const transformedData = {
id: data.Type_Id,
name: data.Type_Name,
typeId: data.Type_Class,
authorityId: data.Plan_Type_ID,
};
return transformedData;
});
};

export type Schema = ReturnType<typeof transform>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as Type from "./Type";
Loading

0 comments on commit 9d23c48

Please sign in to comment.