Search in sources :

Example 1 with Document

use of org.openehealth.ipf.commons.ihe.xds.core.metadata.Document in project ipf by oehf.

the class QueryResponseTransformer method fromEbXML.

/**
 * Transforms a {@link EbXMLQueryResponse} to a {@link QueryResponse}.
 *
 * @param ebXML the ebXML representation. Can be <code>null</code>.
 * @return the response. <code>null</code> if the input was <code>null</code>.
 */
public QueryResponse fromEbXML(EbXMLQueryResponse ebXML) {
    if (ebXML == null) {
        return null;
    }
    var response = new QueryResponse();
    response.setStatus(ebXML.getStatus());
    if (!ebXML.getErrors().isEmpty()) {
        response.setErrors(errorInfoListTransformer.fromEbXML(ebXML.getErrors()));
    }
    var foundNonObjRefs = false;
    for (var extrinsic : ebXML.getExtrinsicObjects(DocumentEntryType.STABLE_OR_ON_DEMAND)) {
        var documentEntry = documentEntryTransformer.fromEbXML(extrinsic);
        response.getDocumentEntries().add(documentEntry);
        if (extrinsic.getDataHandler() != null) {
            response.getDocuments().add(new Document(documentEntry, extrinsic.getDataHandler()));
        }
        foundNonObjRefs = true;
    }
    for (var regPackage : ebXML.getRegistryPackages(Vocabulary.FOLDER_CLASS_NODE)) {
        response.getFolders().add(folderTransformer.fromEbXML(regPackage));
        foundNonObjRefs = true;
    }
    for (var regPackage : ebXML.getRegistryPackages(Vocabulary.SUBMISSION_SET_CLASS_NODE)) {
        response.getSubmissionSets().add(submissionSetTransformer.fromEbXML(regPackage));
        foundNonObjRefs = true;
    }
    for (var association : ebXML.getAssociations()) {
        response.getAssociations().add(associationTransformer.fromEbXML(association));
        foundNonObjRefs = true;
    }
    if (!foundNonObjRefs) {
        var standardLibrary = factory.createObjectLibrary();
        ebXML.getReferences().stream().filter(ref -> standardLibrary.getById(ref.getId()) == null).forEach(ref -> response.getReferences().add(ref));
    }
    return response;
}
Also used : Vocabulary(org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary) AssociationTransformer(org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.AssociationTransformer) DocumentEntryType(org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType) QueryResponse(org.openehealth.ipf.commons.ihe.xds.core.responses.QueryResponse) DocumentEntryTransformer(org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.DocumentEntryTransformer) DataHandler(javax.activation.DataHandler) SubmissionSetTransformer(org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.SubmissionSetTransformer) EbXMLObjectLibrary(org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary) Validate.notNull(org.apache.commons.lang3.Validate.notNull) EbXMLQueryResponse(org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLQueryResponse) Document(org.openehealth.ipf.commons.ihe.xds.core.metadata.Document) FolderTransformer(org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.FolderTransformer) EbXMLFactory(org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory) QueryResponse(org.openehealth.ipf.commons.ihe.xds.core.responses.QueryResponse) EbXMLQueryResponse(org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLQueryResponse) Document(org.openehealth.ipf.commons.ihe.xds.core.metadata.Document)

Example 2 with Document

use of org.openehealth.ipf.commons.ihe.xds.core.metadata.Document in project MobileAccessGateway by i4mi.

the class Iti65RequestConverter method convert.

/**
 * convert ITI-65 to ITI-41 request
 * @param requestBundle
 * @return
 */
