Search in sources :

Example 21 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project beneficiary-fhir-data by CMSgov.

the class CarrierClaimTransformerTest method assertMatches.

/**
 * Verifies that the {@link ExplanationOfBenefit} "looks like" it should, if it were produced from
 * the specified {@link CarrierClaim}.
 *
 * @param claim the {@link CarrierClaim} that the {@link ExplanationOfBenefit} was generated from
 * @param eob the {@link ExplanationOfBenefit} that was generated from the specified {@link
 *     CarrierClaim}
 * @param includedTaxNumbers whether or not to include tax numbers are expected to be included in
 *     the result (see {@link
 *     ExplanationOfBenefitResourceProvider#HEADER_NAME_INCLUDE_TAX_NUMBERS}, defaults to <code>
 *     false</code>)
 * @throws FHIRException (indicates test failure)
 */
static void assertMatches(CarrierClaim claim, ExplanationOfBenefit eob, Optional<Boolean> includedTaxNumbers) throws FHIRException {
    // Test to ensure group level fields between all claim types match
    TransformerTestUtils.assertEobCommonClaimHeaderData(eob, claim.getClaimId(), claim.getBeneficiaryId(), ClaimType.CARRIER, claim.getClaimGroupId().toPlainString(), MedicareSegment.PART_B, Optional.of(claim.getDateFrom()), Optional.of(claim.getDateThrough()), Optional.of(claim.getPaymentAmount()), claim.getFinalAction());
    // Test to ensure common group fields between Carrier and DME match
    TransformerTestUtils.assertEobCommonGroupCarrierDMEEquals(eob, claim.getBeneficiaryId(), claim.getCarrierNumber(), claim.getClinicalTrialNumber(), claim.getBeneficiaryPartBDeductAmount(), claim.getPaymentDenialCode(), claim.getReferringPhysicianNpi(), claim.getProviderAssignmentIndicator(), claim.getProviderPaymentAmount(), claim.getBeneficiaryPaymentAmount(), claim.getSubmittedChargeAmount(), claim.getAllowedChargeAmount());
    assertEquals(5, eob.getDiagnosis().size());
    assertEquals(1, eob.getItem().size());
    TransformerTestUtils.assertAdjudicationTotalAmountEquals(CcwCodebookVariable.PRPAYAMT, claim.getPrimaryPayerPaidAmount(), eob);
    CarrierClaimLine claimLine1 = claim.getLines().get(0);
    ItemComponent eobItem0 = eob.getItem().get(0);
    assertEquals(claimLine1.getLineNumber(), new BigDecimal(eobItem0.getSequence()));
    TransformerTestUtils.assertCareTeamEquals(claimLine1.getPerformingPhysicianNpi().get(), ClaimCareteamrole.PRIMARY, eob);
    CareTeamComponent performingCareTeamEntry = TransformerTestUtils.findCareTeamEntryForProviderNpi(claimLine1.getPerformingPhysicianNpi().get(), eob.getCareTeam());
    TransformerTestUtils.assertHasCoding(CcwCodebookVariable.PRVDR_SPCLTY, claimLine1.getProviderSpecialityCode(), performingCareTeamEntry.getQualification());
    TransformerTestUtils.assertExtensionCodingEquals(CcwCodebookVariable.CARR_LINE_PRVDR_TYPE_CD, claimLine1.getProviderTypeCode(), performingCareTeamEntry);
    TransformerTestUtils.assertExtensionCodingEquals(CcwCodebookVariable.PRTCPTNG_IND_CD, claimLine1.getProviderParticipatingIndCode(), performingCareTeamEntry);
    TransformerTestUtils.assertExtensionCodingEquals(performingCareTeamEntry, TransformerConstants.CODING_NPI_US, TransformerConstants.CODING_NPI_US, "" + claimLine1.getOrganizationNpi().get());
    CareTeamComponent taxNumberCareTeamEntry = TransformerTestUtils.findCareTeamEntryForProviderTaxNumber(claimLine1.getProviderTaxNumber(), eob.getCareTeam());
    if (includedTaxNumbers.orElse(false)) {
        assertNotNull(taxNumberCareTeamEntry);
    } else {
        assertNull(taxNumberCareTeamEntry);
    }
    TransformerTestUtils.assertExtensionCodingEquals(CcwCodebookVariable.PRVDR_STATE_CD, claimLine1.getProviderStateCode(), eobItem0.getLocation());
    TransformerTestUtils.assertExtensionCodingEquals(CcwCodebookVariable.PRVDR_STATE_CD, claimLine1.getProviderStateCode(), eobItem0.getLocation());
    TransformerTestUtils.assertExtensionCodingEquals(CcwCodebookVariable.CARR_LINE_PRCNG_LCLTY_CD, claimLine1.getLinePricingLocalityCode(), eobItem0.getLocation());
    TransformerTestUtils.assertHasCoding(TransformerConstants.CODING_SYSTEM_HCPCS, "" + claim.getHcpcsYearCode().get(), null, claimLine1.getHcpcsCode().get(), eobItem0.getService().getCoding());
    assertEquals(1, eobItem0.getModifier().size());
    TransformerTestUtils.assertHcpcsCodes(eobItem0, claimLine1.getHcpcsCode(), claimLine1.getHcpcsInitialModifierCode(), claimLine1.getHcpcsSecondModifierCode(), claim.getHcpcsYearCode(), 0);
    if (claimLine1.getAnesthesiaUnitCount().compareTo(BigDecimal.ZERO) > 0) {
        TransformerTestUtils.assertExtensionQuantityEquals(CcwCodebookVariable.CARR_LINE_ANSTHSA_UNIT_CNT, claimLine1.getAnesthesiaUnitCount(), eobItem0.getService());
    }
    TransformerTestUtils.assertExtensionCodingEquals(CcwCodebookVariable.CARR_LINE_MTUS_CD, claimLine1.getMtusCode(), eobItem0);
    TransformerTestUtils.assertExtensionQuantityEquals(CcwCodebookVariable.CARR_LINE_MTUS_CNT, claimLine1.getMtusCount(), eobItem0);
    TransformerTestUtils.assertAdjudicationReasonEquals(CcwCodebookVariable.CARR_LINE_RDCD_PMT_PHYS_ASTN_C, claimLine1.getReducedPaymentPhysicianAsstCode(), eobItem0.getAdjudication());
    TransformerTestUtils.assertExtensionIdentifierEquals(CcwCodebookVariable.CARR_LINE_CLIA_LAB_NUM, claimLine1.getCliaLabNumber(), eobItem0.getLocation());
    // verify {@link
    // TransformerUtils#mapEobType(CodeableConcept,ClaimType,Optional,Optional)}
    // method worked as expected for this claim type
    TransformerTestUtils.assertMapEobType(eob.getType(), ClaimType.CARRIER, Optional.of(org.hl7.fhir.dstu3.model.codesystems.ClaimType.PROFESSIONAL), Optional.of(claim.getNearLineRecordIdCode()), Optional.of(claim.getClaimTypeCode()));
    // Test to ensure common item fields between Carrier and DME match
    TransformerTestUtils.assertEobCommonItemCarrierDMEEquals(eobItem0, eob, claimLine1.getServiceCount(), claimLine1.getPlaceOfServiceCode(), claimLine1.getFirstExpenseDate(), claimLine1.getLastExpenseDate(), claimLine1.getBeneficiaryPaymentAmount(), claimLine1.getProviderPaymentAmount(), claimLine1.getBeneficiaryPartBDeductAmount(), claimLine1.getPrimaryPayerCode(), claimLine1.getPrimaryPayerPaidAmount(), claimLine1.getBetosCode(), claimLine1.getPaymentAmount(), claimLine1.getPaymentCode(), claimLine1.getCoinsuranceAmount(), claimLine1.getSubmittedChargeAmount(), claimLine1.getAllowedChargeAmount(), claimLine1.getProcessingIndicatorCode(), claimLine1.getServiceDeductibleCode(), claimLine1.getDiagnosisCode(), claimLine1.getDiagnosisCodeVersion(), claimLine1.getHctHgbTestTypeCode(), claimLine1.getHctHgbTestResult(), claimLine1.getCmsServiceTypeCode(), claimLine1.getNationalDrugCode());
    // Test lastUpdated
    TransformerTestUtils.assertLastUpdatedEquals(claim.getLastUpdated(), eob);
}
Also used : CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) BigDecimal(java.math.BigDecimal)

