Exemplo n.º 1
0
 def list(self):
     if self.request.GET.__contains__('unhcr'):
         res = SerializedSynchronizationProcessor(
             self.device).search_patient_unhcr(self.request.GET['unhcr'])
     elif self.request.GET.__contains__('birthYear'):
         year = self.request.GET['birthYear']
         city = None
         first_name = None
         last_name = None
         gender = None
         if self.request.GET.__contains__('birthCity'):
             city = self.request.GET['birthCity']
         if self.request.GET.__contains__('firstName'):
             first_name = self.request.GET['firstName']
         if self.request.GET.__contains__('lastName'):
             last_name = self.request.GET['lastName']
         if self.request.GET.__contains__('gender'):
             gender = self.request.GET['gender']
         res = SerializedSynchronizationProcessor(
             self.device).search_patient(year, first_name, last_name, city,
                                         gender)
     else:
         raise NotFound()
     if self._use_transport_encryption():
         res = self.serializer.serialize(res).encode("utf-8")
         res = self.device.key.encrypt(res)
     return Data(res, should_prepare=False)
Exemplo n.º 2
0
 def test_deserialize_superfluous_fields(self):
     ''' Make sure you can't overwrite internals by specifying unusual field names - since we just paste them into __dict__ atm '''
     ssp = SerializedSynchronizationProcessor(self.d1)
     p1 = Patient()
     with patch("sana_pchr.sync.SynchronizationProcessor.apply_changes") as patched_intake:
         ssp.apply_changes({"Patient": [{"uuid": str(p1.uuid), "top_secret_field": "DROP ALL THE TABLES"}]})
         p1m = patched_intake.call_args[0][0][0]
         self.assertFalse(hasattr(p1m, "top_secret_field"))
Exemplo n.º 3
0
 def list(self):
     if self.request.GET.__contains__('contact'):
         res = SerializedSynchronizationProcessor(
             self.device).search_physician_contact(
                 self.request.GET['contact']),
     elif self.request.GET.__contains__('add_physician'):
         res = SerializedSynchronizationProcessor(
             self.device).add_physician(self.request.GET['add_physician'])
     else:
         raise NotFound()
     return Data(res, should_prepare=False)
Exemplo n.º 4
0
 def test_deserialize_m2m(self):
     ''' Ensure that existing records can be updated from their serialized counterparts '''
     ssp = SerializedSynchronizationProcessor(self.d1)
     p1 = Patient.objects.create(firstName="roth")
     py1 = Physician.objects.create(firstName='ilise', lastName='bhat', hashedPIN='1234')
     rel = Patient_Physician(patient=p1, physician=py1)
     ssp.apply_changes({"Patient_Physician": [
         {"uuid": str(rel.uuid), "patient_uuid": str(rel.patient.uuid), "physician_uuid": str(rel.physician.uuid)}]})
     relm = Patient_Physician.objects.get(uuid=rel.uuid)
     self.assertEqual(relm.patient, p1)
     self.assertEqual(relm.physician, py1)
Exemplo n.º 5
0
 def test_deserialize_insert(self):
     ''' Ensure that new records can be inserted from their serialized counterparts '''
     ssp = SerializedSynchronizationProcessor(self.d1)
     p1 = Patient()
     mod_date = p1.updated + timedelta(seconds=5)
     with patch("sana_pchr.sync.SynchronizationProcessor.apply_changes") as patched_intake:
         ssp.apply_changes({"Patient": [{"uuid": str(p1.uuid), "firstName": "isa", "updated": mod_date.isoformat(),
                                         "synchronized": "sure is handy thisll get deleted before parsing"}]})
         p1m = patched_intake.call_args[0][0][0]
         self.assertEqual(p1m.firstName, "isa")
         # The timestamp will get parsed when someone calls full_clean()
         # That's not really the purview of this wrapper - so just use the string
         self.assertEqual(p1m.updated, mod_date.isoformat())
Exemplo n.º 6
0
    def test_serialize(self):
        ''' Make sure the serialization wrapper doesn't light on fire '''
        ssp = SerializedSynchronizationProcessor(self.d1)
        py1 = Physician.objects.create(firstName='ilise', lastName='bhat', hashedPIN='1234')
        p1 = Patient.objects.create(firstName="roth")
        Patient_Physician(patient=p1, physician=py1).save()
        Clinic_Physician(clinic=self.c1, physician=py1).save()

        with patch("sana_pchr.sync.SynchronizationProcessor.calculate_delta", return_value=[(Patient, [p1])]):
            res = ssp.calculate_delta("the beginning of time")
            # Good enough for here
            # I don't really want to unit-test the individual serializations
            # ...and I'd rather defer that kind of stuff to the API tests where I can use approvals
            assert (hasattr(res, "keys"))
Exemplo n.º 7
0
 def list(self):
     if self.request.GET.__contains__('synchronized_after'):
         datestring = self.request.GET["synchronized_after"]
         datestring = datestring.replace(" ", "+")
         synchronized_after_ts = dateutil.parser.parse(datestring)
         if not synchronized_after_ts.tzinfo:
             synchronized_after_ts = pytz.utc.localize(synchronized_after_ts)
         res = SerializedSynchronizationProcessor(self.device).calculate_delta(synchronized_after_ts)
     elif self.request.GET.__contains__('add_patient'):
         res = SerializedSynchronizationProcessor(self.device).add_patient(self.request.GET['add_patient'],
                                                                           self.request.GET['physician'])
     elif self.request.GET.__contains__('add_physician'):
         res = SerializedSynchronizationProcessor(self.device).add_physician(self.request.GET['add_physician'])
         return Data(res, should_prepare=False)
     else:
         raise NotFound()
     if self._use_transport_encryption():
         res = self.serializer.serialize(res).encode("utf-8")
         res = self.device.key.encrypt(res)
     return Data(res, should_prepare=False)
Exemplo n.º 8
0
 def create(self):
     if self._use_transport_encryption():
         try:
             data = self.serializer.deserialize(self.device.key.decrypt(self.data))
         except Credential.AuthenticationException:
             raise Unauthorized()
     else:
         data = self.data
     try:
         SerializedSynchronizationProcessor(self.device).apply_changes(data)
     except DjValidationError as e:
         # This isn't the best - they'll see messages associated with field names, but not the model of that field
         # But, requestors should probably get it right on the first try and not have to rely on the error message programatically
         raise ValidationError(e)