Search in sources :

Example 1 with Device

use of org.hl7.fhir.r4.model.Device in project udmi by faucetsdn.

the class ProxyTarget method parseUdmiMetadta.

private Metadata parseUdmiMetadta(String deviceId) {
    try {
        Device device = cloudIotManager.fetchDevice(deviceId);
        Map<String, String> metadata = device.getMetadata();
        if (metadata == null) {
            return new Metadata();
        }
        String udmi_metadata = metadata.get(UDMI_METADATA);
        if (udmi_metadata == null) {
            return new Metadata();
        }
        return OBJECT_MAPPER.readValue(udmi_metadata, Metadata.class);
    } catch (Exception e) {
        throw new RuntimeException("While loading device udmi metadata for " + deviceId, e);
    }
}
Also used : Device(com.google.api.services.cloudiot.v1.model.Device) Metadata(udmi.schema.Metadata)

Example 2 with Device

use of org.hl7.fhir.r4.model.Device in project udmi by faucetsdn.

the class CloudIotManager method fetchDeviceList.

public Set<String> fetchDeviceList() {
    Preconditions.checkNotNull(cloudIotService, "CloudIoT service not initialized");
    Set<Device> allDevices = new HashSet<>();
    String nextPageToken = null;
    try {
        do {
            ListDevicesResponse response = cloudIotRegistries.devices().list(getRegistryPath()).setPageToken(nextPageToken).setPageSize(LIST_PAGE_SIZE).execute();
            List<Device> devices = response.getDevices();
            allDevices.addAll(devices == null ? ImmutableList.of() : devices);
            System.err.printf("Retrieved %d devices from registry...%n", allDevices.size());
            nextPageToken = response.getNextPageToken();
        } while (nextPageToken != null);
        return allDevices.stream().map(Device::getId).collect(Collectors.toSet());
    } catch (Exception e) {
        throw new RuntimeException("While listing devices for registry " + registryId, e);
    }
}
Also used : Device(com.google.api.services.cloudiot.v1.model.Device) ListDevicesResponse(com.google.api.services.cloudiot.v1.model.ListDevicesResponse) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 3 with Device

use of org.hl7.fhir.r4.model.Device in project summary-care-record-api by NHSDigital.

the class AgentDeviceMapper method map.

@Override
public List<? extends Resource> map(Node agentDevice) {
    List<Resource> resources = new ArrayList<>();
    var role = new PractitionerRole();
    role.setId(randomUUID());
    var device = mapDevice(agentDevice);
    var org = mapOrganization(agentDevice);
    device.setOwner(new Reference(org));
    role.setOrganization(new Reference(org));
    resources.add(device);
    resources.add(org);
    resources.add(role);
    return resources;
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) Resource(org.hl7.fhir.r4.model.Resource) ArrayList(java.util.ArrayList) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole)

Example 4 with Device

use of org.hl7.fhir.r4.model.Device in project summary-care-record-api by NHSDigital.

the class AgentDeviceMapper method mapDevice.

private Device mapDevice(Node agentDevice) {
    Device device;
    Optional<Node> deviceSds = xmlUtils.detachOptionalNodeByXPath(agentDevice, AGENT_DEVICE_SDS_XPATH);
    Optional<Node> deviceHl7 = xmlUtils.detachOptionalNodeByXPath(agentDevice, AGENT_DEVICE_XPATH);
    if (deviceSds.isPresent()) {
        device = deviceSdsMapper.mapDeviceSds(deviceSds.get());
    } else if (deviceHl7.isPresent()) {
        device = deviceMapper.mapDevice(deviceHl7.get());
    } else {
        device = new Device();
        device.setId(randomUUID());
    }
    xmlUtils.getOptionalValueByXPath(agentDevice, ID_ROOT_XPATH).ifPresent(id -> device.addIdentifier().setValue(id));
    return device;
}
Also used : Device(org.hl7.fhir.r4.model.Device) Node(org.w3c.dom.Node)

Example 5 with Device

use of org.hl7.fhir.r4.model.Device in project summary-care-record-api by NHSDigital.

the class DeviceMapper method mapDevice.

public Device mapDevice(Node deviceHl7) {
    Device deviceFhir = new Device();
    deviceFhir.setId(randomUUID());
    xmlUtils.getOptionalValueByXPath(deviceHl7, ID_EXTENSION_XPATH).ifPresent(id -> deviceFhir.addIdentifier().setValue(id));
    xmlUtils.detachOptionalNodeByXPath(deviceHl7, CODE_ELEMENT_XPATH).ifPresent(code -> deviceFhir.setType(new CodeableConcept(new Coding().setCode(xmlUtils.getValueByXPath(code, CODE_ATTRIBUTE_XPATH)).setDisplay(xmlUtils.getValueByXPath(code, CODE_DISPLAY_XPATH)))));
    addName(deviceHl7, deviceFhir, NAME_XPATH, OTHER);
    addName(deviceHl7, deviceFhir, MANUFACTURER_MODE_NAME_XPATH, MANUFACTURERNAME);
    xmlUtils.detachOptionalNodeByXPath(deviceHl7, DESCRIPTION_XPATH).ifPresent(descNode -> deviceFhir.addNote(new Annotation().setText(descNode.getTextContent())));
    xmlUtils.detachOptionalNodeByXPath(deviceHl7, SOFTWARE_NAME_XPATH).ifPresent(software -> deviceFhir.addVersion(new DeviceVersionComponent().setValue(software.getTextContent())));
    return deviceFhir;
}
Also used : DeviceVersionComponent(org.hl7.fhir.r4.model.Device.DeviceVersionComponent) Coding(org.hl7.fhir.r4.model.Coding) Device(org.hl7.fhir.r4.model.Device) Annotation(org.hl7.fhir.r4.model.Annotation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

Device (com.google.api.services.cloudiot.v1.model.Device)21 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)13 JsonFactory (com.google.api.client.json.JsonFactory)13 CloudIot (com.google.api.services.cloudiot.v1.CloudIot)13 HttpCredentialsAdapter (com.google.auth.http.HttpCredentialsAdapter)13 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)13 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 Test (org.junit.jupiter.api.Test)9 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)7 Device (org.hl7.fhir.r4.model.Device)7 Practitioner (org.hl7.fhir.r4.model.Practitioner)7 Reference (org.hl7.fhir.r4.model.Reference)7 ArrayList (java.util.ArrayList)6 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)6 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)6 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 DeviceCredential (com.google.api.services.cloudiot.v1.model.DeviceCredential)5 PublicKeyCredential (com.google.api.services.cloudiot.v1.model.PublicKeyCredential)5 Coding (org.hl7.fhir.r4.model.Coding)5 Identifier (org.hl7.fhir.r4.model.Identifier)5