Coverage for tasks/tests/factories.py: 94%

1"""

2 camcops_server/tasks/tests/factories.py

3

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

5

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

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

8

9 This file is part of CamCOPS.

10

11 CamCOPS 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 CamCOPS 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 CamCOPS. If not, see <https://www.gnu.org/licenses/>.

23

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

25

26**Factory Boy SQL Alchemy test factories for tasks.**

27

28"""

29

30 import factory

31 import pendulum

32 from typing import Any, cast, TYPE_CHECKING

33

34 from camcops_server.cc_modules.cc_task import Task

35 from camcops_server.cc_modules.cc_testfactories import (

36 BlobFactory,

37 Fake,

38 GenericTabletRecordFactory,

39)

40

41 from camcops_server.tasks.ace3 import Ace3, MiniAce

42 from camcops_server.tasks.aims import Aims

43 from camcops_server.tasks.apeqpt import Apeqpt

44 from camcops_server.tasks.apeq_cpft_perinatal import APEQCPFTPerinatal

45 from camcops_server.tasks.aq import Aq

46 from camcops_server.tasks.asdas import Asdas

47 from camcops_server.tasks.audit import Audit, AuditC

48 from camcops_server.tasks.badls import Badls

49 from camcops_server.tasks.basdai import Basdai

50 from camcops_server.tasks.bdi import Bdi

51 from camcops_server.tasks.bmi import Bmi

52 from camcops_server.tasks.bprs import Bprs

53 from camcops_server.tasks.bprse import Bprse

54 from camcops_server.tasks.cage import Cage

55 from camcops_server.tasks.cape42 import Cape42

56 from camcops_server.tasks.caps import Caps

57 from camcops_server.tasks.cardinal_expdetthreshold import (

58 CardinalExpDetThreshold,

59)

60 from camcops_server.tasks.cardinal_expectationdetection import (

61 CardinalExpectationDetection,

62 ExpDetTrial,

63 ExpDetTrialGroupSpec,

64)

65 from camcops_server.tasks.cbir import CbiR

66 from camcops_server.tasks.ceca import CecaQ3

67 from camcops_server.tasks.cesd import Cesd

68 from camcops_server.tasks.cesdr import Cesdr

69 from camcops_server.tasks.cet import Cet

70 from camcops_server.tasks.cgi_task import Cgi, CgiI

71 from camcops_server.tasks.cgisch import CgiSch

72 from camcops_server.tasks.chit import Chit

73 from camcops_server.tasks.cia import Cia

74 from camcops_server.tasks.cisr import Cisr

75 from camcops_server.tasks.ciwa import Ciwa

76 from camcops_server.tasks.contactlog import ContactLog

77 from camcops_server.tasks.cope import CopeBrief

78 from camcops_server.tasks.core10 import Core10

79 from camcops_server.tasks.cpft_covid_medical import CpftCovidMedical

80 from camcops_server.tasks.cpft_lps import (

81 CPFTLPSDischarge,

82 CPFTLPSReferral,

83 CPFTLPSResetResponseClock,

84)

85 from camcops_server.tasks.cpft_research_preferences import (

86 CpftResearchPreferences,

87)

88 from camcops_server.tasks.dad import Dad

89 from camcops_server.tasks.das28 import Das28

90 from camcops_server.tasks.dast import Dast

91 from camcops_server.tasks.deakin_s1_healthreview import DeakinS1HealthReview

92 from camcops_server.tasks.demoquestionnaire import DemoQuestionnaire

93 from camcops_server.tasks.demqol import Demqol, DemqolProxy

94 from camcops_server.tasks.diagnosis import (

95 DiagnosisIcd10,

96 DiagnosisIcd10Item,

97 DiagnosisIcd9CM,

98 DiagnosisIcd9CMItem,

99)

100 from camcops_server.tasks.distressthermometer import DistressThermometer

101 from camcops_server.tasks.edeq import Edeq

102 from camcops_server.tasks.elixhauserci import ElixhauserCI

103 from camcops_server.tasks.epds import Epds

104 from camcops_server.tasks.empsa import Empsa

105 from camcops_server.tasks.eq5d5l import Eq5d5l

106 from camcops_server.tasks.esspri import Esspri

107 from camcops_server.tasks.factg import Factg

108 from camcops_server.tasks.fast import Fast

109 from camcops_server.tasks.fft import Fft

110 from camcops_server.tasks.frs import Frs

111 from camcops_server.tasks.gad7 import Gad7

112 from camcops_server.tasks.gaf import Gaf

113 from camcops_server.tasks.gbo import Gbogpc, Gbogras, Gbogres

114 from camcops_server.tasks.gds import Gds15

115 from camcops_server.tasks.gmcpq import GMCPQ

116 from camcops_server.tasks.hads import Hads, HadsRespondent

117 from camcops_server.tasks.hama import Hama

118 from camcops_server.tasks.hamd import Hamd

119 from camcops_server.tasks.hamd7 import Hamd7

120 from camcops_server.tasks.honos import Honos, Honos65, Honosca

121 from camcops_server.tasks.icd10depressive import Icd10Depressive

122 from camcops_server.tasks.icd10manic import Icd10Manic

123 from camcops_server.tasks.icd10mixed import Icd10Mixed

124 from camcops_server.tasks.icd10schizophrenia import Icd10Schizophrenia

