Skip to content

psbrandt/openmrs-contrib-reactexample

Repository files navigation

OpenMRS OpenMRS

OpenMRS React Example Application

Demonstration of using React and openmrs.js

💡 This is a small app hacked together in a group programming session during the Stripe Open-Source Retreat. You probably shouldn't use it for anything.

Use this Example

Clone the repository and then run npm install to install all the dependencies.

Run npm start to start the application on localhost:3001.

OpenMRS Server

The OpenMRS server details are as follows:

openmrs.js basics

Installing openmrs.js

npm install openmrs.js

The web bundle will be at node_modules/openmrs.js/lib/openmrs.bundle.min.js.

Logging In

const o = new OpenMRS('https://openmrs.psbrandt.io/openmrs');

const deferred = o.login('admin', 'Admin123');

deferred.then(() => {
  // do stuff
});

Creating A Patient

Notes

  • Patient identifiers must be have a valid Luhn mod 30 check digit. See this example of how it's generated using luhn-mod-n.
  • Long UUIDs should be used as-is.

Minimum Info

const patient = {
  "person": {
    "names": [{
      "givenName": "Nik",
      "familyName": "Graf",
    }],
    "gender": "M",
  },
  "identifiers": [{
    "identifierType": "05a29f94-c0ed-11e2-94be-8c13b969e334", // fixed value
    "identifier": "9AW2N9PHC7WJ2FC7YLV",                      // valid Luhn mod 30 check digit
    "location": "8d6c993e-c2cc-11de-8d13-0010c6dffd0f",       // fixed value
  }]
};

o.api.patient.createPatient({
  resource: patient,
}).then(() => {
  // do more suff
}).catch((err) => {
  console.log(err);
});

More Info

const patient = {
  "person": {
    "names": [{
      "givenName": "Pascal",
      "familyName": "Brandt",
    }],
    "gender": "M",
    "birthdate": "1986-7-18",
    "addresses": [{
      "preferred": true,
      "address1": "546 Awejug Park",
      "cityVillage": "Cilbugaz",
      "stateProvince": "MB",
      "country": "Saint Lucia",
      "postalCode": "41156",
    }],
    "attributes": [{
      "attributeType": {
        "uuid": "14d4f066-15f5-102d-96e4-000c29c2a5d7",       // fixed value
      },
      "value": "(319) 498-9859",
    }]
  },
  "identifiers": [{
    "identifierType": "05a29f94-c0ed-11e2-94be-8c13b969e334", // fixed value
    "identifier": "9AW2N9PHC7WJ2FC7YLV",                      // valid Luhn mod 30 check digit
    "location": "8d6c993e-c2cc-11de-8d13-0010c6dffd0f",       // fixed value
  }]
};

o.api.patient.createPatient({
  resource: patient,
}).then(() => {
  // do more suff
}).catch((err) => {
  console.log(err);
});

Patient Search

o.api.patient.getAllPatients({
  q: "Nik", // search query
  v: "full",
}).then((results) => {
  console.log(results.obj);
}).catch((err) => {
  console.log(err);
});

API Docs

License

MPL 2.0 w/ HD

About

🚀 Example OpenMRS app using React

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published