Search in sources :

Example 56 with PractitionerRole

use of org.hl7.fhir.r4.model.PractitionerRole in project MobileAccessGateway by i4mi.

the class BaseQueryResponseConverter method transformAuthor.

/**
 * XDS Author -> FHIR Reference
 * @param author
 * @return
 */
public Reference transformAuthor(Author author) {
    Person person = author.getAuthorPerson();
    if (isPatientAuthor(author)) {
        Patient patient = transformPatient(person);
        Reference result = new Reference();
        List<Telecom> telecoms = author.getAuthorTelecom();
        for (Telecom telecom : telecoms) patient.addTelecom(transform(telecom));
        result.setResource(patient);
        return result;
    }
    Practitioner containedPerson = transformPractitioner(person);
    PractitionerRole role = null;
    List<org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization> orgs = author.getAuthorInstitution();
    List<Identifiable> roles = author.getAuthorRole();
    List<Identifiable> specialities = author.getAuthorSpecialty();
    if (!orgs.isEmpty() || !roles.isEmpty() || !specialities.isEmpty()) {
        role = new PractitionerRole();
        if (containedPerson != null)
            role.setPractitioner((Reference) new Reference().setResource(containedPerson));
    }
    for (org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization org : orgs) {
        role.setOrganization((Reference) new Reference().setResource(transform(org)));
    }
    for (Identifiable roleId : roles) {
        role.addCode(transform(roleId));
    }
    for (Identifiable specId : specialities) {
        role.addSpecialty(transform(specId));
    }
    Reference result = new Reference();
    List<Telecom> telecoms = author.getAuthorTelecom();
    if (role == null) {
        for (Telecom telecom : telecoms) containedPerson.addTelecom(transform(telecom));
        result.setResource(containedPerson);
    } else {
        for (Telecom telecom : telecoms) role.addTelecom(transform(telecom));
        result.setResource(role);
    }
    return result;
}
Also used : Organization(org.hl7.fhir.r4.model.Organization) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.hl7.fhir.r4.model.Patient) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) Identifiable(org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable) Practitioner(org.hl7.fhir.r4.model.Practitioner) Telecom(org.openehealth.ipf.commons.ihe.xds.core.metadata.Telecom) Person(org.openehealth.ipf.commons.ihe.xds.core.metadata.Person)

Example 57 with PractitionerRole

use of org.hl7.fhir.r4.model.PractitionerRole in project MobileAccessGateway by i4mi.

the class Iti65RequestConverter method processDocumentReference.

/**
 * ITI-65: process DocumentReference resource from Bundle
 * @param reference
 * @param entry
 */
