Search in sources :

Example 56 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource in project nia-patient-switching-standard-adaptor by NHSDigital.

the class ConsultationListMapperTest method setUpConsultation.

private ListResource setUpConsultation() {
    ListResource consultation = new ListResource();
    consultation.setDateElement(DateFormatUtil.parseToDateTimeType("20130213152000")).setTitle("test-title").setSubject(new Reference(new Patient().setId(PATIENT_ID))).setEncounter(new Reference(encounter)).setId(ENCOUNTER_ID + CONSULTATION_ID_SUFFIX);
    return consultation;
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) Patient(org.hl7.fhir.dstu3.model.Patient) ListResource(org.hl7.fhir.dstu3.model.ListResource)

Example 57 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource in project nia-patient-switching-standard-adaptor by NHSDigital.

the class ConsultationListMapperTest method setUpTopic.

private ListResource setUpTopic() {
    ListResource consultation = new ListResource();
    consultation.setDateElement(DateFormatUtil.parseToDateTimeType("20110213152000")).setTitle("test-title").setSubject(new Reference(new Patient().setId(PATIENT_ID))).setEncounter(new Reference(encounter)).setId(COMPOUND_STATEMENT_ID);
    return consultation;
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) Patient(org.hl7.fhir.dstu3.model.Patient) ListResource(org.hl7.fhir.dstu3.model.ListResource)

Example 58 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource 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)

Example 59 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource in project MobileAccessGateway by i4mi.

the class Iti65ResponseConverter method translateToFhir.

/**
 * convert ITI-41 response to ITI-65 response
 */
@Override
public Object translateToFhir(Response input, Map<String, Object> parameters) {
    if (input.getStatus().equals(Status.SUCCESS)) {
        Bundle responseBundle = new Bundle();
        Bundle requestBundle = (Bundle) parameters.get(Utils.KEPT_BODY);
        responseBundle.getMeta().addProfile("http://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.ProvideDocumentBundleResponse");
        for (Bundle.BundleEntryComponent requestEntry : requestBundle.getEntry()) {
            Bundle.BundleEntryResponseComponent response = new Bundle.BundleEntryResponseComponent().setStatus("201 Created").setLastModified(new Date());
            if (requestEntry.getResource() instanceof Binary) {
                String uniqueId = (String) requestEntry.getResource().getUserData("masterIdentifier");
                response.setLocation(config.getUriMagXdsRetrieve() + "?uniqueId=" + uniqueId + "&repositoryUniqueId=" + config.getRepositoryUniqueId());
            } else if (requestEntry.getResource() instanceof ListResource) {
                String id = config.getSchemeMapper().getScheme(((ListResource) requestEntry.getResource()).getId());
                response.setLocation("List/" + id);
            } else if (requestEntry.getResource() instanceof DocumentReference) {
                String id = config.getSchemeMapper().getScheme(((DocumentReference) requestEntry.getResource()).getId());
                response.setLocation("DocumentReference/" + id);
            }
            responseBundle.addEntry().setResponse(response);
        }
        return responseBundle;
    } else {
        processError(input);
        return null;
    }
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Binary(org.hl7.fhir.r4.model.Binary) ListResource(org.hl7.fhir.r4.model.ListResource) Date(java.util.Date) DocumentReference(org.hl7.fhir.r4.model.DocumentReference)

Aggregations

ListResource (org.hl7.fhir.r5.model.ListResource)12 Element (org.w3c.dom.Element)12 ListResourceEntryComponent (org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent)11 ListResource (org.hl7.fhir.dstu3.model.ListResource)10 Reference (org.hl7.fhir.dstu3.model.Reference)10 ListEntryComponent (org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)9 ArrayList (java.util.ArrayList)8 ListResource (org.hl7.fhir.r4.model.ListResource)8 Reference (org.hl7.fhir.r4.model.Reference)6 HashMap (java.util.HashMap)5 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)5 SectionComponent (org.hl7.fhir.dstu3.model.Composition.SectionComponent)4 Patient (org.hl7.fhir.r4.model.Patient)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 List (java.util.List)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2