eXistDB简单通讯06(RPC)

  • 保存文件
  • 取回文件

1、GetFileRPC.java

package com.neohope.existdb.test;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Vector;

public class GetFileRPC {
    public static void GetXML(String documentId, String user, String pwd) throws Exception {
        String uri = "http://localhost:8080/exist/xmlrpc";
        XmlRpcClient client = new XmlRpcClient();
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL(uri));
        config.setBasicUserName(user);
        config.setBasicPassword(pwd);
        client.setConfig(config);

        HashMap<String, String> options = new HashMap<String, String>();
        options.put("indent", "yes");
        options.put("encoding", "UTF-8");
        options.put("expand-xincludes", "yes");
        options.put("process-xsl-pi", "no");

        Vector<Object> params = new Vector<Object>();
        params.addElement(documentId);
        params.addElement(options);
        String xml = (String)
                client.execute("getDocumentAsString", params);
        System.out.println(xml);
    }

    public static void GetXMLChuncked(String documentId, String outPath, String user, String pwd) throws IOException, XmlRpcException {
        String url = "http://localhost:8080/exist/xmlrpc";

        XmlRpcClient client = new XmlRpcClient();
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL(url));
        config.setBasicUserName(user);
        config.setBasicPassword(pwd);
        client.setConfig(config);

        Hashtable<String, String> options = new Hashtable<String, String>();
        options.put("indent", "no");
        options.put("encoding", "UTF-8");

        Vector<Object> params = new Vector<Object>();
        params.addElement(documentId);
        params.addElement(options);

        FileOutputStream fos = new FileOutputStream(outPath);
        HashMap<?, ?> ht = (HashMap<?, ?>) client.execute("getDocumentData", params);
        int offset = ((Integer) ht.get("offset")).intValue();
        byte[] data = (byte[]) ht.get("data");
        String handle = (String) ht.get("handle");
        fos.write(data);

        while (offset != 0) {
            params.clear();
            params.addElement(handle);
            params.addElement(new Integer(offset));

            ht = (HashMap<?, ?>) client.execute("getNextChunk", params);
            data = (byte[]) ht.get("data");
            offset = ((Integer) ht.get("offset")).intValue();
            fos.write(data);
        }
        fos.close();
    }

    public static void main(String args[]) throws Exception {
        String user = "neotest";
        String pwd = "neotest";
        //GetXML("/db/CDA/入院患者护理评估单05.xml", user, pwd);
        GetXMLChuncked("/db/PNG/兔子.png","兔子1.png", user, pwd);
    }
}

eXistDB简单通讯05(RPC)

  • 保存文件
  • 取回文件

1、SaveFileRPC.java

package com.neohope.existdb.test;

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.net.URL;
import java.util.Vector;

public class SaveFileRPC {
    public static void SaveXML(String xmlFilePath, String user, String pw) throws Exception {
        String url = "http://localhost:8080/exist/xmlrpc";
        String path = "/db/CDA/入院患者护理评估单05.xml";

        XmlRpcClient client = new XmlRpcClient();
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL(url));
        config.setBasicUserName(user);
        config.setBasicPassword(pw);
        client.setConfig(config);

        BufferedReader f = new BufferedReader(new FileReader(xmlFilePath));
        String line;
        StringBuffer xml = new StringBuffer();
        while ((line = f.readLine()) != null)
            xml.append(line);
        f.close();

        Vector<Object> params = new Vector<Object>();
        params.addElement(xml.toString());
        params.addElement(path);
        params.addElement(new Integer(0));
        Boolean result = (Boolean) client.execute("parse", params);

