From 18cc86290d0a391ef8441cac6b9de8ab7dcb4054 Mon Sep 17 00:00:00 2001 From: Christopher Ronning <127991809+chris-ronning-ny@users.noreply.github.com> Date: Mon, 11 Sep 2023 17:06:24 -0400 Subject: [PATCH] [DPC-3599] Opt-out Import Database Migrations (#1941) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🎫 Ticket https://jira.cms.gov/browse/DPC-3599 ## 🛠 Changes This PR does the following: 1. A database migration for `dpc_consent` db. It creates a table called `opt_out_file`, consisting of metadata for each opt out file we import, as well as a foreign key `opt_out_file_id` on the `consent` table. For every beneficiary who chooses to opt out, we'll be storing a record in the `consent` table. The Many-to-One relationship here allows us to tie each record to an opt out file and timestamp, for visibility/transparency. 2. Creates an `OptOutFileEntity` for the ORM, so that our Java code can interact with it. 3. Updates the `ConsentEntity` to reflect the Many-to-One relationship. ## ✅ Acceptance Validation - Successfully ran the migration on my local environment without any issues. - Successfully compiled `dpc-common` and `dpc-consent`. ## 🔒 Security Implications - [ ] This PR adds a new software dependency or dependencies. - [ ] This PR modifies or invalidates one or more of our security controls. - [ ] This PR stores or transmits data that was not stored or transmitted before. - [ ] This PR requires additional review of its security implications for other reasons. If any security implications apply, add Jason Ashbaugh (GitHub username: StewGoin) as a reviewer and do not merge this PR without his approval. --------- Co-authored-by: Ashley Weaver <134093673+ashley-weaver@users.noreply.github.com> --- .../consent/entities/ConsentEntity.java | 7 ++ .../consent/entities/OptOutFileEntity.java | 88 +++++++++++++++++++ .../src/main/resources/consent.migrations.xml | 26 ++++++ 3 files changed, 121 insertions(+) create mode 100644 dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/OptOutFileEntity.java diff --git a/dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/ConsentEntity.java b/dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/ConsentEntity.java index 30e7f6c621..91e80d124b 100644 --- a/dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/ConsentEntity.java +++ b/dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/ConsentEntity.java @@ -94,6 +94,10 @@ public ConsentEntity() { @Column(name = "source_code") private String sourceCode; + @ManyToOne() + @JoinColumn(name = "opt_out_file_id") + private OptOutFileEntity optOutFile; + public UUID getId() { return id; } @@ -182,6 +186,9 @@ public void setUpdatedAt(OffsetDateTime updatedAt) { public void setSourceCode(String sourceCode) { this.sourceCode = sourceCode; } + public OptOutFileEntity getOptOutFile() { return optOutFile; } + + public void setOptOutFile(OptOutFileEntity optOutFile) { this.optOutFile = optOutFile; } public static ConsentEntity defaultConsentEntity(Optional id, Optional hicn, Optional mbi) { ConsentEntity ce = new ConsentEntity(); diff --git a/dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/OptOutFileEntity.java b/dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/OptOutFileEntity.java new file mode 100644 index 0000000000..a21b8e5f68 --- /dev/null +++ b/dpc-common/src/main/java/gov/cms/dpc/common/consent/entities/OptOutFileEntity.java @@ -0,0 +1,88 @@ +package gov.cms.dpc.common.consent.entities; + +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; +import javax.persistence.*; +import java.io.Serializable; +import java.time.LocalDate; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.util.Optional; +import java.util.UUID; + +@Entity(name = "opt_out_file") +public class OptOutFileEntity implements Serializable { + public static final String IMPORT_STATUS_IN_PROGRESS = "In-Progress"; + public static final String IMPORT_STATUS_COMPLETED = "Completed"; + public static final String IMPORT_STATUS_FAILED = "Failed"; + + public OptOutFileEntity() {} + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false, columnDefinition = "uuid") + private UUID id; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "timestamp", nullable = false) + private LocalDate timestamp; + + @Column(name = "import_status") + private String importStatus; + + @Column(name = "created_at", columnDefinition = "TIMESTAMP WITH TIME ZONE") + @CreationTimestamp + private OffsetDateTime createdAt; + + @Column(name = "updated_at", columnDefinition = "TIMESTAMP WITH TIME ZONE") + @UpdateTimestamp + private OffsetDateTime updatedAt; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public String getName() { return name; } + + public void setName(String name) { this.name = name; } + + public LocalDate getTimestamp() { return timestamp; } + + public void setTimestamp(LocalDate timestamp) { this.timestamp = timestamp; } + + public String getImportStatus() { return importStatus; } + + public void setImportStatus(String importStatus) { this.importStatus = importStatus; } + + public OffsetDateTime getCreatedAt() { return createdAt; } + + public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; } + + public OffsetDateTime getUpdatedAt() { return updatedAt; } + + public void setUpdatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; } + + public static OptOutFileEntity defaultOptOutEntity(Optional id, Optional name) { + OptOutFileEntity optOut = new OptOutFileEntity(); + + optOut.setId(UUID.randomUUID()); + id.ifPresent(optOut::setId); + + optOut.setName("TestOptOutFile"); + name.ifPresent(optOut::setName); + + optOut.setImportStatus(IMPORT_STATUS_COMPLETED); + + optOut.setTimestamp(LocalDate.now(ZoneId.of("UTC"))); + optOut.setCreatedAt(OffsetDateTime.now(ZoneId.of("UTC"))); + optOut.setUpdatedAt(OffsetDateTime.now(ZoneId.of("UTC"))); + + return optOut; + } +} diff --git a/dpc-consent/src/main/resources/consent.migrations.xml b/dpc-consent/src/main/resources/consent.migrations.xml index 75090b4bd5..72fb1889a7 100644 --- a/dpc-consent/src/main/resources/consent.migrations.xml +++ b/dpc-consent/src/main/resources/consent.migrations.xml @@ -58,4 +58,30 @@ + + + + + + + + + + + + + + + + + + + +