def create_patient(): patientId = utils.makeId() patients = db.getPatients() ids = [patient.id for patient in patients] while patientId in ids: patientId = utils.makeId() return create_patient_with_id(patientId)
def create_doctor(): doctorId = utils.makeId() doctors = db.getDoctors() ids = [docotr.id for docotr in doctors] while doctorId in ids: doctorId = utils.makeId() return create_doctor_with_id(doctorId)
def findUnmatchedDRNumbers (): """ Find DR numbers for which no asset is currently located """ am_items = AssetMap("nldr_data").items print "%d asset map items" % len(am_items) # print "\n e.g. '%s'" % am_items[2] from dr_mappings import DRMappings drmap = DRMappings() drnums = drmap.keys() print "%d dr numbers" % len (drnums) drlookup = {} unmatched_DRs = [] for dr in drmap.keys(): idNum = utils.getIdNum (dr) #print "idNum: ", idNum assetId = utils.makeId ("asset", idNum) #print "assetId: ", assetId if assetId not in am_items: unmatched_DRs.append (dr) unmatched_DRs.sort() return unmatched_DRs
def matchAllDrNumbersToRecords(): from dr_mappings import DRMappings for drNumber in DRMappings().keys(): asset = utils.makeId("asset", utils.getIdNum(drNumber)) try: recId = AssetRecordGetter(asset).result.recId # print asset, recId except: print sys.exc_info()[1]
def populate(self): """ populate the composite DR map - handmapped DRs are taken as is - DRMappings try to find the RecordID associated with a DR number by converting DR to asset id and then using webservice to find the record in which this asset is cataloged """ for drNum in self.drNumbers: if drNum in self.handMappings.keys(): # take handMappings verbatim self[drNum] = self.handMappings[drNum] else: idNum = utils.getIdNum(drNum) assetId = utils.makeId("asset", idNum) try: result = AssetRecordGetter(assetId).result self[drNum] = result.recId print "%s -> %s" % (drNum, self[drNum]) except AssetRecordGetterException: self.errors.append(sys.exc_info()[1])
from main import app, db from utils import makeId, getHash import json session = db.session BUCKET_ID = makeId() BUCKET_PASSWORD = "******" PASSWORD_HASH = getHash(BUCKET_PASSWORD) SHORTCUT_HASH = "mountains" LINK = "https://en.wikipedia.org/wiki/List_of_mountains_by_elevation" DESCR = "List of mountains by elevation" print("################ DB TESTS ###################") # Provided DB tests ## No buckets to begin with assert (len(db.getBuckets()) == 0) ## Adding a bucket db.addBucket(id=BUCKET_ID, passwordHash=PASSWORD_HASH) assert (len(db.getBuckets()) == 1) bucket = db.getBucket(BUCKET_ID) assert (bucket is not None) assert (bucket.id == BUCKET_ID) assert (bucket.passwordHash == PASSWORD_HASH) assert (db.getBucket(BUCKET_ID + "bah") is None) assert (db.getBuckets()[0] is bucket) db.commit() ## Deleting the bucket db.deleteBucket(bucket) bucket = db.getBucket(BUCKET_ID) assert (bucket is None)
from main import app, db from utils import makeId, getHash import utils import json from datetime import datetime, timedelta #for testing session = db.session PATIENT_ID = makeId() DOCTOR_ID = makeId() print("################ DB TESTS ###################") print("###### PATIENT TESTS ######") # No Patients to begin with assert (len(db.getPatients()) == 0) # Creating a patient db.addPatient(id=PATIENT_ID, FirstName="Bob", LastName="Mann") assert (len(db.getPatients()) == 1) assert (db.getPatients()[0].FirstName == "Bob") assert (db.getPatients()[0].LastName == "Mann") # Creating a patient with the default db.addPatient_default(id=1) assert (len(db.getPatients()) == 2) patient_1 = db.getPatient(PATIENT_ID) assert (patient_1.id is not None) assert (patient_1.id == PATIENT_ID) assert (patient_1.FirstName == "Bob") patient_2 = db.getPatient(2) assert patient_2 is None patient_2 = db.getPatient(1) assert patient_2.FirstName == "Jane"
def bucket_create(): bucketId = utils.makeId() return bucket_create_with_id(bucketId)
def shortcut_create(bucketId): hash = utils.makeId() return shortcut_create_with_hash(bucketId, hash)
def reportAllDrNumbersToRecords(): from dr_mappings import DRMappings for drNumber in DRMappings().keys(): asset = utils.makeId("asset", utils.getIdNum(drNumber)) recId = AssetRecordGetter(asset)