diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/commons/LookUpSamhsaSecurityTags.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/commons/LookUpSamhsaSecurityTags.java new file mode 100644 index 0000000000..598e2817f3 --- /dev/null +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/commons/LookUpSamhsaSecurityTags.java @@ -0,0 +1,193 @@ +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. */ +@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 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 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; + } + + // 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 type the FHIR Claim resource + * @return the claim type (e.g., "Inpatient", "Outpatient", etc.) + */ + private String getClaimType(CodeableConcept type) { + // 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 queryTagsForClaim(String claimId, Class tagClass) { + Set 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 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 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"; + } + + /** + * Helper method to determine the security level based on the collected tags. + * + * @param claimId value of claimId + * @param tagClass value of tagClass + * @return SecurityLevel + */ + public String getClaimSecurityLevel(String claimId, Class tagClass) { + + return determineSecurityLevel(queryTagsForClaim(claimId, tagClass)); + // return queryTagsForClaim(claimId, tagClass); + + } +} diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/CarrierClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/CarrierClaimTransformerV2.java index 18aabb3d6c..592c866c4f 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/CarrierClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/CarrierClaimTransformerV2.java @@ -10,9 +10,11 @@ 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.LookUpSamhsaSecurityTags; import gov.cms.bfd.server.war.commons.MedicareSegment; import gov.cms.bfd.server.war.commons.Profile; import gov.cms.bfd.server.war.commons.carin.C4BBAdjudication; @@ -27,6 +29,7 @@ import org.hl7.fhir.r4.model.ExplanationOfBenefit.CareTeamComponent; import org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent; import org.hl7.fhir.r4.model.Reference; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -48,6 +51,9 @@ final class CarrierClaimTransformerV2 implements ClaimTransformerInterfaceV2 { private static final String METRIC_NAME = MetricRegistry.name(CarrierClaimTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -102,6 +108,15 @@ private ExplanationOfBenefit transformClaim(CarrierClaim claimGroup, boolean inc // Required values not directly mapped eob.getMeta().addProfile(Profile.C4BB.getVersionedEobNonclinicianUrl()); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), CarrierTag.class); + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); + // TODO: ExplanationOfBenefit.outcome is a required field. Needs to be mapped. // eob.setOutcome(?) diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/DMEClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/DMEClaimTransformerV2.java index df02d767f5..fd05e60ab3 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/DMEClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/DMEClaimTransformerV2.java @@ -10,9 +10,11 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; import gov.cms.bfd.model.rif.entities.DMEClaim; import gov.cms.bfd.model.rif.entities.DMEClaimLine; +import gov.cms.bfd.model.rif.samhsa.DmeTag; 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.LookUpSamhsaSecurityTags; import gov.cms.bfd.server.war.commons.MedicareSegment; import gov.cms.bfd.server.war.commons.Profile; import gov.cms.bfd.server.war.commons.carin.C4BBAdjudication; @@ -27,6 +29,7 @@ import org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent; import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.Quantity; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms CCW {@link DMEClaim} instances into FHIR {@link ExplanationOfBenefit} resources. */ @@ -46,6 +49,9 @@ final class DMEClaimTransformerV2 implements ClaimTransformerInterfaceV2 { private static final String METRIC_NAME = MetricRegistry.name(DMEClaimTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -101,6 +107,15 @@ private ExplanationOfBenefit transformClaim(DMEClaim claimGroup, boolean include // Required values not directly mapped eob.getMeta().addProfile(Profile.C4BB.getVersionedEobInpatientUrl()); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), DmeTag.class); + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); + // Common group level fields between all claim types // Claim Type + Claim ID => ExplanationOfBenefit.id // CLM_ID => ExplanationOfBenefit.identifier diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/HHAClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/HHAClaimTransformerV2.java index 42da112fad..8a725cfe82 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/HHAClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/HHAClaimTransformerV2.java @@ -9,8 +9,10 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; import gov.cms.bfd.model.rif.entities.HHAClaim; import gov.cms.bfd.model.rif.entities.HHAClaimLine; +import gov.cms.bfd.model.rif.samhsa.HhaTag; import gov.cms.bfd.server.war.commons.C4BBInstutionalClaimSubtypes; 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.Profile; import gov.cms.bfd.server.war.commons.carin.C4BBClaimProfessionalAndNonClinicianCareTeamRole; @@ -23,6 +25,7 @@ import org.hl7.fhir.r4.model.ExplanationOfBenefit; import org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent; import org.hl7.fhir.r4.model.Quantity; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms CCW {@link HHAClaim} instances into FHIR {@link ExplanationOfBenefit} resources. */ @@ -39,6 +42,9 @@ final class HHAClaimTransformerV2 implements ClaimTransformerInterfaceV2 { private static final String METRIC_NAME = MetricRegistry.name(HHAClaimTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -87,6 +93,14 @@ private ExplanationOfBenefit transformClaim(HHAClaim claimGroup) { // Required values not directly mapped eob.getMeta().addProfile(Profile.C4BB.getVersionedEobNonclinicianUrl()); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), HhaTag.class); + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); // Common group level fields between all claim types // Claim Type + Claim ID => ExplanationOfBenefit.id // CLM_ID => ExplanationOfBenefit.identifier diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/HospiceClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/HospiceClaimTransformerV2.java index e804570141..810e3efee2 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/HospiceClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/HospiceClaimTransformerV2.java @@ -9,8 +9,10 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; import gov.cms.bfd.model.rif.entities.HospiceClaim; import gov.cms.bfd.model.rif.entities.HospiceClaimLine; +import gov.cms.bfd.model.rif.samhsa.HospiceTag; import gov.cms.bfd.server.war.commons.C4BBInstutionalClaimSubtypes; 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.Profile; import gov.cms.bfd.server.war.commons.carin.C4BBAdjudication; @@ -23,6 +25,7 @@ import java.util.Optional; import org.hl7.fhir.r4.model.ExplanationOfBenefit; import org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -41,6 +44,9 @@ final class HospiceClaimTransformerV2 implements ClaimTransformerInterfaceV2 { private static final String METRIC_NAME = MetricRegistry.name(HospiceClaimTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -89,6 +95,14 @@ private ExplanationOfBenefit transformClaim(HospiceClaim claimGroup) { // Required values not directly mapped eob.getMeta().addProfile(Profile.C4BB.getVersionedEobInpatientUrl()); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), HospiceTag.class); + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); // Common group level fields between all claim types // Claim Type + Claim ID => ExplanationOfBenefit.id // CLM_ID => ExplanationOfBenefit.identifier diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/InpatientClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/InpatientClaimTransformerV2.java index e188bf36dd..89e9924a15 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/InpatientClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/InpatientClaimTransformerV2.java @@ -9,9 +9,11 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; import gov.cms.bfd.model.rif.entities.InpatientClaim; import gov.cms.bfd.model.rif.entities.InpatientClaimLine; +import gov.cms.bfd.model.rif.samhsa.InpatientTag; import gov.cms.bfd.server.war.commons.C4BBInstutionalClaimSubtypes; 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.Profile; import gov.cms.bfd.server.war.commons.TransformerConstants; @@ -25,6 +27,7 @@ import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.ExplanationOfBenefit; import org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -43,6 +46,9 @@ final class InpatientClaimTransformerV2 implements ClaimTransformerInterfaceV2 { private static final String METRIC_NAME = MetricRegistry.name(InpatientClaimTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -92,6 +98,15 @@ private ExplanationOfBenefit transformClaim(InpatientClaim claimGroup) { // Required values not directly mapped eob.getMeta().addProfile(Profile.C4BB.getVersionedEobInpatientUrl()); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), InpatientTag.class); + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); + // Common group level fields between all claim types // Claim Type + Claim ID => ExplanationOfBenefit.id // CLM_ID => ExplanationOfBenefit.identifier diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/OutpatientClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/OutpatientClaimTransformerV2.java index db8b2a9303..b4ef39cb04 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/OutpatientClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/OutpatientClaimTransformerV2.java @@ -11,8 +11,10 @@ import gov.cms.bfd.model.rif.entities.InpatientClaim; import gov.cms.bfd.model.rif.entities.OutpatientClaim; import gov.cms.bfd.model.rif.entities.OutpatientClaimLine; +import gov.cms.bfd.model.rif.samhsa.OutpatientTag; import gov.cms.bfd.server.war.commons.C4BBInstutionalClaimSubtypes; 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.Profile; import gov.cms.bfd.server.war.commons.carin.C4BBAdjudication; @@ -25,6 +27,7 @@ import java.util.Optional; import org.hl7.fhir.r4.model.ExplanationOfBenefit; import org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -47,6 +50,9 @@ final class OutpatientClaimTransformerV2 implements ClaimTransformerInterfaceV2 private static final String METRIC_NAME = MetricRegistry.name(OutpatientClaimTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -101,6 +107,15 @@ private ExplanationOfBenefit transformClaim(OutpatientClaim claimGroup) { // Required values not directly mapped eob.getMeta().addProfile(Profile.C4BB.getVersionedEobOutpatientUrl()); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), OutpatientTag.class); + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); + // Common group level fields between all claim types // Claim Type + Claim ID => ExplanationOfBenefit.id // CLM_ID => ExplanationOfBenefit.identifier diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/SNFClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/SNFClaimTransformerV2.java index e15f9830a2..760f541e8c 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/SNFClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/SNFClaimTransformerV2.java @@ -10,9 +10,11 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; 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.server.war.commons.C4BBInstutionalClaimSubtypes; import gov.cms.bfd.server.war.commons.ClaimType; import gov.cms.bfd.server.war.commons.CommonTransformerUtils; +import gov.cms.bfd.server.war.commons.LookUpSamhsaSecurityTags; import gov.cms.bfd.server.war.commons.MedicareSegment; import gov.cms.bfd.server.war.commons.Profile; import gov.cms.bfd.server.war.commons.carin.C4BBClaimInstitutionalCareTeamRole; @@ -26,6 +28,7 @@ import org.hl7.fhir.r4.model.ExplanationOfBenefit; import org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent; import org.hl7.fhir.r4.model.Period; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms CCW {@link SNFClaim} instances into FHIR {@link ExplanationOfBenefit} resources. */ @@ -42,6 +45,9 @@ public class SNFClaimTransformerV2 implements ClaimTransformerInterfaceV2 { private static final String METRIC_NAME = MetricRegistry.name(SNFClaimTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -91,6 +97,15 @@ private ExplanationOfBenefit transformClaim(SNFClaim claimGroup) { // Required values not directly mapped eob.getMeta().addProfile(Profile.C4BB.getVersionedEobInpatientUrl()); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), SnfTag.class); + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); + // Common group level fields between all claim types // Claim Type + Claim ID => ExplanationOfBenefit.id // CLM_ID => ExplanationOfBenefit.identifier diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/FissClaimResponseTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/FissClaimResponseTransformerV2.java index 8133343d6b..0affcde39b 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/FissClaimResponseTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/FissClaimResponseTransformerV2.java @@ -8,6 +8,7 @@ import gov.cms.bfd.model.rda.entities.RdaFissClaim; import gov.cms.bfd.model.rda.entities.RdaFissRevenueLine; 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; import gov.cms.bfd.server.war.r4.providers.pac.common.AbstractTransformerV2; import gov.cms.bfd.server.war.r4.providers.pac.common.FissTransformerV2; @@ -27,6 +28,7 @@ import org.hl7.fhir.r4.model.Meta; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.codesystems.ClaimType; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms FISS/MCS instances into FHIR {@link ClaimResponse} resources. */ @@ -41,6 +43,9 @@ public class FissClaimResponseTransformerV2 extends AbstractTransformerV2 private static final String METRIC_NAME = MetricRegistry.name(FissClaimResponseTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * The known FISS status codes and their associated {@link ClaimResponse.RemittanceOutcome} * mappings. @@ -114,7 +119,25 @@ private ClaimResponse transformClaim(RdaFissClaim claimGroup) { claim.setRequest(new Reference(String.format("Claim/f-%s", claimGroup.getClaimId()))); claim.setItem(getClaimItems(claimGroup)); - claim.setMeta(new Meta().setLastUpdated(Date.from(claimGroup.getLastUpdated()))); + // claim.getType(), claim.getIdElement().getIdPart() + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel(claim.getType(), claim.getIdPart()); + + // Create a list of Coding objects to match the required type + List 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; diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/FissClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/FissClaimTransformerV2.java index ed25704d30..026b23807e 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/FissClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/FissClaimTransformerV2.java @@ -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; @@ -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. */ @@ -62,6 +64,9 @@ public class FissClaimTransformerV2 extends AbstractTransformerV2 /** The Metric registry. */ private final MetricRegistry metricRegistry; + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** The METRIC_NAME constant. */ private static final String METRIC_NAME = MetricRegistry.name(FissClaimTransformerV2.class.getSimpleName(), "transform"); @@ -135,7 +140,25 @@ private Claim transformClaim(RdaFissClaim claimGroup, boolean includeTaxNumbers) claim.setInsurance(getInsurance(claimGroup)); claim.setItem(getClaimItems(claimGroup)); - claim.setMeta(new Meta().setLastUpdated(Date.from(claimGroup.getLastUpdated()))); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + claim.getType(), claim.getIdElement().getIdPart()); + + // Create a list of Coding objects to match the required type + List 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; diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/McsClaimResponseTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/McsClaimResponseTransformerV2.java index f952c18494..9620f36995 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/McsClaimResponseTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/McsClaimResponseTransformerV2.java @@ -6,6 +6,7 @@ import com.newrelic.api.agent.Trace; import gov.cms.bfd.model.rda.entities.RdaMcsClaim; 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; import gov.cms.bfd.server.war.r4.providers.pac.common.McsTransformerV2; import gov.cms.bfd.server.war.r4.providers.pac.common.ResourceTransformer; @@ -16,11 +17,13 @@ import java.util.Map; import org.hl7.fhir.r4.model.Claim; import org.hl7.fhir.r4.model.ClaimResponse; +import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Meta; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.codesystems.ClaimType; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms FISS/MCS instances into FHIR {@link ClaimResponse} resources. */ @@ -35,6 +38,9 @@ public class McsClaimResponseTransformerV2 extends AbstractTransformerV2 private static final String METRIC_NAME = MetricRegistry.name(McsClaimResponseTransformerV2.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * There are only 2 statuses currently being used, and only the ones listed below are mapped to * "CANCELLED". For brevity, the rest are defaulted to "ACTIVE" using {@link @@ -128,7 +134,24 @@ private ClaimResponse transformClaim(RdaMcsClaim claimGroup) { claim.setPatient(new Reference("#patient")); claim.setRequest(new Reference(String.format("Claim/m-%s", claimGroup.getIdrClmHdIcn()))); - claim.setMeta(new Meta().setLastUpdated(Date.from(claimGroup.getLastUpdated()))); + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel(claim.getType(), claim.getIdPart()); + + // Create a list of Coding objects to match the required type + List 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; diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/McsClaimTransformerV2.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/McsClaimTransformerV2.java index 3a42d2cef3..52f7749230 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/McsClaimTransformerV2.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/r4/providers/pac/McsClaimTransformerV2.java @@ -8,6 +8,7 @@ import gov.cms.bfd.model.rda.entities.RdaMcsDiagnosisCode; import gov.cms.bfd.server.war.commons.BBCodingSystems; 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.r4.providers.pac.common.AbstractTransformerV2; import gov.cms.bfd.server.war.r4.providers.pac.common.McsTransformerV2; @@ -36,6 +37,7 @@ import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.codesystems.ClaimType; 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. */ @@ -44,6 +46,9 @@ public class McsClaimTransformerV2 extends AbstractTransformerV2 implements ResourceTransformer { + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** The metric name. */ private static final String METRIC_NAME = MetricRegistry.name(McsClaimResponseTransformerV2.class.getSimpleName(), "transform"); @@ -129,7 +134,26 @@ private Claim transformClaim(RdaMcsClaim claimGroup, boolean includeTaxNumbers) claim.setItem(getItems(claimGroup)); claim.setCreated(new Date()); - claim.setMeta(new Meta().setLastUpdated(Date.from(claimGroup.getLastUpdated()))); + + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + claim.getType(), claim.getIdElement().getIdPart()); + + // Create a list of Coding objects to match the required type + List 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()))); return claim; } diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/CarrierClaimTransformer.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/CarrierClaimTransformer.java index b9ab773ff8..ae10557243 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/CarrierClaimTransformer.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/CarrierClaimTransformer.java @@ -11,8 +11,10 @@ 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.IdentifierType; +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.sharedutils.exceptions.BadCodeMonkeyException; @@ -23,6 +25,7 @@ import org.hl7.fhir.dstu3.model.ExplanationOfBenefit; import org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent; import org.hl7.fhir.dstu3.model.codesystems.ClaimCareteamrole; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms {@link CarrierClaim} instances into FHIR {@link ExplanationOfBenefit} resources. */ @@ -42,6 +45,9 @@ final class CarrierClaimTransformer implements ClaimTransformerInterface { private static final String METRIC_NAME = MetricRegistry.name(CarrierClaimTransformer.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -314,6 +320,16 @@ private ExplanationOfBenefit transformClaim(CarrierClaim claimGroup, boolean inc } TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated()); + + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), CarrierTag.class); + + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); return eob; } } diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/DMEClaimTransformer.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/DMEClaimTransformer.java index 6a73b9d83d..c2534380fe 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/DMEClaimTransformer.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/DMEClaimTransformer.java @@ -9,8 +9,11 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; import gov.cms.bfd.model.rif.entities.DMEClaim; import gov.cms.bfd.model.rif.entities.DMEClaimLine; +import gov.cms.bfd.model.rif.samhsa.CarrierTag; +import gov.cms.bfd.model.rif.samhsa.DmeTag; import gov.cms.bfd.server.war.commons.ClaimType; import gov.cms.bfd.server.war.commons.IdentifierType; +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.sharedutils.exceptions.BadCodeMonkeyException; @@ -22,6 +25,7 @@ import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.Quantity; import org.hl7.fhir.dstu3.model.codesystems.ClaimCareteamrole; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms {@link DMEClaim} instances into FHIR {@link ExplanationOfBenefit} resources. */ @@ -38,6 +42,10 @@ final class DMEClaimTransformer implements ClaimTransformerInterface { private static final String METRIC_NAME = MetricRegistry.name(DMEClaimTransformer.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired + private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -303,6 +311,16 @@ private ExplanationOfBenefit transformClaim(DMEClaim claimGroup, boolean include } } TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated()); + + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), DmeTag.class); + + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); return eob; } } diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/HHAClaimTransformer.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/HHAClaimTransformer.java index 45b16c161a..9a62fa08c5 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/HHAClaimTransformer.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/HHAClaimTransformer.java @@ -10,7 +10,10 @@ import gov.cms.bfd.model.rif.entities.HHAClaim; import gov.cms.bfd.model.rif.entities.HHAClaimLine; import gov.cms.bfd.model.rif.entities.OutpatientClaim; +import gov.cms.bfd.model.rif.samhsa.DmeTag; +import gov.cms.bfd.model.rif.samhsa.HhaTag; 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.sharedutils.exceptions.BadCodeMonkeyException; import java.util.Arrays; @@ -22,6 +25,7 @@ import org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent; import org.hl7.fhir.dstu3.model.UnsignedIntType; import org.hl7.fhir.dstu3.model.codesystems.BenefitCategory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms CCW {@link HHAClaim} instances into FHIR {@link ExplanationOfBenefit} resources. */ @@ -37,6 +41,10 @@ final class HHAClaimTransformer implements ClaimTransformerInterface { private static final String METRIC_NAME = MetricRegistry.name(HHAClaimTransformer.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired + private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -197,6 +205,16 @@ private ExplanationOfBenefit transformClaim(HHAClaim claimGroup) { } TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated()); + + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), HhaTag.class); + + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); return eob; } } diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/HospiceClaimTransformer.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/HospiceClaimTransformer.java index 529ea9e2ed..a21b9becb5 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/HospiceClaimTransformer.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/HospiceClaimTransformer.java @@ -9,7 +9,10 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; import gov.cms.bfd.model.rif.entities.HospiceClaim; import gov.cms.bfd.model.rif.entities.HospiceClaimLine; +import gov.cms.bfd.model.rif.samhsa.HhaTag; +import gov.cms.bfd.model.rif.samhsa.HospiceTag; 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.sharedutils.exceptions.BadCodeMonkeyException; import java.util.Arrays; @@ -18,6 +21,7 @@ import org.hl7.fhir.dstu3.model.Address; import org.hl7.fhir.dstu3.model.ExplanationOfBenefit; import org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -35,6 +39,10 @@ final class HospiceClaimTransformer implements ClaimTransformerInterface { private static final String METRIC_NAME = MetricRegistry.name(HospiceClaimTransformer.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired + private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -197,6 +205,16 @@ private ExplanationOfBenefit transformClaim(HospiceClaim claimGroup) { eob, item, claimLine.getDeductibleCoinsuranceCd()); } TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated()); + + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), HospiceTag.class); + + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); return eob; } } diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/InpatientClaimTransformer.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/InpatientClaimTransformer.java index 9a64b9a99f..f082319117 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/InpatientClaimTransformer.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/InpatientClaimTransformer.java @@ -9,7 +9,10 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; import gov.cms.bfd.model.rif.entities.InpatientClaim; import gov.cms.bfd.model.rif.entities.InpatientClaimLine; +import gov.cms.bfd.model.rif.samhsa.HospiceTag; +import gov.cms.bfd.model.rif.samhsa.InpatientTag; 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.sharedutils.exceptions.BadCodeMonkeyException; import java.util.Collections; @@ -17,6 +20,7 @@ import org.hl7.fhir.dstu3.model.Address; import org.hl7.fhir.dstu3.model.ExplanationOfBenefit; import org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -34,6 +38,10 @@ final class InpatientClaimTransformer implements ClaimTransformerInterface { private static final String METRIC_NAME = MetricRegistry.name(InpatientClaimTransformer.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired + private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -277,6 +285,16 @@ private ExplanationOfBenefit transformClaim(InpatientClaim claimGroup) { eob, item, claimLine.getDeductibleCoinsuranceCd()); } TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated()); + + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), InpatientTag.class); + + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); return eob; } } diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/OutpatientClaimTransformer.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/OutpatientClaimTransformer.java index e1b87c354c..8946565d89 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/OutpatientClaimTransformer.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/OutpatientClaimTransformer.java @@ -10,7 +10,10 @@ import gov.cms.bfd.model.rif.entities.InpatientClaim; import gov.cms.bfd.model.rif.entities.OutpatientClaim; import gov.cms.bfd.model.rif.entities.OutpatientClaimLine; +import gov.cms.bfd.model.rif.samhsa.InpatientTag; +import gov.cms.bfd.model.rif.samhsa.OutpatientTag; 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.sharedutils.exceptions.BadCodeMonkeyException; import java.util.Arrays; @@ -19,6 +22,7 @@ import org.hl7.fhir.dstu3.model.Address; import org.hl7.fhir.dstu3.model.ExplanationOfBenefit; import org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -38,6 +42,10 @@ final class OutpatientClaimTransformer implements ClaimTransformerInterface { private static final String METRIC_NAME = MetricRegistry.name(OutpatientClaimTransformer.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired + private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -316,6 +324,16 @@ private ExplanationOfBenefit transformClaim(OutpatientClaim claimGroup) { } } TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated()); + + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), OutpatientTag.class); + + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); return eob; } } diff --git a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/SNFClaimTransformer.java b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/SNFClaimTransformer.java index 58cd9e2011..e7efc2f67f 100644 --- a/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/SNFClaimTransformer.java +++ b/apps/bfd-server/bfd-server-war/src/main/java/gov/cms/bfd/server/war/stu3/providers/SNFClaimTransformer.java @@ -10,8 +10,11 @@ import gov.cms.bfd.model.codebook.data.CcwCodebookVariable; import gov.cms.bfd.model.rif.entities.SNFClaim; import gov.cms.bfd.model.rif.entities.SNFClaimLine; +import gov.cms.bfd.model.rif.samhsa.OutpatientTag; +import gov.cms.bfd.model.rif.samhsa.SnfTag; import gov.cms.bfd.server.war.commons.ClaimType; import gov.cms.bfd.server.war.commons.CommonTransformerUtils; +import gov.cms.bfd.server.war.commons.LookUpSamhsaSecurityTags; import gov.cms.bfd.server.war.commons.MedicareSegment; import gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException; import java.math.BigDecimal; @@ -23,6 +26,7 @@ import org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent; import org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent; import org.hl7.fhir.dstu3.model.Period; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** Transforms CCW {@link SNFClaim} instances into FHIR {@link ExplanationOfBenefit} resources. */ @@ -39,6 +43,10 @@ public class SNFClaimTransformer implements ClaimTransformerInterface { private static final String METRIC_NAME = MetricRegistry.name(SNFClaimTransformer.class.getSimpleName(), "transform"); + /** Injecting lookUpSamhsaSecurityTags. */ + @Autowired + private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + /** * Instantiates a new transformer. * @@ -239,6 +247,16 @@ private ExplanationOfBenefit transformClaim(SNFClaim claimGroup) { eob, item, claimLine.getDeductibleCoinsuranceCd()); } TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated()); + + String securityTag = + lookUpSamhsaSecurityTags.getClaimSecurityLevel( + String.valueOf(claimGroup.getClaimId()), SnfTag.class); + + eob.getMeta() + .addSecurity() + .setSystem("https://terminology.hl7.org/6.1.0/CodeSystem-v3-Confidentiality.html") + .setCode(securityTag) + .setDisplay(securityTag); return eob; } } diff --git a/apps/bfd-server/bfd-server-war/src/test/java/gov/cms/bfd/server/war/stu3/providers/LookUpSamhsaSecurityTagsTest.java b/apps/bfd-server/bfd-server-war/src/test/java/gov/cms/bfd/server/war/stu3/providers/LookUpSamhsaSecurityTagsTest.java new file mode 100644 index 0000000000..9db3b8f17d --- /dev/null +++ b/apps/bfd-server/bfd-server-war/src/test/java/gov/cms/bfd/server/war/stu3/providers/LookUpSamhsaSecurityTagsTest.java @@ -0,0 +1,64 @@ +package gov.cms.bfd.server.war.stu3.providers; + +import gov.cms.bfd.server.war.commons.LookUpSamhsaSecurityTags; +import jakarta.persistence.EntityManager; +import jakarta.persistence.Query; +import org.hl7.fhir.r4.model.CodeableConcept; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; + +class LookUpSamhsaSecurityTagsTest { + + @Mock + private EntityManager entityManager; + + @Mock + private Query query; + + @InjectMocks + private LookUpSamhsaSecurityTags lookUpSamhsaSecurityTags; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); // Initialize mocks + } + + @Test + void testGetClaimSecurityLevel_Inpatient() { + CodeableConcept type = new CodeableConcept(); + type.addCoding().setCode("INP"); + + Set mockTags = new HashSet<>(); + mockTags.add("R"); + when(entityManager.createQuery(anyString())).thenReturn(query); + when(query.getResultList()).thenReturn(new java.util.ArrayList<>(mockTags)); + + String securityLevel = lookUpSamhsaSecurityTags.getClaimSecurityLevel(type, "12345"); + assertEquals("Restricted", securityLevel, "Security level should be 'Restricted' for Inpatient claim with 'R' tag"); + } + + @Test + void testGetClaimSecurityLevel_Outpatient() { + CodeableConcept type = new CodeableConcept(); + type.addCoding().setCode("OUT"); + + Set mockTags = new HashSet<>(); + mockTags.add("NormalTag"); + when(entityManager.createQuery(anyString())).thenReturn(query); + when(query.getResultList()).thenReturn(new java.util.ArrayList<>(mockTags)); + + String securityLevel = lookUpSamhsaSecurityTags.getClaimSecurityLevel(type, "67890"); + assertEquals("Normal", securityLevel, "Security level should be 'Normal' for Outpatient claim with 'NormalTag'"); + } + +} +