125 from camcops_server.tasks.icd10schizotypal import Icd10Schizotypal

126 from camcops_server.tasks.icd10specpd import Icd10SpecPD

127 from camcops_server.tasks.ided3d import IDED3D

128 from camcops_server.tasks.iesr import Iesr

129 from camcops_server.tasks.ifs import Ifs

130 from camcops_server.tasks.irac import Irac

131 from camcops_server.tasks.isaaq10 import Isaaq10

132 from camcops_server.tasks.isaaqed import IsaaqEd

133 from camcops_server.tasks.khandaker_insight_medical import (

134 KhandakerInsightMedical,

135)

136 from camcops_server.tasks.khandaker_mojo_medical import KhandakerMojoMedical

137 from camcops_server.tasks.khandaker_mojo_sociodemographics import (

138 KhandakerMojoSociodemographics,

139)

140 from camcops_server.tasks.khandaker_mojo_medicationtherapy import (

141 KhandakerMojoMedicationTherapy,

142)

143 from camcops_server.tasks.kirby_mcq import Kirby

144 from camcops_server.tasks.lynall_iam_life import LynallIamLifeEvents

145 from camcops_server.tasks.lynall_iam_medical import LynallIamMedicalHistory

146 from camcops_server.tasks.maas import Maas

147 from camcops_server.tasks.mast import Mast

148 from camcops_server.tasks.mds_updrs import MdsUpdrs

149 from camcops_server.tasks.mfi20 import Mfi20

150 from camcops_server.tasks.moca import Moca

151 from camcops_server.tasks.nart import Nart

152 from camcops_server.tasks.npiq import NpiQ

153 from camcops_server.tasks.ors import Ors

154 from camcops_server.tasks.panss import Panss

155 from camcops_server.tasks.paradise24 import Paradise24

156 from camcops_server.tasks.pbq import Pbq

157 from camcops_server.tasks.pcl5 import Pcl5

158 from camcops_server.tasks.pcl import PclC, PclM, PclS

159 from camcops_server.tasks.pdss import Pdss

160 from camcops_server.tasks.perinatalpoem import PerinatalPoem

161 from camcops_server.tasks.photo import (

162 Photo,

163 PhotoSequence,

164 PhotoSequenceSinglePhoto,

165)

166 from camcops_server.tasks.phq15 import Phq15

167 from camcops_server.tasks.phq8 import Phq8

168 from camcops_server.tasks.phq9 import Phq9

169 from camcops_server.tasks.progressnote import ProgressNote

170 from camcops_server.tasks.pswq import Pswq

171 from camcops_server.tasks.psychiatricclerking import PsychiatricClerking

172 from camcops_server.tasks.qolbasic import QolBasic

173 from camcops_server.tasks.qolsg import QolSG

174 from camcops_server.tasks.rand36 import Rand36

175 from camcops_server.tasks.rapid3 import Rapid3

176 from camcops_server.tasks.service_satisfaction import (

177 PatientSatisfaction,

178 ReferrerSatisfactionGen,

179 ReferrerSatisfactionSpec,

180)

181 from camcops_server.tasks.sfmpq2 import Sfmpq2

182 from camcops_server.tasks.shaps import Shaps

183 from camcops_server.tasks.slums import Slums

184 from camcops_server.tasks.smast import Smast

185 from camcops_server.tasks.srs import Srs

186 from camcops_server.tasks.suppsp import Suppsp

187 from camcops_server.tasks.wemwbs import Swemwbs, Wemwbs

188 from camcops_server.tasks.wsas import Wsas

189 from camcops_server.tasks.ybocs import Ybocs, YbocsSc

190 from camcops_server.tasks.zbi import Zbi12

191

192 if TYPE_CHECKING:

193 from factory.builder import Resolver

194

195

196 class TaskFactory(GenericTabletRecordFactory):

197 class Meta:

198 abstract = True

199

200 @factory.lazy_attribute

201 def when_created(self) -> pendulum.DateTime:

202 datetime = cast(

203 pendulum.DateTime, pendulum.parse(self.default_iso_datetime)

204 )

205

206 return datetime

207

208

209 class TaskHasPatientFactory(TaskFactory):

210 class Meta:

211 abstract = True

212

213 patient_id = None

214

215 @classmethod

216 def create(cls, *args: Any, **kwargs: Any) -> Task:

217 patient = kwargs.pop("patient", None)

218 if patient is not None:

219 if "patient_id" in kwargs:

220 raise TypeError(

221 "Both 'patient' and 'patient_id' keyword arguments "

222 "unexpectedly passed to a task factory. Use one or the "

223 "other."

224 )

225 kwargs["patient_id"] = patient.id

226

227 if "_device" not in kwargs:

228 kwargs["_device"] = patient._device

229

230 if "_era" not in kwargs:

231 kwargs["_era"] = patient._era

232

233 if "_group" not in kwargs:

234 kwargs["_group"] = patient._group

235

236 if "_current" not in kwargs:

237 kwargs["_current"] = True

238

239 return super().create(*args, **kwargs)

240

241

242 class APEQCPFTPerinatalFactory(TaskFactory):

243 class Meta:

244 model = APEQCPFTPerinatal

245

246 id = factory.Sequence(lambda n: n + 1)

247

248

249 class ApeqptFactory(TaskFactory):

250 class Meta:

251 model = Apeqpt

252

253 id = factory.Sequence(lambda n: n + 1)

254

255

256 class BmiFactory(TaskHasPatientFactory):

257 class Meta:

258 model = Bmi

259

260 id = factory.Sequence(lambda n: n + 1)

261

262 height_m = factory.LazyFunction(Fake.en_gb.height_m)

263 mass_kg = factory.LazyFunction(Fake.en_gb.mass_kg)

264 waist_cm = factory.LazyFunction(Fake.en_gb.waist_cm)

265

266

267 class Core10Factory(TaskHasPatientFactory):

268 class Meta:

269 model = Core10

270

271 id = factory.Sequence(lambda n: n + 1)

272

273 q1 = 0

274 q2 = 0

275 q3 = 0

276 q4 = 0

277 q5 = 0

278 q6 = 0

279 q7 = 0

280 q8 = 0

281 q9 = 0

282 q10 = 0

283

284

285 class DiagnosisIcd10Factory(TaskHasPatientFactory):

286 class Meta:

287 model = DiagnosisIcd10

288

289 id = factory.Sequence(lambda n: n + 1)

290

291

292 class DiagnosisItemFactory(GenericTabletRecordFactory):

293 class Meta:

294 abstract = True

295

296

297 class DiagnosisIcd10ItemFactory(DiagnosisItemFactory):

298 class Meta:

299 model = DiagnosisIcd10Item

300

301 id = factory.Sequence(lambda n: n + 1)

302 seqnum = factory.Sequence(lambda n: n + 1)

303

304 @classmethod

305 def create(cls, *args: Any, **kwargs: Any) -> DiagnosisIcd10Item:

306 diagnosis_icd10 = kwargs.pop("diagnosis_icd10", None)

307 if diagnosis_icd10 is not None:

308 if "diagnosis_icd10_id" in kwargs:

309 raise TypeError(

310 "Both 'diagnosis_icd10' and 'diagnosis_icd10_id' keyword "

311 "arguments unexpectedly passed to a task factory. Use one "

312 "or the other."

313 )

314 kwargs["diagnosis_icd10_id"] = diagnosis_icd10.id

315

316 if "_device" not in kwargs:

317 kwargs["_device"] = diagnosis_icd10._device

318

319 if "_era" not in kwargs:

320 kwargs["_era"] = diagnosis_icd10._era

321

322 if "_current" not in kwargs:

323 kwargs["_current"] = True

324

325 return super().create(*args, **kwargs)

326

327

328 class DiagnosisIcd9CMFactory(TaskHasPatientFactory):

329 class Meta:

330 model = DiagnosisIcd9CM

331

332 id = factory.Sequence(lambda n: n + 1)

333

334

335 class DiagnosisIcd9CMItemFactory(DiagnosisItemFactory):

336 class Meta:

337 model = DiagnosisIcd9CMItem

338

339 id = factory.Sequence(lambda n: n + 1)

340 seqnum = factory.Sequence(lambda n: n + 1)

341

342 @classmethod

343 def create(cls, *args: Any, **kwargs: Any) -> DiagnosisIcd9CMItem:

344 diagnosis_icd9cm = kwargs.pop("diagnosis_icd9cm", None)

345 if diagnosis_icd9cm is not None:

346 if "diagnosis_icd9cm_id" in kwargs:

347 raise TypeError(

348 "Both 'diagnosis_icd9cm' and 'diagnosis_icd9cm_id' "

349 "keyword arguments unexpectedly passed to a task factory. "

350 "Use one or the other."

351 )

352 kwargs["diagnosis_icd9cm_id"] = diagnosis_icd9cm.id

353

354 if "_device" not in kwargs:

355 kwargs["_device"] = diagnosis_icd9cm._device

356

357 if "_era" not in kwargs:

358 kwargs["_era"] = diagnosis_icd9cm._era

359

360 if "_current" not in kwargs:

361 kwargs["_current"] = True

362

363 return super().create(*args, **kwargs)

364

365

366 class Gad7Factory(TaskHasPatientFactory):

367 class Meta:

368 model = Gad7

369

370 id = factory.Sequence(lambda n: n + 1)

371

372

373 class KhandakerMojoMedicationTherapyFactory(TaskHasPatientFactory):

374 class Meta:

375 model = KhandakerMojoMedicationTherapy

376

377 id = factory.Sequence(lambda n: n + 1)

378

379

380 class MaasFactory(TaskHasPatientFactory):

381 class Meta:

382 model = Maas

383

384 id = factory.Sequence(lambda n: n + 1)

385

386

387 class PerinatalPoemFactory(TaskFactory):

388 class Meta:

389 model = PerinatalPoem

390

391 id = factory.Sequence(lambda n: n + 1)

392

393

394 class Phq9Factory(TaskHasPatientFactory):

395 class Meta:

396 model = Phq9

397

398 id = factory.Sequence(lambda n: n + 1)

399

400

401 class Ace3Factory(TaskHasPatientFactory):

402 class Meta:

403 model = Ace3

404

405 id = factory.Sequence(lambda n: n + 1)

406

407

408 class AimsFactory(TaskHasPatientFactory):

409 class Meta:

410 model = Aims

411

412 id = factory.Sequence(lambda n: n + 1)

413

414

415 class AqFactory(TaskHasPatientFactory):

416 class Meta:

417 model = Aq

