Search in sources :

Example 36 with PractitionerRole

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

the class DiagnosisMapper method mapInformant.

private void mapInformant(List<Resource> resources, Encounter encounter, Node informant) {
    DateTimeType time = parseDate(xmlUtils.getValueByXPath(informant, DIAGNOSIS_PARTICIPANT_TIME_XPATH), DateTimeType.class);
    participantMapper.map(informant).stream().peek(it -> resources.add(it)).filter(it -> it instanceof PractitionerRole || it instanceof RelatedPerson).forEach(it -> encounter.addParticipant(new EncounterParticipantComponent().setPeriod(new Period().setStartElement(time)).addType(getParticipationType("INF", "informant")).setIndividual(new Reference(it))));
}
Also used : SneakyThrows(lombok.SneakyThrows) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Encounter(org.hl7.fhir.r4.model.Encounter) Node(org.w3c.dom.Node) CodedEntryMapper(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntryMapper) Observation(org.hl7.fhir.r4.model.Observation) NodeList(org.w3c.dom.NodeList) Period(org.hl7.fhir.r4.model.Period) Resource(org.hl7.fhir.r4.model.Resource) FINISHED(org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Component(org.springframework.stereotype.Component) List(java.util.List) XmlToFhirMapper.parseDate(uk.nhs.adaptors.scr.mappings.from.hl7.XmlToFhirMapper.parseDate) Coding(org.hl7.fhir.r4.model.Coding) FhirHelper.randomUUID(uk.nhs.adaptors.scr.utils.FhirHelper.randomUUID) Optional(java.util.Optional) XmlUtils(uk.nhs.adaptors.scr.utils.XmlUtils) Annotation(org.hl7.fhir.r4.model.Annotation) CodedEntry(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Reference(org.hl7.fhir.r4.model.Reference) Period(org.hl7.fhir.r4.model.Period) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson)

Example 37 with PractitionerRole

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

the class FindingMapper method mapInformant.

private void mapInformant(List<Resource> resources, Encounter encounter, Node informant) {
    DateTimeType time = parseDate(xmlUtils.getValueByXPath(informant, FINDING_PARTICIPANT_TIME_XPATH), DateTimeType.class);
    participantMapper.map(informant).stream().peek(it -> resources.add(it)).filter(it -> it instanceof PractitionerRole || it instanceof RelatedPerson).map(Reference::new).forEach(it -> encounter.addParticipant(new EncounterParticipantComponent().setPeriod(new Period().setStartElement(time)).addType(getParticipationType("INF", "informant")).setIndividual(it)));
}
Also used : SneakyThrows(lombok.SneakyThrows) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Identifier(org.hl7.fhir.r4.model.Identifier) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) FINAL(org.hl7.fhir.r4.model.Observation.ObservationStatus.FINAL) Encounter(org.hl7.fhir.r4.model.Encounter) ENTEREDINERROR(org.hl7.fhir.r4.model.Observation.ObservationStatus.ENTEREDINERROR) Node(org.w3c.dom.Node) CodedEntryMapper(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntryMapper) Meta(org.hl7.fhir.r4.model.Meta) Observation(org.hl7.fhir.r4.model.Observation) NodeList(org.w3c.dom.NodeList) Period(org.hl7.fhir.r4.model.Period) Resource(org.hl7.fhir.r4.model.Resource) FINISHED(org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Component(org.springframework.stereotype.Component) List(java.util.List) XmlToFhirMapper.parseDate(uk.nhs.adaptors.scr.mappings.from.hl7.XmlToFhirMapper.parseDate) Coding(org.hl7.fhir.r4.model.Coding) PerformerParticipationMode.getParticipationModeDisplay(uk.nhs.adaptors.scr.mappings.from.hl7.PerformerParticipationMode.getParticipationModeDisplay) FhirHelper.randomUUID(uk.nhs.adaptors.scr.utils.FhirHelper.randomUUID) Optional(java.util.Optional) XmlUtils(uk.nhs.adaptors.scr.utils.XmlUtils) CodedEntry(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Period(org.hl7.fhir.r4.model.Period) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson)

Example 38 with PractitionerRole

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

the class ParticipantAgentMapper method setParticipantAgents.

public static void setParticipantAgents(Bundle bundle, Reference individual, Participant participant) {
    var practitionerRole = getResourceByReference(bundle, individual.getReference(), PractitionerRole.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is missing PractitionerRole %s that is linked to Encounter", individual.getReference())));
    LOGGER.debug("Looking up Practitioner for PractitionerRole.id={}", practitionerRole.getIdElement().getIdPart());
    if (practitionerRole.getPractitioner().isEmpty()) {
        throw new FhirValidationException(String.format("PractitionerRole %s is missing Practitioner reference", practitionerRole.getId()));
    }
    var practitioner = getResourceByReference(bundle, practitionerRole.getPractitioner().getReference(), Practitioner.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is missing Practitioner %s that is linked to PractitionerRole %s", practitionerRole.getPractitioner().getReference(), practitionerRole.getId())));
    if ("http://fhir.nhs.net/Id/sds-role-profile-id".equals(practitionerRole.getIdentifierFirstRep().getSystem())) {
        Identifier practitionerIdentifier = practitioner.getIdentifierFirstRep();
        if (!USER_SDS_SYSTEM.equals(practitionerIdentifier.getSystem())) {
            throw new FhirValidationException("Invalid practitioner identifier system: " + practitionerIdentifier.getSystem());
        }
        if (!practitionerIdentifier.hasValue()) {
            throw new FhirValidationException("Missing practitioner identifier value");
        }
        var agentPersonSDS = new AgentPersonSDS();
        agentPersonSDS.setIdExtension(practitionerRole.getIdentifierFirstRep().getValue());
        var personSDS = new PersonSDS("agentPersonSDS");
        personSDS.setIdExtension(practitionerIdentifier.getValue());
        personSDS.setName(practitioner.getNameFirstRep().getText());
        agentPersonSDS.setAgentPersonSDS(personSDS);
        participant.setAgentPersonSDS(agentPersonSDS);
    } else if ("https://fhir.nhs.uk/CodeSystem/HL7v3-SDSJobRoleName".equals(practitionerRole.getCodeFirstRep().getCodingFirstRep().getSystem())) {
        var organization = getResourceByReference(bundle, practitionerRole.getOrganization().getReference(), org.hl7.fhir.r4.model.Organization.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is missing Organization %s that is linked to PractitionerRole %s", practitionerRole.getOrganization().getReference(), practitionerRole.getId())));
        var agentPerson = new AgentPerson();
        agentPerson.setCodeCode(practitionerRole.getCodeFirstRep().getCodingFirstRep().getCode());
        agentPerson.setCodeDisplayName(practitionerRole.getCodeFirstRep().getCodingFirstRep().getDisplay());
        agentPerson.setAddress(organization.getAddressFirstRep().getText());
        agentPerson.setTelecom(organization.getTelecom().stream().map(telecom -> new AgentPerson.Telecom().setUse(AgentPerson.Telecom.mapUse(Optional.ofNullable(telecom.getUse()).orElse(ContactPoint.ContactPointUse.WORK))).setValue(telecom.getValue())).collect(Collectors.toList()));
        var person = new Person("agentPerson");
        person.setName(practitioner.getNameFirstRep().getText());
        agentPerson.setAgentPerson(person);
        Identifier identifier = organization.getIdentifierFirstRep();
        if (organization.getTypeFirstRep().getCodingFirstRep().getCode() != null) {
            var representedOrganization = new Organization("representedOrganization");
            representedOrganization.setIdRoot(identifier.getSystem());
            representedOrganization.setIdExtension(identifier.getValue());
            representedOrganization.setCodeCode(organization.getTypeFirstRep().getCodingFirstRep().getCode());
            representedOrganization.setName(organization.getName());
            agentPerson.setRepresentedOrganization(representedOrganization);
        } else if (organization.hasIdentifier()) {
            var representedOrganizationSDS = new OrganizationSDS("representedOrganizationSDS");
            if (ORG_SDS_SYSTEM.equals(identifier.getSystem())) {
                if (!identifier.hasValue()) {
                    throw new FhirValidationException("Organization.identifier.value element is missing");
                }
                representedOrganizationSDS.setIdRoot("1.2.826.0.1285.0.1.10");
            } else {
                representedOrganizationSDS.setIdRoot("1.2.826.0.1285.0.2.0.109");
            }
            representedOrganizationSDS.setIdExtension(identifier.getValue());
            representedOrganizationSDS.setName(organization.getName());
            agentPerson.setRepresentedOrganizationSDS(representedOrganizationSDS);
        }
        participant.setAgentPerson(agentPerson);
    } else {
        throw new FhirValidationException(String.format("Invalid PractitionerRole %s identifier.system or code.coding.system", practitionerRole.getId()));
    }
}
Also used : AgentPerson(uk.nhs.adaptors.scr.models.xml.AgentPerson) MANUFACTURERNAME(org.hl7.fhir.r4.model.Device.DeviceNameType.MANUFACTURERNAME) Organization(uk.nhs.adaptors.scr.models.xml.Organization) PersonSDS(uk.nhs.adaptors.scr.models.xml.PersonSDS) Identifier(org.hl7.fhir.r4.model.Identifier) DeviceSDS(uk.nhs.adaptors.scr.models.xml.DeviceSDS) NonAgentRole(uk.nhs.adaptors.scr.models.xml.NonAgentRole) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Reference(org.hl7.fhir.r4.model.Reference) StringUtils(org.apache.commons.lang3.StringUtils) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) OTHER(org.hl7.fhir.r4.model.Device.DeviceNameType.OTHER) Person(uk.nhs.adaptors.scr.models.xml.Person) HumanName(org.hl7.fhir.r4.model.HumanName) AgentPersonSDS(uk.nhs.adaptors.scr.models.xml.AgentPersonSDS) Device(uk.nhs.adaptors.scr.models.xml.Device) Practitioner(org.hl7.fhir.r4.model.Practitioner) AgentDevice(uk.nhs.adaptors.scr.models.xml.AgentDevice) DateUtil.formatDateToHl7(uk.nhs.adaptors.scr.utils.DateUtil.formatDateToHl7) AgentPerson(uk.nhs.adaptors.scr.models.xml.AgentPerson) FhirHelper.getDomainResourceList(uk.nhs.adaptors.scr.utils.FhirHelper.getDomainResourceList) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) FhirHelper.getResourceByReference(uk.nhs.adaptors.scr.utils.FhirHelper.getResourceByReference) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Collectors(java.util.stream.Collectors) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Slf4j(lombok.extern.slf4j.Slf4j) Participant(uk.nhs.adaptors.scr.models.xml.Participant) Coding(org.hl7.fhir.r4.model.Coding) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) OrganizationSDS(uk.nhs.adaptors.scr.models.xml.OrganizationSDS) PersonSDS(uk.nhs.adaptors.scr.models.xml.PersonSDS) AgentPersonSDS(uk.nhs.adaptors.scr.models.xml.AgentPersonSDS) Organization(uk.nhs.adaptors.scr.models.xml.Organization) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) OrganizationSDS(uk.nhs.adaptors.scr.models.xml.OrganizationSDS) Practitioner(org.hl7.fhir.r4.model.Practitioner) Identifier(org.hl7.fhir.r4.model.Identifier) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Person(uk.nhs.adaptors.scr.models.xml.Person) AgentPerson(uk.nhs.adaptors.scr.models.xml.AgentPerson) AgentPersonSDS(uk.nhs.adaptors.scr.models.xml.AgentPersonSDS)

Example 39 with PractitionerRole

use of org.hl7.fhir.r4.model.PractitionerRole 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);
}
Also used : MANUFACTURERNAME(org.hl7.fhir.r4.model.Device.DeviceNameType.MANUFACTURERNAME) Organization(uk.nhs.adaptors.scr.models.xml.Organization) PersonSDS(uk.nhs.adaptors.scr.models.xml.PersonSDS) Identifier(org.hl7.fhir.r4.model.Identifier) DeviceSDS(uk.nhs.adaptors.scr.models.xml.DeviceSDS) NonAgentRole(uk.nhs.adaptors.scr.models.xml.NonAgentRole) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Reference(org.hl7.fhir.r4.model.Reference) StringUtils(org.apache.commons.lang3.StringUtils) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) OTHER(org.hl7.fhir.r4.model.Device.DeviceNameType.OTHER) Person(uk.nhs.adaptors.scr.models.xml.Person) HumanName(org.hl7.fhir.r4.model.HumanName) AgentPersonSDS(uk.nhs.adaptors.scr.models.xml.AgentPersonSDS) Device(uk.nhs.adaptors.scr.models.xml.Device) Practitioner(org.hl7.fhir.r4.model.Practitioner) AgentDevice(uk.nhs.adaptors.scr.models.xml.AgentDevice) DateUtil.formatDateToHl7(uk.nhs.adaptors.scr.utils.DateUtil.formatDateToHl7) AgentPerson(uk.nhs.adaptors.scr.models.xml.AgentPerson) FhirHelper.getDomainResourceList(uk.nhs.adaptors.scr.utils.FhirHelper.getDomainResourceList) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) FhirHelper.getResourceByReference(uk.nhs.adaptors.scr.utils.FhirHelper.getResourceByReference) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Collectors(java.util.stream.Collectors) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Slf4j(lombok.extern.slf4j.Slf4j) Participant(uk.nhs.adaptors.scr.models.xml.Participant) Coding(org.hl7.fhir.r4.model.Coding) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) OrganizationSDS(uk.nhs.adaptors.scr.models.xml.OrganizationSDS) Organization(uk.nhs.adaptors.scr.models.xml.Organization) Identifier(org.hl7.fhir.r4.model.Identifier) Device(uk.nhs.adaptors.scr.models.xml.Device) AgentDevice(uk.nhs.adaptors.scr.models.xml.AgentDevice) AgentDevice(uk.nhs.adaptors.scr.models.xml.AgentDevice) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) OrganizationSDS(uk.nhs.adaptors.scr.models.xml.OrganizationSDS) DeviceSDS(uk.nhs.adaptors.scr.models.xml.DeviceSDS)

