From e2d6b31a16bc9c84c8d7f95688a17cd62db4c2cd Mon Sep 17 00:00:00 2001 From: James Cline Date: Mon, 16 Apr 2012 18:23:08 +0000 Subject: [PATCH] loadPhoto(), renamePatient(patient,fN,lN), renamePhoto partially done --- src/database/fs.py | 54 ++++++++++++++++++++++++++++++++++ src/database/patientstorage.py | 5 ++-- src/database/photostorage.py | 8 ++--- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/database/fs.py b/src/database/fs.py index 556f029..8856b1e 100644 --- a/src/database/fs.py +++ b/src/database/fs.py @@ -633,3 +633,57 @@ def loadPhotosetTreatments(self, photoset): # TODO: error codes print("could not access: " + directory) return None + + def loadPhoto(self, photo): + """ + Loads the actual photo. + + Arguments: + photo: The photo object who's data we want. + + Returns: + The image data for the photo. + + Throws: + IOError + ? + """ + directory = self.generatePhotosetDir(photo.photoset) + if os.path.isdir(directory): + f = open(directory + photo.name) + data = f.read() + + return data + + def renamePatient(self, patient, firstName, lastName): + uid = patient.uid + fromDirectory = self.generatePatientDir(patient) + toDirectory = self.root + "/" + lastName + ", " + firstName + "#" + str(uid) + + if os.path.isdir(toDirectory): + raise Exception + + shutil.copytree(fromDirectory, toDirectory) + + shutil.rmtree(fromDirectory) + + + def renamePhoto(self, photo, name): + """ + Renames a photo in the filesystem. + + Arguments: + photo: The photo object we want to rename. + name: The new name. + + Returns: + N/A + + Throws: + Error + """ + directory = self.generatePhotosetDir(photo.photoset) + if os.path.isdir(directory): + shutil.copy(directory + "/" + photo.name, directory + "/" + name) + #shutil.rm + diff --git a/src/database/patientstorage.py b/src/database/patientstorage.py index e9c8a39..a118894 100644 --- a/src/database/patientstorage.py +++ b/src/database/patientstorage.py @@ -142,11 +142,12 @@ def createPatient(self, firstName, lastName, physicians): self.fsm.addPhysicians(patient, physicians) return patient - def editName(self, firstName, lastName): + def editName(self, patient, firstName, lastName): """ Changes the name of a patient and adjusts it's database entries. Arguments: + firstName: The first name of the patient. lastName: The last name of the patient. @@ -157,7 +158,7 @@ def editName(self, firstName, lastName): ? """ if not self.checkNewFS(): - pass + self.fsm.renamePatient(patient, firstName, lastName) def editPhysicians(self, patient, physicians): """ diff --git a/src/database/photostorage.py b/src/database/photostorage.py index a650015..921415a 100644 --- a/src/database/photostorage.py +++ b/src/database/photostorage.py @@ -21,12 +21,12 @@ def __init__(self, dbm, fsm): self.dbm = dbm self.fsm = fsm - def getPhotoData(self, phot): - pass + def getPhotoData(self, photo): + return self.fsm.getPhoto(photo) - def renamePhoto(self, phot, toName): + def renamePhoto(self, photo, toName): pass - def movePhoto(self, phot, toPhotoset): + def movePhoto(self, photo, toPhotoset): pass