This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AppDelegate.h" | |
#import "PatientTableViewController.h" | |
@implementation AppDelegate | |
@synthesize window = _window; | |
@synthesize managedObjectContext = __managedObjectContext; | |
@synthesize managedObjectModel = __managedObjectModel; | |
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "DrugFetcher.h" | |
#import "/usr/include/sqlite3.h" | |
#import "Drug.h" | |
@implementation DrugFetcher | |
#define DATABASE_NAME @"drug_list.sqlite3" | |
+ (void) populateDrugsInManagedObjectContext:(NSManagedObjectContext *)context | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |