Skip to content

Commit

Permalink
Merge branch 'feature/samhsa2.0' into BFD-3664
Browse files Browse the repository at this point in the history
  • Loading branch information
dondevun authored Jan 24, 2025
2 parents ea43adf + b86c73b commit 672a86e
Show file tree
Hide file tree
Showing 98 changed files with 3,780 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import gov.cms.bfd.pipeline.ccw.rif.extract.s3.DataSetManifest.PreValidationProperties;
import gov.cms.bfd.pipeline.sharedutils.IdHasher;
import gov.cms.bfd.pipeline.sharedutils.TransactionManager;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.samhsa.backfill.SamhsaBackfillService;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityTransaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import gov.cms.bfd.pipeline.sharedutils.adapters.SamhsaSnfAdapter;
import gov.cms.bfd.pipeline.sharedutils.model.SamhsaEntry;
import gov.cms.bfd.pipeline.sharedutils.model.TableEntry;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.model.TagDetails;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import gov.cms.bfd.model.rif.samhsa.CarrierTag;
import gov.cms.bfd.pipeline.sharedutils.SamhsaUtil;
import gov.cms.bfd.pipeline.sharedutils.model.SamhsaFields;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.model.TagDetails;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import gov.cms.bfd.model.rif.samhsa.DmeTag;
import gov.cms.bfd.pipeline.sharedutils.SamhsaUtil;
import gov.cms.bfd.pipeline.sharedutils.model.SamhsaFields;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.model.TagDetails;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import gov.cms.bfd.model.rif.samhsa.HhaTag;
import gov.cms.bfd.pipeline.sharedutils.SamhsaUtil;
import gov.cms.bfd.pipeline.sharedutils.model.SamhsaFields;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.model.TagDetails;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import gov.cms.bfd.model.rif.samhsa.HospiceTag;
import gov.cms.bfd.pipeline.sharedutils.SamhsaUtil;
import gov.cms.bfd.pipeline.sharedutils.model.SamhsaFields;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.model.TagDetails;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import gov.cms.bfd.model.rif.samhsa.InpatientTag;
import gov.cms.bfd.pipeline.sharedutils.SamhsaUtil;
import gov.cms.bfd.pipeline.sharedutils.model.SamhsaFields;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.model.TagDetails;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import gov.cms.bfd.model.rif.samhsa.OutpatientTag;
import gov.cms.bfd.pipeline.sharedutils.SamhsaUtil;
import gov.cms.bfd.pipeline.sharedutils.model.SamhsaFields;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.model.TagDetails;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package gov.cms.bfd.pipeline.sharedutils.adapters;

import static java.util.Map.*;
import static java.util.Map.entry;

import gov.cms.bfd.model.rif.entities.SNFClaim;
import gov.cms.bfd.model.rif.entities.SNFClaimLine;
import gov.cms.bfd.model.rif.samhsa.SnfTag;
import gov.cms.bfd.pipeline.sharedutils.SamhsaUtil;
import gov.cms.bfd.pipeline.sharedutils.model.SamhsaFields;
import gov.cms.bfd.pipeline.sharedutils.model.TagCode;
import gov.cms.bfd.pipeline.sharedutils.model.TagDetails;
import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package gov.cms.bfd.server.war.commons;

import gov.cms.bfd.sharedutils.TagCode;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.Query;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hl7.fhir.r4.model.Coding;
import org.springframework.stereotype.Service;

/** Find security level. */
@Service
public final class SecurityTagManager {

/** The Entity manager. */
private EntityManager entityManager;

/**
* Sets the {@link #entityManager}.
*
* @param entityManager a JPA {@link EntityManager} connected to the application's database
*/
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}

/**
* Query tags for a specific claim from a specific table.
*
* @param claimId the name of the variable
* @param tagClass the name of the tag class
* @return queryTagsForClaim
*/
public Set<String> queryTagsForClaim(String claimId, Class<?> tagClass) {

String sql = "SELECT t.code FROM " + tagClass.getSimpleName() + " t WHERE t.claim = :claim";

Query query = entityManager.createQuery(sql);
query.setParameter("claim", claimId);

@SuppressWarnings("unchecked")
List<String> resultList = query.getResultList();

return new HashSet<>(resultList);
}