Example 22 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProviderIT method assertExistingPatientIncludeIdentifiersExpected.

/**
 * Asserts that {@link
 * gov.cms.bfd.server.war.r4.providers.R4PatientResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
 * contains expected/present identifiers for a {@link Patient}.
 *
 * @param includeIdentifiersValue header value
 * @param expectingMbi true if expecting a MBI
 * @param includeAddressValues header value
 */
public void assertExistingPatientIncludeIdentifiersExpected(boolean expectingMbi, RequestHeaders requestHeader) {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    Patient expected = BeneficiaryTransformerV2.transform(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), beneficiary, requestHeader);
    IGenericClient fhirClient = createFhirClient(requestHeader);
    Patient patient = fhirClient.read().resource(Patient.class).withId(beneficiary.getBeneficiaryId()).execute();
    // Because of how transform doesn't go through R4PatientResourceProvider, `expected` won't have
    // the historical MBI data.
    // Also, SAMPLE_A does not have mbi history (it used to); however, what used to be denoted as
    // historical
    // is not provided as the 'current' MBI identifier (no historical).
    comparePatient(expected, patient);
    /*
     * Ensure the unhashed values for MBI are present.
     */
    Boolean mbiUnhashedPresent = false;
    Iterator<Identifier> identifiers = patient.getIdentifier().iterator();
    while (identifiers.hasNext()) {
        Identifier identifier = identifiers.next();
        if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_BENE_ID)) {
            mbiUnhashedPresent = true;
        }
    }
    // Unhashed MBI should always be present in V2
    assertTrue(mbiUnhashedPresent);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Date(java.util.Date) ExtraParamsInterceptor(gov.cms.bfd.server.war.stu3.providers.ExtraParamsInterceptor) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) Identifier(org.hl7.fhir.r4.model.Identifier) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Patient(org.hl7.fhir.r4.model.Patient) Iterator(java.util.Iterator) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Bundle(org.hl7.fhir.r4.model.Bundle) Identifier(org.hl7.fhir.r4.model.Identifier) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Patient(org.hl7.fhir.r4.model.Patient) Beneficiary(gov.cms.bfd.model.rif.Beneficiary)

