{"activeVersionTag":"latest","latestAvailableVersionTag":"latest","collection":{"info":{"_postman_id":"c2914a69-f502-4200-b167-98079f5cd23e","name":"LIMSABC Model  API - Released","description":"The LIMSABC API Web Service (`Page_ApiWS`) is the foundational base class that provides a standardized framework for all API endpoints in the LIMSABC system. This base class handles authentication, response formatting, error management, and provides a consistent structure for all API controllers.\n\n# Base API Framework\n\n## Core Features\n\n- **Standardized Response Format**: All APIs return consistent JSON/XML/HTML responses\n    \n- **Authentication Management**: Built-in user authentication and authorization\n    \n- **Error Handling**: Comprehensive error code system with HTTP status mapping\n    \n- **Multiple Output Formats**: Support for JSON, XML, and HTML responses\n    \n- **Database Integration**: Automatic user context setting for database operations\n    \n\n# Response Structure\n\nAll API responses follow a standardized three-field structure:\n\n``` json\n{\n    \"code\": 1,\n    \"status\": 200,\n    \"data\": \"response_payload\"\n}\n\n ```\n\n## Response Fields\n\n| Field | Type | Description |\n| --- | --- | --- |\n| `code` | integer | API response code (internal system code) |\n| `status` | integer | HTTP status code (standard HTTP response) |\n| `data` | mixed | Response payload or error message |\n\n# API Response Codes\n\nThe system uses a comprehensive error code system that maps to standard HTTP status codes:\n\n| Code | Constant | HTTP Status | Message | Description |\n| --- | --- | --- | --- | --- |\n| 0 | `WS_ERROR_UNK` | 400 | Unknown Error | Unspecified or unexpected error |\n| 1 | `WS_SUCCESS` | 200 | Success | Request processed successfully |\n| 2 | `WS_HTTPS_REQUIRED` | 403 | HTTPS Required | Secure connection required |\n| 3 | `WS_AUTH_REQUIRED` | 401 | Authentication Required | User authentication needed |\n| 4 | `WS_AUTH_FAILED` | 401 | Authentication Failed | Invalid credentials provided |\n| 5 | `WS_INVALID_REQUEST` | 404 | Invalid Request | Requested resource not found |\n| 6 | `WS_INVALID_FORMAT` | 400 | Invalid Response Format | Invalid or missing parameters |\n\n# Output Formats\n\n## JSON Format (Default)\n\n- **Content-Type**: `application/json; charset=utf-8`\n    \n- **Usage**: Most common format for API responses\n    \n- **Example**:\n    \n    ``` json\n            {\n              \"code\": 1,\n              \"status\": 200,\n              \"data\": {\n                  \"result\": \"success\",\n                  \"message\": \"Operation completed\",\n                  \"records\": []\n              }\n            }\n    \n     ```\n    \n\n## XML Format\n\n- **Content-Type**: `application/xml; charset=utf-8`\n    \n- **Usage**: Legacy system integration or specific client requirements\n    \n- **Example**:\n    \n    ``` xml\n            <response>\n              <code class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27;>1</code>\n              <status>200</status>\n              <data>\n                  <result>success</result>\n                  <message>Operation completed</message>\n              </data>\n            </response>\n    \n     ```\n    \n\n## HTML/Plain Text Format\n\n- **Content-Type**: `text/html; charset=utf-8`\n    \n- **Usage**: Direct content display or simple text responses\n    \n- **Output**: Raw data content only (no wrapper structure)\n    \n\n# Authentication System\n\n## Automatic Authentication Check\n\nEvery API request automatically undergoes authentication validation:\n\n1. **User Authentication**: Verifies user login status\n    \n2. **Database Context**: Sets current user context for database operations\n    \n3. **Error Handling**: Returns appropriate error codes for authentication failures\n    \n\n## Authentication Error Responses\n\n- **Code 3**: Authentication required but not provided\n    \n- **Code 4**: Authentication provided but invalid/expired\n    \n- **Code 2**: HTTPS required for secure operations\n    \n\n# Database Integration\n\n## User Context Setting\n\n``` php\n$this->api->db->query(\"set @current_php_user_name = '\".$this->api->auth->get('username').\"'\");\n\n ```\n\nThis ensures all database operations are performed with proper user context for:\n\n- Audit logging\n    \n- Data access control\n    \n- User-specific data filtering\n    \n\n# Error Handling and Logging\n\n## Critical Error Logging\n\nAuthentication and system errors are automatically logged:\n\n``` php\n$this->log_critical(\"API_CRITICAL_ERROR HTTP_ERROR_CODE_\" . $http_code . \" \" . $message . \" \" . $code);\n\n ```\n\n## Error Response Flow\n\n1. **Exception Detection**: Catches authentication and system errors\n    \n2. **Code Mapping**: Maps exception codes to API response codes\n    \n3. **Response Generation**: Creates standardized error response\n    \n4. **Logging**: Records critical errors for monitoring\n    \n5. **Response Delivery**: Sends formatted error response to client\n    \n\n# HTTP Status Code Mapping\n\n| HTTP Code | Status Text | Usage |\n| --- | --- | --- |\n| 200 | OK | Successful requests |\n| 400 | Bad Request | Invalid parameters or format errors |\n| 401 | Unauthorized | Authentication required or failed |\n| 403 | Forbidden | HTTPS required or access denied |\n| 404 | Not Found | Invalid request or resource not found |\n\n# Implementation Guidelines\n\n## For API Developers\n\nWhen creating new API controllers that extend `Page_ApiWS`:\n\n1. **Inherit Authentication**: Authentication is handled automatically\n    \n2. **Use Standard Response Format**: Follow the three-field response structure\n    \n3. **Handle Errors Gracefully**: Use the predefined error codes\n    \n4. **Set Appropriate Headers**: The base class handles standard headers\n    \n5. **Terminate with** **`deliver_response()`**: Always use the provided response method\n    \n\n## Response Generation Pattern\n\n``` php\n$response['code'] = $this->WS_SUCCESS;  // or appropriate error code\n$response['status'] = $this->api_response_code[$response['code']]['HTTP Response'];\n$response['data'] = $your_response_data;\n$this->deliver_response($format, $response);\n\n ```\n\n# Security Features\n\n- **Authentication Enforcement**: All endpoints require valid authentication\n    \n- **User Context Tracking**: Database operations are user-scoped\n    \n- **Error Logging**: Security events are logged for monitoring\n    \n- **Input Validation**: Framework supports parameter validation\n    \n- **HTTPS Enforcement**: Can require secure connections\n    \n\n# Extending the Base Class\n\n## Model API Controller Example\n\nThe `page_apiws_model` class demonstrates how to extend `Page_ApiWS`:\n\n``` php\nclass page_apiws_model extends Page_ApiWS\n{\n    public function init()\n    {\n        parent::init();  // Inherits authentication and setup\n        // Custom logic here\n        // Use $this->WS_SUCCESS, $this->WS_INVALID_FORMAT, etc.\n        // Call $this->deliver_response($format, $response)\n    }\n}\n\n ```\n\n# Exposed Models\n\nThe models currently exposed are:\n\n- accident_Type\n    \n- billing_Status\n    \n- Client\n    \n- client_Site\n    \n- Dept\n    \n- Doctor\n    \n- doctor_favorite_Order\n    \n- entity_State\n    \n- Ethnicity\n    \n- Gender\n    \n- Icd\n    \n- insurance_Provider\n    \n- Medication\n    \n- Panel\n    \n- panel_Categories\n    \n- panel_Category\n    \n- panel_Test\n    \n- Patient\n    \n- Poct\n    \n- poct_Result\n    \n- requisition_Bill\n    \n- requisition_bill_Field\n    \n- sample_Type\n    \n- Status\n    \n- site_Doctor","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","isPublicCollection":false,"owner":"6362152","team":221073,"collectionId":"c2914a69-f502-4200-b167-98079f5cd23e","publishedId":"2s7ZE5rQE1","public":true,"publicUrl":"https://apidocs.limsabc.com","privateUrl":"https://go.postman.co/documentation/6362152-c2914a69-f502-4200-b167-98079f5cd23e","customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"EF5B25"},"documentationLayout":"classic-double-column","customisation":{"metaTags":[{"name":"description","value":""},{"name":"title","value":""}],"appearance":{"default":"system_default","themes":[{"name":"dark","logo":null,"colors":{"top-bar":"212121","right-sidebar":"303030","highlight":"FF6C37"}},{"name":"light","logo":null,"colors":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"EF5B25"}}]}},"version":"8.10.1","publishDate":"2025-10-06T06:28:44.000Z","activeVersionTag":"latest","documentationTheme":"light","metaTags":{"title":"","description":""},"logos":{"logoLight":null,"logoDark":null}},"statusCode":200},"environments":[{"name":"LIMSABC TEST","id":"f8a92c2b-407f-42b8-9200-96e8ada898d5","owner":"6152868","values":[{"key":"SERVER_URL","value":"https://interfaces.limsabc.com","enabled":true,"type":"default"}],"published":true}],"user":{"authenticated":false,"permissions":{"publish":false}},"run":{"button":{"js":"https://run.pstmn.io/button.js","css":"https://run.pstmn.io/button.css"}},"web":"https://www.getpostman.com/","team":{"logo":"https://res.cloudinary.com/postman/image/upload/t_team_logo_pubdoc/v1/team/6f47d172f8f9b5c41fbfb81c7c497c69955ae20880e1f8b9db29add7a390c8db","favicon":"https://limsabc.com/favicon.ico"},"isEnvFetchError":false,"languages":"[{\"key\":\"csharp\",\"label\":\"C#\",\"variant\":\"HttpClient\"},{\"key\":\"csharp\",\"label\":\"C#\",\"variant\":\"RestSharp\"},{\"key\":\"curl\",\"label\":\"cURL\",\"variant\":\"cURL\"},{\"key\":\"dart\",\"label\":\"Dart\",\"variant\":\"http\"},{\"key\":\"go\",\"label\":\"Go\",\"variant\":\"Native\"},{\"key\":\"http\",\"label\":\"HTTP\",\"variant\":\"HTTP\"},{\"key\":\"java\",\"label\":\"Java\",\"variant\":\"OkHttp\"},{\"key\":\"java\",\"label\":\"Java\",\"variant\":\"Unirest\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"Fetch\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"jQuery\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"XHR\"},{\"key\":\"c\",\"label\":\"C\",\"variant\":\"libcurl\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Axios\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Native\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Request\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Unirest\"},{\"key\":\"objective-c\",\"label\":\"Objective-C\",\"variant\":\"NSURLSession\"},{\"key\":\"ocaml\",\"label\":\"OCaml\",\"variant\":\"Cohttp\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"cURL\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"Guzzle\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"HTTP_Request2\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"pecl_http\"},{\"key\":\"powershell\",\"label\":\"PowerShell\",\"variant\":\"RestMethod\"},{\"key\":\"python\",\"label\":\"Python\",\"variant\":\"http.client\"},{\"key\":\"python\",\"label\":\"Python\",\"variant\":\"Requests\"},{\"key\":\"r\",\"label\":\"R\",\"variant\":\"httr\"},{\"key\":\"r\",\"label\":\"R\",\"variant\":\"RCurl\"},{\"key\":\"ruby\",\"label\":\"Ruby\",\"variant\":\"Net::HTTP\"},{\"key\":\"shell\",\"label\":\"Shell\",\"variant\":\"Httpie\"},{\"key\":\"shell\",\"label\":\"Shell\",\"variant\":\"wget\"},{\"key\":\"swift\",\"label\":\"Swift\",\"variant\":\"URLSession\"}]","languageSettings":[{"key":"csharp","label":"C#","variant":"HttpClient"},{"key":"csharp","label":"C#","variant":"RestSharp"},{"key":"curl","label":"cURL","variant":"cURL"},{"key":"dart","label":"Dart","variant":"http"},{"key":"go","label":"Go","variant":"Native"},{"key":"http","label":"HTTP","variant":"HTTP"},{"key":"java","label":"Java","variant":"OkHttp"},{"key":"java","label":"Java","variant":"Unirest"},{"key":"javascript","label":"JavaScript","variant":"Fetch"},{"key":"javascript","label":"JavaScript","variant":"jQuery"},{"key":"javascript","label":"JavaScript","variant":"XHR"},{"key":"c","label":"C","variant":"libcurl"},{"key":"nodejs","label":"NodeJs","variant":"Axios"},{"key":"nodejs","label":"NodeJs","variant":"Native"},{"key":"nodejs","label":"NodeJs","variant":"Request"},{"key":"nodejs","label":"NodeJs","variant":"Unirest"},{"key":"objective-c","label":"Objective-C","variant":"NSURLSession"},{"key":"ocaml","label":"OCaml","variant":"Cohttp"},{"key":"php","label":"PHP","variant":"cURL"},{"key":"php","label":"PHP","variant":"Guzzle"},{"key":"php","label":"PHP","variant":"HTTP_Request2"},{"key":"php","label":"PHP","variant":"pecl_http"},{"key":"powershell","label":"PowerShell","variant":"RestMethod"},{"key":"python","label":"Python","variant":"http.client"},{"key":"python","label":"Python","variant":"Requests"},{"key":"r","label":"R","variant":"httr"},{"key":"r","label":"R","variant":"RCurl"},{"key":"ruby","label":"Ruby","variant":"Net::HTTP"},{"key":"shell","label":"Shell","variant":"Httpie"},{"key":"shell","label":"Shell","variant":"wget"},{"key":"swift","label":"Swift","variant":"URLSession"}],"languageOptions":[{"label":"C# - HttpClient","value":"csharp - HttpClient - C#"},{"label":"C# - RestSharp","value":"csharp - RestSharp - C#"},{"label":"cURL - cURL","value":"curl - cURL - cURL"},{"label":"Dart - http","value":"dart - http - Dart"},{"label":"Go - Native","value":"go - Native - Go"},{"label":"HTTP - HTTP","value":"http - HTTP - HTTP"},{"label":"Java - OkHttp","value":"java - OkHttp - Java"},{"label":"Java - Unirest","value":"java - Unirest - Java"},{"label":"JavaScript - Fetch","value":"javascript - Fetch - JavaScript"},{"label":"JavaScript - jQuery","value":"javascript - jQuery - JavaScript"},{"label":"JavaScript - XHR","value":"javascript - XHR - JavaScript"},{"label":"C - libcurl","value":"c - libcurl - C"},{"label":"NodeJs - Axios","value":"nodejs - Axios - NodeJs"},{"label":"NodeJs - Native","value":"nodejs - Native - NodeJs"},{"label":"NodeJs - Request","value":"nodejs - Request - NodeJs"},{"label":"NodeJs - Unirest","value":"nodejs - Unirest - NodeJs"},{"label":"Objective-C - NSURLSession","value":"objective-c - NSURLSession - Objective-C"},{"label":"OCaml - Cohttp","value":"ocaml - Cohttp - OCaml"},{"label":"PHP - cURL","value":"php - cURL - PHP"},{"label":"PHP - Guzzle","value":"php - Guzzle - PHP"},{"label":"PHP - HTTP_Request2","value":"php - HTTP_Request2 - PHP"},{"label":"PHP - pecl_http","value":"php - pecl_http - PHP"},{"label":"PowerShell - RestMethod","value":"powershell - RestMethod - PowerShell"},{"label":"Python - http.client","value":"python - http.client - Python"},{"label":"Python - Requests","value":"python - Requests - Python"},{"label":"R - httr","value":"r - httr - R"},{"label":"R - RCurl","value":"r - RCurl - R"},{"label":"Ruby - Net::HTTP","value":"ruby - Net::HTTP - Ruby"},{"label":"Shell - Httpie","value":"shell - Httpie - Shell"},{"label":"Shell - wget","value":"shell - wget - Shell"},{"label":"Swift - URLSession","value":"swift - URLSession - Swift"}],"layoutOptions":[{"value":"classic-single-column","label":"Single Column"},{"value":"classic-double-column","label":"Double Column"}],"versionOptions":[],"environmentOptions":[{"value":"0","label":"No Environment"},{"label":"LIMSABC TEST","value":"6152868-f8a92c2b-407f-42b8-9200-96e8ada898d5"}],"canonicalUrl":"https://apidocs.limsabc.com/view/metadata/2s7ZE5rQE1"}