<commit_before>angular.module('os.biospecimen.specimen')
  .factory('SpecimenUtil', function(
    $modal, $q, $parse, $location,
    ParticipantSpecimensViewState, Specimen, PvManager, Alerts, Util) {

    var URL_LEN_LIMIT = 8192; // 8 KB

    function collectAliquots(scope) {
      var spec = scope.aliquotSpec;
      var parent = scope.parentSpecimen;
      var extensionDetail = getExtensionDetail(scope);
      if (!extensionDetail) {
        extensionDetail = scope.aliquotSpec.extensionDetail;
      }

      if (!!spec.qtyPerAliquot && !!spec.noOfAliquots) {
        var requiredQty = spec.qtyPerAliquot * spec.noOfAliquots;
        if (parent.type == spec.type &&
          parent.availableQty != undefined && requiredQty > parent.availableQty &&
          !scope.ignoreQtyWarning) {

          showInsufficientQtyWarning({
            ok: function () {
              scope.ignoreQtyWarning = true;
              scope.collectAliquots();
            }
          });
          return;
        }
      } else if (!!spec.qtyPerAliquot) {
        spec.noOfAliquots = Math.floor(parent.availableQty / spec.qtyPerAliquot);
      } else if (!!spec.noOfAliquots) {
        spec.qtyPerAliquot = Math.round(parent.availableQty / spec.noOfAliquots * 10000) / 10000;
      }

      if (scope.aliquotSpec.createdOn < scope.parentSpecimen.createdOn) {
        Alerts.error("specimens.errors.created_on_lt_parent");
        return;
      } else if (scope.aliquotSpec.createdOn > Date.now()) {
        Alerts.error("specimens.errors.created_on_gt_curr_time");
        return;
      }

      parent.isOpened = parent.hasChildren = true;
      parent.depth = 0;
      parent.closeAfterChildrenCreation = spec.closeParent;

      var derived = undefined;
      if (spec.specimenClass != parent.specimenClass || spec.type != parent.type) {
        derived = getSpmnToSave(
          'Derived', spec, parent,
          Math.round(spec.qtyPerAliquot * spec.noOfAliquots),
          spec.concentration,
          scope.cpr.derivativeLabelFmt);
      }

      var aliquot = getSpmnToSave(
        'Aliquot', spec, (derived ? derived : parent),
        spec.qtyPerAliquot,<commit_msg>In specimen collection page, display the parent specimen's storage location as 'Not Stored' if following conditions satisfy:   - has at least one child.   - no location has been chosen in previous steps.<commit_after>angular.module('os.biospecimen.specimen')
  .factory('SpecimenUtil', function(
    $modal, $q, $parse, $location,
    ParticipantSpecimensViewState, Specimen, PvManager, Alerts, Util) {

    var URL_LEN_LIMIT = 8192; // 8 KB

    function collectAliquots(scope) {
      var spec = scope.aliquotSpec;
      var parent = scope.parentSpecimen;
      var extensionDetail = getExtensionDetail(scope);
      if (!extensionDetail) {
        extensionDetail = scope.aliquotSpec.extensionDetail;
      }

      if (!!spec.qtyPerAliquot && !!spec.noOfAliquots) {
        var requiredQty = spec.qtyPerAliquot * spec.noOfAliquots;
        if (parent.type == spec.type &&
          parent.availableQty != undefined && requiredQty > parent.availableQty &&
          !scope.ignoreQtyWarning) {

          showInsufficientQtyWarning({
            ok: function () {
              scope.ignoreQtyWarning = true;
              scope.collectAliquots();
            }
          });
          return;
        }
      } else if (!!spec.qtyPerAliquot) {
        spec.noOfAliquots = Math.floor(parent.availableQty / spec.qtyPerAliquot);
      } else if (!!spec.noOfAliquots) {
        spec.qtyPerAliquot = Math.round(parent.availableQty / spec.noOfAliquots * 10000) / 10000;
      }

      if (scope.aliquotSpec.createdOn < scope.parentSpecimen.createdOn) {
        Alerts.error("specimens.errors.created_on_lt_parent");
        return;
      } else if (scope.aliquotSpec.createdOn > Date.now()) {
        Alerts.error("specimens.errors.created_on_gt_curr_time");
        return;
      }

      parent.isOpened = parent.hasChildren = true;
      parent.depth = 0;
      parent.closeAfterChildrenCreation = spec.closeParent;
      parent.storageType = !parent.storageLocation.name && (parent.storageType || 'Virtual');

      var derived = undefined;
      if (spec.specimenClass != parent.specimenClass || spec.type != parent.type) {
        derived = getSpmnToSave(
          'Derived', spec, parent,
          Math.round(spec.qtyPerAliquot * spec.noOfAliquots),
          spec.concentration,
          scope.cpr.derivativeLabelFmt);
      }

      var aliquot = getSpmnToSave(
        'Aliquot', spec, (derived ? derived : parent),
        spec.qtyPerAliquot,
{'fraction_non_alphanumeric': 0.11077455646906101, 'fraction_numerical': 0.006923409779316313, 'mean_word_length': 2.56988416988417, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2272496', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1392, 'n_words': 256}