418

419 id = factory.Sequence(lambda n: n + 1)

420

421

422 class AsdasFactory(TaskHasPatientFactory):

423 class Meta:

424 model = Asdas

425

426 id = factory.Sequence(lambda n: n + 1)

427

428

429 class AuditFactory(TaskHasPatientFactory):

430 class Meta:

431 model = Audit

432

433 id = factory.Sequence(lambda n: n + 1)

434

435

436 class AuditCFactory(TaskHasPatientFactory):

437 class Meta:

438 model = AuditC

439

440 id = factory.Sequence(lambda n: n + 1)

441

442

443 class BadlsFactory(TaskHasPatientFactory):

444 class Meta:

445 model = Badls

446

447 id = factory.Sequence(lambda n: n + 1)

448

449

450 class BasdaiFactory(TaskHasPatientFactory):

451 class Meta:

452 model = Basdai

453

454 id = factory.Sequence(lambda n: n + 1)

455

456

457 class BdiFactory(TaskHasPatientFactory):

458 class Meta:

459 model = Bdi

460

461 id = factory.Sequence(lambda n: n + 1)

462

463

464 class BprsFactory(TaskHasPatientFactory):

465 class Meta:

466 model = Bprs

467

468 id = factory.Sequence(lambda n: n + 1)

469

470

471 class BprseFactory(TaskHasPatientFactory):

472 class Meta:

473 model = Bprse

474

475 id = factory.Sequence(lambda n: n + 1)

476

477

478 class CageFactory(TaskHasPatientFactory):

479 class Meta:

480 model = Cage

481

482 id = factory.Sequence(lambda n: n + 1)

483

484

485 class Cape42Factory(TaskHasPatientFactory):

486 class Meta:

487 model = Cape42

488

489 id = factory.Sequence(lambda n: n + 1)

490

491

492 class CapsFactory(TaskHasPatientFactory):

493 class Meta:

494 model = Caps

495

496 id = factory.Sequence(lambda n: n + 1)

497

498

499 class CardinalExpectationDetectionFactory(TaskHasPatientFactory):

500 class Meta:

501 model = CardinalExpectationDetection

502

503 id = factory.Sequence(lambda n: n + 1)

504 num_blocks = factory.LazyFunction(Fake.en_gb.pyint)

505

506 @factory.post_generation

507 def trials(

508 obj: "Resolver", create: bool, num_trials: int, **kwargs: Any

509 ) -> None:

510 if not create:

511 return

512

513 if num_trials:

514 ExpDetTrialFactory.create_batch(

515 size=num_trials,

516 cardinal_expdet_id=obj.id,

517 _device=obj._device,

518 )

519

520 @factory.post_generation

521 def groupspecs(

522 obj: "Resolver", create: bool, num_groupspecs: int, **kwargs: Any

523 ) -> None:

524 if not create:

525 return

526

527 if num_groupspecs:

528 ExpDetTrialGroupSpecFactory.create_batch(

529 size=num_groupspecs,

530 cardinal_expdet_id=obj.id,

531 _device=obj._device,

532 )

533

534

535 class ExpDetTrialFactory(GenericTabletRecordFactory):

536 class Meta:

537 model = ExpDetTrial

538

539 id = factory.Sequence(lambda n: n + 1)

540 trial = factory.Sequence(lambda n: n + 1)

541

542

543 class ExpDetTrialGroupSpecFactory(GenericTabletRecordFactory):

544 class Meta:

545 model = ExpDetTrialGroupSpec

546

547 id = factory.Sequence(lambda n: n + 1)

548 group_num = factory.Sequence(lambda n: n + 1)

549

550

551 class CardinalExpDetThresholdFactory(TaskHasPatientFactory):

552 class Meta:

553 model = CardinalExpDetThreshold

554

555 id = factory.Sequence(lambda n: n + 1)

556

557

558 class CbiRFactory(TaskHasPatientFactory):

559 class Meta:

560 model = CbiR

561

562 id = factory.Sequence(lambda n: n + 1)

563

564

565 class CecaQ3Factory(TaskHasPatientFactory):

566 class Meta:

567 model = CecaQ3

568

569 id = factory.Sequence(lambda n: n + 1)

570

571

572 class CesdFactory(TaskHasPatientFactory):

573 class Meta:

574 model = Cesd

575

576 id = factory.Sequence(lambda n: n + 1)

577

578

579 class CesdrFactory(TaskHasPatientFactory):

580 class Meta:

581 model = Cesdr

582

583 id = factory.Sequence(lambda n: n + 1)

584

585

586 class CetFactory(TaskHasPatientFactory):

587 class Meta:

588 model = Cet

589

590 id = factory.Sequence(lambda n: n + 1)

591

592

593 class CgiFactory(TaskHasPatientFactory):

594 class Meta:

595 model = Cgi

596

597 id = factory.Sequence(lambda n: n + 1)

598

599

600 class CgiIFactory(TaskHasPatientFactory):

601 class Meta:

602 model = CgiI

603

604 id = factory.Sequence(lambda n: n + 1)

605

606

607 class CgiSchFactory(TaskHasPatientFactory):

608 class Meta:

609 model = CgiSch

610

611 id = factory.Sequence(lambda n: n + 1)

612

613

614 class ChitFactory(TaskHasPatientFactory):

615 class Meta:

616 model = Chit

