medpromptjs 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +3 -28
  2. package/dist/agent.d.ts +31 -0
  3. package/dist/chain.d.ts +32 -0
  4. package/dist/index.d.ts +3 -3
  5. package/dist/medpromptjs.cjs.development.js +215 -243
  6. package/dist/medpromptjs.cjs.development.js.map +1 -1
  7. package/dist/medpromptjs.cjs.production.min.js +1 -1
  8. package/dist/medpromptjs.cjs.production.min.js.map +1 -1
  9. package/dist/medpromptjs.esm.js +214 -243
  10. package/dist/medpromptjs.esm.js.map +1 -1
  11. package/dist/mydi.d.ts +17 -0
  12. package/dist/tool.d.ts +27 -0
  13. package/package.json +3 -3
  14. package/src/agent.ts +79 -0
  15. package/src/chain.ts +72 -0
  16. package/src/index.ts +3 -5
  17. package/src/mydi.ts +25 -0
  18. package/src/tool.ts +59 -0
  19. package/dist/agents/explain_agent.d.ts +0 -6
  20. package/dist/agents/index.d.ts +0 -2
  21. package/dist/bootstrap.d.ts +0 -1
  22. package/dist/chains/index.d.ts +0 -2
  23. package/dist/chains/self_gen_cot_chain.d.ts +0 -26
  24. package/dist/server/index.d.ts +0 -3
  25. package/dist/server/sample_app.d.ts +0 -3
  26. package/dist/tools/find_patient.d.ts +0 -19
  27. package/dist/tools/index.d.ts +0 -2
  28. package/dist/utils/fhir_server.d.ts +0 -4
  29. package/dist/utils/get_medical_record.d.ts +0 -8
  30. package/dist/utils/hapi_server.d.ts +0 -5
  31. package/dist/utils/index.d.ts +0 -4
  32. package/src/agents/explain_agent.ts +0 -37
  33. package/src/agents/index.ts +0 -4
  34. package/src/bootstrap.ts +0 -17
  35. package/src/chains/index.ts +0 -2
  36. package/src/chains/self_gen_cot_chain.ts +0 -82
  37. package/src/server/index.ts +0 -5
  38. package/src/server/sample_app.js +0 -47
  39. package/src/server/sample_app.ts +0 -51
  40. package/src/tools/find_patient.ts +0 -51
  41. package/src/tools/index.ts +0 -4
  42. package/src/utils/fhir_server.ts +0 -11
  43. package/src/utils/get_medical_record.ts +0 -44
  44. package/src/utils/hapi_server.ts +0 -19
  45. package/src/utils/index.ts +0 -6
