Coverage for crateweb/consent/lookup_dummy.py: 25%

16 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-08-27 10:34 -0500

1""" 

2crate_anon/crateweb/consent/lookup_dummy.py 

3 

4=============================================================================== 

5 

6 Copyright (C) 2015, University of Cambridge, Department of Psychiatry. 

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

8 

9 This file is part of CRATE. 

10 

11 CRATE is free software: you can redistribute it and/or modify 

12 it under the terms of the GNU General Public License as published by 

13 the Free Software Foundation, either version 3 of the License, or 

14 (at your option) any later version. 

15 

16 CRATE is distributed in the hope that it will be useful, 

17 but WITHOUT ANY WARRANTY; without even the implied warranty of 

18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

19 GNU General Public License for more details. 

20 

21 You should have received a copy of the GNU General Public License 

22 along with CRATE. If not, see <https://www.gnu.org/licenses/>. 

23 

24=============================================================================== 

25 

26**Function to "look up" patient details from a fictional dummy database.** 

27 

28""" 

29 

30from typing import List 

31 

32from django.core.exceptions import ObjectDoesNotExist 

33 

34from crate_anon.crateweb.consent.models import ( 

35 DummyPatientSourceInfo, 

36 PatientLookup, 

37 PatientLookupBase, 

38) 

39 

40 

41# ============================================================================= 

42# Dummy clinical database (part of CRATE) 

43# ============================================================================= 

44 

45 

46# noinspection PyUnusedLocal 

47def lookup_dummy_clinical( 

48 lookup: PatientLookup, decisions: List[str], secret_decisions: List[str] 

49) -> None: 

50 """ 

51 Looks up a patient from the fictional dummy database. 

52 

53 Args: 

54 lookup: a :class:`crate_anon.crateweb.consent.models.PatientLookup` 

55 decisions: list of human-readable decisions; will be modified 

56 secret_decisions: list of human-readable decisions containing secret 

57 (identifiable) information; will be modified 

58 """ 

59 try: 

60 dummylookup = DummyPatientSourceInfo.objects.get( 

61 nhs_number=lookup.nhs_number 

62 ) 

63 except ObjectDoesNotExist: 

64 decisions.append("Patient not found in dummy lookup") 

65 return 

66 # noinspection PyProtectedMember 

67 fieldnames = [f.name for f in PatientLookupBase._meta.get_fields()] 

68 for fieldname in fieldnames: 

69 setattr(lookup, fieldname, getattr(dummylookup, fieldname)) 

70 lookup.pt_found = True 

71 lookup.gp_found = True 

72 lookup.clinician_found = True 

73 decisions.append("Copying all information from dummy lookup")