/**
* Determines the security level based on the collected tags.
*
* @param claimId value of claimId
* @param tagClass value of tagClass
* @return SecurityLevel
*/
public List<Coding> getClaimSecurityLevel(String claimId, Class<?> tagClass) {

// Query tags associated with the claim
List<String> securityTags = queryTagsForClaim(claimId, tagClass).stream().toList();

List<Coding> securityTagCoding = new ArrayList<>();

// If no security tags are found, directly add the default "Normal" tag
if (securityTags.isEmpty()) {
Coding coding = new Coding();
coding
.setSystem(TransformerConstants.SAMHSA_CONFIDENTIALITY_CODE_SYSTEM_URL)
.setCode("N")
.setDisplay("Normal");
securityTagCoding.add(coding);
} else {
// Check for each tag and set corresponding code and display
for (String securityTag : securityTags) {
Coding coding = new Coding();
// Convert the securityTag string to the TagCode enum
TagCode tagCode = TagCode.fromString(securityTag);
// Check each security tag and apply corresponding values
if (tagCode != null) {
switch (tagCode) {
case R:
coding
.setSystem(TransformerConstants.SAMHSA_CONFIDENTIALITY_CODE_SYSTEM_URL)
.setCode(TagCode.R.toString())
.setDisplay(TagCode.R.getDisplayName());
break;
case _42CFRPart2:
coding
.setSystem(TransformerConstants.SAMHSA_ACT_CODE_SYSTEM_URL)
.setCode(TagCode._42CFRPart2.toString())
.setDisplay(TagCode._42CFRPart2.getDisplayName());
break;
}
}
securityTagCoding.add(coding);
}
}

return securityTagCoding;
}

