openmrs.js (JavaScript API Wrapper)

@pascal for the use of Concepts OWA we’ve created https://github.com/rkorytkowski/openmrs-owa-conceptdictionary/blob/master/app/js/openmrs.js which allows us to easily work with openmrs rest resources. You could see how it is used here https://github.com/rkorytkowski/openmrs-owa-conceptdictionary/blob/master/app/js/classAdd.controller.js#L2525 It is simple enough for us and we can CRUD on virtually any resource. I’m currently working on adding support for paging of results and it will be complete.

That said I haven’t seen any js API auto-generated from swagger and I’m interested how it would improve the experience.

We would be happy to contribute the openmrsRest service to common openmrs.js.

3 Likes

Is it possible to define JS objects for all the domain model ? Using just associative maps and converting to JSON seems a bit fragile. In this particular case, concept class attributes are defined in the controller and are not reusable.

Okay thanks @raff, I hadn’t seen that. Let me get an initial version of auto-generated code ready and then we can compare the approaches.

1 Like

One of our priorities (IMO more important than json forms) should be to provide a way to translate OWA pages based on the locale selected in OpenMRS together with Transifex support.

3 Likes

Thanks @raff, good point. I’ll create a ticket for tracking this work.

I’m curious about how to approach this. I know how to solve it in Angular, and other frameworks have similar mechanisms.

But if we want a static framework-independent solution to this, we need something like a preprocessor that is run on html files as we serve them up. (Note that we would not actually want to use the current cookie locale resolver in that case, since it would make the static resources uncacheable.) This, however, is totally antithetical to how OWAs are supposed to work.

I was thinking about this in the context of how letting a distro or sysadmin configure some global CSS to be applied to every page (even OWA ones) in this comment (my code snippet was eaten my markdown, so I just fixed that now):

At this point I think the right approach is to just promote best-practice usage of a particular AngularJS approach (by default I’d choose the one Bahmni chose) + the same for other frameworks. (Including for my global CSS example, where that CSS can be loaded dynamically via JS.) But I’m curious whether anyone else thinks that macro preprocessing of the HTML files we serve is even worth considering.

1 Like

I agree with this. Also, l10n is done in the presentation layer, so should be done in an idiomatic way for whatever presentation tool is being used. That said, I think it would be good to take a look at some frameworks (Angular, React, etc) and try to provide whatever services might be useful.

https://issues.openmrs.org/browse/OMRSJS-6

1 Like

We’ve moved our angular approach to OpenMRS resources to a separate repo. This should make it easier for others to use if interested.

2 Likes

I’ve put together an initial proof of concept here: https://github.com/psbrandt/openmrs.js. This version currently does nothing besides wrap the Swagger object, but you’re all welcome to take a first look.

1 Like

So one nitpick – Shouldn’t lib/ be ignored, and be created during the build process? If you want – Travis can generate development and/or nightly builds – if that’s your end goal…just a suggestion.

My reasoning is that it is a build artifact and shouldn’t be cluttering the VCS history. It’s why we don’t track bower_components and node_modules.

1 Like

It’s debatable. Some big projects like bootstrap and lodash publish build artifacts to GitHub. Some other projects do this, but not in the master branch. I believe the reason for this is to enable installing with Bower.

That said, I’ve removed the lib directory, since I’m actually in favor of npm for all the things.

2 Likes

We need moar shields (because @michael nitpicked)

This one is teed up for you, @burke ^^

2 Likes
1 Like

I am a huge fan of http://forthebadge.com/

2 Likes

I published some examples of how openmrs.js can be used here. So far I have:

  1. Basic node console usage
  2. A script to create random patients
  3. Basic browser console usage

Feedback welcome :slight_smile:.

3 Likes

Pascal, any interest in giving a demo during a call?

2 Likes

Sure @jdick. Pretty much everything you need to know is in the README and in the examples, but I’m happy to give a demo if people would like one.

I’m working on a React example with some friends, but it isn’t ready yet.

It looks like the library has been installed quite a few times. Does anyone have any feedback?

2 Likes

I can’t agree more with this:

4 Likes

That article pretty much nailed it.