public ProvideAndRegisterDocumentSet convert(@Body Bundle requestBundle) {
    SubmissionSet submissionSet = new SubmissionSet();
    ProvideAndRegisterDocumentSetBuilder builder = new ProvideAndRegisterDocumentSetBuilder(true, submissionSet);
    // create mapping fullUrl -> resource for each resource in bundle
    Map<String, Resource> resources = new HashMap<String, Resource>();
    ListResource manifestNeu = null;
    for (Bundle.BundleEntryComponent requestEntry : requestBundle.getEntry()) {
        Resource resource = requestEntry.getResource();
        /*if (resource instanceof DocumentManifest) {
            	manifest = (DocumentManifest) resource;            	
            } else*/
        if (resource instanceof DocumentReference) {
            resources.put(requestEntry.getFullUrl(), resource);
        } else if (resource instanceof ListResource) {
            manifestNeu = (ListResource) resource;
        // resources.put(requestEntry.getFullUrl(), resource);
        } else if (resource instanceof Binary) {
            resources.put(requestEntry.getFullUrl(), resource);
        } else {
            throw new IllegalArgumentException(resource + " is not allowed here");
        }
    }
    /*if (manifest != null) {
		  processDocumentManifest(manifest, submissionSet);
	    } else {*/
    processDocumentManifest(manifestNeu, submissionSet);
    // set limited metadata
    for (CanonicalType profile : requestBundle.getMeta().getProfile()) {
        if ("http://ihe.net/fhir/StructureDefinition/IHE_MHD_Provide_Comprehensive_DocumentBundle".equals(profile.getValue())) {
            submissionSet.setLimitedMetadata(false);
        } else if ("http://ihe.net/fhir/StructureDefinition/IHE_MHD_Provide_Minimal_DocumentBundle".equals(profile.getValue())) {
            submissionSet.setLimitedMetadata(true);
        } else if ("http://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Comprehensive.ProvideBundle".equals(profile.getValue())) {
            submissionSet.setLimitedMetadata(false);
        } else if ("http://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Minimal.ProvideBundle".equals(profile.getValue())) {
            submissionSet.setLimitedMetadata(true);
        }
    }
    // process all resources referenced in DocumentManifest.content
    for (ListEntryComponent listEntry : manifestNeu.getEntry()) {
        Reference content = listEntry.getItem();
        String refTarget = content.getReference();
        Resource resource = resources.get(refTarget);
        if (resource instanceof DocumentReference) {
            DocumentReference documentReference = (DocumentReference) resource;
            Document doc = new Document();
            DocumentEntry entry = new DocumentEntry();
            processDocumentReference(documentReference, entry);
            doc.setDocumentEntry(entry);
            entry.setRepositoryUniqueId(config.getRepositoryUniqueId());
            // create associations
            for (DocumentReferenceRelatesToComponent relatesTo : documentReference.getRelatesTo()) {
                Reference target = relatesTo.getTarget();
                DocumentRelationshipType code = relatesTo.getCode();
                Association association = new Association();
                switch(code) {
                    case REPLACES:
                        association.setAssociationType(AssociationType.REPLACE);
                        break;
                    case TRANSFORMS:
                        association.setAssociationType(AssociationType.TRANSFORM);
                        break;
                    case SIGNS:
                        association.setAssociationType(AssociationType.SIGNS);
                        break;
                    case APPENDS:
                        association.setAssociationType(AssociationType.APPEND);
                        break;
                    default:
                }
                association.setSourceUuid(entry.getEntryUuid());
                association.setTargetUuid(transformUriFromReference(target));
                builder.withAssociation(association);
            }
            // get binary content from attachment.data or from referenced Binary resource
            Attachment attachment = documentReference.getContentFirstRep().getAttachment();
            if (attachment.hasData()) {
                doc.setDataHandler(new DataHandler(new ByteArrayDataSource(attachment.getData(), attachment.getContentType())));
                byte[] decoded = attachment.getData();
                entry.setSize((long) decoded.length);
                entry.setHash(SHAsum(decoded));
            } else if (attachment.hasUrl()) {
                String contentURL = attachment.getUrl();
                Resource binaryContent = resources.get(contentURL);
                if (binaryContent instanceof Binary) {
                    String contentType = attachment.getContentType();
                    Binary binary = (Binary) binaryContent;
                    if (binary.hasContentType() && !binary.getContentType().equals(contentType))
                        throw new InvalidRequestException("ContentType in Binary and in DocumentReference must match");
                    doc.setDataHandler(new DataHandler(new ByteArrayDataSource(binary.getData(), contentType)));
                    byte[] decoded = binary.getData();
                    entry.setSize((long) decoded.length);
                    entry.setHash(SHAsum(decoded));
                    Identifier masterIdentifier = documentReference.getMasterIdentifier();
                    binary.setUserData("masterIdentifier", noPrefix(masterIdentifier.getValue()));
                }
            }
            builder.withDocument(doc);
        }
    }
    return builder.build();
}
Also used : DocumentReferenceRelatesToComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent) HashMap(java.util.HashMap) SubmissionSet(org.openehealth.ipf.commons.ihe.xds.core.metadata.SubmissionSet) Attachment(org.hl7.fhir.r4.model.Attachment) LocalizedString(org.openehealth.ipf.commons.ihe.xds.core.metadata.LocalizedString) DataHandler(javax.activation.DataHandler) Document(org.openehealth.ipf.commons.ihe.xds.core.metadata.Document) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Association(org.openehealth.ipf.commons.ihe.xds.core.metadata.Association) Identifier(org.hl7.fhir.r4.model.Identifier) ProvideAndRegisterDocumentSetBuilder(org.openehealth.ipf.commons.ihe.xds.core.requests.builder.ProvideAndRegisterDocumentSetBuilder) DocumentEntry(org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntry) ListEntryComponent(org.hl7.fhir.r4.model.ListResource.ListEntryComponent) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) ByteArrayDataSource(com.sun.istack.ByteArrayDataSource) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) DocumentRelationshipType(org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType) Bundle(org.hl7.fhir.r4.model.Bundle) 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) Binary(org.hl7.fhir.r4.model.Binary) ListResource(org.hl7.fhir.r4.model.ListResource)

Aggregations

DataHandler (javax.activation.DataHandler)2 Document (org.openehealth.ipf.commons.ihe.xds.core.metadata.Document)2 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)1 ByteArrayDataSource (com.sun.istack.ByteArrayDataSource)1 HashMap (java.util.HashMap)1 Validate.notNull (org.apache.commons.lang3.Validate.notNull)1 Attachment (org.hl7.fhir.r4.model.Attachment)1 Binary (org.hl7.fhir.r4.model.Binary)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)1 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)1 DocumentReferenceRelatesToComponent (org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceRelatesToComponent)1 DocumentRelationshipType (org.hl7.fhir.r4.model.DocumentReference.DocumentRelationshipType)1 DomainResource (org.hl7.fhir.r4.model.DomainResource)1 Identifier (org.hl7.fhir.r4.model.Identifier)1 ListResource (org.hl7.fhir.r4.model.ListResource)1 ListEntryComponent (org.hl7.fhir.r4.model.ListResource.ListEntryComponent)1 Reference (org.hl7.fhir.r4.model.Reference)1 Resource (org.hl7.fhir.r4.model.Resource)1 EbXMLFactory (org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory)1