use of org.hl7.fhir.instance.model.api.IAnyResource in project cqf-ruler by DBCG.
the class ReportProvider method patientReport.
private Parameters.ParametersParameterComponent patientReport(Patient thePatient, Period thePeriod, String serverBase) {
String patientId = thePatient.getIdElement().getIdPart();
final Map<IIdType, IAnyResource> bundleEntries = new HashMap<>();
bundleEntries.put(thePatient.getIdElement(), thePatient);
ReferenceParam subjectParam = new ReferenceParam(patientId);
search(MeasureReport.class, Searches.byParam("subject", subjectParam)).getAllResourcesTyped().forEach(measureReport -> {
if (measureReport.getPeriod().getEnd().before(thePeriod.getStart()) || measureReport.getPeriod().getStart().after(thePeriod.getEnd())) {
return;
}
bundleEntries.putIfAbsent(measureReport.getIdElement(), measureReport);
getEvaluatedResources(measureReport).values().forEach(resource -> bundleEntries.putIfAbsent(resource.getIdElement(), resource));
});
Bundle patientReportBundle = new Bundle();
patientReportBundle.setMeta(new Meta().addProfile(PATIENT_REPORT_PROFILE_URL));
patientReportBundle.setType(Bundle.BundleType.COLLECTION);
patientReportBundle.setTimestamp(new Date());
patientReportBundle.setId(patientId + "-report");
patientReportBundle.setIdentifier(new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID().toString()));
bundleEntries.entrySet().forEach(resource -> patientReportBundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource.getValue()).setFullUrl(Operations.getFullUrl(serverBase, resource.getValue().fhirType(), resource.getValue().getIdElement().getIdPart()))));
Parameters.ParametersParameterComponent patientParameter = new Parameters.ParametersParameterComponent();
patientParameter.setResource(patientReportBundle);
patientParameter.setId(thePatient.getIdElement().getIdPart() + "-report");
patientParameter.setName("return");
return patientParameter;
}
use of org.hl7.fhir.instance.model.api.IAnyResource 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.IAnyResource in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method createAdjudicationWithReason.
/**
* @param rootResource the root FHIR {@link IAnyResource} that the resultant {@link
* AdjudicationComponent} will be contained in
* @param ccwVariable the {@link CcwCodebookInterface} being coded
* @param reasonCode the value to use for the {@link AdjudicationComponent#getReason()}'s {@link
* Coding#getCode()} for the resulting {@link Coding}
* @return the output {@link AdjudicationComponent} for the specified input values
*/
static AdjudicationComponent createAdjudicationWithReason(IAnyResource rootResource, CcwCodebookInterface ccwVariable, Object reasonCode) {
// Cheating here, since they use the same URL.
String categoryConceptCode = CCWUtils.calculateVariableReferenceUrl(ccwVariable);
CodeableConcept category = createCodeableConcept(TransformerConstants.CODING_CCW_ADJUDICATION_CATEGORY, categoryConceptCode);
category.getCodingFirstRep().setDisplay(ccwVariable.getVariable().getLabel());
AdjudicationComponent adjudication = new AdjudicationComponent(category);
adjudication.setReason(createCodeableConcept(rootResource, ccwVariable, reasonCode));
return adjudication;
}
use of org.hl7.fhir.instance.model.api.IAnyResource in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method createCodeableConceptForFieldId.
/**
* Unlike {@link #createCodeableConcept(IAnyResource, CcwCodebookVariable, Optional)}, this method
* creates a {@link CodeableConcept} that's intended for use as a field ID/discriminator: the
* {@link Variable#getId()} will be used for the {@link Coding#getCode()}, rather than the {@link
* Coding#getSystem()}.
*
* @param rootResource the root FHIR {@link IAnyResource} that the resultant {@link
* CodeableConcept} will be contained in
* @param codingSystem the {@link Coding#getSystem()} to use
* @param ccwVariable the {@link CcwCodebookInterface} being coded
* @return the output {@link CodeableConcept} for the specified input values
*/
private static CodeableConcept createCodeableConceptForFieldId(IAnyResource rootResource, String codingSystem, CcwCodebookInterface ccwVariable) {
String code = CCWUtils.calculateVariableReferenceUrl(ccwVariable);
Coding coding = new Coding(codingSystem, code, ccwVariable.getVariable().getLabel());
return new CodeableConcept().addCoding(coding);
}
use of org.hl7.fhir.instance.model.api.IAnyResource in project beneficiary-fhir-data by CMSgov.
the class TransformerUtilsV2 method createExtensionCoding.
/**
* @param rootResource the root FHIR {@link IAnyResource} that the resultant {@link Extension}
* will be contained in
* @param ccwVariable the {@link CcwCodebookInterface} being coded
* @param code the value to use for {@link Coding#getCode()} for the resulting {@link Coding}
* @return the output {@link Extension}, with {@link Extension#getValue()} set to a new {@link
* Coding} to represent the specified input values
*/
static Extension createExtensionCoding(IAnyResource rootResource, CcwCodebookInterface ccwVariable, Optional<?> code) {
if (!code.isPresent()) {
throw new IllegalArgumentException();
}
Coding coding = createCoding(rootResource, ccwVariable, code.get());
String extensionUrl = CCWUtils.calculateVariableReferenceUrl(ccwVariable);
Extension extension = new Extension(extensionUrl, coding);
return extension;
}
Aggregations