public void processDocumentReference(DocumentReference reference, DocumentEntry entry) {
    if (reference.getIdElement() != null) {
        entry.setEntryUuid(reference.getIdElement().getIdPart());
    } else {
        entry.assignEntryUuid();
        reference.setId(entry.getEntryUuid());
    }
    Identifier masterIdentifier = reference.getMasterIdentifier();
    entry.setUniqueId(noPrefix(masterIdentifier.getValue()));
    // limitedMetadata -> meta.profile canonical [0..*]
    // No action
    // availabilityStatus -> status code {DocumentReferenceStatus} [1..1]
    // approved -> status=current
    // deprecated -> status=superseded
    // Other status values are allowed but are not defined in this mapping to XDS.
    DocumentReferenceStatus status = reference.getStatus();
    switch(status) {
        case CURRENT:
            entry.setAvailabilityStatus(AvailabilityStatus.APPROVED);
            break;
        case SUPERSEDED:
            entry.setAvailabilityStatus(AvailabilityStatus.DEPRECATED);
            break;
        default:
            throw new InvalidRequestException("Unknown document status");
    }
    // contentTypeCode -> type CodeableConcept [0..1]
    CodeableConcept type = reference.getType();
    entry.setTypeCode(transform(type));
    // classCode -> category CodeableConcept [0..*]
    List<CodeableConcept> category = reference.getCategory();
    entry.setClassCode(transform(category));
    // patientId -> subject Reference(Patient| Practitioner| Group| Device) [0..1],
    Reference subject = reference.getSubject();
    entry.setPatientId(transformReferenceToIdentifiable(subject, reference));
    // creationTime -> date instant [0..1]
    entry.setCreationTime(timestampFromDate(reference.getDateElement()));
    // PractitionerRole| Organization| Device| Patient| RelatedPerson) [0..*]
    for (Reference authorRef : reference.getAuthor()) {
        entry.getAuthors().add(transformAuthor(authorRef, reference.getContained(), null));
    }
    if (reference.hasAuthenticator()) {
        Reference authenticatorRef = reference.getAuthenticator();
        Resource authenticator = findResource(authenticatorRef, reference.getContained());
        if (authenticator instanceof Practitioner) {
            entry.setLegalAuthenticator(transform((Practitioner) authenticator));
        } else if (authenticator instanceof PractitionerRole) {
            Practitioner practitioner = (Practitioner) findResource(((PractitionerRole) authenticator).getPractitioner(), reference.getContained());
            if (practitioner != null)
                entry.setLegalAuthenticator(transform(practitioner));
        } else
            throw new InvalidRequestException("No authenticator of type Organization supported.");
    }
    // title -> description string [0..1]
    String title = reference.getDescription();
    if (title != null)
        entry.setTitle(localizedString(title));
    // confidentialityCode -> securityLabel CodeableConcept [0..*] Note: This
    // is NOT the DocumentReference.meta, as that holds the meta tags for the
    // DocumentReference itself.
    List<CodeableConcept> securityLabels = reference.getSecurityLabel();
    transformCodeableConcepts(securityLabels, entry.getConfidentialityCodes());
    // mimeType -> content.attachment.contentType [1..1] code [0..1]
    DocumentReferenceContentComponent content = reference.getContentFirstRep();
    if (content == null)
        throw new InvalidRequestException("Missing content field in DocumentReference");
    Attachment attachment = content.getAttachment();
    if (attachment == null)
        throw new InvalidRequestException("Missing attachment field in DocumentReference");
    entry.setMimeType(attachment.getContentType());
    // languageCode -> content.attachment.language code [0..1]
    entry.setLanguageCode(attachment.getLanguage());
    // size -> content.attachment.size integer [0..1] The size is calculated
    if (attachment.hasSize())
        entry.setSize((long) attachment.getSize());
    // on the data prior to base64 encoding, if the data is base64 encoded.
    // hash -> content.attachment.hash string [0..1]
    byte[] hash = attachment.getHash();
    if (hash != null)
        entry.setHash(Hex.encodeHexString(hash));
    // comments -> content.attachment.title string [0..1]
    String comments = attachment.getTitle();
    if (comments != null)
        entry.setComments(localizedString(comments));
    // creationTime -> content.attachment.creation dateTime [0..1]
    if (attachment.hasCreation()) {
        if (entry.getCreationTime() == null)
            entry.setCreationTime(timestampFromDate(attachment.getCreationElement()));
        else if (!timestampFromDate(attachment.getCreationElement()).equals(entry.getCreationTime()))
            throw new InvalidRequestException("DocumentReference.date does not match attachment.creation element");
    }
    // formatCode -> content.format Coding [0..1]
    Coding coding = content.getFormat();
    entry.setFormatCode(transform(coding));
    DocumentReferenceContextComponent context = reference.getContext();
    // Instead: referenceIdList -> related.identifier
    for (Reference ref : context.getRelated()) {
        Identifiable refId = transformReferenceToIdentifiable(ref, reference);
        if (refId != null) {
            ReferenceId referenceId = new ReferenceId();
            referenceId.setAssigningAuthority(new CXiAssigningAuthority(null, refId.getAssigningAuthority().getUniversalId(), refId.getAssigningAuthority().getUniversalIdType()));
            referenceId.setId(refId.getId());
            entry.getReferenceIdList().add(referenceId);
        }
    }
    // Currently not mapped
    /*for (Reference encounterRef : context.getEncounter()) {
        	ReferenceId referenceId = new ReferenceId();
        	Identifiable id = transformReferenceToIdentifiable(encounterRef, reference);
        	if (id != null) {
        	  referenceId.setIdTypeCode(ReferenceId.ID_TYPE_ENCOUNTER_ID);        	
        	  referenceId.setId(id.getId());
        	  //referenceId.setAssigningAuthority(new CXiAid.getAssigningAuthority().getUniversalId());
			  entry.getReferenceIdList().add(referenceId );
        }*/
    // eventCodeList -> context.event CodeableConcept [0..*]
    List<CodeableConcept> events = context.getEvent();
    transformCodeableConcepts(events, entry.getEventCodeList());
    // serviceStartTime serviceStopTime -> context.period Period [0..1]
    Period period = context.getPeriod();
    if (period != null) {
        entry.setServiceStartTime(timestampFromDate(period.getStartElement()));
        entry.setServiceStopTime(timestampFromDate(period.getEndElement()));
    }
    // healthcareFacilityTypeCode -> context.facilityType CodeableConcept
    // [0..1]
    entry.setHealthcareFacilityTypeCode(transformCodeableConcept(context.getFacilityType()));
    // practiceSettingCode -> context.practiceSetting CodeableConcept [0..1]
    entry.setPracticeSettingCode(transformCodeableConcept(context.getPracticeSetting()));
    Extension originalRole = reference.getExtensionByUrl("http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-ext-author-authorrole");
    if (originalRole != null) {
        if (originalRole.getValue() instanceof Coding) {
            Coding value = (Coding) originalRole.getValue();
            String system = noPrefix(value.getSystem());
            String code = value.getCode();
            entry.setExtraMetadata(Collections.singletonMap("urn:e-health-suisse:2020:originalProviderRole", Collections.singletonList(code + "^^^&" + system + "&ISO")));
        }
    }
    Extension deletionStatus = reference.getExtensionByUrl("http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-ext-deletionstatus");
    if (deletionStatus != null) {
        if (deletionStatus.getValue() instanceof Coding) {
            Coding value = (Coding) deletionStatus.getValue();
            String code = value.getCode();
            entry.setExtraMetadata(Collections.singletonMap("urn:e-health-suisse:2019:deletionStatus", Collections.singletonList("urn:e-health-suisse:2019:deletionStatus:" + code)));
        }
    }
    // Patient.identifier.use element set to ‘usual’.
    if (context.hasSourcePatientInfo()) {
        entry.setSourcePatientId(transformReferenceToIdentifiable(context.getSourcePatientInfo(), reference));
        entry.setSourcePatientInfo(transformReferenceToPatientInfo(context.getSourcePatientInfo(), reference));
    }
}
Also used : CXiAssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.CXiAssigningAuthority) DocumentReferenceContextComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContextComponent) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Resource(org.hl7.fhir.r4.model.Resource) ListResource(org.hl7.fhir.r4.model.ListResource) DomainResource(org.hl7.fhir.r4.model.DomainResource) Period(org.hl7.fhir.r4.model.Period) Attachment(org.hl7.fhir.r4.model.Attachment) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) LocalizedString(org.openehealth.ipf.commons.ihe.xds.core.metadata.LocalizedString) Identifiable(org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable) Practitioner(org.hl7.fhir.r4.model.Practitioner) Extension(org.hl7.fhir.r4.model.Extension) Identifier(org.hl7.fhir.r4.model.Identifier) ReferenceId(org.openehealth.ipf.commons.ihe.xds.core.metadata.ReferenceId) Coding(org.hl7.fhir.r4.model.Coding) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) DocumentReferenceStatus(org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) DocumentReferenceContentComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContentComponent)

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