Search in sources :

Example 1 with IBaseHasExtensions

use of org.hl7.fhir.instance.model.api.IBaseHasExtensions in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addExtensionValueQuantity.

/**
 * Adds an {@link Extension} to the specified {@link DomainResource}. {@link Extension#getValue()}
 * will be set to a {@link Quantity} with the specified system and value.
 *
 * @param fhirElement the FHIR element to add the {@link Extension} to
 * @param extensionUrl the {@link Extension#getUrl()} to use
 * @param quantitySystem the {@link Quantity#getSystem()} to use
 * @param quantityValue the {@link Quantity#getValue()} to use
 */
static void addExtensionValueQuantity(IBaseHasExtensions fhirElement, String extensionUrl, String quantitySystem, BigDecimal quantityValue) {
    IBaseExtension<?, ?> extension = fhirElement.addExtension();
    extension.setUrl(extensionUrl);
    extension.setValue(new Quantity().setSystem(extensionUrl).setValue(quantityValue));
// CodeableConcept codeableConcept = new CodeableConcept();
// extension.setValue(codeableConcept);
// 
// Coding coding = codeableConcept.addCoding();
// coding.setSystem(codingSystem).setCode(codingCode);
}
Also used : SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) Quantity(org.hl7.fhir.dstu3.model.Quantity)

Example 2 with IBaseHasExtensions

use of org.hl7.fhir.instance.model.api.IBaseHasExtensions in project bunsen by cerner.

the class HapiCompositeConverter method fromHapi.

@Override
public Object fromHapi(Object input) {
    IBase composite = (IBase) input;
    Object[] values = new Object[children.size()];
    int valueIndex = 0;
    Iterator<StructureField<HapiConverter<T>>> schemaIterator = children.iterator();
    if (composite instanceof IAnyResource) {
        // Id element
        StructureField<HapiConverter<T>> schemaEntry = schemaIterator.next();
        values[0] = schemaEntry.result().fromHapi(((IAnyResource) composite).getIdElement());
        valueIndex++;
        // Meta element
        schemaEntry = schemaIterator.next();
        values[valueIndex] = schemaEntry.result().fromHapi(((IAnyResource) composite).getMeta());
        valueIndex++;
    }
    Map<String, List> properties = fhirSupport.compositeValues(composite);
    // Co-iterate with an index so we place the correct values into the corresponding locations.
    for (; valueIndex < children.size(); ++valueIndex) {
        StructureField<HapiConverter<T>> schemaEntry = schemaIterator.next();
        String propertyName = schemaEntry.propertyName();
        // Append the [x] suffix for choice properties.
        if (schemaEntry.isChoice()) {
            propertyName = propertyName + "[x]";
        }
        HapiConverter<T> converter = schemaEntry.result();
        List propertyValues = properties.get(propertyName);
        if (propertyValues != null && !propertyValues.isEmpty()) {
            if (isMultiValued(converter.getDataType())) {
                values[valueIndex] = schemaEntry.result().fromHapi(propertyValues);
            } else {
                values[valueIndex] = schemaEntry.result().fromHapi(propertyValues.get(0));
            }
        } else if (converter.extensionUrl() != null) {
            // No corresponding property for the name, so see if it is an Extension or ModifierExtention
            List<? extends IBaseExtension> extensions = schemaEntry.isModifier() ? ((IBaseHasModifierExtensions) composite).getModifierExtension() : ((IBaseHasExtensions) composite).getExtension();
            for (IBaseExtension extension : extensions) {
                if (extension.getUrl().equals(converter.extensionUrl())) {
                    values[valueIndex] = schemaEntry.result().fromHapi(extension);
                }
            }
        } else if (converter instanceof MultiValueConverter && ((MultiValueConverter) converter).getElementConverter().extensionUrl() != null) {
            final String extensionUrl = ((MultiValueConverter) converter).getElementConverter().extensionUrl();
            List<? extends IBaseExtension> extensions = schemaEntry.isModifier() ? ((IBaseHasModifierExtensions) composite).getModifierExtension() : ((IBaseHasExtensions) composite).getExtension();
            final List<? extends IBaseExtension> extensionList = extensions.stream().filter(extension -> extension.getUrl().equals(extensionUrl)).collect(Collectors.toList());
            if (extensionList.size() > 0) {
                values[valueIndex] = schemaEntry.result().fromHapi(extensionList);
            }
        }
    }
    return createComposite(values);
}
Also used : IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) IBaseHasModifierExtensions(org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions) Iterator(java.util.Iterator) BaseRuntimeElementDefinition(ca.uhn.fhir.context.BaseRuntimeElementDefinition) IBase(org.hl7.fhir.instance.model.api.IBase) RuntimeElemContainedResourceList(ca.uhn.fhir.context.RuntimeElemContainedResourceList) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) Collectors(java.util.stream.Collectors) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) List(java.util.List) BaseRuntimeChildDefinition(ca.uhn.fhir.context.BaseRuntimeChildDefinition) Map(java.util.Map) BaseRuntimeElementCompositeDefinition(ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition) IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) IBaseHasModifierExtensions(org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions) RuntimeElemContainedResourceList(ca.uhn.fhir.context.RuntimeElemContainedResourceList) List(java.util.List) IBase(org.hl7.fhir.instance.model.api.IBase) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension)

