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

Allow for the creation of FHIR Profiles + Metadata without the passing of string paths to JavaScript files #249

Closed
zeevo opened this issue Sep 7, 2020 · 10 comments
Assignees

Comments

@zeevo
Copy link
Contributor

zeevo commented Sep 7, 2020

Do you want to request a feature, report a bug, or improve documentation?

feature

Currently, node-fhir-server-core works by providing the server with paths to JavaScript files, in which node-fhir-server-core then requires these modules in order to create REST + Search endpoints. But there is a problem with this design: File paths may not exist (dealing with relative pathing vs absolute pathing decreases Developer Experience), and more importantly: You cannot support TypeScript or Babel-ified projects. The reason being, is that transpiling changes file names and file locations.

I order to support a multitude of Developer Experiences and environments, node-fhir-server-core should support the creation of FHIR resource endpoints programmatically in the form of a addService, addMetadata API.

Thanks @Ahryman40k and Issue #213 for highlighting this issue.

A final solution has yet to be agreed upon.

@zeevo zeevo self-assigned this Sep 7, 2020
@Ahryman40k
Copy link

Ahryman40k commented Sep 23, 2020 via email

@zeevo
Copy link
Contributor Author

zeevo commented Oct 7, 2020

Right-- so I want to get some work done on this and do a 3.0.0 release along with #256

I'm thinking of a new way to use node-fhir-server-core in a better, more programmatical way. Something along the lines of...

const { FHIRServer, VERSIONS, Profile } = require('@asymmetrik/node-fhir-server-core');

const config = require('./config');
const db = require('./db');

class Patient extends Profile {
  constructor() {
    super({ version: VERSIONS['4_0_0'] });
  }
  searchById({ id }) {
    return db.findByPk(id);
  }

  async create({ resource }) {
    const { id } = await db.create(resource);
    return id;
  }

  // and so on for searchByVersionId, update, remove, etc
}

const server = new FHIRServer(config);

server.addProfile(Patient);

server.listen();

Thoughts? Perhaps there is a better way of doing this?

@Ahryman40k
Copy link

Hi @zeevosec,

You come here with an OOP solution. But depending of what Profile exposes and what FHIR resources need ( searchById, create, custom ? ... ) you can quickly drive into hell.
There is of course another ways, no one is right or wrong but both have pro and cons.
What do you think about decorator + metadata solution ? (See angular, nestjs, etc ... ) A lot of modern frameworks use that way. Of course multiplying decoration over classes and methods is also a bit tedious, plus you need a start point to init everything ( see boostrap method in angular or nestjs). It also looks like black magic !
Finally you can also have a functional programming approach and deal with a way to push methods the object could contain provided from a client side. It makes type more abstract, difficult to maintain and you need to have a good knowledge of the framework.

Hope this helps to start a discussion
:)

@sychus
Copy link
Contributor

sychus commented Oct 8, 2020

Hi @zeevosec.
Yes! I agree with that approach. Maybe it's also a good time to migrate to typescript!. If you need help, count on me! ;-)

@Ahryman40k
Copy link

If you migrate to Typescript, I will be pleased to help ^^

@zeevo
Copy link
Contributor Author

zeevo commented Oct 9, 2020

I really like a decorator solution @Ahryman40k. What does this look like from the library consumer's point of view?

I also would like to migrate to TypeScript! @sychus

@Ahryman40k
Copy link

With a Typescript library, you can use Javascript or Typescript client code.
Decorators make possible to annotate and modify classes and properties at design time. In javascript, it looks like:

class C {
  @enumerable(false)
  method() { }
}

function enumerable(value) {
  return function (target, key, descriptor) {
     descriptor.enumerable = value;
     return descriptor;
  }
}

I also invite you to read this article.
Decorators are just functions, it means you also need a metadata mechanism, see this article too

Even if these mechanisms are mostly used in Typescript with Angular, they are available in Javascript ! Even If I'm not 100% sure, I think it's available for ES5. It means from consumer point of view, there is no need to move to Typescript. Although I strongly encouraged them to do so for a lot of reasons :)

@zeevo
Copy link
Contributor Author

zeevo commented Oct 9, 2020

I believe the "@" syntax is still experimental, meaning consumers would be required to be either in TypeScript or in an experimental NodeJS release. Correct me if I'm wrong.

Decorator Proposal for ES6

I want to find a way where older node versions are supported, and TypeScript is not a requirement for consumers.

@zeevo zeevo pinned this issue Oct 9, 2020
@zeevo zeevo changed the title Allow for the creation of FHIR resources + services + metadata without the passing of string paths to JavaScript files Allow for the creation of FHIR Profiles + Metadata without the passing of string paths to JavaScript files Oct 9, 2020
@Ahryman40k
Copy link

Ahryman40k commented Oct 9, 2020

@zeevosec
When you said

older node versions

You think above what version ?

I don't know how to use this.

@dominathan dominathan unpinned this issue Apr 29, 2021
@luan-dev
Copy link
Contributor

Closing stale issue. Please reopen if this is a mistake

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

No branches or pull requests

4 participants