ExplanationOfBenefitResourceProvider implements IResourceProvider { static Set<ClaimType> parseTypeParam(TokenAndListParam type) { if (type == null) type = new TokenAndListParam() .addAnd(new TokenOrListParam().add(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE, null)); Set<ClaimType> claimTypes = new HashSet<ClaimType>(Arrays.asList(ClaimType.values())); for (TokenOrListParam typeToken : type.getValuesAsQueryTokens()) { Set<ClaimType> claimTypesInner = new HashSet<ClaimType>(); for (TokenParam codingToken : typeToken.getValuesAsQueryTokens()) { if (codingToken.getModifier() != null) throw new IllegalArgumentException(); Optional<ClaimType> claimType = codingToken.getValue() != null ? ClaimType.parse(codingToken.getValue().toLowerCase()) : Optional.empty(); if (codingToken.getSystem() != null && codingToken.getSystem().equals(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE) && !claimType.isPresent()) { claimTypesInner.addAll(Arrays.asList(ClaimType.values())); } else if (codingToken.getSystem() == null || codingToken.getSystem().equals(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE)) { if (claimType.isPresent()) claimTypesInner.add(claimType.get()); } } claimTypes.retainAll(claimTypesInner); } return claimTypes; }  @PersistenceContext void setEntityManager(EntityManager entityManager); @Inject void setMetricRegistry(MetricRegistry metricRegistry); @Inject void setSamhsaFilterer(SamhsaMatcher samhsaMatcher); @Override Class<? extends IBaseResource> getResourceType(); @SuppressWarnings({ "rawtypes", "unchecked" }) @Read(version = false) ExplanationOfBenefit read(@IdParam IdType eobId); @Search Bundle findByPatient(
			@RequiredParam(name = ExplanationOfBenefit.SP_PATIENT) ReferenceParam patient,
			@OptionalParam(name = "type") TokenAndListParam type,
			@OptionalParam(name = "startIndex") String startIndex,
			@OptionalParam(name = "excludeSAMHSA") String excludeSamhsa,
			RequestDetails requestDetails);  }
@Test public void parseTypeParam() { TokenAndListParam typeParamNull = null; Set<ClaimType> typesForNull = ExplanationOfBenefitResourceProvider.parseTypeParam(typeParamNull); Assert.assertEquals(ClaimType.values().length, typesForNull.size()); TokenAndListParam typeParamSystemWildcard = new TokenAndListParam() .addAnd(new TokenOrListParam().add(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE, null)); Set<ClaimType> typesForSystemWildcard = ExplanationOfBenefitResourceProvider .parseTypeParam(typeParamSystemWildcard); Assert.assertEquals(ClaimType.values().length, typesForSystemWildcard.size()); TokenAndListParam typeParamSingle = new TokenAndListParam().addAnd( new TokenOrListParam(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE, ClaimType.CARRIER.name())); Set<ClaimType> typesForSingle = ExplanationOfBenefitResourceProvider.parseTypeParam(typeParamSingle); Assert.assertEquals(1, typesForSingle.size()); Assert.assertTrue(typesForSingle.contains(ClaimType.CARRIER)); TokenAndListParam typeParamSingleNullSystem = new TokenAndListParam() .addAnd(new TokenOrListParam(null, ClaimType.CARRIER.name())); Set<ClaimType> typesForSingleNullSystem = ExplanationOfBenefitResourceProvider .parseTypeParam(typeParamSingleNullSystem); Assert.assertEquals(1, typesForSingleNullSystem.size()); Assert.assertTrue(typesForSingleNullSystem.contains(ClaimType.CARRIER)); TokenAndListParam typeParamSingleInvalidSystem = new TokenAndListParam() .addAnd(new TokenOrListParam("foo", ClaimType.CARRIER.name())); Set<ClaimType> typesForSingleInvalidSystem = ExplanationOfBenefitResourceProvider .parseTypeParam(typeParamSingleInvalidSystem); Assert.assertEquals(0, typesForSingleInvalidSystem.size()); TokenAndListParam typeParamSingleInvalidCode = new TokenAndListParam() .addAnd(new TokenOrListParam(null, "foo")); Set<ClaimType> typesForSingleInvalidCode = ExplanationOfBenefitResourceProvider .parseTypeParam(typeParamSingleInvalidCode); Assert.assertEquals(0, typesForSingleInvalidCode.size()); TokenAndListParam typeParamTwoEntries = new TokenAndListParam() .addAnd(new TokenOrListParam(null, ClaimType.CARRIER.name(), ClaimType.DME.name())) .addAnd(new TokenOrListParam(null, ClaimType.CARRIER.name())); Set<ClaimType> typesForTwoEntries = ExplanationOfBenefitResourceProvider.parseTypeParam(typeParamTwoEntries); Assert.assertEquals(1, typesForTwoEntries.size()); Assert.assertTrue(typesForTwoEntries.contains(ClaimType.CARRIER)); }
@Test(expected = IllegalArgumentException.class) public void parseTypeParam_modifiers() { TokenAndListParam typeParam = new TokenAndListParam().addAnd( new TokenOrListParam() .add(new TokenParam(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE, ClaimType.CARRIER.name()) .setModifier(TokenParamModifier.ABOVE))); ExplanationOfBenefitResourceProvider.parseTypeParam(typeParam); }