Search in sources :

Example 11 with ProvideAndRegisterDocumentSetRequestType

use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType in project nhin-d by DirectProject.

the class DefaultXdsXdmTransformerTest method testTransform.

public void testTransform() throws Exception {
    // Create a collection of documents
    DirectDocuments documents = new DirectDocuments();
    documents.getSubmissionSet().setId("1");
    documents.getSubmissionSet().setName("2");
    documents.getSubmissionSet().setDescription("3");
    documents.getSubmissionSet().setSubmissionTime(new Date());
    documents.getSubmissionSet().setIntendedRecipient(Arrays.asList("5.1", "5.2"));
    documents.getSubmissionSet().setAuthorPerson("6");
    documents.getSubmissionSet().setAuthorInstitution(Arrays.asList("7.1", "7.2"));
    documents.getSubmissionSet().setAuthorRole("8");
    documents.getSubmissionSet().setAuthorSpecialty("9");
    documents.getSubmissionSet().setAuthorTelecommunication("10");
    documents.getSubmissionSet().setContentTypeCode("11");
    documents.getSubmissionSet().setContentTypeCode_localized("12");
    documents.getSubmissionSet().setUniqueId("13");
    documents.getSubmissionSet().setSourceId("14");
    documents.getSubmissionSet().setPatientId("xxx");
    DirectDocument2 doc1 = new DirectDocument2();
    doc1.setData(new String("data1").getBytes());
    DirectDocument2.Metadata metadata1 = doc1.getMetadata();
    metadata1.setMimeType("text/xml");
    metadata1.setId("1.2");
    metadata1.setDescription("1.3");
    metadata1.setCreationTime(new Date());
    metadata1.setLanguageCode("1.5");
    metadata1.setServiceStartTime(new Date());
    metadata1.setServiceStopTime(new Date());
    metadata1.setSourcePatient(new SimplePerson("1.Bob", "1.Smith"));
    metadata1.setAuthorPerson("1.10");
    metadata1.setAuthorInstitution(Arrays.asList("1.11.1", "1.11.2"));
    metadata1.setAuthorRole("1.12");
    metadata1.setAuthorSpecialty("1.13");
    metadata1.setClassCode(ClassCodeEnum.HISTORY_AND_PHYSICAL.getValue());
    metadata1.setClassCode_localized(ClassCodeEnum.HISTORY_AND_PHYSICAL.getValue());
    metadata1.setConfidentialityCode("1.16");
    metadata1.setConfidentialityCode_localized("1.17");
    metadata1.setFormatCode(FormatCodeEnum.HL7_CCD_DOCUMENT);
    metadata1.setHealthcareFacilityTypeCode(HealthcareFacilityTypeCodeEnum.OF.getValue());
    metadata1.setHealthcareFacilityTypeCode_localized(HealthcareFacilityTypeCodeEnum.OF.getValue());
    metadata1.setPracticeSettingCode(PracticeSettingCodeEnum.MULTIDISCIPLINARY.getValue());
    metadata1.setPracticeSettingCode_localized(PracticeSettingCodeEnum.MULTIDISCIPLINARY.getValue());
    metadata1.setLoinc(LoincEnum.LOINC_34133_9.getValue());
    metadata1.setLoinc_localized(LoincEnum.LOINC_34133_9.getValue());
    metadata1.setPatientId("xxx");
    metadata1.setUniqueId("1.27");
    DirectDocument2 doc2 = new DirectDocument2();
    doc2.setData(new String("data2").getBytes());
    DirectDocument2.Metadata metadata2 = doc2.getMetadata();
    metadata2.setMimeType("text/xml");
    metadata2.setId("2.2");
    metadata2.setDescription("2.3");
    metadata2.setCreationTime(new Date());
    metadata2.setLanguageCode("2.5");
    metadata2.setServiceStartTime(new Date());
    metadata2.setServiceStopTime(new Date());
    metadata2.setSourcePatient(new SimplePerson("2.Bob", "2.Smith"));
    metadata2.setAuthorPerson("2.10");
    metadata2.setAuthorInstitution(Arrays.asList("2.11.1", "2.11.2"));
    metadata2.setAuthorRole("2.12");
    metadata2.setAuthorSpecialty("2.13");
    metadata2.setClassCode(ClassCodeEnum.HISTORY_AND_PHYSICAL.getValue());
    metadata2.setClassCode_localized(ClassCodeEnum.HISTORY_AND_PHYSICAL.getValue());
    metadata2.setConfidentialityCode("2.16");
    metadata2.setConfidentialityCode_localized("2.17");
    metadata2.setFormatCode(FormatCodeEnum.IMMUNIZATION_REGISTRY_CONTENT_CRC);
    metadata2.setHealthcareFacilityTypeCode(HealthcareFacilityTypeCodeEnum.OF.getValue());
    metadata2.setHealthcareFacilityTypeCode_localized(HealthcareFacilityTypeCodeEnum.OF.getValue());
    metadata2.setPracticeSettingCode(PracticeSettingCodeEnum.MULTIDISCIPLINARY.getValue());
    metadata2.setPracticeSettingCode_localized(PracticeSettingCodeEnum.MULTIDISCIPLINARY.getValue());
    metadata2.setLoinc(LoincEnum.LOINC_34133_9.getValue());
    metadata2.setLoinc_localized(LoincEnum.LOINC_34133_9.getValue());
    metadata2.setPatientId("xxx");
    metadata2.setUniqueId("2.27");
    documents.getDocuments().add(doc1);
    documents.getDocuments().add(doc2);
    ProvideAndRegisterDocumentSetRequestType request = documents.toProvideAndRegisterDocumentSetRequestType();
    QName qname = new QName("urn:ihe:iti:xds-b:2007", "ProvideAndRegisterDocumentSet_bRequest");
    String body = XmlUtils.marshal(qname, request, ihe.iti.xds_b._2007.ObjectFactory.class);
    System.out.println(body);
    XdsXdmTransformer transformer = new DefaultXdsXdmTransformer();
    File f = transformer.transform(request);
    System.out.println(f.getAbsolutePath());
}
Also used : QName(javax.xml.namespace.QName) XdsXdmTransformer(org.nhindirect.xd.transform.XdsXdmTransformer) Date(java.util.Date) DirectDocument2(org.nhindirect.xd.common.DirectDocument2) DirectDocuments(org.nhindirect.xd.common.DirectDocuments) File(java.io.File) SimplePerson(org.nhindirect.xd.transform.pojo.SimplePerson) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Example 12 with ProvideAndRegisterDocumentSetRequestType

