#openMEDIS REST API Specification v1
Base URL http://example.com/api/public/v1
===
- openMEDIS is a tool to collect, do inventory and process information on health technology infrastructure, e.g. medical devices. More information: http://www.swisstph.ch/?id=1245
- As an addition to the browser-based openMEDIS, the mobile client for Android phones lets you manage assets, requests an interventions with your openMEDIS account: Google Play Store
- This is the reference document for the REST API and resources for an openMEDIS database. The REST API is for developers who want to integrate openMEDIS with other standalone or web applications, and administrators who want to script interactions with the openMEDIS server. REST = Representational State Transfer: Link1, Link2
- All responses are gzip encoded to save bandwidth.
- All responses and requests should have the HTTP-Header:
Content-Type: application/json;charset=utf-8
- #1 Authentication
- #2 User/login
- #3-1 Create new asset
- #3-2 Update asset
- #3-3 Delete asset
- #4-1 Create new request
- #4-2 Update request
- #4-3 Delete request
- #5-1 Create new intervention
- #5-2 Update intervention
- #5-3 Delete intervention
- #5-4 Create new intervention material
- #5-4 Create new intervention work
- #6-1 Export whole database content
- #6-2 Export whole database metainformation
You can link to subtitles of this document with anchors, e.g. with example.com/#2-1
- The REST API uses a HMAC authentication.
- Currently, only the
/loginroute and this specification document at/can be accessed without authentication.
Every request needs two HTTP header fields, e.g. for the demo/demo user on a GET request:
X-PublicKey: 7286a32e66c2e8d38f6f51e91fa3d9ec4f33e09880a8c8835a2689e92236a1d4
X-Hash: e651e0f6450f89d82ab0a34c1d421097a635897f5e719179e49263ff145e6ed9
-
X-PublicKey: This is the Public Key associated with every user with a login. It is generated only once on the server (and can not be repeated to get a different Public Key) on a
/loginPOST request if valid credentials are provided (see 2.1 POST Login for details). -
X-Hash: This is the hash of the content in the HTTP request body and the private key stored internally on the client.
- The secret private key associated with every user: a SHA256 hash of the concatenated username and password, e.g. in PHP:
$private_key = hash('sha256', $username . $password); - The HTTP request body (on a GET request it is empty String). JSON request must be minified (whitespaces count for hash generation)
- So the whole X-Hash creation looks like this in PHP (similar "HMAC"-functions are available on many client platforms.)
$hash = hash_hmac('sha256', $content, $private_key);
- The secret private key associated with every user: a SHA256 hash of the concatenated username and password, e.g. in PHP:
If no valid headers are provided in the request, a 401 Unauthorized status code will throw with no response HTTP body.
Creates a keys (public/private) to use for the Authentication and returns attributes including the public key (the private key never gets sent) of this user. No Authentication headers required, only username and password:
#####Request example (should be minified)
{"username":"demo","password":"demo"}
Success 200 OK
{
"error": false,
"login_id": 123,
"username": "demo",
"group_id": 3,
"locale": "en"
"access_level": " AND (facilities.FacilityID = 11 OR facilities.FacilityID = 14 OR facilities.FacilityID = 13 OR facilities.FacilityID = 17 OR facilities.FacilityID = 16 OR facilities.FacilityID = 15 OR facilities.FacilityID = 12)",
"public_key": "7286a32e66c2e8d38f6f51e91fa3d9ec4f34e09881a8c8835a2689e92236a1d4"
}
Authorization required 401 Unauthorized
{
"error": true,
"message": "Login failed. Incorrect credentials"
}
Important: A user has only access to assets / requests / interventions based on his access level which is specified in the employee table. A request to /database/export returns only these based on the access level.
Creates a new asset
#####Request example (should be minified)
{
"AssetFullName": "Aparat ultrasonograf",
"GenericAssetID": 14278,
"UMDNS": 14278,
"ManufacturerID": "4b0bebf192bfb",
"Model": "Aloca SSD-1100",
"SerialNumber": "Mo2701",
"InternalIventoryNumber": "1381018",
"LocationID": "4b8fb11102c59",
"ResponsiblePers": "asistenta superioar?",
"AssetStatusID": 1,
"AssetUtilizationId": 1,
"PurchaseDate": "2002-01-10",
"InstallationDate": null,
"Lifetime": 7,
"PurchasePrice": 264295,
"CurrentValue": 0,
"WarrantyContractID": 2,
"AgentID": "4c90677ca7db7",
"WarrantyContractExp": null,
"WarrantyContractNotes": "nr.24 din 24.01.2010",
"EmployeeID": "4c91bf1be32f6",
"SupplierID": "4c497f7c7ef04",
"DonorID": "4cc6a5791a3bd",
"ServiceManual": "",
"Notes": null,
"Picture": "gen_images/14278.jpg",
"lastmodified": "2010-03-31 13:20:21",
"by_user": "anastasia",
"URL_Manual": null,
"MetrologyDocument": null,
"MetrologyDate": null,
"Metrology": null
}
Required params:
GenericAssetID, AssetFullName, ManufacturerID, Model, WarrantyContractID, SerialNumber, LocationID, DonorID, AssetStatusID, AssetUtilizationID, AgentID, SupplierID
Missing field(s) – 400 (Bad Request)
{
"error": true,
"message": "Required field Metrology missing, empty or null"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not create asset"
}
Success – 201 (Created)
{
"error": false,
"message": "Asset created"
}
Updates an existing asset
#####Request example (json should be minified)
{
"AssetFullName": "Aparat ultrasonograf",
"GenericAssetID": 14278,
"UMDNS": 14278,
"ManufacturerID": "4b0bebf192bfb",
"Model": "Aloca SSD-1100",
"SerialNumber": "Mo2701",
"InternalIventoryNumber": "1381018",
"LocationID": "4b8fb11102c59",
"ResponsiblePers": "asistenta superioar?",
"AssetStatusID": 1,
"AssetUtilizationId": 1,
"PurchaseDate": "2002-01-10",
"InstallationDate": null,
"Lifetime": 7,
"PurchasePrice": 264295,
"CurrentValue": 0,
"WarrantyContractID": 2,
"AgentID": "4c90677ca7db7",
"WarrantyContractExp": null,
"WarrantyContractNotes": "nr.24 din 24.01.2010",
"EmployeeID": "4c91bf1be32f6",
"SupplierID": "4c497f7c7ef04",
"DonorID": "4cc6a5791a3bd",
"ServiceManual": "",
"Notes": null,
"Picture": "gen_images/14278.jpg",
"lastmodified": "2010-03-31 13:20:21",
"by_user": "anastasia",
"URL_Manual": null,
"MetrologyDocument": null,
"MetrologyDate": null,
"Metrology": null
}
Required params:
GenericAssetID, AssetFullName, ManufacturerID, Model, WarrantyContractID, SerialNumber, LocationID, DonorID, AssetStatusID, AssetUtilizationID, AgentID, SupplierID
#####Response
Missing field(s) – 400 (Bad Request)
{
"error": true,
"message": "Required field xy missing, empty or null"
}
Server error – 500 (Internal Server error)
{
"error": true,
"message": "Could not update asset"
}
Success – 200 (OK)
{
"error": false,
"message": "Asset updated"
}
Deletes an asset and it's requests, intervention and intervention work/material.
#####Response
Not found – 404 (Not found)
{
"error": true,
"message": "Asset does not exist"
}
Server error – 500 (Internal Server error)
{
"error": true,
"message": "Could not delete asset"
}
Success – 200 (OK)
{
"error": false,
"message": "Asset deleted"
}
adds a request to an asset where the AssetID is specified in the URL.
{
"Request_date":"2014-02-14",
"Request_desc":"needsrepair",
"Request_contact_name":"Nicola Keller",
"Request_note":"somenotes",
"Request_st_id":1,
"VisiTpID":4
}
Required params:
Request_date, Request_desc, Request_contact_name, Request_note, Request_st_id, VisiTpID`
Success - 201 (Created)
{
"error": false,
"message": "Request added",
"request_id": "53ce4f80b5db6",
"asset_id": "4b0beb98ce160"
}
Missing fields 400 (Bad Request)
{
"error": true,
"message": "Required field xy missing, empty or null"
}
Server error500 (Internal server error)
{
"error": true,
"message": "Could not add request"
}
Updates existing request of an specific asset
{
"Request_date":"2014-02-14",
"Request_desc":"blub",
"Request_contact_name":"democontact",
"Request_note":"somenotes",
"Request_st_id":"1",
"VisiTpID":"4"
}
Required params:
Request_date, Request_desc, Request_contact_name, Request_note, Request_st_id, VisiTpID`
Success - 200 (OK)
{
"error": false,
"message": "Request updated"
}
Missing field(s) – 400 (Bad Request)
{
"error": true,
"message": "Required field xy missing, empty or null"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not update request"
}
Deletes existing request and associated interventions and its material or work.
Success - 200 (OK)
{
"error": false,
"message": "Request deleted"
}
Not found – 404 (Not found)
{
"error": true,
"message": "Request not found"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not delete Request"
}
Creates new intervention on a specified request
{
"Date":"2014-01-01",
"EmployeeID":"4d64045c4a525",
"AssetStatusID":1,
"FaildPart":"Cable",
"FailurCategID":2,
"FailureCauseID":1,
"Interv_desc":"blub",
"Comments":"yes",
"RespEng":"4c8fcac9f06fa",
"TotalWork":1,
"TotalCosts":2
}
Required fields:
Date, EmployeeID, AssetStatusID, 'AssetID_Visit', FaildPart, FailurCategID, FailureCauseID, Interv_desc, Comments, RespEng, TotalWork, TotalCosts
Success - 200 (OK)
{
"message": "Intervention added",
"intervention_id": "53cf9860dd600"
}
Missing field(s) – 400 (Bad Request)
{
"error": true,
"message": "Required field xy missing, empty or null"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not add intervention"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not select intervention type of request"
}
Updates existing intervention on a specified request
{
"Date":"2014-01-01",
"EmployeeID":"4d64045c4a525",
"AssetStatusID":1,
"FaildPart":"Cable Red",
"FailurCategID":2,
"FailureCauseID":1,
"Interv_desc":"blub",
"Comments":"yes",
"RespEng":"4c8fcac9f06fa",
"TotalWork":1,
"TotalCosts":2
}
Required fields:
Date, EmployeeID, AssetStatusID, 'AssetID_Visit', FaildPart, FailurCategID, FailureCauseID, Interv_desc, Comments, RespEng, TotalWork, TotalCosts
Success - 200 (OK)
{
"error": false,
"message": "Intervention updated",
"request_id": "53ce48a405cd9",
"intervention_id": "53cf9860dd600"
}
Missing field(s) – 400 (Bad Request)
{
"error": true,
"message": "Required field xy missing, empty or null"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not update intervention"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not select intervention type of request"
}
Deletes existing intervention and associated intervention material or work.
Success - 200 (OK)
{
"error": false,
"message": "Intervention deleted"
}
Not found – 404 (Not found)
{
"error": true,
"message": "Intervention does not exist"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not delete intervention"
}
Creates new intervention material
{
"Description":"test",
"Amount":10,
"PartNumber":"abc",
"UnitPrice":5.0,
"IntervID":"0edc3bfd4e"
}
Required fields:
Description, Amount, PartNumber, UnitPrice, IntervID
Success - 200 (OK)
{
"error": false,
"message": "Intervention material created"
}
Missing field(s) – 400 (Bad Request)
{
"error": true,
"message": "Required field xy missing, empty or null"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not create intervention material"
}
Creates new intervention work
{
"IntervID":"53d0cc77124de",
"Action":"yes",
"Date_action":"2014-01-01",
"Time":20
}
Required fields:
IntervID, Action, Date_action, Time
Success - 200 (OK)
{
"error": false,
"message": "Intervention work created",
"work_id": "53d0cc77124de"
}
Missing field(s) – 400 (Bad Request)
{
"error": true,
"message": "Required field xy missing, empty or null"
}
Server error – 500 (Internal server error)
{
"error": true,
"message": "Could not create intervention work"
}
Returns database content for specified tables (in config.php editable). Largest response (ca. 600 assets = 80kB/response). This is the most important route for Android app for downloading server data.
Important: A user has only access to assets / requests / interventions based on his access level which is specified in the employee table. A request to returns only these based on the access level.
{
"assets":[
{
"AssetID":"4b67517f4462a",
"GenericAssetID":"12636",
"UMDNS":"12636",
"AssetFullName":"Dash",
"ManufacturerID":"4c44276c3c2c0",
"Model":"4000 ",
"SerialNumber":"SD008484463GA",
...
},
],
"location":[
{
"LocationID":"4b6b4f5120321",
"FacilityID":"11",
"DeptID":"2",
...
},
...
Returns database scheme for specified tables (in config.php editable). For each field the meta information of all specified tables (in config.php editable):
Fieldname, type, Null, Primary Key, Default, Extra
{
"assets":[
{
"Field":"AssetID",
"Type":"char(13)",
"Null":"NO",
"Key":"PRI",
"Default":null,
"Extra":""
},
...
===