use of org.hl7.fhir.r4b.model.Meta in project bunsen by cerner.
the class SparkRowConverterTest method testMetaElement.
@Test
public void testMetaElement() {
String id = testPatient.getId();
Meta meta = testPatient.getMeta();
Assert.assertEquals(id, testPatientDecoded.getId());
Assert.assertEquals(meta.getTag().size(), testPatientDecoded.getMeta().getTag().size());
Assert.assertEquals(meta.getTag().get(0).getCode(), testPatientDecoded.getMeta().getTag().get(0).getCode());
Assert.assertEquals(meta.getTag().get(0).getSystem(), testPatientDecoded.getMeta().getTag().get(0).getSystem());
}
use of org.hl7.fhir.r4b.model.Meta 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.r4b.model.Meta in project dpc-app by CMSgov.
the class MockBlueButtonClient method requestNextBundleFromServer.
@Override
// Date class is used by FHIR stu3 Meta model
@SuppressWarnings("JdkObsolete")
public Bundle requestNextBundleFromServer(Bundle bundle, Map<String, String> headers) throws ResourceNotFoundException {
// This is code is very specific to the bb-test-data directory and its contents
final var nextLink = bundle.getLink(Bundle.LINK_NEXT).getUrl();
final var nextUrl = URI.create(nextLink);
final var params = URLEncodedUtils.parse(nextUrl.getQuery(), StandardCharsets.UTF_8);
final var patient = params.stream().filter(pair -> pair.getName().equals("patient")).findFirst().orElseThrow().getValue();
final var startIndex = params.stream().filter(pair -> pair.getName().equals("startIndex")).findFirst().orElseThrow().getValue();
var path = SAMPLE_EOB_PATH_PREFIX + patient + "_" + startIndex + ".xml";
try (InputStream sampleData = MockBlueButtonClient.class.getClassLoader().getResourceAsStream(path)) {
final var nextBundle = parser.parseResource(Bundle.class, sampleData);
nextBundle.getMeta().setLastUpdated(Date.from(BFD_TRANSACTION_TIME.toInstant()));
return nextBundle;
} catch (IOException ex) {
throw new ResourceNotFoundException("Missing next bundle");
}
}
use of org.hl7.fhir.r4b.model.Meta in project dpc-app by CMSgov.
the class OrganizationEntityConverter method fromFHIR.
@Override
public OrganizationEntity fromFHIR(FHIREntityConverter converter, Organization resource) {
final OrganizationEntity entity = new OrganizationEntity();
// Add the profile metadata
final Meta meta = new Meta();
meta.addProfile(OrganizationProfile.PROFILE_URI);
// If we have an ID, and it parses, use it
final String idString = resource.getId();
UUID orgID;
if (idString == null) {
orgID = UUID.randomUUID();
} else {
// If we have an ID, we need to strip off the ID header, since we already know the resource type
orgID = FHIRExtractors.getEntityUUID(idString);
}
entity.setId(orgID);
// Find the first Organization ID that we can use
final Optional<Identifier> identifier = resource.getIdentifier().stream().filter(resourceID -> {
final String system = resourceID.getSystem();
try {
final DPCIdentifierSystem idSys = DPCIdentifierSystem.fromString(system);
// MBI does not work, so filter it out
return idSys != DPCIdentifierSystem.MBI;
} catch (Exception e) {
return false;
}
}).findFirst();
if (identifier.isEmpty()) {
throw new DataFormatException("Identifier must be NPPES or PECOS");
}
entity.setOrganizationID(new OrganizationEntity.OrganizationID(DPCIdentifierSystem.fromString(identifier.get().getSystem()), identifier.get().getValue()));
entity.setOrganizationName(resource.getName());
entity.setOrganizationAddress(converter.fromFHIR(AddressEntity.class, resource.getAddressFirstRep()));
// Add all contact info
final List<ContactEntity> contactEntities = resource.getContact().stream().map(r -> converter.fromFHIR(ContactEntity.class, r)).collect(Collectors.toList());
// Add the entity reference
contactEntities.forEach(contact -> contact.setOrganization(entity));
entity.setContacts(contactEntities);
return entity;
}
use of org.hl7.fhir.r4b.model.Meta in project dpc-app by CMSgov.
the class PractitionerValidationTest method generateFakePractitioner.
private Practitioner generateFakePractitioner() {
final Practitioner practitioner = new Practitioner();
final Meta meta = new Meta();
meta.addProfile(PractitionerProfile.PROFILE_URI);
practitioner.setMeta(meta);
practitioner.setId("test-practitioner");
return practitioner;
}
Aggregations