        if (result.booleanValue())
            System.out.println("document stored.");
        else
            System.out.println("could not store document.");
    }

    public static void SaveXMLChuncked(String xmlFilePath, String user, String pwd) throws Exception {
        String url = "http://localhost:8080/exist/xmlrpc";
        String path = "/db/PNG/兔子.png";

        XmlRpcClient client = new XmlRpcClient();
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL(url));
        config.setBasicUserName(user);
        config.setBasicPassword(pwd);
        client.setConfig(config);

        Vector<Object> params = new Vector<Object>();
        String handle = null;
        InputStream fis = new FileInputStream(xmlFilePath);
        byte[] buf = new byte[4096];
        int len;
        while ((len = fis.read(buf)) > 0) {
            params.clear();
            if (handle != null) {
                params.addElement(handle);
            }
            params.addElement(buf);
            params.addElement(new Integer(len));
            handle = (String) client.execute("upload", params);
        }
        fis.close();

        params.clear();
        params.addElement(handle);
        params.addElement(path);
        params.addElement(new Boolean(true));
        params.addElement("image/png");
        Boolean result = (Boolean) client.execute("parseLocal", params); // exceptions

        if (result.booleanValue())
            System.out.println("document stored.");
        else
            System.out.println("could not store document.");
    }

    public static void main(String args[]) throws Exception {
        String user = "neotest";
        String pwd = "neotest";
        SaveXML("PATH_TO_FILE\\入院患者护理评估单05.xml", user, pwd);
        //SaveXMLChuncked("D:\\MyProjects\\IDEA14\\TestExistDB\\XMLFiles\\兔子.png", user, pwd);
    }
}

eXistDB简单通讯04

  • 保存文件
  • 取回文件
  • 查询
  • 嵌套查询

1、Base.java

package com.neohope.existdb.test;

import org.exist.util.serializer.SAXSerializer;
import org.exist.util.serializer.SerializerPool;

import javax.xml.transform.OutputKeys;
import java.io.OutputStreamWriter;
import java.util.Properties;

public class Base {
    protected final static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";
    protected final static String driver = "org.exist.xmldb.DatabaseImpl";
    protected static  Class<?> cl = null;

