Permalink
Browse files

loadPhoto(), renamePatient(patient,fN,lN), renamePhoto partially done

  • Loading branch information...
1 parent 0bd16df commit e2d6b31a16bc9c84c8d7f95688a17cd62db4c2cd @jcline jcline committed Apr 16, 2012
Showing with 61 additions and 6 deletions.
  1. +54 −0 src/database/fs.py
  2. +3 −2 src/database/patientstorage.py
  3. +4 −4 src/database/photostorage.py
View
@@ -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
+
@@ -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):
"""
@@ -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

0 comments on commit e2d6b31

Please sign in to comment.