Example 3 with IBaseHasExtensions

use of org.hl7.fhir.instance.model.api.IBaseHasExtensions in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addExtensionCoding.

/**
 * Adds an {@link Extension} to the specified {@link DomainResource}. {@link Extension#getValue()}
 * will be set to a {@link CodeableConcept} containing a single {@link Coding}, with the specified
 * system and code.
 *
 * <p>Data Architecture Note: The {@link CodeableConcept} might seem extraneous -- why not just
 * add the {@link Coding} directly to the {@link Extension}? The main reason for doing it this way
 * is consistency: this is what FHIR seems to do everywhere.
 *
 * @param fhirElement the FHIR element to add the {@link Extension} to
 * @param extensionUrl the {@link Extension#getUrl()} to use
 * @param codingSystem the {@link Coding#getSystem()} to use
 * @param codingDisplay the {@link Coding#getDisplay()} to use
 * @param codingCode the {@link Coding#getCode()} to use
 */
static void addExtensionCoding(IBaseHasExtensions fhirElement, String extensionUrl, String codingSystem, String codingDisplay, String codingCode) {
    IBaseExtension<?, ?> extension = fhirElement.addExtension();
    extension.setUrl(extensionUrl);
    if (codingDisplay == null)
        extension.setValue(new Coding().setSystem(codingSystem).setCode(codingCode));
    else
        extension.setValue(new Coding().setSystem(codingSystem).setCode(codingCode).setDisplay(codingDisplay));
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding)

Example 4 with IBaseHasExtensions

use of org.hl7.fhir.instance.model.api.IBaseHasExtensions in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addExtensionValueIdentifier.

/**
 * Adds an {@link Extension} to the specified {@link DomainResource}. {@link Extension#getValue()}
 * will be set to a {@link Identifier} with the specified url, system, and value.
 *
 * @param fhirElement the FHIR element to add the {@link Extension} to
 * @param extensionUrl the {@link Extension#getUrl()} to use
 * @param extensionSystem the {@link Identifier#getSystem()} to use
 * @param extensionValue the {@link Identifier#getValue()} to use
 */
static void addExtensionValueIdentifier(IBaseHasExtensions fhirElement, String extensionUrl, String extensionSystem, String extensionValue) {
    IBaseExtension<?, ?> extension = fhirElement.addExtension();
    extension.setUrl(extensionUrl);
    Identifier valueIdentifier = new Identifier();
    valueIdentifier.setSystem(extensionSystem).setValue(extensionValue);
    extension.setValue(valueIdentifier);
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) CurrencyIdentifier(gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer.CurrencyIdentifier)

Example 5 with IBaseHasExtensions

use of org.hl7.fhir.instance.model.api.IBaseHasExtensions in project beneficiary-fhir-data by CMSgov.

the class TransformerTestUtils method assertQuantityUnitInfoEquals.

/**
 * @param ccwVariableForQuantity the {@link CcwCodebookVariable} that was mapped to a {@link
 *     Quantity} {@link Extension}
 * @param ccwVariableForUnit the {@link CcwCodebookVariable} that was mapped to a {@link Quantity}
 *     unit
 * @param expectedUnitCode the expected {@link Quantity#getCode()} value
 * @param actualElement the FHIR element to find and verify the {@link Extension} of
 */
