def get_next_id_for(self, key): """Get a preview of the next number """ portal_type = key.split("-")[0] config = get_config(None, portal_type=portal_type) id_template = config.get("form", "") number = self.storage.get(key) + 1 spec = { "seq": number, "alpha": Alphanumber(number), "year": get_current_year(), "parent_analysisrequest": "ParentAR", "parent_ar_id": "ParentARId", "sampleType": key.replace(portal_type, "").strip("-"), } return id_template.format(**spec)
def get_variables(context, **kw): """Prepares a dictionary of key->value pairs usable for ID formatting """ # allow portal_type override portal_type = get_type_id(context, **kw) # The variables map hold the values that might get into the constructed id variables = { "context": context, "id": api.get_id(context), "portal_type": portal_type, "year": get_current_year(), "yymmdd": get_yymmdd(), "parent": api.get_parent(context), "seq": 0, "alpha": Alphanumber(0), } # Augment the variables map depending on the portal type if portal_type in AR_TYPES: now = DateTime() sampling_date = context.getSamplingDate() sampling_date = sampling_date and DT2dt(sampling_date) or DT2dt(now) date_sampled = context.getDateSampled() date_sampled = date_sampled and DT2dt(date_sampled) or DT2dt(now) test_count = 1 variables.update({ "clientId": context.getClientID(), "dateSampled": date_sampled, "samplingDate": sampling_date, "sampleType": context.getSampleType().getPrefix(), "test_count": test_count }) # Partition if portal_type == "AnalysisRequestPartition": parent_ar = context.getParentAnalysisRequest() parent_ar_id = api.get_id(parent_ar) parent_base_id = strip_suffix(parent_ar_id) partition_count = get_partition_count(context) variables.update({ "parent_analysisrequest": parent_ar, "parent_ar_id": parent_ar_id, "parent_base_id": parent_base_id, "partition_count": partition_count, }) # Retest elif portal_type == "AnalysisRequestRetest": # Note: we use "parent" instead of "invalidated" for simplicity parent_ar = context.getInvalidated() parent_ar_id = api.get_id(parent_ar) parent_base_id = strip_suffix(parent_ar_id) # keep the full ID if the retracted AR is a partition if context.isPartition(): parent_base_id = parent_ar_id retest_count = get_retest_count(context) test_count = test_count + retest_count variables.update({ "parent_analysisrequest": parent_ar, "parent_ar_id": parent_ar_id, "parent_base_id": parent_base_id, "retest_count": retest_count, "test_count": test_count, }) # Secondary elif portal_type == "AnalysisRequestSecondary": primary_ar = context.getPrimaryAnalysisRequest() primary_ar_id = api.get_id(primary_ar) parent_base_id = strip_suffix(primary_ar_id) secondary_count = get_secondary_count(context) variables.update({ "parent_analysisrequest": primary_ar, "parent_ar_id": primary_ar_id, "parent_base_id": parent_base_id, "secondary_count": secondary_count, }) elif portal_type == "ARReport": variables.update({ "clientId": context.aq_parent.getClientID(), }) # Look for a variables adapter adapter = queryAdapter(context, IIdServerVariables) if adapter: vars = adapter.get_variables(**kw) variables.update(vars) return variables
def get_variables(context, **kw): """Prepares a dictionary of key->value pairs usable for ID formatting """ # allow portal_type override portal_type = kw.get("portal_type") or api.get_portal_type(context) # The variables map hold the values that might get into the constructed id variables = { 'context': context, 'id': api.get_id(context), 'portal_type': portal_type, 'year': get_current_year(), 'parent': api.get_parent(context), 'seq': 0, 'alpha': Alphanumber(0), } # Augment the variables map depending on the portal type if portal_type == "AnalysisRequest": variables.update({ 'sampleId': context.getSample().getId(), 'sample': context.getSample(), }) elif portal_type == "SamplePartition": variables.update({ 'sampleId': context.aq_parent.getId(), 'sample': context.aq_parent, }) elif portal_type == "Sample": # get the prefix of the assigned sample type sample_id = context.getId() sample_type = context.getSampleType() sampletype_prefix = sample_type.getPrefix() date_now = DateTime() sampling_date = context.getSamplingDate() date_sampled = context.getDateSampled() # Try to get the date sampled and sampling date if sampling_date: samplingDate = DT2dt(sampling_date) else: # No Sample Date? logger.error("Sample {} has no sample date set".format(sample_id)) # fall back to current date samplingDate = DT2dt(date_now) if date_sampled: dateSampled = DT2dt(date_sampled) else: # No Sample Date? logger.error("Sample {} has no sample date set".format(sample_id)) dateSampled = DT2dt(date_now) variables.update({ 'clientId': context.aq_parent.getClientID(), 'dateSampled': dateSampled, 'samplingDate': samplingDate, 'sampleType': sampletype_prefix, }) elif portal_type == "ARReport": variables.update({ 'clientId': context.aq_parent.getClientID(), }) return variables
def get_variables(context, **kw): """Prepares a dictionary of key->value pairs usable for ID formatting """ # allow portal_type override portal_type = get_type_id(context, **kw) # The variables map hold the values that might get into the constructed id variables = { 'context': context, 'id': api.get_id(context), 'portal_type': portal_type, 'year': get_current_year(), 'parent': api.get_parent(context), 'seq': 0, 'alpha': Alphanumber(0), } # Augment the variables map depending on the portal type if portal_type in AR_TYPES: now = DateTime() sampling_date = context.getSamplingDate() sampling_date = sampling_date and DT2dt(sampling_date) or DT2dt(now) date_sampled = context.getDateSampled() date_sampled = date_sampled and DT2dt(date_sampled) or DT2dt(now) test_count = 1 variables.update({ "clientId": context.getClientID(), "dateSampled": date_sampled, "samplingDate": sampling_date, "sampleType": context.getSampleType().getPrefix(), "test_count": test_count, # BHP-specific "studyId": context.aq_parent.getTaxNumber(), }) # Partition if portal_type == "AnalysisRequestPartition": # 09202AAJ60 # + 09202AAJ6002 # + 09202AAJ600201 # {studyId}{sampleType}{parent_alpha}{partition_count} # 09 20 AAJ60 02 parent_ar = context.getParentAnalysisRequest() parent_ar_id = api.get_id(parent_ar) parent_base_id = strip_suffix(parent_ar_id) partition_count = get_partition_count(context) parent_alpha = get_sample_alpha(parent_ar) parent_part_num = get_sample_partition_number(parent_ar) variables.update({ "parent_analysisrequest": parent_ar, "parent_ar_id": parent_ar_id, "parent_base_id": parent_base_id, # BHP-specific "partition_count": "{:02d}".format(partition_count + 1), "parent_alpha": "{}{}".format(parent_alpha, parent_part_num), }) # Retest elif portal_type == "AnalysisRequestRetest": # Note: we use "parent" instead of "invalidated" for simplicity parent_ar = context.getInvalidated() parent_ar_id = api.get_id(parent_ar) parent_base_id = strip_suffix(parent_ar_id) # keep the full ID if the retracted AR is a partition if context.isPartition(): parent_base_id = parent_ar_id retest_count = get_retest_count(context) test_count = test_count + retest_count variables.update({ "parent_analysisrequest": parent_ar, "parent_ar_id": parent_ar_id, "parent_base_id": parent_base_id, "retest_count": retest_count, "test_count": test_count, }) # Secondary elif portal_type == "AnalysisRequestSecondary": primary_ar = context.getPrimaryAnalysisRequest() primary_ar_id = api.get_id(primary_ar) parent_base_id = strip_suffix(primary_ar_id) secondary_count = get_secondary_count(context) variables.update({ "parent_analysisrequest": primary_ar, "parent_ar_id": primary_ar_id, "parent_base_id": parent_base_id, "secondary_count": secondary_count, }) elif portal_type == "ARReport": variables.update({ "clientId": context.aq_parent.getClientID(), }) return variables