Example 23 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project beneficiary-fhir-data by CMSgov.

the class OutpatientClaimTransformerTest method assertMatches.

/**
 * Verifies that the {@link ExplanationOfBenefit} "looks like" it should, if it were produced from
 * the specified {@link OutpatientClaim}.
 *
 * @param claim the {@link OutpatientClaim} that the {@link ExplanationOfBenefit} was generated
 *     from
 * @param eob the {@link ExplanationOfBenefit} that was generated from the specified {@link
 *     OutpatientClaim}
 * @throws FHIRException (indicates test failure)
 */
static void assertMatches(OutpatientClaim claim, ExplanationOfBenefit eob) throws FHIRException {
    // Test to ensure group level fields between all claim types match
    TransformerTestUtils.assertEobCommonClaimHeaderData(eob, claim.getClaimId(), claim.getBeneficiaryId(), ClaimType.OUTPATIENT, claim.getClaimGroupId().toPlainString(), MedicareSegment.PART_B, Optional.of(claim.getDateFrom()), Optional.of(claim.getDateThrough()), Optional.of(claim.getPaymentAmount()), claim.getFinalAction());
    // test the common field provider number is set as expected in the EOB
    TransformerTestUtils.assertProviderNumber(eob, claim.getProviderNumber());
    TransformerTestUtils.assertAdjudicationTotalAmountEquals(CcwCodebookVariable.NCH_BENE_PTB_DDCTBL_AMT, claim.getDeductibleAmount(), eob);
    TransformerTestUtils.assertAdjudicationTotalAmountEquals(CcwCodebookVariable.NCH_PROFNL_CMPNT_CHRG_AMT, claim.getProfessionalComponentCharge(), eob);
    TransformerTestUtils.assertAdjudicationTotalAmountEquals(CcwCodebookVariable.NCH_BENE_PTB_COINSRNC_AMT, claim.getCoinsuranceAmount(), eob);
    TransformerTestUtils.assertAdjudicationTotalAmountEquals(CcwCodebookVariable.CLM_OP_PRVDR_PMT_AMT, claim.getProviderPaymentAmount(), eob);
    TransformerTestUtils.assertAdjudicationTotalAmountEquals(CcwCodebookVariable.CLM_OP_BENE_PMT_AMT, claim.getBeneficiaryPaymentAmount(), eob);
    // Test to ensure common group fields between Inpatient, Outpatient and SNF
    TransformerTestUtils.assertEobCommonGroupInpOutSNFEquals(eob, claim.getBloodDeductibleLiabilityAmount(), claim.getOperatingPhysicianNpi(), claim.getOtherPhysicianNpi(), claim.getClaimQueryCode(), claim.getMcoPaidSw());
    // Test to ensure common group fields between Inpatient, Outpatient HHA, Hospice
    // and SNF match
    TransformerTestUtils.assertEobCommonGroupInpOutHHAHospiceSNFEquals(eob, claim.getOrganizationNpi(), claim.getClaimFacilityTypeCode(), claim.getClaimFrequencyCode(), claim.getClaimNonPaymentReasonCode(), claim.getPatientDischargeStatusCode().get(), claim.getClaimServiceClassificationTypeCode(), claim.getClaimPrimaryPayerCode(), claim.getAttendingPhysicianNpi(), claim.getTotalChargeAmount(), claim.getPrimaryPayerPaidAmount(), claim.getFiscalIntermediaryNumber(), claim.getFiDocumentClaimControlNumber(), claim.getFiOriginalClaimControlNumber());
    assertTrue(countDiagnosisCodes(claim) >= eob.getDiagnosis().size(), "Expect actual diagnosis count is less than or equal to the claim count");
    if (claim.getProcedure1Code().isPresent()) {
        CCWProcedure ccwProcedure = new CCWProcedure(claim.getProcedure1Code(), claim.getProcedure1CodeVersion(), claim.getProcedure1Date());
        TransformerTestUtils.assertHasCoding(ccwProcedure.getFhirSystem().toString(), claim.getProcedure1Code().get(), eob.getProcedure().get(0).getProcedureCodeableConcept().getCoding());
        assertEquals(claim.getProcedure1Date().get().atStartOfDay(ZoneId.systemDefault()).toInstant(), eob.getProcedure().get(0).getDate().toInstant());
    }
    assertTrue(1 <= eob.getItem().size(), "Expect actual item count is above 0");
    ItemComponent eobItem0 = eob.getItem().get(0);
    OutpatientClaimLine claimLine1 = claim.getLines().get(0);
    assertEquals(new Integer(claimLine1.getLineNumber().intValue()), new Integer(eobItem0.getSequence()));
    assertEquals(claim.getProviderStateCode(), eobItem0.getLocationAddress().getState());
    // TODO re-map as described in CBBF-111
    /*
     * TransformerTestUtils.assertHasCoding(TransformerConstants.CODING_NDC,
     * claimLine1.getNationalDrugCode().get(), eobItem0.getService());
     */
    TransformerTestUtils.assertAdjudicationReasonEquals(CcwCodebookVariable.REV_CNTR_1ST_ANSI_CD, claimLine1.getRevCntr1stAnsiCd(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationReasonEquals(CcwCodebookVariable.REV_CNTR_2ND_ANSI_CD, claimLine1.getRevCntr2ndAnsiCd(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationReasonEquals(CcwCodebookVariable.REV_CNTR_3RD_ANSI_CD, claimLine1.getRevCntr3rdAnsiCd(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationReasonEquals(CcwCodebookVariable.REV_CNTR_4TH_ANSI_CD, claimLine1.getRevCntr4thAnsiCd(), eobItem0.getAdjudication());
    TransformerTestUtils.assertHcpcsCodes(eobItem0, claimLine1.getHcpcsCode(), claimLine1.getHcpcsInitialModifierCode(), claimLine1.getHcpcsSecondModifierCode(), Optional.empty(), 0);
    TransformerTestUtils.assertExtensionCodingEquals(CcwCodebookVariable.REV_CNTR_IDE_NDC_UPC_NUM, claimLine1.getNationalDrugCode(), eobItem0.getService());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_BLOOD_DDCTBL_AMT, claimLine1.getBloodDeductibleAmount(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_CASH_DDCTBL_AMT, claimLine1.getCashDeductibleAmount(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_COINSRNC_WGE_ADJSTD_C, claimLine1.getWageAdjustedCoinsuranceAmount(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_RDCD_COINSRNC_AMT, claimLine1.getReducedCoinsuranceAmount(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_1ST_MSP_PD_AMT, claimLine1.getFirstMspPaidAmount(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_1ST_MSP_PD_AMT, claimLine1.getSecondMspPaidAmount(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_PRVDR_PMT_AMT, claimLine1.getProviderPaymentAmount(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_BENE_PMT_AMT, claimLine1.getBenficiaryPaymentAmount(), eobItem0.getAdjudication());
    TransformerTestUtils.assertAdjudicationAmountEquals(CcwCodebookVariable.REV_CNTR_PTNT_RSPNSBLTY_PMT, claimLine1.getPatientResponsibilityAmount(), eobItem0.getAdjudication());
    String claimControlNumber = "0000000000";
    // Test to ensure item level fields between Inpatient, Outpatient, HHA, Hopsice
    // and SNF match
    TransformerTestUtils.assertEobCommonItemRevenueEquals(eobItem0, eob, claimLine1.getRevenueCenterCode(), claimLine1.getRateAmount(), claimLine1.getTotalChargeAmount(), claimLine1.getNonCoveredChargeAmount(), claimLine1.getUnitCount(), claimControlNumber, claimLine1.getNationalDrugCodeQuantity(), claimLine1.getNationalDrugCodeQualifierCode(), claimLine1.getRevenueCenterRenderingPhysicianNPI(), 1);
    // Test to ensure item level fields between Outpatient, HHA and Hospice match
    TransformerTestUtils.assertEobCommonItemRevenueOutHHAHospice(eobItem0, claimLine1.getRevenueCenterDate(), claimLine1.getPaymentAmount());
    // verify {@link
    // TransformerUtils#mapEobType(CodeableConcept,ClaimType,Optional,Optional)}
    // method worked as expected for this claim type
    TransformerTestUtils.assertMapEobType(eob.getType(), ClaimType.OUTPATIENT, Optional.of(org.hl7.fhir.dstu3.model.codesystems.ClaimType.PROFESSIONAL), Optional.of(claim.getNearLineRecordIdCode()), Optional.of(claim.getClaimTypeCode()));
    TransformerTestUtils.assertExtensionCodingEquals(CcwCodebookVariable.REV_CNTR_STUS_IND_CD, claimLine1.getStatusCode(), eobItem0.getRevenue());
    // Test lastUpdated
    TransformerTestUtils.assertLastUpdatedEquals(claim.getLastUpdated(), eob);
}
Also used : CCWProcedure(gov.cms.bfd.server.war.commons.CCWProcedure) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine)

Example 24 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project kindling by HL7.

the class Publisher method checkFragment.

public void checkFragment(Fragment f) {
    try {
        // System.out.println("    "+f.page+"/"+f.id);
        String xml = f.getXml();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(xml));
        Document doc = builder.parse(is);
        org.w3c.dom.Element base = doc.getDocumentElement();
        String type = base.getAttribute("fragment");
        if (!page.getDefinitions().hasPrimitiveType(type)) {
            if (f.isJson()) {
                org.hl7.fhir.r5.elementmodel.JsonParser p = new org.hl7.fhir.r5.elementmodel.JsonParser(page.getWorkerContext());
                p.setupValidation(ValidationPolicy.QUICK, null);
                p.parse(base.getTextContent(), type);
            } else {
                org.hl7.fhir.r5.elementmodel.XmlParser p = new org.hl7.fhir.r5.elementmodel.XmlParser(page.getWorkerContext());
                p.setupValidation(ValidationPolicy.QUICK, null);
                p.parse(XMLUtil.getFirstChild(base), type);
            }
        }
    } catch (Exception e) {
        page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.STRUCTURE, f.getPage(), "Fragment Error in page " + f.getPage() + (f.id != null ? "#" + f.id : "") + ": " + e.getMessage(), IssueSeverity.ERROR));
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) Document(org.w3c.dom.Document) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Element(org.w3c.dom.Element) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 25 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project kindling by HL7.

the class PageProcessor method produceStructureDefinitionExamples.

private String produceStructureDefinitionExamples(ResourceDefn resource) throws Exception {
    StringBuilder s = new StringBuilder();
    s.append("<div id=\"tabs\">\r\n");
    s.append("<ul>\r\n");
    s.append("  <li><a href=\"#tabs-1\">Base Types</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-2\">Resources</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-3\">Constraints</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-4\">Extensions</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-5\">Examples</a></li>\r\n");
    s.append("</ul>\r\n");
    s.append("<div id=\"tabs-1\">\r\n");
    // base types
    s.append("<table class=\"list\">\r\n");
    genStructureExampleCategory(s, "Abstract Types", "3");
    genStructureExample(s, definitions.getElementLink(), "element.profile", "element", "Element");
    genStructureExample(s, definitions.getBackboneLink(), "backboneelement.profile", "backboneelement", "BackBoneElement");
    genStructureExample(s, "resource.html", "resource.profile", "resource", "Resource");
    genStructureExample(s, "domainresource.html", "domainresource.profile", "domainresource", "DomainResource");
    genStructureExampleCategory(s, "Primitive Types", "3");
    List<String> names = new ArrayList<String>();
    names.addAll(definitions.getPrimitives().keySet());
    Collections.sort(names);
    for (String n : names) {
        DefinedCode dc = definitions.getPrimitives().get(n);
        genStructureExample(s, "datatypes.html#" + dc.getCode(), dc.getCode().toLowerCase() + ".profile", dc.getCode().toLowerCase(), dc.getCode());
    }
    genStructureExampleCategory(s, "Data Types", "3");
    names.clear();
    names.addAll(definitions.getTypes().keySet());
    names.addAll(definitions.getInfrastructure().keySet());
    Collections.sort(names);
    for (String n : names) {
        org.hl7.fhir.definitions.model.TypeDefn t = definitions.getTypes().get(n);
        if (t == null)
            t = definitions.getInfrastructure().get(n);
        genStructureExample(s, getLinkFor("", t.getName()), t.getName().toLowerCase() + ".profile", t.getName().toLowerCase(), t.getName());
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-2\">\r\n");
    s.append("<table class=\"list\">\r\n");
    genStructureExampleCategory(s, "Resources", "3");
    for (String n : definitions.sortedResourceNames()) {
        ResourceDefn r = definitions.getResources().get(n);
        genStructureExample(s, r.getName().toLowerCase() + ".html", r.getName().toLowerCase() + ".profile", r.getName().toLowerCase(), r.getName());
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-3\">\r\n");
    s.append("<table class=\"list\">\r\n");
    Map<String, ConstraintStructure> constraints = new HashMap<String, ConstraintStructure>();
    for (Profile pp : definitions.getPackList()) {
        for (ConstraintStructure p : pp.getProfiles()) constraints.put(p.getId(), p);
    }
    for (String rn : definitions.sortedResourceNames()) for (Profile ap : definitions.getResourceByName(rn).getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) constraints.put(p.getId(), p);
    names.clear();
    names.addAll(constraints.keySet());
    Collections.sort(names);
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        boolean started = false;
        for (String n : names) {
            ConstraintStructure p = constraints.get(n);
            if (ig == p.getUsage()) {
                if (!started) {
                    started = true;
                    genStructureExampleCategory(s, ig.getName(), "3");
                }
                String prefix = ig.isCore() ? "" : ig.getCode() + "/";
                genStructureExample(s, prefix + p.getId().toLowerCase() + ".html", prefix + p.getId().toLowerCase() + ".profile", p.getId().toLowerCase(), p.getTitle());
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-4\">\r\n");
    s.append("<table class=\"list\">\r\n");
    names.clear();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) names.add(sd.getUrl());
    Collections.sort(names);
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        boolean started = false;
        for (String n : names) {
            StructureDefinition ed = workerContext.fetchResource(StructureDefinition.class, n);
            if (ig.getCode().equals(ToolResourceUtilities.getUsage(ed))) {
                if (!started) {
                    started = true;
                    genStructureExampleCategory(s, ig.getName(), "3");
                }
                String prefix = ig.isCore() ? "" : ig.getCode() + "/";
                genStructureExample(s, prefix + "extension-" + ed.getId().toLowerCase() + ".html", prefix + "extension-" + ed.getId().toLowerCase(), ed.getId().toLowerCase(), ed.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/") ? ed.getUrl().substring(40) : ed.getUrl(), ed.getName());
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-5\">\r\n");
    s.append("<table class=\"list\">\r\n");
    for (Example e : resource.getExamples()) {
        if (e.isRegistered() && Utilities.noString(e.getIg()))
            produceExampleListEntry(s, e, null, null);
    }
    for (Profile p : resource.getConformancePackages()) {
        for (Example e : p.getExamples()) {
            produceExampleListEntry(s, e, p, null);
        }
    }
    for (Profile p : definitions.getPackList()) {
        ImplementationGuideDefn ig = definitions.getIgs().get(p.getCategory());
        for (Example e : p.getExamples()) {
            String rn = e.getResourceName();
            if (Utilities.noString(rn))
                rn = e.getXml().getDocumentElement().getNodeName();
            if (rn.equals(resource.getName()))
                produceExampleListEntry(s, e, p, ig);
        }
    }
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        if (ig.getIg() != null) {
            for (ImplementationGuideDefinitionResourceComponent res : ig.getIg().getDefinition().getResource()) {
                Example e = (Example) res.getUserData(ToolResourceUtilities.NAME_RES_EXAMPLE);
                if (res.hasExample() && e != null && e.getResourceName().equals(resource.getName()))
                    produceExampleListEntry(s, res, ig);
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("</div>\r\n");
    s.append("\r\n");
    s.append("<script src=\"external/jquery/jquery.js\"> </script>\r\n");
    s.append("<script src=\"jquery-ui.min.js\"> </script>\r\n");
    s.append("<script>\r\n");
    s.append("try {\r\n");
    s.append("  var currentTabIndex = sessionStorage.getItem('fhir-sdelist-tab-index');\r\n");
    s.append("}\r\n");
    s.append("catch(exception){\r\n");
    s.append("}\r\n");
    s.append("\r\n");
    s.append("if (!currentTabIndex)\r\n");
    s.append("  currentTabIndex = '0';\r\n");
    s.append("  \r\n");
    s.append("$( '#tabs' ).tabs({\r\n");
    s.append("         active: currentTabIndex,\r\n");
    s.append("         activate: function( event, ui ) {\r\n");
    s.append("             var active = $('.selector').tabs('option', 'active');\r\n");
    s.append("             currentTabIndex = ui.newTab.index();\r\n");
    s.append("             document.activeElement.blur();\r\n");
    s.append("             try {\r\n");
    s.append("               sessionStorage.setItem('fhir-sdelist-tab-index', currentTabIndex);\r\n");
    s.append("             }\r\n");
    s.append("             catch(exception){\r\n");
    s.append("             }\r\n");
    s.append("         }\r\n");
    s.append("     });\r\n");
    s.append("</script>\r\n");
    s.append("\r\n");
    return s.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Profile(org.hl7.fhir.definitions.model.Profile) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Aggregations

Test (org.junit.jupiter.api.Test)427 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)104 ArrayList (java.util.ArrayList)101 IOException (java.io.IOException)78 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)65 List (java.util.List)64 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 FileOutputStream (java.io.FileOutputStream)59 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 File (java.io.File)57 InputStream (java.io.InputStream)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Bundle (org.hl7.fhir.dstu3.model.Bundle)48 MethodSource (org.junit.jupiter.params.provider.MethodSource)46 Arrays (java.util.Arrays)45 Collectors (java.util.stream.Collectors)45