    static{
        try {
            cl = Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    protected static SAXSerializer getSAXSerializer()
    {
        Properties outputProperties = new Properties();
        outputProperties.setProperty(OutputKeys.INDENT, "yes");
        SAXSerializer serializer = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
        serializer.setOutput(new OutputStreamWriter(System.out), outputProperties);
        return serializer;
    }

    protected static void releaseSAXSerializer(SAXSerializer serializer) {
        SerializerPool.getInstance().returnObject(serializer);
    }
}

Continue reading eXistDB简单通讯04

eXistDB简单通讯03

  • 保存文件
  • 取回文件
  • 查询
  • 嵌套查询

1、Base.java

package com.neohope.existdb.test;

import org.exist.util.serializer.SAXSerializer;
import org.exist.util.serializer.SerializerPool;

import javax.xml.transform.OutputKeys;
import java.io.OutputStreamWriter;
import java.util.Properties;

public class Base {
    protected final static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";
    protected final static String driver = "org.exist.xmldb.DatabaseImpl";
    protected static  Class<?> cl = null;

    static{
        try {
            cl = Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    protected static SAXSerializer getSAXSerializer()
    {
        Properties outputProperties = new Properties();
        outputProperties.setProperty(OutputKeys.INDENT, "yes");
        SAXSerializer serializer = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
        serializer.setOutput(new OutputStreamWriter(System.out), outputProperties);
        return serializer;
    }

    protected static void releaseSAXSerializer(SAXSerializer serializer) {
        SerializerPool.getInstance().returnObject(serializer);
    }
}

Continue reading eXistDB简单通讯03

eXistDB简单通讯02

  • 保存文件
  • 取回文件
  • 查询
  • 嵌套查询

1、Base.java

package com.neohope.existdb.test;

import org.exist.util.serializer.SAXSerializer;
import org.exist.util.serializer.SerializerPool;

import javax.xml.transform.OutputKeys;
import java.io.OutputStreamWriter;
import java.util.Properties;

public class Base {
    protected final static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";
    protected final static String driver = "org.exist.xmldb.DatabaseImpl";
    protected static  Class<?> cl = null;

    static{
        try {
            cl = Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    protected static SAXSerializer getSAXSerializer()
    {
        Properties outputProperties = new Properties();
        outputProperties.setProperty(OutputKeys.INDENT, "yes");
        SAXSerializer serializer = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
        serializer.setOutput(new OutputStreamWriter(System.out), outputProperties);
        return serializer;
    }

    protected static void releaseSAXSerializer(SAXSerializer serializer) {
        SerializerPool.getInstance().returnObject(serializer);
    }
}

Continue reading eXistDB简单通讯02

eXistDB简单通讯01

  • 保存文件
  • 取回文件
  • 查询
  • 嵌套查询

1、Base.java

package com.neohope.existdb.test;

import org.exist.util.serializer.SAXSerializer;
import org.exist.util.serializer.SerializerPool;

import javax.xml.transform.OutputKeys;
import java.io.OutputStreamWriter;
import java.util.Properties;

public class Base {
    protected final static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";
    protected final static String driver = "org.exist.xmldb.DatabaseImpl";
    protected static  Class<?> cl = null;

    static{
        try {
            cl = Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    protected static SAXSerializer getSAXSerializer()
    {
        Properties outputProperties = new Properties();
        outputProperties.setProperty(OutputKeys.INDENT, "yes");
        SAXSerializer serializer = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
        serializer.setOutput(new OutputStreamWriter(System.out), outputProperties);
        return serializer;
    }

    protected static void releaseSAXSerializer(SAXSerializer serializer) {
        SerializerPool.getInstance().returnObject(serializer);
    }
}

Continue reading eXistDB简单通讯01

eXistDB查询测试04入院记录HX

xquery version "3.0";
(:查询入院记录,并并给出住院号:)
collection('/db/HX_RYJL')/DocObjContent/NewCtrl[@Id='53119AC4B15CC61B_住院号']/Content_Text
xquery version "3.0";
(:查询入院记录,并并给出个人信息:)
for $DocObjContent in collection('/db/HX_RYJL')/DocObjContent
return
    <patient>
        <patientId value='{$DocObjContent/NewCtrl[@Id='53119AC4B15CC61B_住院号']}'></patientId>
        <area value='{$DocObjContent/NewCtrl[@Id='CB608F4C0FA682EF_病区名称']}'></area>
        <patientName value='{$DocObjContent/NewCtrl[@Id='19BD50BF516552A7_患者姓名']}'></patientName>
        <breath value='{$DocObjContent/NewCtrl[@Id='77423F11443D7D11_性别中文']}'></breath>
        <patientId value='{$DocObjContent/NewCtrl[@Id='5F513A94E1DA8BD3_年龄']}'> </patientId>
    </patient>
xquery version "3.0";
(:查询入院记录,并并给出常用信息:)
for $DocObjContent in collection('/db/HX_RYJL')/DocObjContent
return
    <patient>
        <patientId value='{$DocObjContent/NewCtrl[@Id='53119AC4B15CC61B_住院号']}'></patientId>
        <area value='{$DocObjContent/NewCtrl[@Id='CB608F4C0FA682EF_病区名称']}'></area>
        <patientName value='{$DocObjContent/NewCtrl[@Id='19BD50BF516552A7_患者姓名']}'></patientName>
        <breath value='{$DocObjContent/NewCtrl[@Id='77423F11443D7D11_性别中文']}'></breath>
        <patientId value='{$DocObjContent/NewCtrl[@Id='5F513A94E1DA8BD3_年龄']}'> </patientId>
        <chiefComplaint value='{$DocObjContent/NewCtrl[@Id='主诉']}'> </chiefComplaint>
        <ethnic value='{$DocObjContent/NewCtrl[@Id='9B787211E2563732_民族']}'> </ethnic>
        <address value='{$DocObjContent/NewCtrl[@Id='BF4E1AEA9E7094D7_户口地址']}'> </address>
        <married value='{$DocObjContent/NewCtrl[@Id='AC26C755C722B756_婚否']}'> </married>
    </patient>

eXistDB查询测试03入院护理评估单

xquery version "3.0";
(:查询入院护理评估单CDA,并并给出患者体温:)
collection('/db/ZS_RYHLPGD')/ClinicalDocument/component/structuredBody/component/section/text/McsDocFormList/HiupMcsDocForm/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12365']/text
xquery version "3.0";
(:查询入院护理评估单CDA,并并给出患者的体温脉搏呼吸:)
for $RecordList in collection('/db/ZS_RYHLPGD')/ClinicalDocument/component/structuredBody/component/section/text/McsDocFormList/HiupMcsDocForm/hiupMcsDocFormRecordsList
return
    <patient>
        <tempture value='{$RecordList/HiupMcsDocFormRecords[nodeId='12365']/text}摄氏度'></tempture>
        <pulse value='{$RecordList/HiupMcsDocFormRecords[nodeId='12366']/text}次每分'></pulse>
        <bloodpressure value='{$RecordList/HiupMcsDocFormRecords[nodeId='12368']/text}'></bloodpressure>
        <breath value='{$RecordList/HiupMcsDocFormRecords[nodeId='12367']/text}次每分'></breath>
        <patientId value='{$RecordList/HiupMcsDocFormRecords[nodeId='12350']/text}'> </patientId>
    </patient>
xquery version "3.0";
(:查询入院护理评估单CDA,并并给出患者常用信息:)
for $RecordList in collection('/db/ZS_RYHLPGD')/ClinicalDocument/component/structuredBody/component/section/text/McsDocFormList/HiupMcsDocForm
return
    <patient>
        <name value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12347']/text}'></name>
        <age value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12355']/text}'></age>
        <sex value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12352']/text}'></sex>
        
        <tempture value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12365']/text}摄氏度'></tempture>
        <pulse value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12366']/text}次每分'></pulse>
        <bloodpressure value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12368']/text}'></bloodpressure>
        <breath value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12367']/text}次每分'></breath>
        
        <patientId value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12350']/text}'> </patientId>
        <flowId value='{$RecordList/patientId}'> </flowId>
        <area value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12348']/text}'></area>
        <bedno value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12349']/text}'></bedno>
        <indate value='{$RecordList/hiupMcsDocFormRecordsList/HiupMcsDocFormRecords[nodeId='12370']/text}'></indate>
    </patient>

eXistDB查询测试02病案首页HT

xquery version "3.0";
(:查询病案首页CDA,并并给出患者姓名:)
collection('/db/ZS_FrontPageEMR')/ClinicalDocument/component/structuredBody/component/section/text/List/BAVisit/baidname
xquery version "3.0";
(:查询病案首页CDA,并并给出患者的基本信息:)
for $ClinicalList in collection('/db/ZS_FrontPageEMR')/ClinicalDocument/component/structuredBody/component/section/text/List
return
    <patient>
        <name value='{$ClinicalList/BAVisit/baidname}'></name>
        <sex value='{$ClinicalList/BAVisit/baidsexname}'></sex>
        <birthTime value='{$ClinicalList/BAVisit/baidbirthday}'></birthTime>
        <age value='{$ClinicalList/BAVisit/bamxage}'></age>
        <nationality value='{$ClinicalList/BAVisit/baidnative}'></nationality>
        <address value='{$ClinicalList/BAPatientRecordInfo/baidxzz}'></address>
        <ethnic value='{$ClinicalList/BAVisit/baidnation}'></ethnic>
        <phone value='{$ClinicalList/BAPatientRecordInfo/bamxlxtele}'></phone>
        
        <patientId value='{$ClinicalList/BAVisit/bamxprn}'> </patientId>
        <flowId value='{$ClinicalList/BAVisit/bamxjzh}'> </flowId>
    </patient>

Continue reading eXistDB查询测试02病案首页HT

eXistDB查询测试01病案首页EMR

(:查询文档标题:)
xquery version "3.0";
collection('/db/ZS_FrontPageBA/病案首页01')/ClinicalDocument/title
(:查询患者ID:)
xquery version "3.0";
collection('/db/ZS_FrontPageBA')/ClinicalDocument/recordTarget/patientRole/id[@assigningAuthorityName='XDS.Patientid' and @root='2.16.840.1.113883.4.487.2.1.4']
xquery version "3.0";
(:查询患者的id,并修改返回结构:)
for $anid in collection('/db/ZS_FrontPageBA')/ClinicalDocument/recordTarget/patientRole/id[@assigningAuthorityName='XDS.Patientid' and @root='2.16.840.1.113883.4.487.2.1.4']
return
    <patient patientId='{$anid/@extension}' patientDomain='{$anid/@root}'> </patient>
(:查询患者入院诊断:)
xquery version "3.0";
for $diagnose in collection('/db/ZS_FrontPageBA')/ClinicalDocument/component/structuredBody/component/section[title="入院诊断"]/text
return
    <indiagnose value='{$diagnose}'></indiagnose>

Continue reading eXistDB查询测试01病案首页EMR