617

618 id = factory.Sequence(lambda n: n + 1)

619

620

621 class CiaFactory(TaskHasPatientFactory):

622 class Meta:

623 model = Cia

624

625 id = factory.Sequence(lambda n: n + 1)

626

627

628 class CisrFactory(TaskHasPatientFactory):

629 class Meta:

630 model = Cisr

631

632 id = factory.Sequence(lambda n: n + 1)

633

634

635 class CiwaFactory(TaskHasPatientFactory):

636 class Meta:

637 model = Ciwa

638

639 id = factory.Sequence(lambda n: n + 1)

640

641

642 class ContactLogFactory(TaskHasPatientFactory):

643 class Meta:

644 model = ContactLog

645

646 id = factory.Sequence(lambda n: n + 1)

647

648

649 class CopeBriefFactory(TaskHasPatientFactory):

650 class Meta:

651 model = CopeBrief

652

653 id = factory.Sequence(lambda n: n + 1)

654

655

656 class CpftCovidMedicalFactory(TaskHasPatientFactory):

657 class Meta:

658 model = CpftCovidMedical

659

660 id = factory.Sequence(lambda n: n + 1)

661

662

663 class CPFTLPSDischargeFactory(TaskHasPatientFactory):

664 class Meta:

665 model = CPFTLPSDischarge

666

667 id = factory.Sequence(lambda n: n + 1)

668

669

670 class CPFTLPSReferralFactory(TaskHasPatientFactory):

671 class Meta:

672 model = CPFTLPSReferral

673

674 id = factory.Sequence(lambda n: n + 1)

675

676

677 class CPFTLPSResetResponseClockFactory(TaskHasPatientFactory):

678 class Meta:

679 model = CPFTLPSResetResponseClock

680

681 id = factory.Sequence(lambda n: n + 1)

682

683

684 class CpftResearchPreferencesFactory(TaskHasPatientFactory):

685 class Meta:

686 model = CpftResearchPreferences

687

688 id = factory.Sequence(lambda n: n + 1)

689

690

691 class DadFactory(TaskHasPatientFactory):

692 class Meta:

693 model = Dad

694

695 id = factory.Sequence(lambda n: n + 1)

696

697

698 class Das28Factory(TaskHasPatientFactory):

699 class Meta:

700 model = Das28

701

702 id = factory.Sequence(lambda n: n + 1)

703

704

705 class DastFactory(TaskHasPatientFactory):

706 class Meta:

707 model = Dast

708

709 id = factory.Sequence(lambda n: n + 1)

710

711

712 class DeakinS1HealthReviewFactory(TaskHasPatientFactory):

713 class Meta:

714 model = DeakinS1HealthReview

715

716 id = factory.Sequence(lambda n: n + 1)

717

718

719 class DemoQuestionnaireFactory(TaskFactory):

720 class Meta:

721 model = DemoQuestionnaire

722

723 id = factory.Sequence(lambda n: n + 1)

724

725

726 class DemqolFactory(TaskHasPatientFactory):

727 class Meta:

728 model = Demqol

729

730 id = factory.Sequence(lambda n: n + 1)

731

732

733 class DemqolProxyFactory(TaskHasPatientFactory):

734 class Meta:

735 model = DemqolProxy

736

737 id = factory.Sequence(lambda n: n + 1)

738

739

740 class DistressThermometerFactory(TaskHasPatientFactory):

741 class Meta:

742 model = DistressThermometer

743

744 id = factory.Sequence(lambda n: n + 1)

745

746

747 class EdeqFactory(TaskHasPatientFactory):

748 class Meta:

749 model = Edeq

750

751 id = factory.Sequence(lambda n: n + 1)

752

753

754 class ElixhauserCIFactory(TaskHasPatientFactory):

755 class Meta:

756 model = ElixhauserCI

757

758 id = factory.Sequence(lambda n: n + 1)

759

760

761 class EmpsaFactory(TaskHasPatientFactory):

762 class Meta:

763 model = Empsa

764

765 id = factory.Sequence(lambda n: n + 1)

766

767

768 class EpdsFactory(TaskHasPatientFactory):

769 class Meta:

770 model = Epds

771

772 id = factory.Sequence(lambda n: n + 1)

773

774

775 class Eq5d5lFactory(TaskHasPatientFactory):

776 class Meta:

777 model = Eq5d5l

778

779 id = factory.Sequence(lambda n: n + 1)

780

781

782 class EsspriFactory(TaskHasPatientFactory):

783 class Meta:

784 model = Esspri

785

786 id = factory.Sequence(lambda n: n + 1)

787

788

789 class FactgFactory(TaskHasPatientFactory):

790 class Meta:

791 model = Factg

792

793 id = factory.Sequence(lambda n: n + 1)

794

795

796 class FastFactory(TaskHasPatientFactory):

797 class Meta:

798 model = Fast

799

800 id = factory.Sequence(lambda n: n + 1)

801

802

803 class FftFactory(TaskHasPatientFactory):

804 class Meta:

805 model = Fft

806

807 id = factory.Sequence(lambda n: n + 1)

808

809

810 class FrsFactory(TaskHasPatientFactory):

811 class Meta:

812 model = Frs

813

814 id = factory.Sequence(lambda n: n + 1)

815

816

817 class GafFactory(TaskHasPatientFactory):

818 class Meta:

819 model = Gaf

820

821 id = factory.Sequence(lambda n: n + 1)

822

823

824 class GbogpcFactory(TaskHasPatientFactory):

825 class Meta:

826 model = Gbogpc

827

828 id = factory.Sequence(lambda n: n + 1)

829

830

831 class GbograsFactory(TaskHasPatientFactory):

832 class Meta:

833 model = Gbogras

834

835 id = factory.Sequence(lambda n: n + 1)

836

837

838 class GbogresFactory(TaskHasPatientFactory):

839 class Meta:

840 model = Gbogres

841

842 id = factory.Sequence(lambda n: n + 1)

843

844

845 class Gds15Factory(TaskHasPatientFactory):

846 class Meta:

847 model = Gds15

848

849 id = factory.Sequence(lambda n: n + 1)

850

851

852 class GMCPQFactory(TaskFactory):

853 class Meta:

854 model = GMCPQ

855

856 id = factory.Sequence(lambda n: n + 1)

857

858

859 class HadsFactory(TaskHasPatientFactory):

860 class Meta:

861 model = Hads

862

863 id = factory.Sequence(lambda n: n + 1)

864

865

866 class HadsRespondentFactory(TaskHasPatientFactory):

867 class Meta:

868 model = HadsRespondent

869

870 id = factory.Sequence(lambda n: n + 1)

871

872

873 class HamaFactory(TaskHasPatientFactory):

874 class Meta:

875 model = Hama

876

877 id = factory.Sequence(lambda n: n + 1)

878

879

880 class HamdFactory(TaskHasPatientFactory):

881 class Meta:

882 model = Hamd

883

884 id = factory.Sequence(lambda n: n + 1)

885

886

887 class Hamd7Factory(TaskHasPatientFactory):

888 class Meta:

889 model = Hamd7

890

891 id = factory.Sequence(lambda n: n + 1)

892

893

894 class HonosFactory(TaskHasPatientFactory):

895 class Meta:

896 model = Honos

897

898 id = factory.Sequence(lambda n: n + 1)

899

900

901 class Honos65Factory(TaskHasPatientFactory):

902 class Meta:

903 model = Honos65

904

905 id = factory.Sequence(lambda n: n + 1)

906

907

908 class HonoscaFactory(TaskHasPatientFactory):

909 class Meta:

910 model = Honosca

911

912 id = factory.Sequence(lambda n: n + 1)

913

914

915 class Icd10DepressiveFactory(TaskHasPatientFactory):

916 class Meta:

917 model = Icd10Depressive

918

919 id = factory.Sequence(lambda n: n + 1)

920

921

922 class Icd10ManicFactory(TaskHasPatientFactory):

923 class Meta:

924 model = Icd10Manic

925

926 id = factory.Sequence(lambda n: n + 1)

927

928

929 class Icd10MixedFactory(TaskHasPatientFactory):

930 class Meta:

931 model = Icd10Mixed

932

933 id = factory.Sequence(lambda n: n + 1)

934

935

936 class Icd10SchizophreniaFactory(TaskHasPatientFactory):

937 class Meta:

938 model = Icd10Schizophrenia

939

940 id = factory.Sequence(lambda n: n + 1)

941

942

943 class Icd10SchizotypalFactory(TaskHasPatientFactory):

944 class Meta:

945 model = Icd10Schizotypal

946

947 id = factory.Sequence(lambda n: n + 1)

948

949

950 class Icd10SpecPDFactory(TaskHasPatientFactory):

951 class Meta:

952 model = Icd10SpecPD

953

954 id = factory.Sequence(lambda n: n + 1)

955

956

957 class IDED3DFactory(TaskHasPatientFactory):

958 class Meta:

959 model = IDED3D

960

961 id = factory.Sequence(lambda n: n + 1)

962

963

964 class IesrFactory(TaskHasPatientFactory):

965 class Meta:

966 model = Iesr

967

968 id = factory.Sequence(lambda n: n + 1)

969

970

971 class IfsFactory(TaskHasPatientFactory):

972 class Meta:

973 model = Ifs

974

975 id = factory.Sequence(lambda n: n + 1)

976

977

978 class IracFactory(TaskHasPatientFactory):

979 class Meta:

980 model = Irac

981

982 id = factory.Sequence(lambda n: n + 1)

983

984

985 class Isaaq10Factory(TaskHasPatientFactory):

986 class Meta:

987 model = Isaaq10

988

989 id = factory.Sequence(lambda n: n + 1)

990

991

992 class IsaaqEdFactory(TaskHasPatientFactory):

993 class Meta:

994 model = IsaaqEd

995

996 id = factory.Sequence(lambda n: n + 1)

997

998

999 class KhandakerInsightMedicalFactory(TaskHasPatientFactory):

1000 class Meta:

1001 model = KhandakerInsightMedical

1002

1003 id = factory.Sequence(lambda n: n + 1)

1004

1005

1006 class KhandakerMojoMedicalFactory(TaskHasPatientFactory):

1007 class Meta:

1008 model = KhandakerMojoMedical

1009

1010 id = factory.Sequence(lambda n: n + 1)

1011

1012

1013 class KhandakerMojoSociodemographicsFactory(TaskHasPatientFactory):

1014 class Meta:

1015 model = KhandakerMojoSociodemographics

1016

1017 id = factory.Sequence(lambda n: n + 1)