Example 40 with PractitionerRole

use of org.hl7.fhir.r4.model.PractitionerRole in project elexis-server by elexis.

the class PractitionerRoleResourceProvider method practitionerRoleHasCode.

private boolean practitionerRoleHasCode(PractitionerRole pr, Optional<String> codeSystem, Optional<String> codeCode) {
    List<CodeableConcept> roles = pr.getCode();
    for (CodeableConcept code : roles) {
        List<Coding> codings = code.getCoding();
        for (Coding coding : codings) {
            boolean matchingSystem = false;
            boolean matchingCode = false;
            if (codeSystem.isPresent()) {
                matchingSystem = coding.getSystem().equals(codeSystem.get());
            }
            if (codeCode.isPresent()) {
                matchingCode = coding.getCode().equals(codeCode.get());
            }
            if (matchingSystem && matchingCode) {
                return true;
            }
        }
    }
    return false;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

PractitionerRole (org.hl7.fhir.r4.model.PractitionerRole)26 Reference (org.hl7.fhir.r4.model.Reference)19 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)16 Coding (org.hl7.fhir.r4.model.Coding)15 Identifier (org.hl7.fhir.r4.model.Identifier)13 ArrayList (java.util.ArrayList)12 Practitioner (org.hl7.fhir.r4.model.Practitioner)12 Resource (org.hl7.fhir.r4.model.Resource)12 List (java.util.List)11 PractitionerRole (org.hl7.fhir.dstu3.model.PractitionerRole)11 RelatedPerson (org.hl7.fhir.r4.model.RelatedPerson)10 Optional (java.util.Optional)9 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)7 EncounterParticipantComponent (org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent)7 Period (org.hl7.fhir.r4.model.Period)7 Test (org.junit.jupiter.api.Test)7 Identifiable (org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable)7 Component (org.springframework.stereotype.Component)7 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)6 RequiredArgsConstructor (lombok.RequiredArgsConstructor)5