def test_identity_to_json(): group = Group( id=1, name='TestGroup', description='A test group', is_locking=True, client_key='testclientkey', ehb_key='testehbkey', modified=datetime.datetime(2015, 1, 1), created=datetime.datetime(2015, 1, 1), ) jsonStr = group.json_from_identity(group) assert isinstance(jsonStr, str) assert json.loads(jsonStr)
def create_protocol_subject_record_group(protocol, subject): """Create the protocol/subject record group in the EHB.""" try: n = SubjectUtils.protocol_subject_record_group_name( protocol, subject) gh = ServiceClient.get_rh_for(record_type=ServiceClient.GROUP) ck = protocol._settings_prop('CLIENT_KEY', 'key', '') grp = Group(name=n, description='A BRP Protocol Subject Record Group', is_locking=True, client_key=ck) r = gh.create(grp) return r[0].get('success') # TODO: This Exception handling is confusing. Does it work? except: raise logger.error( "Failure creating a subject record group for {0}".format( subject['id'])) return False
def test_identity_to_json_setck(): group = Group( id=1, name='TestGroup', description='A test group', is_locking=True, client_key='testclientkey', ehb_key='testehbkey', modified=datetime.datetime(2015, 1, 1), created=datetime.datetime(2015, 1, 1), ) group.current_client_key('newck') jsonStr = group.json_from_identity(group) assert isinstance(jsonStr, str) Obj = json.loads(jsonStr) assert isinstance(Obj, dict) assert Obj['current_client_key'] == 'newck'
def delete_protocol_subject_record_group(protocol, subject): try: n = SubjectUtils.protocol_subject_record_group_name(protocol, subject) gh = ServiceClient.get_rh_for(record_type=ServiceClient.GROUP) ck = protocol._settings_prop('CLIENT_KEY', 'key', '') grp = Group( name=n, description='A BRP Protocol Subject Record Group', is_locking=True, client_key=ck ) r = gh.delete(grp) return r[0].get('success') except: return False
def createEhbProtocolGroup(self): gh = ServiceClient.get_rh_for(record_type=ServiceClient.GROUP) try: gh.get(name=self.ehb_group_name()) except RequestedRangeNotSatisfiable: grp = Group( name=self.ehb_group_name(), description='A BRP Protocol Group', is_locking=True, client_key=self._client_key() ) r = gh.create(grp)[0] if not (r.get("success")): raise Exception( 'Unable to create Protocol Subject Group in ehb-service')
def create_protocol_subject_record_group(protocol, subject): try: n = SubjectUtils.protocol_subject_record_group_name(protocol, subject) gh = ServiceClient.get_rh_for(record_type=ServiceClient.GROUP) ck = protocol._settings_prop('CLIENT_KEY', 'key', '') grp = Group( name=n, description='A BRP Protocol Subject Record Group', is_locking=True, client_key=ck ) r = gh.create(grp) return r[0].get('success') except: logger.error("Failure creating a subject record group for {0}".format(n)) return False
def migrate_subject(self, subject, protocol): try: # Create a Group for this subject / protocol combination orh = ServiceClient.get_rh_for(record_type=ServiceClient.ORGANIZATION) ehb_org = orh.get(id=subject.organization_id) brp_org = Organization.objects.get(name=ehb_org.name) gh = ServiceClient.get_rh_for(record_type=ServiceClient.GROUP) ck = self._settings_prop('CLIENT_KEY', 'key', '') n = 'BRP:'+protocol.immutable_key.key+':'+brp_org.immutable_key.key+':'+subject.organization_subject_id grp = Group(name=n, description='A BRP Protocol Subject Record Group', is_locking=True, client_key=ck) gh.create(grp) print 'created subject records group: {0} for subject: {1} on protocol: {2}'.format( n, subject.organization_subject_id, protocol.name) # Add the subjects records to this group errh = ServiceClient.get_rh_for(record_type=ServiceClient.EXTERNAL_RECORD) records = errh.get(subject_id=subject.id, path=protocol.name) print 'subject {0}, {1}, id={2} has the following records:'.format( subject.last_name, subject.first_name, subject.id) for rec in records: print 'id={0}, path={1}, ex_sys_id={2}, subject_id={3}'.format( rec.id, rec.path, rec.external_system_id, rec.subject_id ) gh.add_records(grp, records) print 'added {0} records for subject: {1} on protocol: {2} to group: {3}'.format( len(records), subject.organization_subject_id, protocol.name, grp.name ) except Exception: print '********failed to move subject records for ', subject.organization_subject_id
def createEhbProtocolGroup(self): """Idempotently save the protocol as an EHB group. Raises an Exception if the group cannot be created. """ gh = ServiceClient.get_rh_for(record_type=ServiceClient.GROUP) try: gh.get(name=self.ehb_group_name()) except PageNotFound: grp = Group(name=self.ehb_group_name(), description='A BRP Protocol Group', is_locking=True, client_key=self._client_key()) r = gh.create(grp)[0] if not (r.get("success")): raise Exception( 'Unable to create Protocol Subject Group in ehb-service')
TestOrganization = Organization(id=1, name='Amazing Children\'s Hospital', subject_id_label='Subject', modified=datetime.datetime(2015, 1, 1), created=datetime.datetime(2015, 1, 1)) TestExternalRecord = ExternalRecord(record_id='xyz123', external_system_id=1, subject_id=1, path='testpath', modified=datetime.datetime(2014, 1, 1), created=datetime.datetime(2014, 1, 1), id=1, label_id=1) TestGroup = Group(id=1, name='TestGroup', is_locking=False, client_key='testck', description='A test group') BRPApiView.s_rh.get = MagicMock(return_value=TestSubject) BRPApiView.s_rh.update = MagicMock(return_value=[{ 'success': True, 'errors': [], 'subject': TestSubject }]) BRPApiView.o_rh.get = MagicMock(return_value=TestOrganization) BRPApiView.er_rh.get = MagicMock(return_value=[ ExternalRecord(record_id='xyz123', external_system_id=1, subject_id=1, path='testpath',