Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
BFD-3665 first draft at getting security tags for claim
  • Loading branch information
MahiFentaye committed Dec 13, 2024
1 parent c08f084 commit cd716cc
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package gov.cms.bfd.server.war.commons;

import gov.cms.bfd.model.rda.samhsa.FissTag;
import gov.cms.bfd.model.rda.samhsa.McsTag;
import gov.cms.bfd.model.rif.samhsa.CarrierTag;
import gov.cms.bfd.model.rif.samhsa.DmeTag;
import gov.cms.bfd.model.rif.samhsa.HhaTag;
import gov.cms.bfd.model.rif.samhsa.HospiceTag;
import gov.cms.bfd.model.rif.samhsa.InpatientTag;
import gov.cms.bfd.model.rif.samhsa.OutpatientTag;
import gov.cms.bfd.model.rif.samhsa.SnfTag;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.Query;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hl7.fhir.r4.model.Claim;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.springframework.stereotype.Service;

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

/** 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;
}

/**
* Method to find the security level of a given claim ID.
*
* @param claim holds Claim
* @return SecurityLevel
*/
public String getClaimSecurityLevel(Claim claim) {
// Identify the claim type (e.g., Inpatient, Outpatient, Carrier, etc.)
String claimType = getClaimType(claim);

Set<String> securityTags = new HashSet<>();

// Query tags based on the claim type
switch (claimType) {
case "Inpatient":
securityTags.addAll(
queryTagsForClaim(claim.getIdElement().getIdPart(), InpatientTag.class));
break;
case "Outpatient":
securityTags.addAll(
queryTagsForClaim(claim.getIdElement().getIdPart(), OutpatientTag.class));
break;
case "Carrier":
securityTags.addAll(queryTagsForClaim(claim.getIdElement().getIdPart(), CarrierTag.class));
break;
case "DME":
securityTags.addAll(queryTagsForClaim(claim.getIdElement().getIdPart(), DmeTag.class));
break;
case "HHA":
securityTags.addAll(queryTagsForClaim(claim.getIdElement().getIdPart(), HhaTag.class));
break;
case "Hospice":
securityTags.addAll(queryTagsForClaim(claim.getIdElement().getIdPart(), HospiceTag.class));
break;
case "SNF":
securityTags.addAll(queryTagsForClaim(claim.getIdElement().getIdPart(), SnfTag.class));
break;
case "FISS":
securityTags.addAll(queryTagsForClaim(claim.getIdElement().getIdPart(), FissTag.class));
break;
case "MCS":
securityTags.addAll(queryTagsForClaim(claim.getIdElement().getIdPart(), McsTag.class));
break;
default:
// No tags for unrecognized claim type
break;
}

// Determine the security level based on the collected tags
return determineSecurityLevel(securityTags);
}

/**
* Helper method to get the claim type from the FHIR Claim resource.
*
* @param claim the FHIR Claim resource
* @return the claim type (e.g., "Inpatient", "Outpatient", etc.)
*/
private String getClaimType(Claim claim) {
// Retrieve the claim type from the Claim resource
CodeableConcept type = claim.getType();
if (type != null && type.hasCoding()) {

String code = type.getCodingFirstRep().getCode();
switch (code) {
case "INP":
return "Inpatient";
case "OUT":
return "Outpatient";
case "CAR":
return "Carrier";
case "DME":
return "DME";
case "HHA":
return "HHA";
case "HOS":
return "Hospice";
case "SNF":
return "SNF";
case "FISS":
return "FISS";
case "MCS":
return "MCS";
default:
return "Unknown";
}
}
return "Unknown"; // Return "Unknown" if type is not set
}

/**
* Helper method to 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
*/
private Set<String> queryTagsForClaim(String claimId, Class<?> tagClass) {
Set<String> tagCodes = new HashSet<>();

String sql;
if (FissTag.class.equals(tagClass) || McsTag.class.equals(tagClass)) {
// For FissTag and McsTag, claimId is a String
sql = "SELECT t.code FROM " + tagClass.getSimpleName() + " t WHERE t.claim = :claim";
} else {
// For other tags (CarrierTag, DmeTag, etc.), claimId is a Long
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();

// Use a parameterized constructor to initialize the Set with the List
tagCodes = new HashSet<>(resultList);
return tagCodes;
}

/**
* Helper method to determine the security level based on the collected tags.
*
* @param securityTags value of securityTags
* @return SecurityLevel
*/
private String determineSecurityLevel(Set<String> securityTags) {
// Define the rules for security levels based on tag codes
for (String tag : securityTags) {
if ("R".equals(tag) || "42CFRPart2".equals(tag)) {
return "Restricted"; // Sensitive data
}
}

// Default to 'Normal' if no sensitive tags are found
return "Normal";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import gov.cms.bfd.server.war.commons.BBCodingSystems;
import gov.cms.bfd.server.war.commons.CCWUtils;
import gov.cms.bfd.server.war.commons.IcdCode;
import gov.cms.bfd.server.war.commons.LookUpSamhsaSecurityTags;
import gov.cms.bfd.server.war.commons.TransformerConstants;
import gov.cms.bfd.server.war.commons.carin.C4BBOrganizationIdentifierType;
import gov.cms.bfd.server.war.commons.carin.C4BBSupportingInfoType;
Expand Down Expand Up @@ -45,6 +46,7 @@
import org.hl7.fhir.r4.model.codesystems.ClaimType;
import org.hl7.fhir.r4.model.codesystems.ExDiagnosistype;
import org.hl7.fhir.r4.model.codesystems.ProcessPriority;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/** Transforms FISS/MCS instances into FHIR {@link Claim} resources. */
Expand All @@ -62,6 +64,9 @@ public class FissClaimTransformerV2 extends AbstractTransformerV2
/** The Metric registry. */
private final MetricRegistry metricRegistry;

/** Injecting lookUpSamhsaSecurityTags. */
@Autowired LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags;

/** The METRIC_NAME constant. */
private static final String METRIC_NAME =
MetricRegistry.name(FissClaimTransformerV2.class.getSimpleName(), "transform");
Expand Down Expand Up @@ -135,7 +140,24 @@ private Claim transformClaim(RdaFissClaim claimGroup, boolean includeTaxNumbers)
claim.setInsurance(getInsurance(claimGroup));
claim.setItem(getClaimItems(claimGroup));

claim.setMeta(new Meta().setLastUpdated(Date.from(claimGroup.getLastUpdated())));
// like lastUpdated is set here we will probably set Meta the same way
String securityTag = lookUpSamhsaSecurityTags.getClaimSecurityLevel(claim);

// Create a list of Coding objects to match the required type
List<Coding> securityTags = new ArrayList<>();

// Create a Coding object for the security level
Coding securityTagCoding =
new Coding()
.setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html")
.setCode(securityTag)
.setDisplay(securityTag);

// Add the Coding to the list
securityTags.add(securityTagCoding);
Meta meta = new Meta();
claim.setMeta(meta.setSecurity(securityTags));
claim.setMeta(meta.setLastUpdated(Date.from(claimGroup.getLastUpdated())));
claim.setCreated(new Date());

return claim;
Expand Down

0 comments on commit cd716cc

Please sign in to comment.