Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BFD-3663: Populate tags for claim / EOB on ingestion from CCW #2497

Open
wants to merge 11 commits into
base: feature/samhsa2.0
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gov.cms.bfd.model.rif.samhsa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.Table;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

/** Entity for a Carrier tag. */
@Entity
@Table(name = "carrier_tags", schema = "ccw")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@IdClass(CcwTagKey.class)
public class CarrierTag {
/** Tag Code. */
@Id
@Column(name = "code", nullable = false)
private String code;

/** the details field. */
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "details", nullable = true)
private List details;

/** The associated claim. */
@Id
@Column(name = "clm_id", nullable = false)
Long claim;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package gov.cms.bfd.model.rif.samhsa;

import java.io.Serializable;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/** The composite key for CCW tags. */
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class CcwTagKey implements Serializable {
/** The associated claim. */
private Long claim;

/** The tag code. */
private String code;

/** {@inheritDoc} */
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CcwTagKey ccwTagKey)) return false;
return this.claim.equals(ccwTagKey.getClaim()) && this.code.equals(ccwTagKey.getCode());
}

/** {@inheritDoc} */
@Override
public int hashCode() {
return Objects.hash(claim, code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gov.cms.bfd.model.rif.samhsa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.Table;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

/** Entity for an MCS tag. */
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
@IdClass(CcwTagKey.class)
@Table(name = "dme_tags", schema = "ccw")
public class DmeTag {
/** The tag code. */
@Id
@Column(name = "code", nullable = false)
private String code;

/** The tag details. */
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "details", nullable = true)
private List details;

/** The associated claim. */
@Id
@Column(name = "clm_id", nullable = false)
Long claim;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gov.cms.bfd.model.rif.samhsa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.Table;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

/** Entity for an MCS tag. */
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
@IdClass(CcwTagKey.class)
@Table(name = "hha_tags", schema = "ccw")
public class HhaTag {
/** The tag code. */
@Id
@Column(name = "code", nullable = false)
private String code;

/** The tag details. */
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "details", nullable = true)
private List details;

/** The associated claim. */
@Id
@Column(name = "clm_id", nullable = false)
Long claim;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gov.cms.bfd.model.rif.samhsa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.Table;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

/** Entity for an MCS tag. */
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
@IdClass(CcwTagKey.class)
@Table(name = "hospice_tags", schema = "ccw")
public class HospiceTag {
/** The tag code. */
@Id
@Column(name = "code", nullable = false)
private String code;

/** The tag details. */
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "details", nullable = true)
private List details;

/** The associated claim. */
@Id
@Column(name = "clm_id", nullable = false)
Long claim;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gov.cms.bfd.model.rif.samhsa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.Table;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

/** Entity for an MCS tag. */
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
@IdClass(CcwTagKey.class)
@Table(name = "inpatient_tags", schema = "ccw")
public class InpatientTag {
/** The tag code. */
@Id
@Column(name = "code", nullable = false)
private String code;

/** The tag details. */
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "details", nullable = true)
private List details;

/** The associated claim. */
@Id
@Column(name = "clm_id", nullable = false)
Long claim;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gov.cms.bfd.model.rif.samhsa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.Table;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

/** Entity for an MCS tag. */
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
@IdClass(CcwTagKey.class)
@Table(name = "outpatient_tags", schema = "ccw")
public class OutpatientTag {
/** The tag code. */
@Id
@Column(name = "code", nullable = false)
private String code;

/** The tag details. */
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "details", nullable = true)
private List details;

/** The associated claim. */
@Id
@Column(name = "clm_id", nullable = false)
Long claim;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gov.cms.bfd.model.rif.samhsa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.Table;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

/** Entity for an MCS tag. */
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
@IdClass(CcwTagKey.class)
@Table(name = "snf_tags", schema = "ccw")
public class SnfTag {
/** The tag code. */
@Id
@Column(name = "code", nullable = false)
private String code;

/** The tag details. */
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "details", nullable = true)
private List details;

/** The associated claim. */
@Id
@Column(name = "clm_id", nullable = false)
Long claim;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import gov.cms.bfd.pipeline.sharedutils.FluxWaiter;
import gov.cms.bfd.pipeline.sharedutils.IdHasher;
import gov.cms.bfd.pipeline.sharedutils.PipelineApplicationState;
import gov.cms.bfd.pipeline.sharedutils.SamhsaUtil;
import gov.cms.bfd.pipeline.sharedutils.TransactionManager;
import gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException;
import jakarta.persistence.Entity;
Expand All @@ -36,6 +37,7 @@
import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -89,6 +91,17 @@ public final class RifLoader {
*/
private static final Duration MAX_INTERRUPTED_WAIT_TIME = Duration.ofMinutes(5);

/** These filetypes will be checked for SAMHSA data. */
private static final RifFileType[] POSSIBLE_SAMHSA_CLAIMS = {
RifFileType.CARRIER,
RifFileType.DME,
RifFileType.HHA,
RifFileType.HOSPICE,
RifFileType.INPATIENT,
RifFileType.OUTPATIENT,
RifFileType.SNF
};

/**
* Constructs a new {@link RifLoader} instance.
*
Expand Down Expand Up @@ -348,11 +361,10 @@ private List<RifRecordLoadResult> processBatchImpl(
*/
LoadedBatchBuilder loadedBatchBuilder =
new LoadedBatchBuilder(loadedFileId, recordsBatch.size());

SamhsaUtil samhsaUtil = SamhsaUtil.getSamhsaUtil();
for (RifRecordEvent<?> rifRecordEvent : recordsBatch) {
RecordAction recordAction = rifRecordEvent.getRecordAction();
RifRecordBase record = rifRecordEvent.getRecord();

LOGGER.trace("Loading '{}' record.", rifFileType);

// Set lastUpdated to the same value for the whole batch
Expand Down Expand Up @@ -399,7 +411,9 @@ private List<RifRecordLoadResult> processBatchImpl(
"Unhandled %s: '%s'.", RecordAction.class, rifRecordEvent.getRecordAction()));
}
} else throw new BadCodeMonkeyException();

if (Arrays.asList(POSSIBLE_SAMHSA_CLAIMS).contains(rifFileType)) {
samhsaUtil.processClaim(record, entityManager);
}
LOGGER.trace("Loaded '{}' record.", rifFileType);

fileEventMetrics
Expand Down
Loading