use crate::dicom::*;
use crate::job::JobInfo;
use compact_str::CompactString;
use nutype::nutype;
use serde::{Deserialize, Serialize};
#[nutype(derive(Serialize, Deserialize, Clone, Display, Debug, Eq, PartialEq, Hash))]
pub struct QueryId(String);
impl ResourceId for QueryId {
type Item = Vec<CompactString>;
fn uri(&self) -> String {
format!("/queries/{}", &self)
}
}
#[nutype(derive(Serialize, Deserialize, Clone, Display, Debug, Eq, PartialEq, Hash))]
pub struct JobId(String);
impl ResourceId for JobId {
type Item = JobInfo;
fn uri(&self) -> String {
format!("/jobs/{}", &self)
}
}
#[nutype(derive(Serialize, Deserialize, Clone, Display, Debug, Eq, PartialEq, Hash))]
pub struct PatientId(String);
impl ResourceId for PatientId {
type Item = Patient<Option<()>>;
fn uri(&self) -> String {
format!("/patients/{}", &self)
}
}
impl<T> DicomResourceId<T> for PatientId {
type Item = Patient<T>;
}
impl AnonymizableId for PatientId {}
impl HierarchalResourceId for PatientId {
type Ancestor = PatientId;
}
#[nutype(derive(Serialize, Deserialize, Clone, Display, Debug, Eq, PartialEq, Hash))]
pub struct StudyId(String);
impl ResourceId for StudyId {
type Item = Option<()>;
fn uri(&self) -> String {
format!("/studies/{}", &self)
}
}
impl<T> DicomResourceId<T> for StudyId {
type Item = Study<T>;
}
impl HierarchalResourceId for StudyId {
type Ancestor = PatientId;
}
impl AnonymizableId for StudyId {}
#[nutype(derive(Serialize, Deserialize, Clone, Display, Debug, Eq, PartialEq, Hash))]
pub struct SeriesId(String);
impl ResourceId for SeriesId {
type Item = Option<()>;
fn uri(&self) -> String {
format!("/series/{}", &self)
}
}
impl<T> DicomResourceId<T> for SeriesId {
type Item = Series<T>;
}
impl HierarchalResourceId for SeriesId {
type Ancestor = StudyId;
}
impl AnonymizableId for SeriesId {}
#[nutype(derive(Serialize, Deserialize, Clone, Display, Debug, Eq, PartialEq, Hash))]
pub struct InstanceId(String);
impl ResourceId for InstanceId {
type Item = Option<()>;
fn uri(&self) -> String {
format!("/instances/{}", &self)
}
}
impl<T> DicomResourceId<T> for InstanceId {
type Item = Instance<T>;
}
impl HierarchalResourceId for InstanceId {
type Ancestor = SeriesId;
}
pub trait ResourceId {
type Item: serde::de::DeserializeOwned;
fn uri(&self) -> String;
}
impl<T> ResourceId for &T
where
T: ResourceId,
{
type Item = T::Item;
fn uri(&self) -> String {
(*self).uri()
}
}
pub trait AnonymizableId: ResourceId {
fn anonymize_uri(&self) -> String {
format!("{}/anonymize", self.uri())
}
}
impl<T> AnonymizableId for &T
where
T: AnonymizableId,
{
fn anonymize_uri(&self) -> String {
(*self).anonymize_uri()
}
}
pub trait DicomResourceId<T>: ResourceId {
type Item: DicomResource<T>;
}
impl<I, T> DicomResourceId<T> for &I
where
I: DicomResourceId<T>,
{
type Item = <I as DicomResourceId<T>>::Item;
}
pub trait HierarchalResourceId: ResourceId {
type Ancestor: ResourceId;
}
impl<T> HierarchalResourceId for &T
where
T: HierarchalResourceId,
{
type Ancestor = T::Ancestor;
}
pub trait RequestedTags {
fn names() -> &'static [&'static str];
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct DeleteResponse<T> {
pub remaining_ancestor: Option<IdAndPath<T>>,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Hash)]
pub struct IdAndPath<T> {
#[serde(rename = "ID")]
pub id: T,
#[serde(rename = "Path")]
pub path: String,
}