Skip to content

Commit

Permalink
[Feature-3495] - CR TDL Updates (#904)
Browse files Browse the repository at this point in the history
* WIP to Split CRs and TDLs on the backend

* Add migrations and tests

* Update migration to update historical data and make Implementation Date nullable on CRs

* Fixed migration type, updated postman collection

* Fix migration condition and automated tests

* Update tests to not check exact dates

* [EASI-3810] - FE CR TDL (#903)

* Init work on crtdl frontend

* Updated form to use new mutations and types

* Fixed incorrect iterable array

* Added month and year form components to addcrtdl

* Added support for converting date values

* Added conditional text for form

* Fixed date parsing

* Added type as a form value

* Added validation and max page size

* Updated readonly

* Updated unit tests

* Updated cypress  tests

* Updated snapshot

* Rant linteR

---------

Co-authored-by: Clay Benson <[email protected]>

* Renamed migration

* Update migration to properly handle existing data

* feat: separate cr and tdl tables in migration

* feat: cr tdl models declared in separate files

* feat: sql queries to their own folders

* feat: cr and tdl to separate resolver files

* feat: cr and tdl to separate store files

* feat: separate cr and tdl tests into separate files

* feat: fix unit test issues

* feat: adjust analyze audit to correctly analyze table names of changes

* feat: rename migrations

* feat: add todo comment to remove the comparison to plan_cr_tdl after deployed for a day

* chore: remove accidentally commented out migrations

---------

Co-authored-by: ClayBenson94 <[email protected]>
Co-authored-by: Steven Wade <[email protected]>
Co-authored-by: Steven Wade <[email protected]>
  • Loading branch information
4 people authored Jan 25, 2024
1 parent 0a01fe1 commit 1f2be4c
Show file tree
Hide file tree
Showing 99 changed files with 6,816 additions and 2,098 deletions.
100 changes: 92 additions & 8 deletions MINT.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -814,14 +814,35 @@
"name": "CRs and TDLs",
"item": [
{
"name": "Create CR/TDL",
"name": "Create CR",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation createPlanCrTdl ($input: PlanCrTdlCreateInput!) {\n createPlanCrTdl (input: $input) {\n id\n modelPlanID\n idNumber\n dateInitiated\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"query": "mutation createPlanCR ($input: PlanCRCreateInput!) {\n createPlanCR (input: $input) {\n id\n modelPlanID\n idNumber\n dateInitiated\n dateImplemented\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"variables": "{\n \"input\": {\n \"modelPlanID\": \"\",\n \"idNumber\": \"\",\n \"dateInitiated\": \"\",\n \"dateImplemented\": \"\",\n \"title\": \"\",\n \"note\": \"\"\n }\n}"
}
},
"url": {
"raw": "{{url}}",
"host": [
"{{url}}"
]
}
},
"response": []
},
{
"name": "Create TDL",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation createPlanTDL ($input: PlanTDLCreateInput!) {\n createPlanTDL (input: $input) {\n id\n modelPlanID\n idNumber\n dateInitiated\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"variables": "{\n \"input\": {\n \"modelPlanID\": \"\",\n \"idNumber\": \"\",\n \"dateInitiated\": \"\",\n \"title\": \"\",\n \"note\": \"\"\n }\n}"
}
},
Expand All @@ -835,14 +856,35 @@
"response": []
},
{
"name": "Get CR/TDL by ID",
"name": "Get CR by ID",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "query planCR ($id: UUID!) {\n planCR (id: $id) {\n id\n modelPlanID\n idNumber\n dateInitiated\n dateImplemented\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"variables": "{\n \"id\": \"\"\n}"
}
},
"url": {
"raw": "{{url}}",
"host": [
"{{url}}"
]
}
},
"response": []
},
{
"name": "Get TDL by ID",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "query crTdl ($id: UUID!) {\n crTdl (id: $id) {\n id\n modelPlanID\n idNumber\n dateInitiated\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"query": "query planTDL ($id: UUID!) {\n planTDL (id: $id) {\n id\n modelPlanID\n idNumber\n dateInitiated\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"variables": "{\n \"id\": \"\"\n}"
}
},
Expand All @@ -856,14 +898,35 @@
"response": []
},
{
"name": "Update CR/TDL",
"name": "Update CR",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation updatePlanCrTdl ($id: UUID!, $changes: PlanCrTdlChanges!) {\n updatePlanCrTdl (id: $id, changes: $changes) {\n id\n modelPlanID\n idNumber\n dateInitiated\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"query": "mutation updatePlanCR ($id: UUID!, $changes: PlanCRChanges!) {\n updatePlanCR (id: $id, changes: $changes) {\n id\n modelPlanID\n idNumber\n dateInitiated\n dateImplemented\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"variables": "{\n \"id\": \"\",\n \"changes\": {\n \"idNumber\": \"\",\n \"dateInitiated\": \"\",\n \"dateImplemented\": \"\",\n \"title\": \"\",\n \"note\": \"\"\n }\n}"
}
},
"url": {
"raw": "{{url}}",
"host": [
"{{url}}"
]
}
},
"response": []
},
{
"name": "Update TDL",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation updatePlanTDL ($id: UUID!, $changes: PlanTDLChanges!) {\n updatePlanTDL (id: $id, changes: $changes) {\n id\n modelPlanID\n idNumber\n dateInitiated\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"variables": "{\n \"id\": \"\",\n \"changes\": {\n \"idNumber\": \"\",\n \"dateInitiated\": \"\",\n \"title\": \"\",\n \"note\": \"\"\n }\n}"
}
},
Expand All @@ -877,14 +940,35 @@
"response": []
},
{
"name": "Delete CR/TDL",
"name": "Delete CR",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation deletePlanCR ($id: UUID!) {\n deletePlanCR (id: $id) {\n id\n modelPlanID\n idNumber\n dateInitiated\n dateImplemented\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"variables": "{\n \"id\": \"\"\n}"
}
},
"url": {
"raw": "{{url}}",
"host": [
"{{url}}"
]
}
},
"response": []
},
{
"name": "Delete TDL",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation deletePlanCrTdl ($id: UUID!) {\n deletePlanCrTdl (id: $id) {\n id\n modelPlanID\n idNumber\n dateInitiated\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"query": "mutation deletePlanTDL ($id: UUID!) {\n deletePlanTDL (id: $id) {\n id\n modelPlanID\n idNumber\n dateInitiated\n title\n note\n createdBy\n createdDts\n modifiedBy\n modifiedDts\n }\n}",
"variables": "{\n \"id\": \"\"\n}"
}
},
Expand Down
17 changes: 9 additions & 8 deletions cmd/dbseed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,16 @@ func (s *Seeder) SeedData() {

// Seed a plan with CRs / TDLs
planWithCrTDLs := s.createModelPlan("Plan With CRs and TDLs", "MINT")
s.addCrTdl(planWithCrTDLs, &model.PlanCrTdlCreateInput{
ModelPlanID: planWithCrTDLs.ID,
IDNumber: "CR-123",
DateInitiated: time.Now(),
Title: "My CR",
Note: nil,
s.addCR(planWithCrTDLs, &model.PlanCRCreateInput{
ModelPlanID: planWithCrTDLs.ID,
IDNumber: "CR-123",
DateInitiated: time.Now(),
DateImplemented: time.Now(),
Title: "My CR",
Note: nil,
})
tdlNote := "My TDL note"
s.addCrTdl(planWithCrTDLs, &model.PlanCrTdlCreateInput{
s.addTDL(planWithCrTDLs, &model.PlanTDLCreateInput{
ModelPlanID: planWithCrTDLs.ID,
IDNumber: "TDL-123",
DateInitiated: time.Now(),
Expand All @@ -177,7 +178,7 @@ func (s *Seeder) SeedData() {

sampleModelName := "Enhancing Oncology Model"
sampleModelPlan := s.createModelPlan(sampleModelName, "MINT")
s.addCrTdl(planWithCrTDLs, &model.PlanCrTdlCreateInput{
s.addTDL(planWithCrTDLs, &model.PlanTDLCreateInput{
ModelPlanID: sampleModelPlan.ID,
IDNumber: "TDL-123",
DateInitiated: time.Now(),
Expand Down
21 changes: 17 additions & 4 deletions cmd/dbseed/resolver_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,30 @@ func (s *Seeder) addPlanCollaborator(
return collaborator
}

// crTdlCreate is a wrapper for resolvers.PlanCrTdlCreate
// addCR is a wrapper for resolvers.PlanCRCreate
// It will panic if an error occurs, rather than bubbling the error up
// It will always add the CR/TDL object with the principal value of the Model Plan's "createdBy"
func (s *Seeder) addCrTdl(mp *models.ModelPlan, input *model.PlanCrTdlCreateInput) *models.PlanCrTdl {
func (s *Seeder) addCR(mp *models.ModelPlan, input *model.PlanCRCreateInput) *models.PlanCR {
princ := s.getTestPrincipalByUUID(mp.CreatedBy)

collaborator, err := resolvers.PlanCrTdlCreate(s.Config.Logger, input, princ, s.Config.Store)
cr, err := resolvers.PlanCRCreate(s.Config.Logger, input, princ, s.Config.Store)
if err != nil {
panic(err)
}
return collaborator
return cr
}

// addTDL is a wrapper for resolvers.PlanTDLCreate
// It will panic if an error occurs, rather than bubbling the error up
// It will always add the CR/TDL object with the principal value of the Model Plan's "createdBy"
func (s *Seeder) addTDL(mp *models.ModelPlan, input *model.PlanTDLCreateInput) *models.PlanTDL {
princ := s.getTestPrincipalByUUID(mp.CreatedBy)

tdl, err := resolvers.PlanTDLCreate(s.Config.Logger, input, princ, s.Config.Store)
if err != nil {
panic(err)
}
return tdl
}

// planDocumentCreate is a wrapper for resolvers.PlanDocumentCreate
Expand Down
19 changes: 13 additions & 6 deletions cypress/e2e/crtdl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,34 @@ describe('Model Plan CRsand TDLs', () => {

cy.get('#cr-tdl-id-number').type('My CR').should('have.value', 'My CR');

cy.get('#cr-tdl-title')
.type('Change request')
.should('have.value', 'Change request');

cy.get('#cr-tdl-date-initiated')
.type('10/26/2028')
.should('have.value', '10/26/2028');

cy.get('#cr-tdl-title')
.type('Change request')
.should('have.value', 'Change request');
cy.get('#date-implemented-month')
.select('01 - January')
.should('have.value', 0);

cy.get('#date-implemented-year').type('2024').should('have.value', 2024);

cy.get('#cr-tdl-note').type('My note').should('have.value', 'My note');

// click upload button
cy.get('#submit-cr-and-tdl').click();

// check if document is in table
cy.get('[data-testid="cr-tdl-table"] tbody tr')
cy.get('[data-testid="cr-tdl-table-cr"] tbody tr')
.should('have.length', 1)
.first()
.within(() => {
cy.contains('My CR');
cy.contains('10/26/2028');
cy.contains('Change request');
cy.contains('10/26/2028');
cy.contains('January 2024');
cy.contains('My note');
});

Expand All @@ -47,6 +54,6 @@ describe('Model Plan CRsand TDLs', () => {
cy.contains('button', 'Remove it').click();

// no cr and tdls are listed
cy.get('[data-testid="no-crtdls"]').contains('p', 'No CRs or TDLs');
cy.get('[data-testid="no-crtdls"]').contains('p', 'No CRs');
});
});
8 changes: 8 additions & 0 deletions migrations/V139__Plan_CR_TDL_To_CR_Table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- https://jiraent.cms.gov/browse/EASI-3495

ALTER TABLE plan_cr_tdl ADD COLUMN date_implemented TIMESTAMP;

ALTER TABLE plan_cr_tdl RENAME TO plan_cr;

/* Update audit table to rename cr_tdl to plan_cr */
UPDATE "audit"."table_config" SET "name"='plan_cr' WHERE "name"='plan_cr_tdl'
16 changes: 16 additions & 0 deletions migrations/V140__Plan_TDL_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Create new table, same format as it was for plan_cr_tdl */
CREATE TABLE plan_tdl (
id uuid PRIMARY KEY,
model_plan_id uuid NOT NULL REFERENCES model_plan(id),
id_number zero_string NOT NULL,
date_initiated timestamp without time zone NOT NULL,
title zero_string NOT NULL,
note text,
created_dts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
modified_dts timestamp with time zone,
created_by uuid NOT NULL REFERENCES user_account(id),
modified_by uuid REFERENCES user_account(id)
);

/* Enable Audting for new table*/
SELECT audit.AUDIT_TABLE('public', 'plan_tdl', 'id', 'model_plan_id', '{created_by,created_dts,modified_by,modified_dts}'::TEXT[], '{}'::TEXT[]);
Loading

0 comments on commit 1f2be4c

Please sign in to comment.