/**
* Determines the security level based on the collected tags.
*
* @param claimId value of claimId
* @param tagClass value of tagClass
* @return SecurityLevel
*/
public List<org.hl7.fhir.dstu3.model.Coding> getClaimSecurityLevelDstu3(
String claimId, Class<?> tagClass) {

List<org.hl7.fhir.dstu3.model.Coding> securityTagCoding = new ArrayList<>();
List<Coding> coding = getClaimSecurityLevel(claimId, tagClass);
for (Coding code : coding) {
org.hl7.fhir.dstu3.model.Coding securityTag = new org.hl7.fhir.dstu3.model.Coding();
securityTag
.setSystem("http://terminology.hl7.org/CodeSystem/v3-Confidentiality")
.setCode(code.getCode())
.setDisplay(code.getDisplay());

securityTagCoding.add(securityTag);
}
return securityTagCoding;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -703,4 +703,19 @@ public enum CurrencyIdentifier {
*/
public static final String C4DIC_LOGO_URL =
"https://www.hhs.gov/sites/default/files/logo-white-lg.png";

/**
* URL for v3 Confidentiality Code System <a
* href="http://terminology.hl7.org/CodeSystem/v3-Confidentiality">HL7 v3 Confidentiality Code
* System</a>.
*/
public static final String SAMHSA_CONFIDENTIALITY_CODE_SYSTEM_URL =
"http://terminology.hl7.org/CodeSystem/v3-Confidentiality";

/**
* URL for v3 Act Code System <a href="http://terminology.hl7.org/CodeSystem/v3-ActCode">v3 Act
* Code System</a>.
*/
public static final String SAMHSA_ACT_CODE_SYSTEM_URL =
"http://terminology.hl7.org/CodeSystem/v3-ActCode";
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@
import gov.cms.bfd.model.codebook.data.CcwCodebookVariable;
import gov.cms.bfd.model.rif.entities.CarrierClaim;
import gov.cms.bfd.model.rif.entities.CarrierClaimLine;
import gov.cms.bfd.model.rif.samhsa.CarrierTag;
import gov.cms.bfd.server.war.commons.ClaimType;
import gov.cms.bfd.server.war.commons.Diagnosis;
import gov.cms.bfd.server.war.commons.Diagnosis.DiagnosisLabel;
import gov.cms.bfd.server.war.commons.MedicareSegment;
import gov.cms.bfd.server.war.commons.Profile;
import gov.cms.bfd.server.war.commons.SecurityTagManager;
import gov.cms.bfd.server.war.commons.carin.C4BBAdjudication;
import gov.cms.bfd.server.war.commons.carin.C4BBClaimProfessionalAndNonClinicianCareTeamRole;
import gov.cms.bfd.server.war.commons.carin.C4BBPractitionerIdentifierType;
import gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.ExplanationOfBenefit;
import org.hl7.fhir.r4.model.ExplanationOfBenefit.CareTeamComponent;
import org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent;
Expand All @@ -48,6 +52,9 @@ final class CarrierClaimTransformerV2 implements ClaimTransformerInterfaceV2 {
private static final String METRIC_NAME =
MetricRegistry.name(CarrierClaimTransformerV2.class.getSimpleName(), "transform");

/** The securityTagManager. */
private final SecurityTagManager securityTagManager;

/**
* Instantiates a new transformer.
*
Expand All @@ -58,14 +65,17 @@ final class CarrierClaimTransformerV2 implements ClaimTransformerInterfaceV2 {
* @param metricRegistry the metric registry
* @param drugCodeDisplayLookup the drug code display lookup
* @param npiOrgLookup the npi org lookup
* @param securityTagManager SamhsaSecurityTags lookup
*/
public CarrierClaimTransformerV2(
MetricRegistry metricRegistry,
FdaDrugCodeDisplayLookup drugCodeDisplayLookup,
NPIOrgLookup npiOrgLookup) {
NPIOrgLookup npiOrgLookup,
SecurityTagManager securityTagManager) {
this.metricRegistry = requireNonNull(metricRegistry);
this.npiOrgLookup = requireNonNull(npiOrgLookup);
this.drugCodeDisplayLookup = requireNonNull(drugCodeDisplayLookup);
this.securityTagManager = requireNonNull(securityTagManager);
}

/**
Expand All @@ -83,7 +93,11 @@ public ExplanationOfBenefit transform(Object claim, boolean includeTaxNumber) {
}
ExplanationOfBenefit eob;
try (Timer.Context ignored = metricRegistry.timer(METRIC_NAME).time()) {
eob = transformClaim((CarrierClaim) claim, includeTaxNumber);
CarrierClaim carrierClaim = (CarrierClaim) claim;
List<Coding> securityTags =
securityTagManager.getClaimSecurityLevel(
String.valueOf(carrierClaim.getClaimId()), CarrierTag.class);
eob = transformClaim(carrierClaim, includeTaxNumber, securityTags);
}
return eob;
}
Expand All @@ -93,15 +107,19 @@ public ExplanationOfBenefit transform(Object claim, boolean includeTaxNumber) {
*
* @param claimGroup the CCW {@link CarrierClaim} to transform
* @param includeTaxNumbers whether to include tax numbers in the response
* @param securityTags securityTags of the claim
* @return a FHIR {@link ExplanationOfBenefit} resource that represents the specified {@link
* CarrierClaim}
*/
private ExplanationOfBenefit transformClaim(CarrierClaim claimGroup, boolean includeTaxNumbers) {
private ExplanationOfBenefit transformClaim(
CarrierClaim claimGroup, boolean includeTaxNumbers, List<Coding> securityTags) {
ExplanationOfBenefit eob = new ExplanationOfBenefit();

// Required values not directly mapped
eob.getMeta().addProfile(Profile.C4BB.getVersionedEobNonclinicianUrl());

eob.getMeta().setSecurity(securityTags);

// TODO: ExplanationOfBenefit.outcome is a required field. Needs to be mapped.
// eob.setOutcome(?)

Expand Down
Loading

0 comments on commit 672a86e

Please sign in to comment.