Skip to content

Commit

Permalink
Merge branch 'release-3.14.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehaic committed Sep 26, 2023
2 parents 1474dc7 + ad624d0 commit 544c0ef
Show file tree
Hide file tree
Showing 18 changed files with 379 additions and 133 deletions.
32 changes: 32 additions & 0 deletions migrations/Version20230906173509.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20230906173509 extends AbstractMigration
{
public function getDescription(): string
{
return 'Adds user for NPH DLW Dosages for finalization records';
}

public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE nph_dlw ADD user_id INT NOT NULL');
$this->addSql('ALTER TABLE nph_dlw ADD CONSTRAINT FK_3F1C65B7A76ED395 FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('CREATE INDEX IDX_3F1C65B7A76ED395 ON nph_dlw (user_id)');
}

public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE nph_dlw DROP FOREIGN KEY FK_3F1C65B7A76ED395');
$this->addSql('DROP INDEX IDX_3F1C65B7A76ED395 ON nph_dlw');
$this->addSql('ALTER TABLE nph_dlw DROP user_id');
}
}
5 changes: 2 additions & 3 deletions src/Controller/NphOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,7 @@ public function dlwSampleCollect(
$dlwForm->handleRequest($request);
if ($dlwForm->isSubmitted()) {
if ($dlwForm->isValid()) {
$nphOrderService->saveDlwCollection($dlwForm->getData(), $participantId, $module, $visit);
$timestamp = new \DateTime('now', new \DateTimeZone($this->getSecurityUser()->getTimezone()));
$this->addFlash('success', 'Saved by ' . $this->getSecurityUser()->getEmail() . ' on ' . $timestamp->format('m-d-Y h:i a'));
$dlwObject = $nphOrderService->saveDlwCollection($dlwForm->getData(), $participantId, $module, $visit);
$disabled = true;
} else {
$disabled = false;
Expand All @@ -558,6 +556,7 @@ public function dlwSampleCollect(
'module' => $module,
'visit' => $visit,
'disabled' => $disabled,
'dlwInfo' => $dlwObject,
'form' => $dlwForm->createView()
]);
}
Expand Down
16 changes: 16 additions & 0 deletions src/Entity/NphDlw.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class NphDlw
#[ORM\Column(nullable: true)]
private ?int $ModifiedTimezoneId = null;

#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private User $User;

public function getId(): int
{
return $this->id;
Expand Down Expand Up @@ -153,4 +157,16 @@ public function setModifiedTimezoneId(?int $ModifiedTimezoneId): static

return $this;
}

public function getUser(): ?User
{
return $this->User;
}

public function setUser(?User $User): static
{
$this->User = $User;

return $this;
}
}
16 changes: 16 additions & 0 deletions src/Entity/NphOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class NphOrder
public const TYPE_NAIL = 'nail';
public const TYPE_DLW = 'urineDlw';
public const TYPE_MODULE_3_SALIVA = 'saliva3';
private const TYPE_DISPLAY_OVERRIDE = [
3 => [
'urine' => 'Spot Urine',
'24urine' => '24 Hour Urine',
'urineDlw' => 'Urine DLW',
'saliva3' => 'Saliva',
],
];

#[ORM\Id]
#[ORM\GeneratedValue]
Expand Down Expand Up @@ -376,4 +384,12 @@ public function getMetadataArray(): ?array
}
return $metadata;
}