1018

1019

1020 class KirbyFactory(TaskHasPatientFactory):

1021 class Meta:

1022 model = Kirby

1023

1024 id = factory.Sequence(lambda n: n + 1)

1025

1026

1027 class LynallIamMedicalHistoryFactory(TaskHasPatientFactory):

1028 class Meta:

1029 model = LynallIamMedicalHistory

1030

1031 id = factory.Sequence(lambda n: n + 1)

1032

1033

1034 class LynallIamLifeEventsFactory(TaskHasPatientFactory):

1035 class Meta:

1036 model = LynallIamLifeEvents

1037

1038 id = factory.Sequence(lambda n: n + 1)

1039

1040

1041 class MastFactory(TaskHasPatientFactory):

1042 class Meta:

1043 model = Mast

1044

1045 id = factory.Sequence(lambda n: n + 1)

1046

1047

1048 class MdsUpdrsFactory(TaskHasPatientFactory):

1049 class Meta:

1050 model = MdsUpdrs

1051

1052 id = factory.Sequence(lambda n: n + 1)

1053

1054

1055 class Mfi20Factory(TaskHasPatientFactory):

1056 class Meta:

1057 model = Mfi20

1058

1059 id = factory.Sequence(lambda n: n + 1)

1060

1061

1062 class MiniAceFactory(TaskHasPatientFactory):

1063 class Meta:

1064 model = MiniAce

1065

1066 id = factory.Sequence(lambda n: n + 1)

1067

1068

1069 class MocaFactory(TaskHasPatientFactory):

1070 class Meta:

1071 model = Moca

1072

1073 id = factory.Sequence(lambda n: n + 1)

1074

1075

1076 class NartFactory(TaskHasPatientFactory):

1077 class Meta:

1078 model = Nart

1079

1080 id = factory.Sequence(lambda n: n + 1)

1081

1082

1083 class NpiQFactory(TaskHasPatientFactory):

1084 class Meta:

1085 model = NpiQ

1086

1087 id = factory.Sequence(lambda n: n + 1)

1088

1089

1090 class OrsFactory(TaskHasPatientFactory):

1091 class Meta:

1092 model = Ors

1093

1094 id = factory.Sequence(lambda n: n + 1)

1095

1096

1097 class PanssFactory(TaskHasPatientFactory):

1098 class Meta:

1099 model = Panss

1100

1101 id = factory.Sequence(lambda n: n + 1)

1102

1103

1104 class Paradise24Factory(TaskHasPatientFactory):

1105 class Meta:

1106 model = Paradise24

1107

1108 id = factory.Sequence(lambda n: n + 1)

1109

1110

1111 class PbqFactory(TaskHasPatientFactory):

1112 class Meta:

1113 model = Pbq

1114

1115 id = factory.Sequence(lambda n: n + 1)

1116

1117

1118 class Pcl5Factory(TaskHasPatientFactory):

1119 class Meta:

1120 model = Pcl5

1121

1122 id = factory.Sequence(lambda n: n + 1)

1123

1124

1125 class PclCFactory(TaskHasPatientFactory):

1126 class Meta:

1127 model = PclC

1128

1129 id = factory.Sequence(lambda n: n + 1)

1130

1131

1132 class PclMFactory(TaskHasPatientFactory):

1133 class Meta:

1134 model = PclM

1135

1136 id = factory.Sequence(lambda n: n + 1)

1137

1138

1139 class PclSFactory(TaskHasPatientFactory):

1140 class Meta:

1141 model = PclS

1142

1143 id = factory.Sequence(lambda n: n + 1)

1144

1145

1146 class PdssFactory(TaskHasPatientFactory):

1147 class Meta:

1148 model = Pdss

1149

1150 id = factory.Sequence(lambda n: n + 1)

1151

1152

1153 class PhotoFactory(TaskHasPatientFactory):

1154 class Meta:

1155 model = Photo

1156

1157 id = factory.Sequence(lambda n: n + 1)

1158

1159 @factory.post_generation

1160 def create_blob(

1161 obj: "Resolver", create: bool, extracted: None, **kwargs: Any

1162 ) -> None:

1163 if not create:

1164 return

1165

1166 if "fieldname" not in kwargs:

1167 kwargs["fieldname"] = "photo_blobid"

1168

1169 if "tablename" not in kwargs:

1170 kwargs["tablename"] = "photo"

1171

1172 if "tablepk" not in kwargs:

1173 kwargs["tablepk"] = obj.id

1174

1175 obj.photo = BlobFactory.create(**kwargs)

1176

1177

1178 class PhotoSequenceFactory(TaskHasPatientFactory):

1179 class Meta:

1180 model = PhotoSequence

1181

1182 id = factory.Sequence(lambda n: n + 1)

1183

1184 @factory.post_generation

1185 def photos(

1186 obj: "Resolver", create: bool, num_photos: int, **kwargs: Any

1187 ) -> None:

1188 if not create:

1189 return

1190

1191 if num_photos:

1192 PhotoSequenceSinglePhotoFactory.create_batch(

1193 size=num_photos,

1194 photosequence_id=obj.id,

1195 _device=obj._device,

1196 photo__patient=obj.patient,

1197 )

1198

1199

1200 class PhotoSequenceSinglePhotoFactory(GenericTabletRecordFactory):

1201 class Meta:

1202 model = PhotoSequenceSinglePhoto

1203

1204 id = factory.Sequence(lambda n: n + 1)

1205 seqnum = factory.Sequence(lambda n: n + 1)

1206

1207 @factory.post_generation

1208 def photo(

1209 obj: "Resolver", create: bool, num_photos: int, **kwargs: Any

1210 ) -> None:

1211 if not create:

1212 return

1213

1214 patient = kwargs["patient"]

1215 obj.photo = PhotoFactory(patient=patient)

1216

1217

1218 class Phq15Factory(TaskHasPatientFactory):

1219 class Meta:

1220 model = Phq15

1221

1222 id = factory.Sequence(lambda n: n + 1)

1223

1224

1225 class Phq8Factory(TaskHasPatientFactory):

1226 class Meta:

1227 model = Phq8

1228

1229 id = factory.Sequence(lambda n: n + 1)

1230

1231

1232 class ProgressNoteFactory(TaskHasPatientFactory):

1233 class Meta:

1234 model = ProgressNote

1235

1236 id = factory.Sequence(lambda n: n + 1)

1237

1238

1239 class PswqFactory(TaskHasPatientFactory):

1240 class Meta:

1241 model = Pswq

1242

1243 id = factory.Sequence(lambda n: n + 1)

1244

1245

1246 class PsychiatricClerkingFactory(TaskHasPatientFactory):

1247 class Meta:

1248 model = PsychiatricClerking

1249

1250 id = factory.Sequence(lambda n: n + 1)

1251

1252

1253 class PatientSatisfactionFactory(TaskHasPatientFactory):

1254 class Meta:

1255 model = PatientSatisfaction

1256

1257 id = factory.Sequence(lambda n: n + 1)

1258

1259

1260 class QolBasicFactory(TaskHasPatientFactory):

1261 class Meta:

1262 model = QolBasic

1263

1264 id = factory.Sequence(lambda n: n + 1)

1265

1266

1267 class QolSGFactory(TaskHasPatientFactory):

1268 class Meta:

1269 model = QolSG

1270

1271 id = factory.Sequence(lambda n: n + 1)

1272

1273

1274 class Rand36Factory(TaskHasPatientFactory):

1275 class Meta:

1276 model = Rand36

1277

1278 id = factory.Sequence(lambda n: n + 1)

1279

1280

1281 class Rapid3Factory(TaskHasPatientFactory):

1282 class Meta:

1283 model = Rapid3

1284

1285 id = factory.Sequence(lambda n: n + 1)

1286

1287

1288 class ReferrerSatisfactionGenFactory(TaskFactory):

1289 class Meta:

1290 model = ReferrerSatisfactionGen

1291

1292 id = factory.Sequence(lambda n: n + 1)

1293

1294

1295 class ReferrerSatisfactionSpecFactory(TaskHasPatientFactory):

1296 class Meta:

1297 model = ReferrerSatisfactionSpec

1298

1299 id = factory.Sequence(lambda n: n + 1)

1300

1301

1302 class Sfmpq2Factory(TaskHasPatientFactory):

1303 class Meta:

1304 model = Sfmpq2

1305

1306 id = factory.Sequence(lambda n: n + 1)

1307

1308

1309 class ShapsFactory(TaskHasPatientFactory):

1310 class Meta:

1311 model = Shaps

1312

1313 id = factory.Sequence(lambda n: n + 1)

1314

1315

1316 class SlumsFactory(TaskHasPatientFactory):

1317 class Meta:

1318 model = Slums

1319

1320 id = factory.Sequence(lambda n: n + 1)

1321

1322

1323 class SmastFactory(TaskHasPatientFactory):

1324 class Meta:

1325 model = Smast

1326

1327 id = factory.Sequence(lambda n: n + 1)

1328

1329

1330 class SrsFactory(TaskHasPatientFactory):

1331 class Meta:

1332 model = Srs

1333

1334 id = factory.Sequence(lambda n: n + 1)

1335

1336

1337 class SuppspFactory(TaskHasPatientFactory):

1338 class Meta:

1339 model = Suppsp

1340

1341 id = factory.Sequence(lambda n: n + 1)

1342

1343

1344 class SwemwbsFactory(TaskHasPatientFactory):

1345 class Meta:

1346 model = Swemwbs

1347

1348 id = factory.Sequence(lambda n: n + 1)

1349

1350

1351 class WemwbsFactory(TaskHasPatientFactory):

1352 class Meta:

1353 model = Wemwbs

1354

1355 id = factory.Sequence(lambda n: n + 1)

1356

1357

1358 class WsasFactory(TaskHasPatientFactory):

1359 class Meta:

1360 model = Wsas

1361

1362 id = factory.Sequence(lambda n: n + 1)

1363

1364

1365 class YbocsFactory(TaskHasPatientFactory):

1366 class Meta:

1367 model = Ybocs

1368

1369 id = factory.Sequence(lambda n: n + 1)

1370

1371

1372 class YbocsScFactory(TaskHasPatientFactory):

1373 class Meta:

1374 model = YbocsSc

1375

1376 id = factory.Sequence(lambda n: n + 1)

1377

1378

1379 class Zbi12Factory(TaskHasPatientFactory):

1380 class Meta:

1381 model = Zbi12

1382

1383 id = factory.Sequence(lambda n: n + 1)