package/src/agent.ts ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Copyright 2024 Bell Eapen
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { PromptTemplate, ChatPromptTemplate } from "@langchain/core/prompts";
18
+ import { LLM } from "langchain/llms/base";
19
+ import { AgentExecutor, createReactAgent, createStructuredChatAgent } from "langchain/agents";
20
+ import type { ToolInterface } from "@langchain/core/tools";
21
+ import mydi from "./mydi";
22
+
23
+ export class BaseAgent {
24
+
25
+ container: any;
26
+ tools: ToolInterface[];
27
+ name: string;
28
+ prompt: PromptTemplate;
29
+ llm: LLM;
30
+ template: string = `
31
+ ## Question: {question}
32
+ ## Answer: {answer}
33
+ Given the above question and answer, generate a chain of thought explanation for the answer.
34
+ First, start with the model generated chain of thought explanation.
35
+ End the chain of though explanation with:
36
+ Therefore, the answer is {answer}.
37
+ `
38
+
39
+ constructor(container: any) {
40
+ this.container = container;
41
+ this.name = this.camelize(this.constructor.name);
42
+ this.tools = this.resolve("tools")
43
+ this.prompt = this.resolve("prompt") !== "" ? this.resolve("prompt") : PromptTemplate.fromTemplate(this.template);
44
+ this.llm = this.resolve("main-llm");
45
+ }
46
+
47
+ resolve(name: string) {
48
+ return mydi(this.container, this.name, name);
49
+ }
50
+
51
+ camelize(str: string) {
52
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
53
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
54
+ }).replace(/\s+/g, '');
55
+ }
56
+
57
+ snake_case(str: string) {
58
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
59
+ return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
60
+ }).replace(/\s+/g, '');
61
+ }
62
+
63
+ async run(input: any) {
64
+ const agent = await createStructuredChatAgent({
65
+ llm: this.llm,
66
+ tools: this.tools,
67
+ prompt: this.prompt,
68
+ });
69
+ const agentExecutor = new AgentExecutor({
70
+ agent: agent,
71
+ tools: this.tools,
72
+ // verbose: true,
73
+ handleParsingErrors:
74
+ "Please try again, paying close attention to the final answer",
75
+ });
76
+ return await agentExecutor.invoke(input);
77
+ }
78
+
79
+ }
package/src/chain.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Copyright 2024 Bell Eapen
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { PromptTemplate, ChatPromptTemplate } from "@langchain/core/prompts";
18
+ import { LLM } from "langchain/llms/base";
19
+ import type { ToolInterface } from "@langchain/core/tools";
20
+ import mydi from "./mydi";
21
+ import { RunnablePassthrough, RunnableSequence } from "@langchain/core/runnables";
22
+
23
+ export class BaseChain {
24
+
25
+ container: any;
26
+ tools: ToolInterface[];
27
+ name: string;
28
+ description: string;
29
+ prompt: PromptTemplate;
30
+ llm: LLM;
31
+ template: string = `
32
+ Summarize the following text:
33
+ {input}
34
+ `
35
+
36
+ constructor(container: any, name: string, description: string, template: string="") {
37
+ this.container = container;
38
+ this.name = name === "" ? this.camelize(this.constructor.name) : name;
39
+ this.description = description === "" ? this.snake_case(this.constructor.name) : description;
40
+ this.tools = this.resolve("tools")
41
+ this.prompt = this.resolve("prompt") !== "" ? this.resolve("prompt") : PromptTemplate.fromTemplate(this.template);
42
+ this.llm = this.resolve("main-llm");
43
+ }
44
+
45
+ resolve(name: string) {
46
+ return mydi(this.container, this.name, name);
47
+ }
48
+
49
+ camelize(str: string) {
50
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
51
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
52
+ }).replace(/\s+/g, '');
53
+ }
54
+
55
+ snake_case(str: string) {
56
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
57
+ return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
58
+ }).replace(/\s+/g, '');
59
+ }
60
+
61
+
62
+ // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/
63
+ //! Override this method
64
+ chain(input: any) {
65
+ const _chain = RunnableSequence.from([
66
+ new RunnablePassthrough(),
67
+ this.prompt,
68
+ this.llm
69
+ ])
70
+ return _chain.invoke(input);
71
+ }
72
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import "./bootstrap";
2
-
3
- export { SelfGenCotChain } from "./chains/self_gen_cot_chain";
4
- export { ExplainAgent } from './agents/explain_agent';
5
-
1
+ export { BaseChain } from "./chain";
2
+ export { BaseAgent } from './agent';
3
+ export { BaseTool } from './tool';
package/src/mydi.ts ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright 2024 Bell Eapen
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const mydi = (c:any, m:string, b:string) => {
18
+ try {
19
+ return c.resolve(m+"_"+b);
20
+ } catch (e) {
21
+ return c.resolve(b);
22
+ }
23
+ }
24
+
25
+ export default mydi;
package/src/tool.ts ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Copyright 2024 Bell Eapen
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { DynamicStructuredTool } from "langchain/tools";
18
+ import mydi from "./mydi";
19
+
20
+ export class BaseTool extends DynamicStructuredTool {
21
+
22
+ container: any;
23
+ name: string;
24
+ description: string;
25
+ schema: any;
26
+ constructor(container: any, name: string, description: string, schema: any, func: any = null) {
27
+ super({
28
+ name: name,
29
+ description: description,
30
+ schema: schema,
31
+ func: func
32
+ });
33
+ this.container = container;
34
+ this.name = name === "" ? this.camelize(this.constructor.name) : name;
35
+ this.description = description === "" ? this.snake_case(this.constructor.name) : description;
36
+ this.schema = schema;
37
+ }
38
+
39
+ func = async (args: any) => {
40
+ return "override this";
41
+ }
42
+
43
+ resolve(name: string) {
44
+ return mydi(this.container, this.name, name);
45
+ }
46
+
47
+ camelize(str: string) {
48
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
49
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
50
+ }).replace(/\s+/g, '');
51
+ }
52
+
53
+ snake_case(str: string) {
54
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
55
+ return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
56
+ }).replace(/\s+/g, '');
57
+ }
58
+
59
+ }
@@ -1,6 +0,0 @@
1
- import "../bootstrap";
2
- export declare class ExplainAgent {
3
- tools: any[];
4
- constructor(tools?: any[]);
5
- run(input: any): Promise<import("langchain/dist/schema").ChainValues>;
6
- }
@@ -1,2 +0,0 @@
1
- import "./bootstrap";
2
- export { ExplainAgent } from "./explain_agent";
@@ -1 +0,0 @@
1
- import "reflect-metadata";
@@ -1,2 +0,0 @@
1
- import "./bootstrap";
2
- export { SelfGenCotChain } from "./self_gen_cot_chain";
@@ -1,26 +0,0 @@
1
- import "../bootstrap";
2
- import { LLMChain } from "langchain/chains";
3
- import { PromptTemplate } from "langchain/prompts";
4
- import { LLM } from "langchain/llms/base";
5
- import { ChainValues } from "langchain/dist/schema";
6
- import { CallbackManagerForChainRun } from "langchain/dist/callbacks";
7
- export declare class SelfGenCotChain {
8
- private llm;
9
- name: string;
10
- description: string;
11
- private template;
12
- constructor(llm?: LLM, name?: string, template?: string, description?: string);
13
- promptTemplate: PromptTemplate;
14
- chain: LLMChain;
15
- call(args: {
16
- question: string;
17
- answer: string;
18
- }): Promise<ChainValues>;
19
- _call(values: ChainValues, runManager?: CallbackManagerForChainRun | undefined): Promise<ChainValues>;
20
- _chainType(): string;
21
- get inputKeys(): string[];
22
- get outputKeys(): string[];
23
- getName(): string;
24
- getTemplate(): string;
25
- getDescription(): string;
26
- }
@@ -1,3 +0,0 @@
1
- import "./bootstrap";
2
- import app from '../../src/server/sample_app';
3
- export default app;
@@ -1,3 +0,0 @@
1
- import "../bootstrap";
2
- declare const app: import("express-serve-static-core").Express;
3
- export default app;
@@ -1,19 +0,0 @@
1
- import "../bootstrap";
2
- import { DynamicStructuredTool } from "langchain/tools";
3
- import { z } from "zod";
4
- export declare const FhirPatientSearchTool: DynamicStructuredTool<z.ZodObject<{
5
- given: z.ZodString;
6
- family: z.ZodString;
7
- birth_date: z.ZodString;
8
- patient_id: z.ZodString;
9
- }, "strip", z.ZodTypeAny, {
10
- given: string;
11
- family: string;
12
- birth_date: string;
13
- patient_id: string;
14
- }, {
15
- given: string;
16
- family: string;
17
- birth_date: string;
18
- patient_id: string;
19
- }>>;
@@ -1,2 +0,0 @@
1
- import "./bootstrap";
2
- export { FhirPatientSearchTool } from "./find_patient";
@@ -1,4 +0,0 @@
1
- export declare abstract class FhirServer {
2
- baseUrl: string | undefined;
3
- abstract call_fhir_server(url: string, params: string): Promise<any>;
4
- }
@@ -1,8 +0,0 @@
1
- import "../bootstrap";
2
- import { FhirServer } from "./fhir_server";
3
- export declare class GetMedicalRecord {
4
- private fhir_server;
5
- constructor(fhir_server: FhirServer);
6
- get(patient_id: string): Promise<any>;
7
- format_query(patient_id: string): string;
8
- }
@@ -1,5 +0,0 @@
1
- import { FhirServer } from "./fhir_server";
2
- export declare class HapiFhirServer extends FhirServer {
3
- baseUrl: string;
4
- call_fhir_server(url: string, params: string): Promise<any>;
5
- }
@@ -1,4 +0,0 @@
1
- import "./bootstrap";
2
- export { FhirServer } from "./fhir_server";
3
- export { GetMedicalRecord } from "./get_medical_record";
4
- export { HapiFhirServer } from "./hapi_server";
@@ -1,37 +0,0 @@
1
- import "../bootstrap";
2
- import { SelfGenCotChain } from "../chains/self_gen_cot_chain";
3
- import { pull } from "langchain/hub";
4
- import type { PromptTemplate } from "@langchain/core/prompts";
5
- import { SequentialChain, LLMChain } from "langchain/chains";
6
- import { container } from "tsyringe";
7
- import { LLM } from "langchain/llms/base";
8
- import { AgentExecutor, createReactAgent } from "langchain/agents";
9
- import { Tool } from "langchain/tools";
10
- import type { ToolInterface } from "@langchain/core/tools";
11
-
12
- export class ExplainAgent {
13
-
14
- tools: any[];
15
-
16
- constructor(tools: any[] = [new SelfGenCotChain()]) {
17
- this.tools = tools;
18
- }
19
-
20
-
21
- async run(input: any){
22
- const promptWithChat = await pull<PromptTemplate>("hwchase17/react-chat");
23
- const llm: LLM = container.resolve("main-llm");
24
- const tools: ToolInterface[] = this.tools;
25
- const agentWithChat = await createReactAgent({
26
- llm,
27
- tools,
28
- prompt: promptWithChat,
29
- });
30
- const agentExecutorWithChat = new AgentExecutor({
31
- agent: agentWithChat,
32
- tools,
33
- });
34
- const result2 = await agentExecutorWithChat.invoke(input);
35
- return result2;
36
- }
37
- }
@@ -1,4 +0,0 @@
1
- import "./bootstrap";
2
-
3
- export { ExplainAgent } from "./explain_agent";
4
-
package/src/bootstrap.ts DELETED
@@ -1,17 +0,0 @@
1
- import "reflect-metadata";
2
- import { HapiFhirServer } from "./utils/hapi_server";
3
- import { container } from "tsyringe";
4
- import { GoogleVertexAI } from "langchain/llms/googlevertexai";
5
-
6
- const google_vertex_ai = new GoogleVertexAI({
7
- model: "text-bison",
8
- temperature: 0.2,
9
- });
10
-
11
- container.register("main-llm", {
12
- useValue: google_vertex_ai,
13
- });
14
-
15
- container.register("FhirServer", {
16
- useClass: HapiFhirServer,
17
- });
@@ -1,2 +0,0 @@
1
- import "./bootstrap";
2
- export { SelfGenCotChain } from "./self_gen_cot_chain";
@@ -1,82 +0,0 @@
1
- import "../bootstrap";
2
- import { SequentialChain, LLMChain, BaseChain } from "langchain/chains";
3
- import { container } from "tsyringe";
4
- import { PromptTemplate } from "langchain/prompts";
5
- import { LLM } from "langchain/llms/base";
6
- import { BaseCache, ChainValues } from "langchain/dist/schema";
7
- import { CallbackManagerForChainRun } from "langchain/dist/callbacks";
8
-
9
-
10
- export class SelfGenCotChain {
11
-
12
- private llm: LLM = container.resolve("main-llm");
13
- name: string = "self generated explanation";
14
- description: string = "Generate a chain of thought explanation for the answer to a question.";
15
- private template: string = `
16
- ## Question: {question}
17
- ## Answer: {answer}
18
- Given the above question and answer, generate a chain of thought explanation for the answer.
19
- First, start with the model generated chain of thought explanation.
20
- End the chain of though explanation with:
21
- Therefore, the answer is {answer}.
22
- `;
23
-
24
- constructor(
25
- llm?: LLM,
26
- name?: string,
27
- template?: string,
28
- description?: string,
29
- ) {
30
- if (llm)
31
- this.llm = llm;
32
- if (name)
33
- this.name = name;
34
- if (template)
35
- this.template = template;
36
- if (description)
37
- this.description = description;
38
- }
39
-
40
- promptTemplate: PromptTemplate = new PromptTemplate({
41
- template: this.template,
42
- inputVariables: ["question", "answer"],
43
- });
44
-
45
- chain: LLMChain = new LLMChain({
46
- llm: this.llm,
47
- prompt: this.promptTemplate,
48
- outputKey: "explanation",
49
- });
50
-
51
- async call(args: { question: string, answer: string }) {
52
- const chainExecutionResult = await this.chain.call(args);
53
- return chainExecutionResult;
54
- }
55
-
56
- _call(values: ChainValues, runManager?: CallbackManagerForChainRun | undefined): Promise<ChainValues> {
57
- throw new Error("Method not implemented.");
58
- }
59
- _chainType(): string {
60
- return "self_gen_cot_chain";
61
- }
62
- get inputKeys(): string[] {
63
- return ["question", "answer"];
64
- }
65
- get outputKeys(): string[] {
66
- return ["explanation"];
67
- }
68
-
69
- public getName() {
70
- return this.name;
71
- }
72
-
73
- public getTemplate() {
74
- return this.template;
75
- }
76
-
77
- public getDescription() {
78
- return this.description;
79
- }
80
-
81
- }
82
-
@@ -1,5 +0,0 @@
1
- import "./bootstrap";
2
-
3
- import app from '../../src/server/sample_app';
4
-
5
- export default app;
@@ -1,47 +0,0 @@
1
- import { SelfGenCotChain, ExplainAgent } from "../../dist/medpromptjs.esm.js"
2
- import dotenv from "dotenv";
3
- import express from "express";
4
- import cors from "cors";
5
- dotenv.config();
6
-
7
-
8
- const app = express();
9
- app.use(cors({ origin: "*" }));
10
-
11
-
12
- const chain = new SelfGenCotChain();
13
- const agent = new ExplainAgent();
14
-
15
- app.get("/explain", async (req, res) => {
16
- const input = req.query.input;
17
- const chat_history = req.query.chat_history;
18
- const input2 = {
19
- input: input,
20
- chat_history: chat_history,
21
- }
22
- if (input && typeof input === "string" && chat_history && typeof chat_history === "string") {
23
- const response = await agent.run(input2);
24
- res.json(response);
25
- } else {
26
- res.json({ error: "No message provided" });
27
- }
28
- });
29
-
30
- app.get("/chain", async (req, res) => {
31
- const question = req.query.question;
32
- const answer = req.query.answer;
33
- const input = {
34
- question: question,
35
- answer: answer,
36
- }
37
- if (question && typeof question === "string" && answer && typeof answer === "string") {
38
- const response = await chain.call(input);
39
- res.json(response);
40
- } else {
41
- res.json({ error: "No message provided" });
42
- }
43
- });
44
-
45
- app.listen(5000, () => {
46
- console.log("Server running on http://localhost:5000");
47
- });
@@ -1,51 +0,0 @@
1
- import "../bootstrap";
2
- import { SelfGenCotChain } from "../chains/self_gen_cot_chain";
3
- import { ExplainAgent } from '../../src/agents/explain_agent';
4
- import * as dotenv from "dotenv";
5
- import express from "express";
6
- import cors from "cors";
7
- dotenv.config();
8
-
9
- const app = express();
10
- app.use(cors({ origin: "*" }));
11
-
12
- const chain = new SelfGenCotChain();
13
- const agent = new ExplainAgent();
14
-
15
- app.get("/explain", async (req: any, res: any) => {
16
- const input = req.query.input;
17
- const chat_history = req.query.chat_history;
18
- const input2 = {
19
- input: input,
20
- chat_history: chat_history,
21
- }
22
- if (input && typeof input === "string" && chat_history && typeof chat_history === "string") {
23
- const response = await agent.run(input2);
24
- res.json(response);
25
- } else {
26
- res.json({ error: "No message provided" });
27
- }
28
- });
29
-
30
-
31
- app.get("/chain", async (req: any, res: any) => {
32
- const question = req.query.question;
33
- const answer = req.query.answer;
34
- const input = {
35
- question: question,
36
- answer: answer,
37
- }
38
- if (question && typeof question === "string" && answer && typeof answer === "string") {
39
- const response = await chain.call(input);
40
- res.json(response);
41
- } else {
42
- res.json({ error: "No message provided" });
43
- }
44
- });
45
-
46
-
47
- app.listen(5000, () => {
48
- console.log("Server running on http://localhost:5000");
49
- });
50
-
51
- export default app;
@@ -1,51 +0,0 @@
1
- import "../bootstrap";
2
- import { DynamicTool, DynamicStructuredTool } from "langchain/tools";
3
- import { z } from "zod";
4
- import { GetMedicalRecord } from "../utils/get_medical_record";
5
- import { container } from "tsyringe";
6
- import { get } from "langchain/util/convex";
7
- import { FhirServer } from "../utils/fhir_server";
8
-
9
-
10
- export const FhirPatientSearchTool = new DynamicStructuredTool({
11
- name: "patient search",
12
- description: `
13
- Searches FHIR server for a patient with available data.
14
- given: Given name of the patient.
15
- family: Family name of the patient.
16
- birth_date: Date of birth of the patient.
17
- patient_id: ID of the patient.
18
- All parameters are optional.
19
- Returns a list of all matching patient names if multiple patients are found.
20
- If no patient is found, returns the string "No patient found".
21
- If only one patient is found, returns the patient ID as a string.
22
- `,
23
- schema: z.object({
24
- given: z.string(),
25
- family: z.string(),
26
- birth_date: z.string(),
27
- patient_id: z.string(),
28
- }),
29
- func: async (args) => {
30
- const fhir_server: FhirServer = container.resolve("FhirServer");
31
- const { given, family, birth_date, patient_id } = args;
32
- let query = "Patient?"
33
- if (patient_id) {
34
- query += `_id=${patient_id}`
35
- }
36
- if (given) {
37
- query += `&given=${given}`
38
- }
39
- if (family) {
40
- query += `&family=${family}`
41
- }
42
- if (birth_date) {
43
- query += `&birthdate=${birth_date}`
44
- }
45
- const data = await fhir_server.call_fhir_server(
46
- "",
47
- query,
48
- );
49
- return data;
50
- },
51
- });
@@ -1,4 +0,0 @@
1
- import "./bootstrap";
2
-
3
- export { FhirPatientSearchTool } from "./find_patient";
4
-