-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BFD-3665 first draft at getting security tags for claim
- Loading branch information
1 parent
c08f084
commit cd716cc
Showing
2 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
176 changes: 176 additions & 0 deletions
176
...bfd-server-war/src/main/java/gov/cms/bfd/server/war/commons/LookUpSamhsaSecurityTags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters