Orthanc服务器使用java上传dicom影像文件

Orthanc服务器搭好后就可以通过AET标识接收来自CT设备发送过来的dcm文件,也可以通过java代码直接发送dcm文件到接口。

代码如下:

复制代码
package mycmf.util;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths; 

/* todo:上传dcm文件到Orthanc服务器   */

public class httpost{ 
	
	String postUrl = "http://127.0.0.1:8042/instances/";
	String upfile = "d:/tmp/aaa.dcm" ;
	
	public static void main(String[] args) throws IOException {
		String ree     = "";
		String postUrl = "http://127.0.0.1:8042/instances/";
		String upfile1 = "d:/tmp/aaa.dcm" ;
		String upfile2 = "d:/tmp/bbb.dcm" ;
		String upfile3 = "d:/tmp/ccc.dcm" ;
		httpost http   = new httpost();
		       ree     =  http.postDcm(upfile1, postUrl , "");
			   System.out.println(ree);
			   ree     =  http.postDcm(upfile2, postUrl , "");
			   System.out.println(ree);
			   ree     =  http.postDcm(upfile3, postUrl , "");
			   System.out.println(ree);
	   /*
	   {
		   "ID" : "ab75a1a7-845fcc81-194b8484-e04fe3f4-7330b852",
		   "ParentPatient" : "38bf71cf-d3b6ba1d-db6cfb58-e793c50d-33538aa4",
		   "ParentSeries" : "c089267e-79df16ea-9d05eef9-584379bd-acf3fe5d",
		   "ParentStudy" : "3ab4506b-5a84e3f4-816c8a3c-9283b402-0eda4767",
		   "Path" : "/instances/ab75a1a7-845fcc81-194b8484-e04fe3f4-7330b852",
		   "Status" : "AlreadyStored"   <-- 重复传送同一个dcm文件会提示已保存
		}
		{
		   "ID" : "f929967c-6bb6581f-9d82fe8b-35d3d395-57ad17ba",
		   "ParentPatient" : "38bf71cf-d3b6ba1d-db6cfb58-e793c50d-33538aa4",
		   "ParentSeries" : "5b194237-b6ff79c1-6e885d0e-f97cfdfa-39c4212b",
		   "ParentStudy" : "3ab4506b-5a84e3f4-816c8a3c-9283b402-0eda4767",
		   "Path" : "/instances/f929967c-6bb6581f-9d82fe8b-35d3d395-57ad17ba",
		   "Status" : "Success"
		}
		{
		   "ID" : "3002cfed-1b0f01e2-01b90ca4-33d0fa15-298f206c",
		   "ParentPatient" : "38bf71cf-d3b6ba1d-db6cfb58-e793c50d-33538aa4",
		   "ParentSeries" : "5b194237-b6ff79c1-6e885d0e-f97cfdfa-39c4212b",
		   "ParentStudy" : "3ab4506b-5a84e3f4-816c8a3c-9283b402-0eda4767",
		   "Path" : "/instances/3002cfed-1b0f01e2-01b90ca4-33d0fa15-298f206c",
		   "Status" : "Success"
		}	    
	    * */
	}
	
	/* 上传dcm文件到Orthanc服务器   */
	/*
	 * String filePath = "E:\\Dicom\\20220331093824\\ExpMPR.303.5.dcm";
     * String ree =  HP.postDcm(filePath,"http://localhost:8042/instances/","");
	 * */
	public String postDcm(String filePath, String orthancUrl, String token) throws IOException {
		String ree = "";
        URL url = new URL(orthancUrl);
        HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();

        httpCon.setDoOutput(true);
        httpCon.setRequestMethod("POST");
      
        //Optional: 如果需要,可以加上token等其它header信息
        httpCon.setRequestProperty ("Authorization", "Bearer " + token);
      
        OutputStream os = httpCon.getOutputStream();
        byte[] bytes = Files.readAllBytes(Paths.get(filePath));
        os.write(bytes);
        os.flush();
        os.close();
        httpCon.connect();

        // 打印出response
        String result;
        BufferedInputStream bis = new BufferedInputStream(httpCon.getInputStream());
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        int result2 = bis.read();
        while(result2 != -1) {
            buf.write((byte) result2);
            result2 = bis.read();
        }
        result = buf.toString();
        bis.close();
        buf.close();
        httpCon.disconnect();
        //System.out.println(result);
        ree = result ;
        return ree ;
    }  
	
	
}

上传成功后出现两个序列组,一个1图,一个2图,因为我测试的3个dcm文件来自两组序列,Orthanc会自动识别所属分组。

文件上传后resources表里对应的记录:

相关推荐
北风toto8 小时前
银河麒麟 V10 内网 YUM 源修复实战教程(U盘中转版)
linux·服务器
韩曙亮8 小时前
【错误记录】网络配置问题处理 ( 获取服务器的 出口 和 入口 IP | 定位网络变化 )
服务器·网络·tcp/ip
开开心心就好8 小时前
文件关联被破坏怎么修?免费工具一键修复
java·服务器·开发语言·pdf·ocr·启发式算法·宽度优先
不停喝水8 小时前
【前端转全栈java速通课】 项目实战④12-14节 拦截器过滤器和全局配置-cors跨域设置-token体系-利用session做验证码
java·开发语言·前端·ai·容器
小白鸽i8 小时前
【linux】麒麟桌面版安装人大金仓V8
linux·运维
鱼宵8 小时前
Spring AI RAG 问答助手:回答带引用,AI 不再睁眼说瞎话
java·人工智能·spring·springai
Ruiery8 小时前
Linux 6.6内核内存管理深度解析(三):页表与缺页处理 — 虚拟地址怎么按需映射到物理页
linux·运维·服务器
研发小能8 小时前
DevOps 流水线怎么选?自研、开源拼装还是企业级平台
运维·开源·devops·嘉为蓝鲸
rannn_1118 小时前
项目缓存实战:热点 Key 击穿、缓存穿透与多级缓存架构
java·缓存·架构
迪康Defender8 小时前
终端安全行为分析:审计日志如何转化为业务报表?落地实践与避坑指南
运维·经验分享·安全·信息可视化·自动化·安全威胁分析·运维开发