Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add elements tags type and eventMap #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CloudWoR
Copy link

@CloudWoR CloudWoR commented Oct 4, 2022

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

@PantelisGeorgiadis
Copy link
Owner

Great work @CloudWoR!
As I commented in the #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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants