Skip to Content
go-dicom(3)
Packages

dicomweb

DICOMweb (PS3.18) over HTTP: a client for QIDO-RS search, WADO-RS retrieve and STOW-RS store, and a server, an http.Handler, that answers the same services over an archive.

import "github.com/amrshadid/go-dicom/dicomweb" · pkg.go.dev

When to use it

  • Search, fetch or upload against a DICOMweb archive (client).
  • Put an HTTP face on an archive you already have, or on a dcmstore store that also answers DIMSE (server).

The command line's qido, wado and stow use the client, and qrscp -web the server.

How it fits together

The server speaks HTTP and leaves storage and matching to the Backend. *dcmstore.Store is a Backend as it is, so one archive can answer DIMSE and HTTP alike.

Key types and functions

NameWhat it is for
NewClient, ClientA client for a base URL such as https://host/dicom-web.
WithBearerToken, WithBasicAuth, WithHTTPClientCredentials and transport.
WithMaxResponseBytesBound what a response may hold.
Client.SearchForStudies, QueryQIDO‑RS; matches, fields, limit and offset.
Client.SearchEachThe same, one result at a time.
Client.RetrieveStudy, Client.RetrieveInstanceWADO‑RS instances as data sets.
Client.RetrieveEach, Client.RetrieveStreamInstances one at a time, without holding all of them.
Client.RetrieveMetadata, Client.RetrieveFrames, Client.RetrieveRenderedMetadata, frames, and rendered pictures.
Client.Store, Client.StoreDatasets, StoreResultSTOW‑RS from files or data sets, with what was stored and what failed.
NewServer, Server, BackendThe server and the archive it serves.
WithMaxStoreBytes, WithFrameEncodingServer limits and how frames are sent.
StatusError, ResponseTooLargeErrorHTTP failures and a response past the bound.

Example

// Serve an archive over DICOMweb, then store, search and retrieve through
// the client. Both ends run in one program.
package main

import (
	"context"
	"fmt"
	"log"
	"net"
	"net/http"
	"os"

	"github.com/amrshadid/go-dicom/dcmstore"
	"github.com/amrshadid/go-dicom/dicomweb"
)

func main() {
	ctx := context.Background()

	store, err := dcmstore.Open(os.Args[1]) // the archive directory
	if err != nil {
		log.Fatal(err)
	}
	ln, err := net.Listen("tcp", "127.0.0.1:43180")
	if err != nil {
		log.Fatal(err)
	}
	mux := http.NewServeMux()
	mux.Handle("/dicom-web/", http.StripPrefix("/dicom-web", dicomweb.NewServer(store)))
	srv := &http.Server{Handler: mux}
	go srv.Serve(ln)
	defer srv.Close()

	client, err := dicomweb.NewClient("http://127.0.0.1:43180/dicom-web")
	if err != nil {
		log.Fatal(err)
	}

	// STOW-RS: send a Part 10 file as it is.
	file, err := os.ReadFile(os.Args[2])
	if err != nil {
		log.Fatal(err)
	}
	stored, err := client.Store(ctx, "", file)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("stored:", len(stored.Stored), "failed:", len(stored.Failed))

	// QIDO-RS: each result is a data set, as a C-FIND result is.
	studies, err := client.SearchForStudies(ctx, dicomweb.Query{
		Match: map[string]string{"PatientName": "Compressed*"},
		Limit: 10,
	})
	if err != nil {
		log.Fatal(err)
	}
	for _, s := range studies {
		study := s.GetStringByKeyword("StudyInstanceUID")
		fmt.Println("study:", s.GetStringByKeyword("PatientName"), study)

		// WADO-RS: the instances without their bulk data.
		meta, err := client.RetrieveMetadata(ctx, study, "", "")
		if err != nil {
			log.Fatal(err)
		}
		for _, m := range meta {
			fmt.Println("  instance:", m.GetStringByKeyword("SOPInstanceUID"), m.GetStringByKeyword("Modality"))
		}
	}
}

It serves a dcmstore archive on 127.0.0.1:43180, stores CT_small.dcm (stored: 1 failed: 0), finds its study and lists its instance's metadata.

Notes

  • The client reads a response up to DefaultMaxResponseBytes unless WithMaxResponseBytes says otherwise; the server reads a STOW-RS request up to DefaultMaxStoreBytes unless WithMaxStoreBytes says otherwise.
  • The server matches literally; a request for fuzzy matching is answered with a warning.
  • Rendered pictures use Dataset.RenderFrame; see Rendering.
  • What is served, and with which media types, is in CONFORMANCE.md §4.1.

Caution

The server does not authenticate. It serves whatever the archive holds to whoever reaches it. Wrap it in a handler that decides who may, and serve it over TLS.

See also

dcmstore · network · matching · DICOMweb client · DICOMweb server · TLS and security

On this page