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表里对应的记录:

相关推荐
张宇Joaquin1 分钟前
鲲鹏统一并行加速库KUPL--众核并行能力介绍
java·开发语言·网络
宸津-代码粉碎机35 分钟前
AI攻防战升级!基于Spring AI构建Java应用自动免疫安全体系
java·大数据·开发语言·人工智能·python·安全·spring
爱喝水的鱼丶1 小时前
SAP-ABAP:ABAP 用户出口开发规范与避坑指南:10 类典型错误与运维方案
运维·性能优化·sap·abap·增强·经验交流·出口
博、、1 小时前
从零构建智慧场馆解决方案:架构设计与开发实践
大数据·运维
敢敢是只喵i1 小时前
给现有业务系统接 AI 助手,入口怎么选?网页聊天、自动化任务与本地 Agent 对比
运维·人工智能·ai·开源·自动化·安全架构
2601_963749102 小时前
越华环保集团数字化污水治理:端边云采集架构与平台对接实现
java·大数据·架构
xcLeigh2 小时前
Go入门:整数类型的溢出与安全边界
java·安全·golang
源码宝2 小时前
SpringBoot+Vue2 诊所门诊管理系统,完整前后端源码,可直接部署上线
java·源码·his系统·门诊系统·程序代码·诊所系统·门诊his
yychen_java2 小时前
九:Text-to-SQL 智能数据查询与 Human-in-the-Loop 人机协作
java·人工智能·架构
章老师说3 小时前
BFE v1.8.6 正式发布:AI 网关计费精细化、Claude 协议与会话亲和性升级
运维·人工智能·ai·负载均衡·ai-native