Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase case id range #2684

Merged
merged 9 commits into from
Dec 6, 2023
23 changes: 11 additions & 12 deletions cg/store/api/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@
class AddHandler(BaseHandler):
"""Methods related to adding new data to the store."""

def generate_unique_petname(self) -> str:
def generate_readable_sample_id(self) -> str:
while True:
seallard marked this conversation as resolved.
Show resolved Hide resolved
random_id = petname.Generate(3, separator="")
if not self.get_sample_by_internal_id(internal_id=random_id):
random_id: str = petname.Generate(3, separator="")
if not self.get_sample_by_internal_id(random_id):
return random_id

def generate_readable_case_id(self) -> str:
seallard marked this conversation as resolved.
Show resolved Hide resolved
while True:
random_id: str = petname.Generate(2, separator="", letters=10)
if not self.get_case_by_internal_id(random_id):
return random_id

def add_customer(
Expand Down Expand Up @@ -173,7 +179,7 @@ def add_sample(
) -> Sample:
"""Build a new Sample record."""

internal_id = internal_id or self.generate_unique_petname()
internal_id = internal_id or self.generate_readable_sample_id()
priority = priority or (Priority.research if downsampled_to else Priority.standard)
return Sample(
comment=comment,
Expand Down Expand Up @@ -204,14 +210,7 @@ def add_case(
) -> Case:
"""Build a new Case record."""

# generate a unique case id
while True:
internal_id = petname.Generate(2, separator="")
if self.get_case_by_internal_id(internal_id) is None:
break
else:
LOG.debug(f"{internal_id} already used - trying another id")

internal_id: str = self.generate_readable_case_id()
return Case(
cohorts=cohorts,
data_analysis=str(data_analysis),
Expand Down
Loading