Skip to content

Commit

Permalink
BFD-3665 unit tests and few updates
Browse files Browse the repository at this point in the history
BFD-3665 unit tests and few updates
  • Loading branch information
MahiFentaye committed Jan 3, 2025
1 parent d202146 commit f66fd07
Show file tree
Hide file tree
Showing 25 changed files with 190 additions and 172 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
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.CodeableConcept;
import org.springframework.stereotype.Service;

/** Find security level. */
Expand All @@ -35,97 +25,6 @@ public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}

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

// claimId = claim.getIdElement().getIdPart()
// CodeableConcept type, claimId

// CodeableConcept type = claim.getType();
String claimType = getClaimType(type);

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

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

/**
* Retrieves the claim type from the Claim resource.
*
* @param type the FHIR Claim resource
* @return the claim type (e.g., "Inpatient", "Outpatient", etc.)
*/
private String getClaimType(CodeableConcept type) {
// 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
}

/**
* Query tags for a specific claim from a specific table.
*
Expand All @@ -134,28 +33,16 @@ private String getClaimType(CodeableConcept type) {
* @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";
// tagCodes.add("42CFRPart2");
// tagCodes.add("R");
} else {
// For other tags (CarrierTag, DmeTag, etc.), claimId is a Long
sql = "SELECT t.code FROM " + tagClass.getSimpleName() + " t WHERE t.claim = :claim";
// tagCodes.add("NormalTag");
}
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();

tagCodes = new HashSet<>(resultList);
return tagCodes;
return new HashSet<>(resultList);
}

/**
Expand Down Expand Up @@ -186,7 +73,5 @@ private String determineSecurityLevel(Set<String> securityTags) {
public String getClaimSecurityLevel(String claimId, Class<?> tagClass) {

return determineSecurityLevel(queryTagsForClaim(claimId, tagClass));
// return queryTagsForClaim(claimId, tagClass);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.newrelic.api.agent.Trace;
import gov.cms.bfd.model.rda.entities.RdaFissClaim;
import gov.cms.bfd.model.rda.entities.RdaFissRevenueLine;
import gov.cms.bfd.model.rda.samhsa.FissTag;
import gov.cms.bfd.server.war.commons.BBCodingSystems;
import gov.cms.bfd.server.war.commons.LookUpSamhsaSecurityTags;
import gov.cms.bfd.server.war.commons.carin.C4BBAdjudicationDiscriminator;
Expand Down Expand Up @@ -121,7 +122,7 @@ private ClaimResponse transformClaim(RdaFissClaim claimGroup) {

// claim.getType(), claim.getIdElement().getIdPart()
String securityTag =
lookUpSamhsaSecurityTags.getClaimSecurityLevel(claim.getType(), claim.getIdPart());
lookUpSamhsaSecurityTags.getClaimSecurityLevel(claim.getId(), FissTag.class);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gov.cms.bfd.model.rda.entities.RdaFissPayer;
import gov.cms.bfd.model.rda.entities.RdaFissProcCode;
import gov.cms.bfd.model.rda.entities.RdaFissRevenueLine;
import gov.cms.bfd.model.rda.samhsa.FissTag;
import gov.cms.bfd.server.war.commons.BBCodingSystems;
import gov.cms.bfd.server.war.commons.CCWUtils;
import gov.cms.bfd.server.war.commons.IcdCode;
Expand Down Expand Up @@ -141,8 +142,7 @@ private Claim transformClaim(RdaFissClaim claimGroup, boolean includeTaxNumbers)
claim.setItem(getClaimItems(claimGroup));

String securityTag =
lookUpSamhsaSecurityTags.getClaimSecurityLevel(
claim.getType(), claim.getIdElement().getIdPart());
lookUpSamhsaSecurityTags.getClaimSecurityLevel(claim.getId(), FissTag.class);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.common.base.Strings;
import com.newrelic.api.agent.Trace;
import gov.cms.bfd.model.rda.entities.RdaMcsClaim;
import gov.cms.bfd.model.rda.samhsa.McsTag;
import gov.cms.bfd.server.war.commons.BBCodingSystems;
import gov.cms.bfd.server.war.commons.LookUpSamhsaSecurityTags;
import gov.cms.bfd.server.war.r4.providers.pac.common.AbstractTransformerV2;
Expand Down Expand Up @@ -135,7 +136,7 @@ private ClaimResponse transformClaim(RdaMcsClaim claimGroup) {
claim.setRequest(new Reference(String.format("Claim/m-%s", claimGroup.getIdrClmHdIcn())));

String securityTag =
lookUpSamhsaSecurityTags.getClaimSecurityLevel(claim.getType(), claim.getIdPart());
lookUpSamhsaSecurityTags.getClaimSecurityLevel(claim.getId(), McsTag.class);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gov.cms.bfd.model.rda.entities.RdaMcsClaim;
import gov.cms.bfd.model.rda.entities.RdaMcsDetail;
import gov.cms.bfd.model.rda.entities.RdaMcsDiagnosisCode;
import gov.cms.bfd.model.rda.samhsa.McsTag;
import gov.cms.bfd.server.war.commons.BBCodingSystems;
import gov.cms.bfd.server.war.commons.IcdCode;
import gov.cms.bfd.server.war.commons.LookUpSamhsaSecurityTags;
Expand Down Expand Up @@ -135,9 +136,8 @@ private Claim transformClaim(RdaMcsClaim claimGroup, boolean includeTaxNumbers)

claim.setCreated(new Date());

String securityTag =
lookUpSamhsaSecurityTags.getClaimSecurityLevel(
claim.getType(), claim.getIdElement().getIdPart());
String claimId = claim.getId().replaceAll("\\D", "");
String securityTag = lookUpSamhsaSecurityTags.getClaimSecurityLevel(claimId, McsTag.class);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ final class CarrierClaimTransformer implements ClaimTransformerInterface {
* @param metricRegistry the metric registry
* @param drugCodeDisplayLookup the drug code display lookup
* @param npiOrgLookup the npi org lookup
* @param lookUpSamhsaSecurityTags SamhsaSecurityTags lookup
*/
public CarrierClaimTransformer(
MetricRegistry metricRegistry,
FdaDrugCodeDisplayLookup drugCodeDisplayLookup,
NPIOrgLookup npiOrgLookup) {
NPIOrgLookup npiOrgLookup,
LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags) {
this.metricRegistry = requireNonNull(metricRegistry);
this.npiOrgLookup = requireNonNull(npiOrgLookup);
this.drugCodeDisplayLookup = requireNonNull(drugCodeDisplayLookup);
this.lookUpSamhsaSecurityTags = lookUpSamhsaSecurityTags;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ final class DMEClaimTransformer implements ClaimTransformerInterface {
*
* @param metricRegistry the metric registry
* @param drugCodeDisplayLookup the drug code display lookup
* @param lookUpSamhsaSecurityTags SamhsaSecurityTag lookup
*/
public DMEClaimTransformer(
MetricRegistry metricRegistry, FdaDrugCodeDisplayLookup drugCodeDisplayLookup) {
MetricRegistry metricRegistry,
FdaDrugCodeDisplayLookup drugCodeDisplayLookup,
LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags) {
this.metricRegistry = requireNonNull(metricRegistry);
this.drugCodeDisplayLookup = requireNonNull(drugCodeDisplayLookup);
this.lookUpSamhsaSecurityTags = requireNonNull(lookUpSamhsaSecurityTags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ final class HHAClaimTransformer implements ClaimTransformerInterface {
*
* @param metricRegistry the metric registry
* @param npiOrgLookup the npi org lookup
* @param lookUpSamhsaSecurityTags SamhsaSecurityTags lookup
*/
public HHAClaimTransformer(MetricRegistry metricRegistry, NPIOrgLookup npiOrgLookup) {
public HHAClaimTransformer(
MetricRegistry metricRegistry,
NPIOrgLookup npiOrgLookup,
LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags) {
this.metricRegistry = requireNonNull(metricRegistry);
this.npiOrgLookup = requireNonNull(npiOrgLookup);
this.lookUpSamhsaSecurityTags = requireNonNull(lookUpSamhsaSecurityTags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ final class HospiceClaimTransformer implements ClaimTransformerInterface {
*
* @param metricRegistry the metric registry
* @param npiOrgLookup the npi org lookup
* @param lookUpSamhsaSecurityTags lookUpSamhsaSecurityTags
*/
public HospiceClaimTransformer(MetricRegistry metricRegistry, NPIOrgLookup npiOrgLookup) {
public HospiceClaimTransformer(
MetricRegistry metricRegistry,
NPIOrgLookup npiOrgLookup,
LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags) {
this.metricRegistry = requireNonNull(metricRegistry);
this.npiOrgLookup = requireNonNull(npiOrgLookup);
this.lookUpSamhsaSecurityTags = requireNonNull(lookUpSamhsaSecurityTags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ final class InpatientClaimTransformer implements ClaimTransformerInterface {
*
* @param metricRegistry the metric registry
* @param npiOrgLookup the npi org lookup
* @param lookUpSamhsaSecurityTags SamhsaSecurityTag lookup
*/
public InpatientClaimTransformer(MetricRegistry metricRegistry, NPIOrgLookup npiOrgLookup) {
public InpatientClaimTransformer(
MetricRegistry metricRegistry,
NPIOrgLookup npiOrgLookup,
LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags) {
this.metricRegistry = requireNonNull(metricRegistry);
this.npiOrgLookup = requireNonNull(npiOrgLookup);
this.lookUpSamhsaSecurityTags = lookUpSamhsaSecurityTags;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ final class OutpatientClaimTransformer implements ClaimTransformerInterface {
*
* @param metricRegistry the metric registry
* @param npiOrgLookup the npi org lookup
* @param lookUpSamhsaSecurityTags SamhsaSecurityTag lookup
*/
public OutpatientClaimTransformer(MetricRegistry metricRegistry, NPIOrgLookup npiOrgLookup) {
public OutpatientClaimTransformer(
MetricRegistry metricRegistry,
NPIOrgLookup npiOrgLookup,
LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags) {
this.metricRegistry = requireNonNull(metricRegistry);
this.npiOrgLookup = requireNonNull(npiOrgLookup);
this.lookUpSamhsaSecurityTags = requireNonNull(lookUpSamhsaSecurityTags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ public class SNFClaimTransformer implements ClaimTransformerInterface {
*
* @param metricRegistry the metric registry
* @param npiOrgLookup the npi org lookup
* @param lookUpSamhsaSecurityTags SamhsaSecurityTag lookup
*/
public SNFClaimTransformer(MetricRegistry metricRegistry, NPIOrgLookup npiOrgLookup) {
public SNFClaimTransformer(
MetricRegistry metricRegistry,
NPIOrgLookup npiOrgLookup,
LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags) {
this.metricRegistry = requireNonNull(metricRegistry);
this.npiOrgLookup = requireNonNull(npiOrgLookup);
this.lookUpSamhsaSecurityTags = requireNonNull(lookUpSamhsaSecurityTags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import gov.cms.bfd.server.war.ServerTestUtils;
import gov.cms.bfd.server.war.commons.CCWUtils;
import gov.cms.bfd.server.war.commons.ClaimType;
import gov.cms.bfd.server.war.commons.LookUpSamhsaSecurityTags;
import gov.cms.bfd.server.war.commons.MedicareSegment;
import gov.cms.bfd.server.war.commons.TransformerConstants;
import gov.cms.bfd.server.war.utils.RDATestUtils;
Expand Down Expand Up @@ -61,6 +62,9 @@ public final class CarrierClaimTransformerTest {
/** The NPI org lookup to use for the test. */
@Mock NPIOrgLookup npiOrgLookup;

/** The lookUpSamhsaSecurityTags. */
@Mock LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags;

/** The mock metric timer. */
@Mock Timer metricsTimer;

Expand All @@ -78,7 +82,8 @@ protected void setup() {
.thenReturn("UNKNOWN");

carrierClaimTransformer =
new CarrierClaimTransformer(metricRegistry, drugDisplayLookup, npiOrgLookup);
new CarrierClaimTransformer(
metricRegistry, drugDisplayLookup, npiOrgLookup, lookUpSamhsaSecurityTags);
}

/**
Expand Down
Loading

0 comments on commit f66fd07

Please sign in to comment.