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

Memcached常用操作

*生产环境建议直接用linux

1、命令行直接运行
1.1、可以直接指定参数运行

#最大16M内存,监听11211端口,最大连接数8
memcached.exe -m 16 -p 11211 -c 8

1.2、可以注册为Windows服务,再运行

#注册为服务
memcached.exe -d install
#开启服务
memcached.exe -d start
#关闭服务
memcached.exe -d stop
#卸载服务
memcached.exe -d uninstall

Continue reading Memcached常用操作

MongoDB副本集(Java)

还是蛮简单的,驱动把任务全部做掉了

package com.djhu.mongodb.test;

import java.util.Arrays;

import org.bson.Document;

import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

public class ReplTest
{
	private static void testInsert() 
	{
		MongoClient mongoClient = new MongoClient(Arrays.asList(
				   new ServerAddress("172.16.172.4", 27017),
				   new ServerAddress("172.16.172.4", 27018),
				   new ServerAddress("172.16.172.4", 27019)));

		MongoDatabase db = mongoClient.getDatabase("test");
		MongoCollection collection = db.getCollection("person");
		
		Document doc = new Document();
		doc.put("name", "tuzi");
		doc.put("age", 27);
		doc.put("sex", "Female");
		collection.insertOne(doc);
	}

	public static void main(String[] args)
	{
		testInsert();
	}
}

如果遇到下面的错误,是因为用了localhost作为replSet的地址,重新config一下就好了

Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
	at java.net.Socket.connect(Socket.java:519)
	at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
	at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
	... 3 more
Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches PrimaryServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}, {address=localhost:27018, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}, {address=localhost:27019, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}, {address=localhost:27020, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
	at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:370)
	at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)
	at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
	at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
	at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68)
	at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:175)
	at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:141)
	at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:72)
	at com.mongodb.Mongo.execute(Mongo.java:747)
	at com.mongodb.Mongo$2.execute(Mongo.java:730)
	at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:482)
	at com.mongodb.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:277)
	at com.djhu.mongodb.test.ReplTest.testInsert(ReplTest.java:28)
	at com.djhu.mongodb.test.ReplTest.main(ReplTest.java:33)

Redis分片(Jedis)

Redis的分片技术一般是通过客户端或代理来实现的

1、用jedis实现分片的时候,服务端不需要做任何配置即可

package com.djhu.redis.test;

import java.util.ArrayList;
import java.util.List;

import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;

public class JedisShardTest
{
	public static void main(String[] args)
	{
		List<JedisShardInfo> jedisShardInfoList = new ArrayList<JedisShardInfo>();
		jedisShardInfoList.add(new JedisShardInfo("172.16.172.4", 6379));
		jedisShardInfoList.add(new JedisShardInfo("172.16.172.4", 6380));

		ShardedJedis sharded = new ShardedJedis(jedisShardInfoList);
		sharded.set("key01", "a");
		sharded.set("key02", "b");
		sharded.set("key03", "c");
		sharded.set("key04", "d");
		sharded.set("key05", "e");
		
		System.out.println(sharded.get("key03"));
	}
}

2、用Jedis连接池实现分片

package com.djhu.redis.test;

import java.util.ArrayList;
import java.util.List;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.util.Hashing;
import redis.clients.util.Sharded;

public class JedisSharedFactory
{
	// 最大可用连接数,默认值为8,如果赋值为-1则表示不限制
	private static int MAX_TOTAL = 256;
	// 最大空闲连接数,默认值为8
	private static int MAX_IDLE = 32;
	// 最小空闲连接数
	private static int MIN_IDLE = 4;
	// 最大等待连接毫秒数,默认值为-1表示永不超时
	private static int MAX_WAIT = 3000;
	// 连接redis超时时间
	private static int TIMEOUT = 3000;
	// true表示验证连接
	private static boolean TEST_ON_BORROW = true;

	//连接池
	private static ShardedJedisPool jedisPool = null;
	public static void initJedisPool()
	{
		try
		{
			JedisPoolConfig config = new JedisPoolConfig();
			config.setMaxTotal(MAX_TOTAL);
			config.setMaxIdle(MAX_IDLE);
			config.setMinIdle(MIN_IDLE);
			config.setMaxWaitMillis(MAX_WAIT);
			config.setTestOnBorrow(TEST_ON_BORROW);
			
			List<JedisShardInfo> jedisShardInfoList = new ArrayList<JedisShardInfo>();
			jedisShardInfoList.add(new JedisShardInfo("172.16.172.4", 6379));
			jedisShardInfoList.add(new JedisShardInfo("172.16.172.4", 6380));
			jedisPool = new ShardedJedisPool(config, jedisShardInfoList,Hashing.MURMUR_HASH,Sharded.DEFAULT_KEY_TAG_PATTERN);
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public synchronized static ShardedJedis getConnection()
	{
		try
		{
			if (jedisPool != null)
			{
				ShardedJedis resource = jedisPool.getResource();
				return resource;
			} else
			{
				return null;
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public static void returnResource(final ShardedJedis jedis)
	{
		if (jedis != null)
		{
			jedis.close();
		}
	}
	
	public static void main(String[] args)
	{
		initJedisPool();
		ShardedJedis redis = getConnection();
		redis.set("key10", "j");
		redis.set("key11", "k");
		redis.set("key12", "l");
		redis.set("key13", "m");
		redis.set("key14", "n");
		
		System.out.print(redis.get("key12"));
		
		returnResource(redis);
	}
}

Jedis连接Redis3 Cluster

1、源码如下

package com.djhu.redis.test;

import java.util.Set;
import java.util.HashSet;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

public class JedisClusterTest
{
	public static void main(String[] args)
	{
		Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();  
        jedisClusterNodes.add(new HostAndPort("172.16.172.4", 6379));  
        jedisClusterNodes.add(new HostAndPort("172.16.172.4", 6380));  
        jedisClusterNodes.add(new HostAndPort("172.16.172.4", 6381));  
        jedisClusterNodes.add(new HostAndPort("172.16.172.4", 6382));  
        jedisClusterNodes.add(new HostAndPort("172.16.172.4", 6383));  
        jedisClusterNodes.add(new HostAndPort("172.16.172.4", 7384));  
        
		//JedisCluster cluster = new JedisCluster(jedisClusterNodes,3000,1000);
        JedisCluster cluster = new JedisCluster(jedisClusterNodes);
		cluster.set("key10", "j");
		cluster.set("key11", "k");
		cluster.set("key12", "l");
		cluster.set("key13", "m");
		cluster.set("key14", "n");
		
		System.out.println(cluster.get("key12"));
		
	}
}

2、如果遇到下面错误,主要是因为建立cluster时,ip用了127.0.0.1。用其他ip重建一下cluster,就可以解决了。

Exception in thread "main" redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException: Too many Cluster redirections?
	at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:34)
	at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:68)
	at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:85)
	at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:68)
	at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:85)
	at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:68)
	at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:29)
	at redis.clients.jedis.JedisCluster.set(JedisCluster.java:75)