use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType in project nhin-d by DirectProject.

the class DefaultXdmXdsTransformer method getDocName.

public String getDocName(File file) throws TransformationException {
    LOGGER.trace("Begin transformation of XDM to XDS (file)");
    ZipFile zipFile = null;
    String objectId = null;
    ProvideAndRegisterDocumentSetRequestType prsr = new ProvideAndRegisterDocumentSetRequestType();
    try {
        zipFile = new ZipFile(file, ZipFile.OPEN_READ);
        Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
        ZipEntry zipEntry = null;
        // load the ZIP archive into memory
        while (zipEntries.hasMoreElements()) {
            zipEntry = zipEntries.nextElement();
            String zname = zipEntry.getName();
            LOGGER.trace("Processing a ZipEntry " + zname);
            if (!zipEntry.isDirectory()) {
                String subsetDirspec = getSubmissionSetDirspec(zipEntry.getName());
                // Read metadata
                if (matchName(zname, subsetDirspec, XDM_FILENAME_METADATA)) {
                    ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
                    SubmitObjectsRequest submitObjectRequest = (SubmitObjectsRequest) XmlUtils.unmarshal(byteArrayOutputStream.toString(), oasis.names.tc.ebxml_regrep.xsd.lcm._3.ObjectFactory.class);
                    prsr.setSubmitObjectsRequest(submitObjectRequest);
                    objectId = getDocName(submitObjectRequest);
                }
            // Read data
            }
        }
        zipFile.close();
    } catch (Exception e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to complete getObjectId.", e);
        }
        throw new TransformationException("Unable to complete getObjectId.", e);
    }
    return objectId;
}
Also used : TransformationException(org.nhindirect.xd.transform.exception.TransformationException) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SubmitObjectsRequest(oasis.names.tc.ebxml_regrep.xsd.lcm._3.SubmitObjectsRequest) TransformationException(org.nhindirect.xd.transform.exception.TransformationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ZipFile(java.util.zip.ZipFile) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Example 13 with ProvideAndRegisterDocumentSetRequestType

use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType in project nhin-d by DirectProject.

the class DefaultXdmXdsTransformer method transform.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.nhindirect.transform.XdmXdsTransformer#transform(javax.activation
     * .DataHandler)
     */
