dcmjs-dimse icon indicating copy to clipboard operation
dcmjs-dimse copied to clipboard

add elements tags type and eventMap

Open CloudWoR opened this issue 2 years ago • 1 comments

I tried to add the enumeration of listening events of Server class, Client class and Request class, and added the type definitions of all Dicom tags

Dicom Tags export

export interface Types {
  T_DicomElements: Partial<DicomElements>;
  T_DicomElements_WML: Partial<DicomElements_WML>;
}

Server class

declare class Server extends AsyncEventEmitter<ServerEventName.EventMap<ServerEventMap>> {
   ...
    on(event: keyof ServerEventMap, listener: ServerEventName.EventMap<ServerEventMap>[keyof ServerEventMap]): this;
   ...
}

Client class

declare class Client extends AsyncEventEmitter<ServerEventName.EventMap<ClientEventMap>> {
  /**
   * Creates an instance of Client.
   */
  constructor();

  on(event: keyof ClientEventMap & string, listener: ServerEventName.EventMap<ClientEventMap>[keyof ClientEventMap]): this;
  ...
}

Reqeust class

declare class Request extends Mixin(Command, AsyncEventEmitter<ServerEventName.EventMap<RequestEventMap>>) {
  /**
   * Creates an instance of Request.
   */
  constructor(type: number, affectedOrRequestedClassUid: string, hasDataset: boolean);

  on<E extends keyof RequestEventMap>(event: E & string, listener: ServerEventName.EventMap<RequestEventMap>[E]): this;
  ...

evnetMap.dto.ts file


declare type ServerEventMap = {
  networkError: 'networkError',
  listening: 'listening',
  cEchoRequest: 'cEchoRequest'
}

declare type RequestEventMap = {
  response: 'response',
  instance: 'instance',
  done: 'done',
}

declare type ClientEventMap = {
  connected: 'connected',
  associationAccepted: 'associationAccepted',
  associationReleased: 'associationReleased',
  cStoreRequest: 'cStoreRequest',
  nEventReportRequest: 'nEventReportRequest',
  networkError: 'networkError',
  close: 'close',
}

declare namespace ServerEventName {
  type AsyncListener<T, R> = ((data: T, callback: (result?: R) => void) => Promise<R>) | ((data: T, callback: (result?: R) => void) => void);
  type EventMap<T> = {
    [event in keyof T]: AsyncListener<any, any>;
  };
}

My code is poorly written. I'm looking forward to your suggestions for modification

CloudWoR avatar Oct 04 '22 04:10 CloudWoR

Great work @CloudWoR! As I commented in the https://github.com/PantelisGeorgiadis/dcmjs-dimse/pull/28, is there any way to extract the DicomElements and DicomElements_WML (which can be consolidated, they both contain DICOM tags) information from dcmjs's dictionary?

PantelisGeorgiadis avatar Oct 06 '22 05:10 PantelisGeorgiadis