use of org.hl7.fhir.instance.model.api.IBaseExtension 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);
}
use of org.hl7.fhir.instance.model.api.IBaseExtension 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);
}
use of org.hl7.fhir.instance.model.api.IBaseExtension 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));
}
use of org.hl7.fhir.instance.model.api.IBaseExtension 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);
}
use of org.hl7.fhir.instance.model.api.IBaseExtension 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());
}
Aggregations