use of uk.nhs.adaptors.scr.models.xml.AgentDevice in project summary-care-record-api by NHSDigital.
the class ParticipantAgentMapper method setAgentDevice.
private static void setAgentDevice(Bundle bundle, Reference individual, Participant.Author1 author) {
var organizationReference = individual.getReference();
var organization = getResourceByReference(bundle, organizationReference, org.hl7.fhir.r4.model.Organization.class).orElseThrow(() -> new FhirValidationException("Bundle is missing Organization %s that is linked to PractitionerRole"));
var device = getDomainResourceList(bundle, org.hl7.fhir.r4.model.Device.class).stream().filter(dev -> organizationReference.equals(dev.getOwner().getReference())).reduce((a, b) -> {
throw new FhirValidationException(String.format("Bundle has more than 1 Device resource referencing %s", organizationReference));
});
var agentDevice = new AgentDevice();
var code = organization.getTypeFirstRep().getCodingFirstRep().getCode();
if (StringUtils.isNotBlank(code)) {
var representedOrganization = new Organization("representedOrganization");
representedOrganization.setIdRoot("1.2.826.0.1285.0.1.10");
representedOrganization.setIdExtension(organization.getIdentifierFirstRep().getValue());
representedOrganization.setCodeCode(code);
representedOrganization.setName(organization.getName());
representedOrganization.setTelecom(organization.getTelecomFirstRep().getValue());
representedOrganization.setAddress(organization.getAddressFirstRep().getText());
agentDevice.setOrganization(representedOrganization);
} else {
Identifier identifier = organization.getIdentifierFirstRep();
if (ORG_SDS_SYSTEM.equals(identifier.getSystem()) && !identifier.hasValue()) {
throw new FhirValidationException("Organization.identifier.value element is missing");
}
var representedOrganizationSDS = new OrganizationSDS("representedOrganizationSDS");
representedOrganizationSDS.setIdRoot("1.2.826.0.1285.0.1.10");
representedOrganizationSDS.setIdExtension(identifier.getValue());
agentDevice.setOrganizationSDS(representedOrganizationSDS);
}
device.ifPresent(it -> {
agentDevice.setIdRoot(it.getIdentifierFirstRep().getValue());
if (SDS_DEVICE_SYSTEM.equals(it.getIdentifierFirstRep().getSystem())) {
var agentDeviceSDS = new DeviceSDS("agentDeviceSDS");
agentDeviceSDS.setIdRoot("1.2.826.0.1285.0.2.0.107");
if (it.getIdentifierFirstRep().hasValue()) {
agentDeviceSDS.setIdExtension(it.getIdentifierFirstRep().getValue());
} else {
throw new FhirValidationException("Device.identifier.value is missing");
}
agentDevice.setDeviceSDS(agentDeviceSDS);
} else {
var agentDevice1 = new Device("agentDevice");
agentDevice1.setIdRoot("1.2.826.0.1285.0.2.0.107");
agentDevice1.setIdExtension(it.getIdentifierFirstRep().getValue());
setDeviceCoding(it, agentDevice1);
it.getDeviceName().stream().filter(deviceName -> deviceName.getType() == OTHER).findFirst().map(org.hl7.fhir.r4.model.Device.DeviceDeviceNameComponent::getName).ifPresent(agentDevice1::setName);
it.getDeviceName().stream().filter(deviceName -> deviceName.getType() == MANUFACTURERNAME).findFirst().map(org.hl7.fhir.r4.model.Device.DeviceDeviceNameComponent::getName).ifPresent(agentDevice1::setManufacturerModelName);
agentDevice1.setDescription(it.getNoteFirstRep().getText());
agentDevice1.setSoftwareName(it.getVersionFirstRep().getValue());
agentDevice.setDevice(agentDevice1);
}
});
author.setAgentDevice(agentDevice);
}
Aggregations