static void assertQuantityUnitInfoEquals(CcwCodebookInterface ccwVariableForQuantity, CcwCodebookInterface ccwVariableForUnit, Object expectedUnitCode, IBaseHasExtensions actualElement) {
    String expectedExtensionUrl = CCWUtils.calculateVariableReferenceUrl(ccwVariableForQuantity);
    Optional<? extends IBaseExtension<?, ?>> actualExtension = actualElement.getExtension().stream().filter(e -> e.getUrl().equals(expectedExtensionUrl)).findFirst();
    assertTrue(actualExtension.isPresent());
    assertTrue(actualExtension.get().getValue() instanceof Quantity);
    Quantity actualQuantity = (Quantity) actualExtension.get().getValue();
    String expectedUnitCodeString;
    if (expectedUnitCode instanceof String)
        expectedUnitCodeString = (String) expectedUnitCode;
    else if (expectedUnitCode instanceof Character)
        expectedUnitCodeString = ((Character) expectedUnitCode).toString();
    else
        throw new BadCodeMonkeyException("Unsupported: " + expectedUnitCode);
    assertEquals(expectedUnitCodeString, actualQuantity.getCode());
    assertEquals(CCWUtils.calculateVariableReferenceUrl(ccwVariableForUnit), actualQuantity.getSystem());
}
Also used : IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) Arrays(java.util.Arrays) CarrierClaimColumn(gov.cms.bfd.model.rif.CarrierClaimColumn) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Extension(org.hl7.fhir.dstu3.model.Extension) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) ClaimCareteamrole(org.hl7.fhir.dstu3.model.codesystems.ClaimCareteamrole) SNFClaimColumn(gov.cms.bfd.model.rif.SNFClaimColumn) BigDecimal(java.math.BigDecimal) FhirContext(ca.uhn.fhir.context.FhirContext) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) SNFClaimLine(gov.cms.bfd.model.rif.SNFClaimLine) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) HHAClaimColumn(gov.cms.bfd.model.rif.HHAClaimColumn) CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) Duration(java.time.Duration) BenefitBalanceComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) Method(java.lang.reflect.Method) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) Reference(org.hl7.fhir.dstu3.model.Reference) DiagnosisComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.DiagnosisComponent) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) InpatientClaimColumn(gov.cms.bfd.model.rif.InpatientClaimColumn) Instant(java.time.Instant) InvocationTargetException(java.lang.reflect.InvocationTargetException) Quantity(org.hl7.fhir.dstu3.model.Quantity) List(java.util.List) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OutpatientClaimColumn(gov.cms.bfd.model.rif.OutpatientClaimColumn) HospiceClaimLine(gov.cms.bfd.model.rif.HospiceClaimLine) HHAClaimLine(gov.cms.bfd.model.rif.HHAClaimLine) HospiceClaimColumn(gov.cms.bfd.model.rif.HospiceClaimColumn) Money(org.hl7.fhir.dstu3.model.Money) InpatientClaimLine(gov.cms.bfd.model.rif.InpatientClaimLine) ReferralRequest(org.hl7.fhir.dstu3.model.ReferralRequest) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine) BenefitComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitComponent) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Period(org.hl7.fhir.dstu3.model.Period) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DMEClaimLine(gov.cms.bfd.model.rif.DMEClaimLine) AdjudicationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.AdjudicationComponent) BenefitCategory(org.hl7.fhir.dstu3.model.codesystems.BenefitCategory) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Resource(org.hl7.fhir.dstu3.model.Resource) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) IOException(java.io.IOException) Observation(org.hl7.fhir.dstu3.model.Observation) BaseDateTimeType(org.hl7.fhir.dstu3.model.BaseDateTimeType) SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) DMEClaimColumn(gov.cms.bfd.model.rif.DMEClaimColumn) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdentifierType(gov.cms.bfd.server.war.commons.IdentifierType) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) Quantity(org.hl7.fhir.dstu3.model.Quantity)

Aggregations

List (java.util.List)2 Coding (org.hl7.fhir.dstu3.model.Coding)2 Identifier (org.hl7.fhir.dstu3.model.Identifier)2 IAnyResource (org.hl7.fhir.instance.model.api.IAnyResource)2 IBaseExtension (org.hl7.fhir.instance.model.api.IBaseExtension)2 IBaseHasExtensions (org.hl7.fhir.instance.model.api.IBaseHasExtensions)2 BaseRuntimeChildDefinition (ca.uhn.fhir.context.BaseRuntimeChildDefinition)1 BaseRuntimeElementCompositeDefinition (ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition)1 BaseRuntimeElementDefinition (ca.uhn.fhir.context.BaseRuntimeElementDefinition)1 FhirContext (ca.uhn.fhir.context.FhirContext)1 RuntimeElemContainedResourceList (ca.uhn.fhir.context.RuntimeElemContainedResourceList)1 TemporalPrecisionEnum (ca.uhn.fhir.model.api.TemporalPrecisionEnum)1 CcwCodebookVariable (gov.cms.bfd.model.codebook.data.CcwCodebookVariable)1 CcwCodebookInterface (gov.cms.bfd.model.codebook.model.CcwCodebookInterface)1 CarrierClaim (gov.cms.bfd.model.rif.CarrierClaim)1 CarrierClaimColumn (gov.cms.bfd.model.rif.CarrierClaimColumn)1 CarrierClaimLine (gov.cms.bfd.model.rif.CarrierClaimLine)1 DMEClaim (gov.cms.bfd.model.rif.DMEClaim)1 DMEClaimColumn (gov.cms.bfd.model.rif.DMEClaimColumn)1 DMEClaimLine (gov.cms.bfd.model.rif.DMEClaimLine)1