@Override
public ProvideAndRegisterDocumentSetRequestType transform(DataHandler dataHandler) throws TransformationException {
    LOGGER.trace("Begin transformation of XDM to XDS (datahandler)");
    File file = null;
    try {
        // Create a temporary work file
        file = fileFromDataHandler(dataHandler);
    } catch (Exception e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Error creating temporary work file, unable to complete transformation.", e);
        }
        throw new TransformationException("Error creating temporary work file, unable to complete transformation.", e);
    }
    ProvideAndRegisterDocumentSetRequestType request = transform(file);
    boolean delete = file.delete();
    if (delete) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Deleted temporary work file " + file.getAbsolutePath());
        }
    } else {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.warn("Unable to delete temporary work file " + file.getAbsolutePath());
        }
    }
    return request;
}
Also used : TransformationException(org.nhindirect.xd.transform.exception.TransformationException) ZipFile(java.util.zip.ZipFile) File(java.io.File) TransformationException(org.nhindirect.xd.transform.exception.TransformationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Example 14 with ProvideAndRegisterDocumentSetRequestType

use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType in project nhin-d by DirectProject.

the class DocumentRepositoryAbstract method provideAndRegisterDocumentSet.

/**
     * Handle an incoming ProvideAndRegisterDocumentSetRequestType object and
     * transform to XDM or relay to another XDR endponit.
     * 
     * @param prdst
     *            The incoming ProvideAndRegisterDocumentSetRequestType object
     * @return a RegistryResponseType object
     * @throws Exception
     */
protected RegistryResponseType provideAndRegisterDocumentSet(ProvideAndRegisterDocumentSetRequestType prdst, SafeThreadData threadData) throws Exception {
    RegistryResponseType resp = null;
    try {
        @SuppressWarnings("unused") InitialContext ctx = new InitialContext();
        DirectDocuments documents = xdsDirectDocumentsTransformer.transform(prdst);
        List<String> forwards = new ArrayList<String>();
        // Get endpoints (first check direct:to header, then go to intendedRecipients)
        if (StringUtils.isNotBlank(threadData.getDirectTo()))
            forwards = Arrays.asList((new URI(threadData.getDirectTo()).getSchemeSpecificPart()));
        else {
            forwards = ParserHL7.parseDirectRecipients(documents);
        }
        // messageId = UUID.randomUUID().toString();  remove this , its is not righ,
        //we should keep the message id of the original message for a lot of reasons vpl
        // TODO patID and subsetId  for atn
        String patId = threadData.getMessageId();
        String subsetId = threadData.getMessageId();
        getAuditMessageGenerator().provideAndRegisterAudit(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
        // Send to SMTP endpoints
        if (getResolver().hasSmtpEndpoints(forwards)) {
            String replyEmail;
            // Get a reply address (first check direct:from header, then go to authorPerson)
            if (StringUtils.isNotBlank(threadData.getDirectFrom()))
                replyEmail = (new URI(threadData.getDirectFrom())).getSchemeSpecificPart();
            else {
                // replyEmail = documents.getSubmissionSet().getAuthorPerson();
                replyEmail = documents.getSubmissionSet().getAuthorTelecommunication();
                //   replyEmail = StringUtils.splitPreserveAllTokens(replyEmail, "^")[0];
                replyEmail = ParserHL7.parseXTN(replyEmail);
                replyEmail = StringUtils.contains(replyEmail, "@") ? replyEmail : "nhindirect@nhindirect.org";
            }
            LOGGER.info("SENDING EMAIL TO " + getResolver().getSmtpEndpoints(forwards) + " with message id " + threadData.getMessageId());
            // Construct message wrapper
            DirectMessage message = new DirectMessage(replyEmail, getResolver().getSmtpEndpoints(forwards));
            message.setSubject("XD* Originated Message");
            message.setBody("Please find the attached XDM file.");
            message.setDirectDocuments(documents);
            // Send mail
            MailClient mailClient = getMailClient();
            String fileName = threadData.getMessageId().replaceAll("urn:uuid:", "");
            mailClient.mail(message, fileName, threadData.getSuffix());
            getAuditMessageGenerator().provideAndRegisterAuditSource(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
        }
        // Send to XD endpoints
        for (String reqEndpoint : getResolver().getXdEndpoints(forwards)) {
            String endpointUrl = getResolver().resolve(reqEndpoint);
            String to = StringUtils.remove(endpointUrl, "?wsdl");
            threadData.setTo(to);
            threadData.setDirectTo(to);
            threadData.save();
            List<Document> docs = prdst.getDocument();
            // Make a copy of the original documents
            List<Document> originalDocs = new ArrayList<Document>();
            for (Document d : docs) originalDocs.add(d);
            // Clear document list
            docs.clear();
            // Re-add documents
            for (Document d : originalDocs) {
                Document doc = new Document();
                doc.setId(d.getId());
                DataHandler dh = d.getValue();
                ByteArrayOutputStream buffOS = new ByteArrayOutputStream();
                dh.writeTo(buffOS);
                byte[] buff = buffOS.toByteArray();
                DataSource source = new ByteArrayDataSource(buff, documents.getDocument(d.getId()).getMetadata().getMimeType());
                DataHandler dhnew = new DataHandler(source);
                doc.setValue(dhnew);
                docs.add(doc);
            }
            LOGGER.info(" SENDING TO ENDPOINT " + to);
            DocumentRepositoryProxy proxy = new DocumentRepositoryProxy(endpointUrl, new DirectSOAPHandlerResolver());
            RegistryResponseType rrt = proxy.provideAndRegisterDocumentSetB(prdst);
            String test = rrt.getStatus();
            if (test.indexOf("Failure") >= 0) {
                String error = "";
                try {
                    error = rrt.getRegistryErrorList().getRegistryError().get(0).getCodeContext();
                } catch (Exception x) {
                }
                throw new Exception("Failure Returned from XDR forward:" + error);
            }
            getAuditMessageGenerator().provideAndRegisterAuditSource(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
        }
        resp = getRepositoryProvideResponse(threadData.getMessageId());
        String relatesTo = threadData.getRelatesTo();
        threadData.setRelatesTo(threadData.getMessageId());
        threadData.setAction("urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse");
        threadData.setTo(null);
        threadData.save();
    } catch (Exception e) {
        e.printStackTrace();
        throw (e);
    }
    return resp;
}
Also used : DirectMessage(org.nhindirect.xd.common.DirectMessage) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) URI(java.net.URI) InitialContext(javax.naming.InitialContext) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) DirectDocuments(org.nhindirect.xd.common.DirectDocuments) MailClient(org.nhind.xdm.MailClient) SmtpMailClient(org.nhind.xdm.impl.SmtpMailClient) DirectSOAPHandlerResolver(org.nhindirect.xd.soap.DirectSOAPHandlerResolver) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) RegistryResponseType(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType) DocumentRepositoryProxy(org.nhindirect.xd.proxy.DocumentRepositoryProxy)

Example 15 with ProvideAndRegisterDocumentSetRequestType

use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType in project nhin-d by DirectProject.

the class XDRTest method testDocumentRepositoryProvideAndRegisterDocumentSetB.

/**
     * Test of documentRepositoryProvideAndRegisterDocumentSetB method, of class XDR.
     */
public void testDocumentRepositoryProvideAndRegisterDocumentSetB() throws Exception {
    System.out.println("documentRepositoryProvideAndRegisterDocumentSetB");
    QName qname = new QName("urn:ihe:iti:xds-b:2007", "ProvideAndRegisterDocumentSetRequestType");
    ProvideAndRegisterDocumentSetRequestType body = null;
    try {
        String request = getTestRequest();
        JAXBElement jb = (JAXBElement) XmlUtils.unmarshal(request, ihe.iti.xds_b._2007.ObjectFactory.class);
        body = (ProvideAndRegisterDocumentSetRequestType) jb.getValue();
    } catch (Exception x) {
        x.printStackTrace();
        fail("Failed unmarshalling request");
    }
    DocumentRepositoryAbstract instance = new XDR();
    // Set test objects
    instance.setAuditMessageGenerator(new AuditMessageGenerator(getLogfile()));
    // instance.setMailClient(new SmtpMailClient("gmail-smtp.l.google.com", "lewistower1@gmail.com", "hadron106"));
    instance.setResolver(new RoutingResolverImpl());
    XdConfig config = new XdConfig();
    config.setMailHost("gmail-smtp.l.google.com");
    config.setMailUser("lewistower1@gmail.com");
    config.setMailPass("hadron106");
    instance.setConfig(config);
    RegistryResponseType result = instance.documentRepositoryProvideAndRegisterDocumentSetB(body);
    if (result.getStatus().contains("Failure")) {
        // some organizational firewalls may block this test, so bail out gracefully if that happens
        return;
    }
    String sresult = null;
    try {
        qname = new QName("urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0", "RegistryResponseType");
        sresult = XmlUtils.marshal(qname, result, oasis.names.tc.ebxml_regrep.xsd.rs._3.ObjectFactory.class);
    } catch (Exception x) {
        x.printStackTrace();
        fail("Failed unmarshalling response");
    }
    // System.out.println(sresult);
    assertTrue(sresult.indexOf("ResponseStatusType:Success") >= 0);
}
Also used : QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) RoutingResolverImpl(org.nhindirect.xd.routing.impl.RoutingResolverImpl) XdConfig(org.nhind.xdr.config.XdConfig) AuditMessageGenerator(com.gsihealth.auditclient.AuditMessageGenerator) RegistryResponseType(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Aggregations

ProvideAndRegisterDocumentSetRequestType (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)12 DataHandler (javax.activation.DataHandler)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IOException (java.io.IOException)5 DirectDocuments (org.nhindirect.xd.common.DirectDocuments)5 TransformationException (org.nhindirect.xd.transform.exception.TransformationException)5 Document (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document)4 DataSource (javax.activation.DataSource)4 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)4 RegistryResponseType (oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 ArrayList (java.util.ArrayList)3 ZipFile (java.util.zip.ZipFile)3 URI (java.net.URI)2 Date (java.util.Date)2 ZipEntry (java.util.zip.ZipEntry)2 Address (javax.mail.Address)2 MessagingException (javax.mail.MessagingException)2 InitialContext (javax.naming.InitialContext)2