diff --git a/src/Form/Nph/NphOrderType.php b/src/Form/Nph/NphOrderType.php index f79873c09..cfac8bb4f 100644 --- a/src/Form/Nph/NphOrderType.php +++ b/src/Form/Nph/NphOrderType.php @@ -155,7 +155,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'view_timezone' => $options['userTimezone'], 'model_timezone' => 'UTC', 'label' => 'Order Creation Time', - 'attr' => ['class' => 'order-ts'] + 'attr' => ['class' => 'order-ts', 'autocomplete' => 'off'], ]); return $builder->getForm(); diff --git a/src/Repository/NphOrderRepository.php b/src/Repository/NphOrderRepository.php index 9746baae4..bb37039b1 100644 --- a/src/Repository/NphOrderRepository.php +++ b/src/Repository/NphOrderRepository.php @@ -216,11 +216,14 @@ public function getDownTimeGeneratedOrdersByModuleAndVisit(string $ParticipantId { $queryBuild = $this->createQueryBuilder('no') ->where('no.participantId = :participantId') + ->join('no.nphSamples', 'ns') ->andWhere('no.module = :module') ->andWhere('no.visitType = :visitType') ->andWhere('no.DowntimeGenerated = 1') + ->andWhere('ns.modifyType != :modifyType OR ns.modifyType IS NULL') ->setParameter('participantId', $ParticipantId) ->setParameter('module', $Module) + ->setParameter('modifyType', NphSample::CANCEL) ->setParameter('visitType', $Visit); return $queryBuild->getQuery()->getResult(); } diff --git a/src/Service/Nph/NphOrderService.php b/src/Service/Nph/NphOrderService.php index 989d303c4..f1bbad97d 100644 --- a/src/Service/Nph/NphOrderService.php +++ b/src/Service/Nph/NphOrderService.php @@ -275,12 +275,12 @@ public function createOrdersAndSamples(array $formData): string return $sampleGroup; } - public function createOrder(string $timePoint, string $orderType, string $orderId = null, bool $downtimeGenerated = false, ?DateTime $downtimeGeneratedTs = new DateTime()): NphOrder + public function createOrder(string $timePoint, string $orderType, string $orderId = null, bool $downtimeGenerated = false, ?DateTime $downtimeGeneratedTs = null): NphOrder { if ($orderId === null) { $orderId = $this->generateOrderId(); } - if ($downtimeGeneratedTs === null) { + if (empty($downtimeGeneratedTs)) { $downtimeGeneratedTs = new DateTime(); } $nphOrder = new NphOrder(); @@ -849,20 +849,24 @@ public function getDowntimeOrderSummary(): array $downtimeGenerated = []; $downtimeGenerated['orderInfo'] = []; $downtimeGenerated['sampleInfo'] = []; - $orderNumber = 1; + $orderNumber = 0; + $seenSampleGroups = []; /** @var NphOrder $order */ foreach ($orders as $order) { if (array_key_exists($order->getTimepoint(), $existingSamples)) { - $downtimeGenerated['orderInfo'][$orderNumber]['orderUser'] = $order->getUser()->getEmail(); - $downtimeGenerated['orderInfo'][$orderNumber]['orderDowntimeCreatedTime'] = $order->getDowntimeGeneratedTs(); - $downtimeGenerated['orderInfo'][$orderNumber]['orderCreatedTime'] = $order->getCreatedTs(); /** @var NphSample $sample */ foreach ($order->getNphSamples() as $sample) { + if (!in_array($sample->getSampleGroup(), $seenSampleGroups, true)) { + $seenSampleGroups[] = $sample->getSampleGroup(); + $orderNumber++; + $downtimeGenerated['orderInfo'][$orderNumber]['orderUser'] = $order->getUser()->getEmail(); + $downtimeGenerated['orderInfo'][$orderNumber]['orderDowntimeCreatedTime'] = $order->getDowntimeGeneratedTs(); + $downtimeGenerated['orderInfo'][$orderNumber]['orderCreatedTime'] = $order->getCreatedTs(); + } if (in_array($sample->getSampleCode(), $existingSamples[$order->getTimepoint()], true)) { $downtimeGenerated['sampleInfo'][$order->getTimepoint()][$sample->getSampleCode()] = $orderNumber; } } - $orderNumber++; } } return $downtimeGenerated; @@ -937,7 +941,7 @@ private function getNumericId(): string return $id; } - private function createOrderWithSamples(string $timePoint, string $orderType, array $samples, string $sampleGroup, bool $downtimeGenerated = false, ?DateTime $downtimeGeneratedCreatedTs = new DateTime()): void + private function createOrderWithSamples(string $timePoint, string $orderType, array $samples, string $sampleGroup, bool $downtimeGenerated = false, ?DateTime $downtimeGeneratedCreatedTs = null): void { $nphOrder = $this->createOrder($timePoint, $orderType, null, $downtimeGenerated, $downtimeGeneratedCreatedTs); foreach ($samples as $sample) { diff --git a/templates/program/nph/order/collect.html.twig b/templates/program/nph/order/collect.html.twig index a34e5aad7..a0fb33604 100644 --- a/templates/program/nph/order/collect.html.twig +++ b/templates/program/nph/order/collect.html.twig @@ -13,7 +13,7 @@ {% if order.downtimeGenerated() %}
- This sample was generated as part of a downtime order initiated by: {{ order.downtimeGeneratedUser.getEmail }} on {{ order.downtimeGeneratedTs|date('n/j/Y') }}. [Order generation time: {{ order.createdTs|date('n/j/Y g:ia')}}] + This sample was generated as part of a downtime order initiated by: {{ order.downtimeGeneratedUser.getEmail }} on {{ order.downtimeGeneratedTs|date('n/j/Y', app.user.timezone) }}. [Order generation time: {{ order.createdTs|date('n/j/Y g:ia', app.user.timezone)}}]
{% endif %}
diff --git a/templates/program/nph/order/generate-orders.html.twig b/templates/program/nph/order/generate-orders.html.twig index 8b0b12ee8..917627e3c 100644 --- a/templates/program/nph/order/generate-orders.html.twig +++ b/templates/program/nph/order/generate-orders.html.twig @@ -44,7 +44,7 @@ {% for orderNumber, order in downtimeOrders['orderInfo'] %}
- + Downtime order initiated by: {{order['orderUser']}}
diff --git a/templates/program/nph/order/sample-finalize.html.twig b/templates/program/nph/order/sample-finalize.html.twig index 17ac188ef..751a37b0e 100644 --- a/templates/program/nph/order/sample-finalize.html.twig +++ b/templates/program/nph/order/sample-finalize.html.twig @@ -203,7 +203,7 @@
{% if order.downtimeGenerated() %}
- This sample was generated as part of a downtime order initiated by: {{ order.downtimeGeneratedUser.getEmail }} on {{ order.downtimeGeneratedTs|date('n/j/Y') }}. [Order generation time: {{ order.createdTs|date('n/j/Y g:ia')}}] + This sample was generated as part of a downtime order initiated by: {{ order.downtimeGeneratedUser.getEmail }} on {{ order.downtimeGeneratedTs|date('n/j/Y', app.user.timezone) }}. [Order generation time: {{ order.createdTs|date('n/j/Y g:ia', app.user.timezone)}}]
{% endif %} {% if isFormDisabled %} diff --git a/templates/program/nph/order/samples.html.twig b/templates/program/nph/order/samples.html.twig index e90d53e94..99929cb5e 100644 --- a/templates/program/nph/order/samples.html.twig +++ b/templates/program/nph/order/samples.html.twig @@ -72,7 +72,7 @@ {% endmacro %} {% macro displayDowntimeGeneratedOrderNumber(downtimeGeneratedOrders, timePoint, sample) %} - {% if downtimeGeneratedOrders['sampleInfo']|length > 0 and downtimeGeneratedOrders['sampleInfo'][timePoint][sample.vars.value] %} + {% if downtimeGeneratedOrders['sampleInfo']|length > 0 and timePoint in downtimeGeneratedOrders['sampleInfo']|keys and downtimeGeneratedOrders['sampleInfo'][timePoint][sample.vars.value] %} {{ downtimeGeneratedOrders['sampleInfo'][timePoint][sample.vars.value] }} {% endif %} {% endmacro %} diff --git a/web/assets/js/views/NphOrderCreate.js b/web/assets/js/views/NphOrderCreate.js index 434758325..01d651e79 100644 --- a/web/assets/js/views/NphOrderCreate.js +++ b/web/assets/js/views/NphOrderCreate.js @@ -178,8 +178,14 @@ $(document).ready(function () { } } - showHideDowntimeCreatedTs(); - $("#nph_order_createdTs").pmiDateTimePicker({ - maxDate: new Date() - }); + function initializeDowntimeCreatedTsDatePicker() { + showHideDowntimeCreatedTs(); + let dateSelector = $("#nph_order_createdTs"); + let currentValue = dateSelector.val(); + $("#nph_order_createdTs").pmiDateTimePicker({ + maxDate: new Date() + }); + dateSelector.val(currentValue); + } + initializeDowntimeCreatedTsDatePicker(); });