Home

Node App

System Setup

  1. Download and install NodeJS
  2. Download and install git bash
  3. Open the git bash tool
  4. Navigate to the directory for the project to be installed
  5. Clone the project
    $ git clone git@github.com:CognizantStudio/medvantage-xml-submitter.git
  6. Go into the newly created directory
    $ cd medvantage-xml-submitter
  7. Change to the master branch
    $ git checkout master

Initial Application Setup

  1. Install the node modules
    $ npm install
  2. Copy the .env.example file
    cp .env.example .env
  3. Edit the .env file to have the currect credentials, change the NODE_ENV=test, to NODE_ENV=production

Setup directories

Here is the list of directories that need to be created at root level of the project. The name can be changed if the .env is also changed, below are the default names.

  • submission: This is the folder where the server will write the XML documents to, this is the folder where AS2 checks for new files.
  • submissionQueue: This is where the /queuedXMLs endpoint writes XML documents to, for queueing.
  • responses: This is where the MDN messages are read from. This is where OpenAS2 writes response messages.
  • backups: This directory is where the server moves MDN files that have been processed from the responses folder.
  • ack_responses: This is where the Ack2 and Ack3 messages are read from. This is where OpenAS2 writes response messages.
  • ack_backups: This directory is where the server moves Ack2 and Ack3 files that have been processed from the ack_responses folder.

Databases

There are 3 tables in the database, Clients, Transactions, and Logs

  • Clients is the users are stored, contains their credentials for accessing the API Layer
  • Transactions is where status data of submitted XMLs are stored
  • Logs is where everything that happens on the server is stored

Database Setup

  1. Download and install 8129231484
  2. Change the production object in config/config.json to have the proper username, password, and host.
  3. Create the database.
    $ node_modules/.bin/sequelize db:create
  4. Migrate the database.
    $ node_modules/.bin/sequelize db:migrate
  5. Seed the database.
    $ node_modules/.bin/sequelize db:seed:all

Building the Server

  1. Build the server
    $ npm run Build
    Note: this will create a new folder at the same level as medvantage-xml-submitter, called medvatage-xml-submitter-production

Production

IIS Node

Documentation for IIS Node can be found here: 4434625981

IIS Node is the connecting code that allows a Node.js app to run on IIS. On the production server (currently 18.220.210.55), any thing placed into the directory C:\Program Files\iisnode\www\ will be accessible on the webserver. You can find all the code for this project in C:\Program Files\iisnode\www\medvantage-xml-transformer-node\.

Pushing Changes to Production

To update change from github to the production server, just navigate to the projects root folder in a bash terminal and run

$ git pull

Then restart the server.

$ npm start

Scheduled Jobs (Deprecated)

There are no more scheduled tasks. Just running npm start will do all the things.

Environment Variables

  • SALT_ROUNDS - Number of rounds for the salting hash for authToken on the Client model.
  • JWT_SECRET - Secret hash used for creating JWT.
  • SUBMISSION_DIR - The directory in which to save the new XML files, this is the folder that OpenAS2 watches and then sends the XML files to the FDA.
  • RESPONSE_DIR - The directory that the mdn_response_job.js watches for MDN responses. Note, in mdn_response_job.js, it appends the date to the end of this variable in the format of 2018-04-20.
  • ACK_RESPONSE_DIR - The directory that the response_job.js watches for MDN responses.
  • BACKUP_DIR - The directory that stores the MDN responses after mdn_response_job.js has read and sent the response back to Salesforce.
  • ACK_BACKUP_DIR - The directory that stores the ACK responses after response_job.js has read and sent the response back to Salesforce.
  • NODE_ENV - The current environment, should be set to production
  • PORT - Mostly used for development, iisnode should automatically set this.
  • SF_CLIENT_ID - Salesforce client id.
  • SF_CLIENT_SECRET - Salesforce client secret.
  • SF_GRANT_TYPE - Salesforce grant type.
  • SF_USERNAME - Salesforce username.
  • SF_PASSWORD - Salesforce password.

API Documentation

Postman Collection

POST "/login"

Use this endpoint to Login to the application. This uses standard JWT authentication, you provide a username and authToken (password) and POST it to this endpoint, this endpoint then returns a JWT that then gets appended to the header of any subsequent call to the API. Place the JWT as a bearer token in an Authorization header.

Exmaple

POST /login HTTP/1.1
Host: localhost:3000
Content-Type: application/json

{
    "username": "Client2",
    "authToken": "abc123"
}

Example Return JSON:

{
    "message": "ok",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaWF0IjoxNTI3ODcxMjYxfQ.x7XIKELzIyyBnAFZU20Svy10PR3XbOdKVLotKfaIU2U"
}

POST "/queuedXMLs"

Use this endpoint to submit XML to the FDA. This uses standard JWT authentication, place the JWT received on /login as a bearer token in an Authorization header. The endpoint will validate the XML against the XSD, re-format and include attachments as a base64-encoded zip, and submit the FDA if there are no errors.

Exmaple

POST /queuedXMLs HTTP/1.1
Host: localhost:3000
Content-Type: text/xml
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTI3ODcwODgzfQ.gRGbSzQAaZiZqs-luWYMRLR_GsxjdaxpCNxInLNzjMo

{
    "<?xml version="1.0" encoding="UTF-8"?><xmlHere></xmlHere>"
}

Example Return JSON:

{
    "message": "Successfully validated and submitted XML."
}

PUT "/transactions/:id"

Use this endpoint to update the status of a given transaction. Authentication is required.

Example

PUT /status/e8f0b548-018a-4c82-a78b-658f975e5b5e HTTP/1.1
Host: localhost:3000
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTI3ODcwODgzfQ.gRGbSzQAaZiZqs-luWYMRLR_GsxjdaxpCNxInLNzjMo
Content-Type: application/json

{
    "status": "Completed"
}

Example Returned JSON:

{
    "fdaTransaction": {
        "id": "e8f0b548-018a-4c82-a78b-658f975e5b5e",
        "status": "Completed",
        "submissionDate": "2018-05-31T19:08:07.109Z",
        "createdAt": "2018-05-31T19:08:07.110Z",
        "updatedAt": "2018-06-05T15:05:42.293Z",
        "ClientId": "a5406b3e-b2a9-40af-9c1e-b2a239aea440"
    }
}

GET "/transactions/id:"

Use this endpoint to get the status of a given transaction. Authentication is required.

Example

GET /status/e8f0b548-018a-4c82-a78b-658f975e5b5e HTTP/1.1
Host: localhost:3000
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTI3ODcwODgzfQ.gRGbSzQAaZiZqs-luWYMRLR_GsxjdaxpCNxInLNzjMo
Content-Type: application/json

Example Returned JSON:

{
  "fdaTransaction": {
      "id": "e8f0b548-018a-4c82-a78b-658f975e5b5e",
      "status": "Started",
      "submissionDate": "2018-05-31T19:08:07.109Z",
      "createdAt": "2018-05-31T19:08:07.110Z",
      "updatedAt": "2018-05-31T19:08:07.110Z",
      "ClientId": "a5406b3e-b2a9-40af-9c1e-b2a239aea440"
  }
}