public function getOrderTypeDisplayName(): string
{
if (isset($this::TYPE_DISPLAY_OVERRIDE[$this->getModule()][$this->getOrderType()])) {
return $this::TYPE_DISPLAY_OVERRIDE[$this->getModule()][$this->getOrderType()];
}
return ucfirst($this->getOrderType());
}
}
4 changes: 3 additions & 1 deletion src/Entity/NphSample.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ public function getRdrSampleObj(string $sampleIdentifier, string $description, a
public function getRdrAliquotsSampleObj(array $aliquotsInfo): array
{
$aliquotObj = [];
$counter = [];
foreach ($this->getNphAliquots() as $aliquot) {
$counter[$aliquot->getAliquotCode()] = isset($counter[$aliquot->getAliquotCode()]) ? $counter[$aliquot->getAliquotCode()] + 1 : 0;
$collectedTs = $aliquot->getAliquotTs();
$collectedTs->setTimezone(new \DateTimeZone('UTC'));
$aliquotsData = [
Expand All @@ -546,7 +548,7 @@ public function getRdrAliquotsSampleObj(array $aliquotsInfo): array
['units' => 'uL',
'volume' => $metadata[$aliquot->getAliquotCode() . 'glycerolAdditiveVolume']
];
$aliquotsData['volume'] += ($metadata[$aliquot->getAliquotCode() . 'glycerolAdditiveVolume'] / 1000);
$aliquotsData['volume'] += ($metadata[$aliquot->getAliquotCode() . 'glycerolAdditiveVolume'][$counter[$aliquot->getAliquotCode()]] / 1000);
}
if ($aliquot->getStatus()) {
$aliquotsData['status'] = $aliquot->getStatus();
Expand Down
14 changes: 10 additions & 4 deletions src/Form/DlwType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Range;

Expand All @@ -33,6 +34,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'Actual Dose (g)*',
'required' => true,
'scale' => 1,
'empty_data' => 0,
'constraints' => new GreaterThan([
'value' => 0,
'message' => 'Dose must be greater than 0.'
])
])
->add('participantWeight', NumberType::class, [
'required' => true,
Expand All @@ -42,19 +48,19 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
if ($value < 0 || $value === null) {
$context->buildViolation('Participant weight required.')
->addViolation();
return false;
}
if ($value == 0) {
$context->buildViolation('Please verify the measurement is correct. Value should be greater than 0 kg.')
->addViolation();
}
if ($value > 907) {
$context->buildViolation('Please verify the measurement is correct. Value should be less than 907 kg.')
->addViolation();
return false;
}
if ($this->getNumDecimalPlaces($value) > 1) {
$context->buildViolation('Please verify the measurement is correct. Value can be entered up to the tenths (0.1) place.')
->addViolation();
return false;
}
return true;
}),
'scale' => 1,
])
Expand Down
61 changes: 52 additions & 9 deletions src/Form/Nph/NphSampleFinalizeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,82 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]);
if (isset($aliquot['collectMetadata']) && $aliquot['collectMetadata']) {
foreach ($aliquot['metadataFields'] as $metadataField) {
$builder->add("{$aliquotCode}{$metadataField['identifier']}", $metadataField['entryType'], [
'label' => $metadataField['label'],
'required' => false,
'attr' => [
'placeholder' => $metadataField['placeholder'] ?? '',
'class' => $metadataField['class'] ?? '',
if ($metadataField['identifier'] === 'glycerolAdditiveVolume') {
$metadataConstraints = [
new Constraints\Callback(function ($value, $context) use ($aliquotCode, $metadataField) {
$key = intval($context->getObject()->getName());
$formData = $context->getRoot()->getData();
$glycerolVolume = $formData[$aliquotCode . $metadataField['identifier']][$key];
if (isset($formData[$aliquotCode][$key])) {
if ($glycerolVolume === null) {
$context->buildViolation('Glycerol Volume: Volume is required')->addViolation();
} elseif ($glycerolVolume === 0) {
$context->buildViolation('Glycerol Volume: Volume must be greater than 0')->addViolation();
} elseif ($glycerolVolume > $metadataField['maxVolume']) {
$context->buildViolation("Glycerol Volume: Please verify the volume is correct. This aliquot should contain a maximum of {$metadataField['maxVolume']} {$metadataField['units']}.")->atPath($aliquotCode . $metadataField['identifier'])->addViolation();
}
}
})
];
$metadataValue = $formData["{$aliquotCode}glycerolAdditiveVolume"] ?? [null];
} else {
$metadataValue = [null];
}
$builder->add("{$aliquotCode}{$metadataField['identifier']}", Type\CollectionType::class, [
'entry_type' => Type\TextType::class,
'entry_options' => [
'label' => $metadataField['label'],
'required' => false,
'attr' => [
'placeholder' => $metadataField['placeholder'] ?? '',
'class' => $metadataField['class'] ?? '',
],
'constraints' => $metadataConstraints ?? [],
],
'data' => $formData[$aliquotCode . $metadataField['identifier']][0] ?? null,
'allow_add' => true,
'allow_delete' => true,
'data' => $metadataValue,
]);
}
}


$volumeConstraints = [
new Constraints\Callback(function ($value, $context) use ($aliquotCode, $aliquot) {
$formData = $context->getRoot()->getData();
$key = intval($context->getObject()->getName());
if ($aliquot['expectedVolume'] && ($formData[$aliquotCode][$key] || $formData["{$aliquotCode}AliquotTs"][$key])
&& $value === null) {
$context->buildViolation('Volume is required')->addViolation();
$errorMessage = 'Volume is required';
if (isset($aliquot['errorMessageVolumePrefix'])) {
$errorMessage = "{$aliquot['errorMessageVolumePrefix']} {$errorMessage}";
}
$context->buildViolation($errorMessage)->addViolation();
}
if ($aliquot['expectedVolume'] === null && !empty($value)) {
$errorMessage = 'Volume should not be entered';
if (isset($aliquot['errorMessageVolumePrefix'])) {
$errorMessage = "{$aliquot['errorMessageVolumePrefix']} {$errorMessage}";
}
$context->buildViolation('Volume should not be entered')->addViolation();
}
})
];
if (isset($aliquot['minVolume'])) {
$errorMessage = 'Volume must be greater than 0';
if (isset($aliquot['errorMessageVolumePrefix'])) {
$errorMessage = "{$aliquot['errorMessageVolumePrefix']} {$errorMessage}";
}
$volumeConstraints[] = new Constraints\GreaterThan([
'value' => $aliquot['minVolume'],
'message' => 'Volume must be greater than 0'
'message' => $errorMessage
]);
}
if (isset($aliquot['maxVolume'])) {
$errorMessage = "Please verify the volume is correct. This aliquot should contain a maximum of {$aliquot['maxVolume']} {$aliquot['units']}.";
if (isset($aliquot['errorMessageVolumePrefix'])) {
$errorMessage = "{$aliquot['errorMessageVolumePrefix']} {$errorMessage}";
}
$volumeConstraints[] = new Constraints\LessThanOrEqual([
'value' => $aliquot['maxVolume'],
'message' => $errorMessage
Expand Down
39 changes: 24 additions & 15 deletions src/Nph/Order/Samples/Module3.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"temperature": "Refrigerated",
"specimen": "Urine",
"type": "urine",
"typeDisplayName": "Spot Urine",
"identifier": "UrineS",
"aliquots": {
"RU1U": {
Expand Down Expand Up @@ -164,36 +165,37 @@
"aliquots": {
"SALIVAA1": {
"identifier": "SA1-U",
"container": "4mL Matrix tube (no glycerol)",
"description": "4mL Matrix tube",
"container": "5mL Matrix tube (no glycerol)",
"description": "5mL Matrix tube",
"expectedAliquots": 1,
"expectedVolume": 2.4,
"expectedVolume": 4,
"units": "mL",
"barcodeLength" : 10,
"barcodePrefix": "MC",
"barcodeErrorMessage": "Aliquot barcode ID invalid. Please enter a valid 4mL matrix aliquot tube barcode ID.",
"minVolume": 0,
"barcodeErrorMessage": "Aliquot barcode ID invalid. Please enter a valid 5mL matrix aliquot tube barcode ID.",
"minVolume": 0.1,
"maxVolume": 4,
"warningMinVolume": 100,
"warningMaxVolume": 4000,
"addNew": false,
"warningMinVolume": 0.1,
"warningMaxVolume": 0.4,
"addNew": true,
"collectMetadata": false
},
"SALIVAA2": {
"identifier": "SA2-U",
"container": "2.5mL Matrix tube (w/glycerol)",
"description": "2.5mL Matrix tube",
"container": "5mL Matrix tube (w/glycerol)",
"description": "5mL Matrix tube",
"expectedAliquots": 1,
"expectedVolume": 2,
"expectedVolume": 2.4,
"units": "mL",
"barcodeLength" : 10,
"barcodePrefix": "MC",
"barcodeErrorMessage": "Aliquot barcode ID invalid. Please enter a valid 2.5mL matrix aliquot tube barcode ID.",
"barcodeErrorMessage": "Aliquot barcode ID invalid. Please enter a valid 5mL matrix aliquot tube barcode ID.",
"minVolume": 0,
"maxVolume": 4,
"maxVolume": 2,
"errorMessageVolumePrefix": "Saliva Volume:",
"warningMinVolume": 100,
"warningMaxVolume": 4000,
"addNew": false,
"warningMaxVolume": 2000,
"addNew": true,
"collectMetadata": true,
"metadataFields": [
{
Expand All @@ -202,6 +204,13 @@
"type": "number",
"label": "Calculated Volume for Glycerol Additive Sample",
"units": "μL",
"minVolume": 0,
"maxVolume": 400,
"warningMinVolume": 0.1,
"warningMaxVolume": 0.4,
"warningMinTotalVolume": 100,
"warningMaxTotalVolume": 2400,
"maxTotalVolume": 2.4,
"entryType": "Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType",
"required": true
}
Expand Down
Loading

0 comments on commit 544c0ef

Please sign in to comment.