У меня есть большой json-файл, содержащий элементы в следующем формате:
{"Disease":["Cholera due to Vibrio cholerae 01, biovar cholerae\r","Cholera due to Vibrio cholerae 01, biovar eltor\r","Cholera, unspecified\r","Typhoid fever, unspecified\r","Typhoid meningitis\r","Typhoid fever with heart involvement\r","Typhoid pneumonia\r","Typhoid arthritis\r","Typhoid osteomyelitis\r","Typhoid fever with other complications\r","Paratyphoid fever A\r","Paratyphoid fever B\r","Paratyphoid fever C\r","Paratyphoid fever, unspecified\r","Salmonella enteritis\r","Salmonella sepsis\r","Localized salmonella infection, unspecified\r"],"Code":["A000","A001","A009","A0100"]}
Моя программа django будет отправлять список значений в скрипт, который должен выполнить поиск AND (то есть он вернетсязначение из словаря, если все строки поиска являются подстрока значения в Disease в json).Он должен будет возвращать несколько значений в виде json, который отправляется в javascript и обрабатывается.
В настоящее время я могу выполнить поиск ИЛИ с помощью следующего кода:
slist = ['myocardial', 'infarction']
def advanced_icd(request, slist):
import json
from myappointments.settings import PROJECT_ROOT
url = PROJECT_ROOT + '/appointments/static/clinic/db/icd10.json'
import pandas as pd
db = pd.read_json(path_or_buf=url)
codedb = db.to_dict()
result_Disease = []
result_Code = []
for (key, Disease), (key1, Code) in zip(codedb['Disease'].items(), codedb['Code'].items()):
for searchstr in slist:
searchstr = searchstr.lower()
if searchstr in Disease.lower():
print("Found a disease at key:%s Disease:%s Code:%s" %
(key, Disease, Code))
result_Disease.append(Disease)
result_Code.append(Code)
outp = json.dumps(
{'Disease': result_Disease, 'Code': result_Code})
print(outp)
advanced_icd("", slist)
Output:
Code:D735sease at key:2844 Disease:Infarction of spleen
Code:G43501ase at key:4777 Disease:Persistent migraine aura without cerebral infarction, not intractable, with status migrainosus