304 lines
8.6 KiB
JavaScript
304 lines
8.6 KiB
JavaScript
/**
|
|
* @fileoverview Generate new endpoint definitions for Laravel Healthcare MCP Server
|
|
* Creates endpoint definitions in the format expected by endpoints.js
|
|
*/
|
|
|
|
import fs from "fs";
|
|
import path from "path";
|
|
|
|
/**
|
|
* Endpoint categories mapping
|
|
*/
|
|
const ENDPOINT_CATEGORIES = {
|
|
MEETINGS: "meetings",
|
|
APPOINTMENTS: "appointment_scheduling",
|
|
PATIENTS: "patient_management",
|
|
DOCTORS: "provider_management",
|
|
LABS: "medical_records",
|
|
NOTES: "medical_records",
|
|
FORMS: "forms_questionnaires",
|
|
DOCUMENTS: "document_management",
|
|
AUTHENTICATION: "user_management",
|
|
USER_MANAGEMENT: "user_management",
|
|
MEDICAL_RECORDS: "medical_records",
|
|
PRESCRIPTIONS: "prescription_management",
|
|
INVENTORY: "inventory",
|
|
LOCATIONS: "location_management",
|
|
INSURANCE: "medical_records",
|
|
PAYMENTS: "billing_orders",
|
|
VITALS: "medical_records",
|
|
TASKS: "user_management",
|
|
TAGS: "medical_records",
|
|
PHONE_LOGS: "medical_records",
|
|
PRODUCTS: "business_operations",
|
|
COMPANY: "business_operations",
|
|
TOKENS: "user_management",
|
|
EMAILS: "messaging",
|
|
ASSISTANT: "ai_integration",
|
|
LIVEKIT: "ai_integration",
|
|
};
|
|
|
|
/**
|
|
* Generate new endpoint definitions
|
|
*/
|
|
function generateNewEndpoints() {
|
|
try {
|
|
// Read the categorized endpoints
|
|
const categorizedPath = path.join(
|
|
process.cwd(),
|
|
"categorized-endpoints.json"
|
|
);
|
|
const categorizedContent = fs.readFileSync(categorizedPath, "utf8");
|
|
const categorized = JSON.parse(categorizedContent);
|
|
|
|
console.log("=== GENERATING NEW ENDPOINT DEFINITIONS ===");
|
|
console.log("");
|
|
|
|
const newEndpoints = {
|
|
PUBLIC_ENDPOINTS: [],
|
|
PROVIDER_ENDPOINTS: [],
|
|
PATIENT_ENDPOINTS: [],
|
|
PARTNER_ENDPOINTS: [],
|
|
AFFILIATE_ENDPOINTS: [],
|
|
NETWORK_ENDPOINTS: [],
|
|
};
|
|
|
|
// Process each authentication type
|
|
Object.keys(categorized).forEach((authType) => {
|
|
const endpoints = categorized[authType];
|
|
const targetArray = getTargetArray(authType, newEndpoints);
|
|
|
|
console.log(
|
|
`Processing ${authType.toUpperCase()}: ${endpoints.length} endpoints`
|
|
);
|
|
|
|
endpoints.forEach((endpoint) => {
|
|
const endpointDef = createEndpointDefinition(endpoint);
|
|
targetArray.push(endpointDef);
|
|
});
|
|
});
|
|
|
|
// Display summary
|
|
console.log("");
|
|
console.log("=== GENERATION SUMMARY ===");
|
|
Object.keys(newEndpoints).forEach((key) => {
|
|
console.log(`${key}: ${newEndpoints[key].length} endpoints`);
|
|
});
|
|
|
|
// Save the new endpoints
|
|
const outputPath = path.join(process.cwd(), "new-endpoints-definitions.js");
|
|
const content = generateEndpointsFile(newEndpoints);
|
|
fs.writeFileSync(outputPath, content);
|
|
|
|
console.log("");
|
|
console.log(`New endpoint definitions saved to: ${outputPath}`);
|
|
|
|
return newEndpoints;
|
|
} catch (error) {
|
|
console.error("Error generating new endpoints:", error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get target array for authentication type
|
|
*/
|
|
function getTargetArray(authType, newEndpoints) {
|
|
switch (authType.toLowerCase()) {
|
|
case "public":
|
|
return newEndpoints.PUBLIC_ENDPOINTS;
|
|
case "provider":
|
|
return newEndpoints.PROVIDER_ENDPOINTS;
|
|
case "patient":
|
|
return newEndpoints.PATIENT_ENDPOINTS;
|
|
case "partner":
|
|
return newEndpoints.PARTNER_ENDPOINTS;
|
|
case "affiliate":
|
|
return newEndpoints.AFFILIATE_ENDPOINTS;
|
|
case "network":
|
|
return newEndpoints.NETWORK_ENDPOINTS;
|
|
default:
|
|
return newEndpoints.PROVIDER_ENDPOINTS;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create endpoint definition in the expected format
|
|
*/
|
|
function createEndpointDefinition(endpoint) {
|
|
const category = mapToEndpointCategory(endpoint.category);
|
|
const parameters = extractParameters(endpoint);
|
|
|
|
return {
|
|
path: endpoint.path,
|
|
method: endpoint.method,
|
|
controller: generateControllerName(endpoint),
|
|
category: category,
|
|
description: endpoint.summary || endpoint.description || "",
|
|
parameters: parameters,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Map functional category to endpoint category
|
|
*/
|
|
function mapToEndpointCategory(category) {
|
|
return ENDPOINT_CATEGORIES[category.toUpperCase()] || "user_management";
|
|
}
|
|
|
|
/**
|
|
* Extract parameters from endpoint
|
|
*/
|
|
function extractParameters(endpoint) {
|
|
const parameters = {};
|
|
|
|
// Add path parameters
|
|
if (endpoint.parameters && endpoint.parameters.length > 0) {
|
|
endpoint.parameters.forEach((param) => {
|
|
parameters[param.name] = {
|
|
type: param.type || "string",
|
|
required: param.required || false,
|
|
description: param.description || `${param.name} parameter`,
|
|
};
|
|
});
|
|
}
|
|
|
|
// Add request body parameters
|
|
if (endpoint.requestBody && endpoint.requestBody.content) {
|
|
const jsonContent = endpoint.requestBody.content["application/json"];
|
|
if (jsonContent && jsonContent.schema && jsonContent.schema.properties) {
|
|
Object.keys(jsonContent.schema.properties).forEach((propName) => {
|
|
const prop = jsonContent.schema.properties[propName];
|
|
parameters[propName] = {
|
|
type: prop.type || "string",
|
|
required: endpoint.requestBody.required || false,
|
|
description:
|
|
prop.description || prop.example || `${propName} parameter`,
|
|
};
|
|
});
|
|
} else if (
|
|
jsonContent &&
|
|
jsonContent.schema &&
|
|
jsonContent.schema.required
|
|
) {
|
|
// Handle required array
|
|
jsonContent.schema.required.forEach((reqParam) => {
|
|
if (!parameters[reqParam]) {
|
|
parameters[reqParam] = {
|
|
type: "string",
|
|
required: true,
|
|
description: `${reqParam} parameter`,
|
|
};
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
return parameters;
|
|
}
|
|
|
|
/**
|
|
* Generate controller name from endpoint
|
|
*/
|
|
function generateControllerName(endpoint) {
|
|
const path = endpoint.path;
|
|
const method = endpoint.method.toLowerCase();
|
|
|
|
// Extract controller pattern from path
|
|
if (path.includes("/api/emr/")) {
|
|
return `EMRAPI\\${capitalizeFirst(method)}Controller@${
|
|
endpoint.operationId || method
|
|
}`;
|
|
} else if (path.includes("/emr-api/")) {
|
|
return `EMRAPI\\${capitalizeFirst(method)}Controller@${
|
|
endpoint.operationId || method
|
|
}`;
|
|
} else if (path.includes("/api/patient/")) {
|
|
return `Patient\\${capitalizeFirst(method)}Controller@${
|
|
endpoint.operationId || method
|
|
}`;
|
|
} else if (path.includes("/api/provider/")) {
|
|
return `Provider\\${capitalizeFirst(method)}Controller@${
|
|
endpoint.operationId || method
|
|
}`;
|
|
} else if (path.includes("/api/assistant/")) {
|
|
return `Assistant\\${capitalizeFirst(method)}Controller@${
|
|
endpoint.operationId || method
|
|
}`;
|
|
} else if (path.includes("/api/")) {
|
|
return `Api\\${capitalizeFirst(method)}Controller@${
|
|
endpoint.operationId || method
|
|
}`;
|
|
} else {
|
|
return `${capitalizeFirst(method)}Controller@${
|
|
endpoint.operationId || method
|
|
}`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Capitalize first letter
|
|
*/
|
|
function capitalizeFirst(str) {
|
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
}
|
|
|
|
/**
|
|
* Generate the endpoints file content
|
|
*/
|
|
function generateEndpointsFile(newEndpoints) {
|
|
let content = `/**
|
|
* @fileoverview New API Endpoints from api-docs.json
|
|
* Generated endpoint definitions for Laravel Healthcare MCP Server
|
|
* Total: ${Object.values(newEndpoints).flat().length} endpoints
|
|
*/
|
|
|
|
import { ENDPOINT_CATEGORIES } from "./endpoints.js";
|
|
|
|
`;
|
|
|
|
// Generate each endpoint array
|
|
Object.keys(newEndpoints).forEach((key) => {
|
|
const endpoints = newEndpoints[key];
|
|
content += `/**
|
|
* ${key.replace("_", " ").toLowerCase()} (${endpoints.length} endpoints)
|
|
*/
|
|
export const NEW_${key} = [\n`;
|
|
|
|
endpoints.forEach((endpoint, index) => {
|
|
content += ` {\n`;
|
|
content += ` path: "${endpoint.path}",\n`;
|
|
content += ` method: "${endpoint.method}",\n`;
|
|
content += ` controller: "${endpoint.controller}",\n`;
|
|
content += ` category: ENDPOINT_CATEGORIES.${endpoint.category.toUpperCase()},\n`;
|
|
const endpointDescription = (endpoint.description || "")
|
|
.toString()
|
|
.replace(/"/g, '\\"');
|
|
content += ` description: "${endpointDescription}",\n`;
|
|
content += ` parameters: {\n`;
|
|
|
|
Object.keys(endpoint.parameters).forEach((paramName) => {
|
|
const param = endpoint.parameters[paramName];
|
|
const description = (param.description || "")
|
|
.toString()
|
|
.replace(/"/g, '\\"');
|
|
content += ` ${paramName}: { type: "${param.type}", required: ${param.required}, description: "${description}" },\n`;
|
|
});
|
|
|
|
content += ` },\n`;
|
|
content += ` }${index < endpoints.length - 1 ? "," : ""}\n`;
|
|
});
|
|
|
|
content += `];\n\n`;
|
|
});
|
|
|
|
return content;
|
|
}
|
|
|
|
// Run the generation
|
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
generateNewEndpoints();
|
|
}
|
|
|
|
export { generateNewEndpoints };
|