-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,64 @@ | ||
"""Anamnesis.ai.""" | ||
# from dotenv import load_dotenv | ||
# load_dotenv() | ||
import json | ||
import os | ||
|
||
from langchain import OpenAI | ||
from langchain.embeddings import HuggingFaceEmbeddings | ||
from langchain.prompts import ( | ||
SemanticSimilarityExampleSelector, | ||
) | ||
from langchain.prompts.prompt import PromptTemplate | ||
from langchain.utilities import SQLDatabase | ||
from langchain.vectorstores import Chroma | ||
from langchain_experimental.sql import SQLDatabaseChain | ||
|
||
with open("resource_templates.json", "r") as f: | ||
resource_templates = json.load(f) | ||
|
||
|
||
def db_chain(): | ||
db_user = "root" | ||
db_password = "root" | ||
db_host = "localhost" | ||
db_name = "Fhir" | ||
|
||
db = SQLDatabase.from_uri( | ||
f"mysql+pymysql://{db_user}:{db_password}@{db_host}/{db_name}", | ||
sample_rows_in_table_info=3, | ||
) | ||
llm = OpenAI(openai_api_key=os.environ["API_KEY"], temperature=0.7) | ||
|
||
embeddings = HuggingFaceEmbeddings( | ||
model_name="sentence-transformers/all-MiniLM-L6-v2" | ||
) | ||
to_vectorize = [" ".join(example.values()) for example in database] | ||
vectorstore = Chroma.from_texts( | ||
to_vectorize, embeddings, metadatas=database | ||
) # need to create a database file to share the format of sql database | ||
example_selector = SemanticSimilarityExampleSelector( | ||
vectorstore=vectorstore, | ||
k=2, | ||
) | ||
fhir_prompt = """You are a FHIR Resource generating expert. Given a converstion between doctor and patient, first create a syntactically correct FHIR resource in JSON Format as specified by the user then look at the results and return the FHIR resource to the input conversation. | ||
Never create random values for values that are not present in the conversation. You must only the columns that are needed to answer the question. Wrap each column name in backticks (`) to denote them as delimited identifiers. | ||
Generate the following FHIR resources based on the conversation and exam: | ||
Patient: Capture the patient's demographics and medical history details. | ||
Practitioner: Identify the doctor involved in the encounter. | ||
Encounter: Describe the patient-doctor interaction, including the reason for the visit. | ||
Observation: Record the patient's reported symptoms and the physical exam findings. | ||
Use clear and concise language for each resource. Maintain patient confidentiality and adhere to HIPAA regulations. Strive for accuracy and consistency in your FHIR structures. | ||
resource_template = resource_templates["resource"] | ||
No pre-amble. | ||
""" | ||
|
||
example_prompt = PromptTemplate( | ||
input_variables=["Conversation"], | ||
template="\nConversation: {Conversation}\nFhir: {Resource}\nResource Template: {ResourceTemplate}", | ||
) | ||
|
||
chain = SQLDatabaseChain.from_llm( | ||
llm, db, verbose=True, prompt=few_shot_prompt | ||
) | ||
return chain |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"AllergyIntolerance": { | ||
"resourceType": "AllergyIntolerance", | ||
"id": "<AllergyIntolerance ID>", | ||
"patient": { | ||
"reference": "Patient/<Patient ID>" | ||
}, | ||
"substance": { | ||
"coding": [] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"resourceType": "CarePlan", | ||
"id": "<Placeholder: diisi setelah care plan tersedia>" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"resourceType": "Condition", | ||
"id": "<Placeholder: diisi setelah diagnosis tersedia>" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"resourceType": "DiagnosticReport", | ||
"id": "<Placeholder: diisi setelah hasil pemeriksaan tersedia>" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"resourceType": "Encounter", | ||
"id": "<Encounter ID>", | ||
"status": "finished", | ||
"subject": { | ||
"reference": "Patient/<Patient ID>" | ||
}, | ||
"participant": [ | ||
{ | ||
"type": [ | ||
{ | ||
"coding": [ | ||
{ | ||
"system": "http://terminology.hl7.org/CodeSystem/encounter-participant-type", | ||
"code": "TPA" | ||
} | ||
] | ||
} | ||
], | ||
"actor": { | ||
"reference": "Practitioner/<Practitioner ID>" | ||
} | ||
} | ||
], | ||
"reasonCode": [ | ||
{ | ||
"coding": [ | ||
{ | ||
"system": "<Reason Code System>", | ||
"code": "<Reason Code>" | ||
} | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"resourceType": "MedicationRequest", | ||
"id": "<Placeholder: diisi setelah prescription details tersedia>" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"resourceType": "Observation", | ||
"id": "<Observation ID>", | ||
"status": "final", | ||
"subject": { | ||
"reference": "Patient/<Patient ID>" | ||
}, | ||
"category": { | ||
"coding": [ | ||
{ | ||
"system": "<Observation Category Coding System>", | ||
"code": "<Observation Category Code>" | ||
} | ||
] | ||
}, | ||
"code": { | ||
"coding": [ | ||
{ | ||
"system": "<Observation Code System>", | ||
"code": "<Observation Code>" | ||
} | ||
] | ||
}, | ||
"value": "<Observation Value>" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"resourceType": "Patient", | ||
"id": "<Patient ID>", | ||
"active": true, | ||
"name": [ | ||
{ | ||
"use": "official", | ||
"text": "<Patient Full Name>" | ||
} | ||
], | ||
"telecom": [ | ||
{ | ||
"system": "phone", | ||
"value": "<Patient Phone Number>" | ||
}, | ||
{ | ||
"system": "email", | ||
"value": "<Patient Email Address>" | ||
} | ||
], | ||
"birthDate": "<Patient Date of Birth>", | ||
"gender": "<Patient Gender>", | ||
"maritalStatus": { | ||
"coding": [ | ||
{ | ||
"system": "<Marital Status Coding System>", | ||
"code": "<Marital Status Code>" | ||
} | ||
] | ||
}, | ||
"address": [ | ||
{ | ||
"use": "home", | ||
"text": "<Patient Address>" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"resourceType": "Practitioner", | ||
"id": "<Practitioner ID>", | ||
"active": true, | ||
"name": [ | ||
{ | ||
"use": "official", | ||
"text": "<Practitioner Full Name>" | ||
} | ||
], | ||
"telecom": [ | ||
{ | ||
"system": "phone", | ||
"value": "<Practitioner Phone Number>" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"resourceType": "Procedure", | ||
"id": "<Placeholder: diisi setelah procedures tersedia>" | ||
} |