Skip to content

Instantly share code, notes, and snippets.

View FlaviuSim's full-sized avatar

Flaviu Simihaian FlaviuSim

View GitHub Profile
def get_drugs(request):
if request.is_ajax():
q = request.GET.get('term', '')
drugs = Drug.objects.filter(short_name__icontains = q )[:20]
results = []
for drug in drugs:
drug_json = {}
drug_json['id'] = drug.rxcui
drug_json['label'] = drug.short_name
drug_json['value'] = drug.short_name
def load_drugs3(file_path):
reader = csv.DictReader(file_path)
for row in reader:
drug = Drug(rxcui=row['Rxcui'], short_name=row['Short Name'], is_brand
= row['Is Brand'])
drug.save
def load_drugs3(file_path):
"this loads drugs from pipe delimited file with headers"
reader = csv.DictReader(file_path)
for row in reader:
drug = Drug(rxcui=row['Rxcui'], short_name=row['Short Name'], is_brand
= row['Is Brand'])
drug.save()
import csv, sys
lengths = {}
with open(sys.argv[1], 'rt') as f:
reader = csv.DictReader(f, delimiter='|')
for index, row in enumerate(reader):
if index == 0:
for heading in row.keys():
lengths[heading] = 0
for column in row.keys():
if (len(row[column]) > lengths[column]):
#import "AppDelegate.h"
#import "PatientTableViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
#import "DrugFetcher.h"
#import "/usr/include/sqlite3.h"
#import "Drug.h"
@implementation DrugFetcher
#define DATABASE_NAME @"drug_list.sqlite3"
+ (void) populateDrugsInManagedObjectContext:(NSManagedObjectContext *)context
{
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
NSError *error = nil;
NSURL *storeURL = [NSURLfileURLWithPath:storePath];
__persistentStoreCoordinator = [[NSPersistentStoreCoordinatoralloc] initWithManagedObjectModel:[selfmanagedObjectModel]];
if (![__persistentStoreCoordinatoraddPersistentStoreWithType:NSSQLiteStoreTypeconfiguration:nilURL:storeURL options:nilerror:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
NSLog(@"Final Store path is: %@", [storeURL path]);
return__persistentStoreCoordinator
NSError *error = nil;
NSURL *storeURL = [NSURLfileURLWithPath:storePath];
__persistentStoreCoordinator = [[NSPersistentStoreCoordinatoralloc] initWithManagedObjectModel:[selfmanagedObjectModel]];
if (![__persistentStoreCoordinatoraddPersistentStoreWithType:NSSQLiteStoreTypeconfiguration:nilURL:storeURL options:nilerror:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
NSLog(@"Final Store path is: %@", [storeURL path]);
return__persistentStoreCoordinator
NSString *storePath = [[[selfapplicationDocumentsDirectory] URLByAppendingPathComponent: @"CoreDataStore.sqlite"] path];
// Check if the store exists in.
if (![[NSFileManagerdefaultManager] fileExistsAtPath:storePath]) {
// copy the payload to the store location.
NSString *bundlePath = [[NSBundlemainBundle] bundlePath];
NSString *bundleStore = [bundlePath stringByAppendingPathComponent:@"persistentStore"];
NSError *error = nil;
[[NSFileManagerdefaultManager] copyItemAtPath:bundleStore toPath:storePath error:&error];