Search in sources :

Example 86 with Meta

use of org.hl7.fhir.r5.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());
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Test(org.junit.Test)

Example 87 with Meta

use of org.hl7.fhir.r5.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);
}
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 88 with Meta

use of org.hl7.fhir.r5.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");
    }
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date) IOException(java.io.IOException) Instant(java.time.Instant) StandardCharsets(java.nio.charset.StandardCharsets) FhirContext(ca.uhn.fhir.context.FhirContext) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) ChronoUnit(java.time.temporal.ChronoUnit) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) URLEncodedUtils(org.apache.http.client.utils.URLEncodedUtils) Map(java.util.Map) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) URI(java.net.URI) ZoneOffset(java.time.ZoneOffset) PerformanceOptionsEnum(ca.uhn.fhir.context.PerformanceOptionsEnum) IParser(ca.uhn.fhir.parser.IParser) InputStream(java.io.InputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)

Example 89 with Meta

use of org.hl7.fhir.r5.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;
}
Also used : FHIREntityConverter(gov.cms.dpc.fhir.converters.FHIREntityConverter) OrganizationProfile(gov.cms.dpc.fhir.validations.profiles.OrganizationProfile) DataFormatException(ca.uhn.fhir.parser.DataFormatException) OrganizationEntity(gov.cms.dpc.common.entities.OrganizationEntity) FHIRConverter(gov.cms.dpc.fhir.converters.FHIRConverter) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AddressEntity(gov.cms.dpc.common.entities.AddressEntity) List(java.util.List) ContactEntity(gov.cms.dpc.common.entities.ContactEntity) org.hl7.fhir.dstu3.model(org.hl7.fhir.dstu3.model) Optional(java.util.Optional) FHIRExtractors(gov.cms.dpc.fhir.FHIRExtractors) DPCIdentifierSystem(gov.cms.dpc.fhir.DPCIdentifierSystem) Collections(java.util.Collections) DPCIdentifierSystem(gov.cms.dpc.fhir.DPCIdentifierSystem) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) OrganizationEntity(gov.cms.dpc.common.entities.OrganizationEntity) ContactEntity(gov.cms.dpc.common.entities.ContactEntity) UUID(java.util.UUID) AddressEntity(gov.cms.dpc.common.entities.AddressEntity)

Example 90 with Meta

use of org.hl7.fhir.r5.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;
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) Meta(org.hl7.fhir.dstu3.model.Meta)

Aggregations

Meta (org.hl7.fhir.r4.model.Meta)40 HashMap (java.util.HashMap)36 Date (java.util.Date)35 Meta (org.hl7.fhir.dstu3.model.Meta)31 IBaseMetaType (org.hl7.fhir.instance.model.api.IBaseMetaType)28 Reference (org.hl7.fhir.r4.model.Reference)26 JsonObject (javax.json.JsonObject)24 Path (javax.ws.rs.Path)24 Produces (javax.ws.rs.Produces)24 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)20 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)18 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)17 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)17 ArrayList (java.util.ArrayList)16 Coding (org.hl7.fhir.r4.model.Coding)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)15 Test (org.junit.jupiter.api.Test)15 Test (org.junit.Test)14 NotImplementedException (org.apache.commons.lang3.NotImplementedException)13 GET (javax.ws.rs.GET)12