class CourseInPlanModel(db.Model): __tablename__ = "CoursesInPlans" plan_id = db.Column(db.Integer, db.ForeignKey("Plans._id"), primary_key=True) course_id = db.Column(db.Integer, db.ForeignKey("Courses._id"), primary_key=True) def json(self) -> Dict: return {"plan_id": self.plan_id, "course_id": self.course_id}
class OrderModel(db.Model): __tablename__ = 'orders' id = db.Column(db.Integer, primary_key=True) arrivalTime = db.Column(db.String(100)) status = db.Column(db.Integer) objectID = db.Column(db.Integer) weight = db.Column(db.Float) profit = db.Column(db.Float) location = db.Column(db.String(100)) address = db.Column(db.String(100)) sequence = db.Column(db.Integer) UserID = db.Column(db.Integer, db.ForeignKey('users.id')) RouteID = db.Column(db.Integer, db.ForeignKey('routes.id'))
class Series(db.Model): __tablename__ = 'series' id = db.Column(db.Integer, primary_key=True) work_item_id = db.Column(db.Integer, db.ForeignKey('work_items.id')) uid = db.Column(db.String, index=True) # Series Instance UID plane = db.Column(db.String, db.Enum('axial', 'sagittal', 'coronal')) created_on = db.Column(db.DateTime, server_default=db.func.now(), index=True) updated_on = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now()) massive_bleeding = db.Column(db.Boolean, default=False) findings = db.relationship('Finding', order_by='Finding.order') def __repr__(self): return "<Series(uid='{}', plane='{}', massive_bleeding={})>".format( self.uid, self.plane, self.massive_bleeding) def to_json_dict(self): return { 'uid': self.uid, 'plane': self.plane, 'massiveBleeding': self.massive_bleeding }
class ItemModel(db.Model): __tablename__ = 'items' id = db.Column(db.Integer, primary_key=True) vegeName = db.Column(db.String(100)) vegeQuantity = db.Column(db.Integer) vegePrice = db.Column(db.Integer) FarmerID = db.Column(db.Integer, db.ForeignKey('farmers.id'))
class OrderModel(db.Model): __tablename__ = 'orders' id = db.Column(db.Integer, primary_key=True) arrivalTime = db.Column(db.String(100)) orderDate = db.Column(db.String(100)) status = db.Column(db.Integer) address = db.Column(db.String(100)) sequence = db.Column(db.Integer) foodName = db.Column(db.String(100)) foodQuantity = db.Column(db.Float) foodPrice = db.Column(db.Float) profit = db.Column(db.Float) UserID = db.Column(db.Integer, db.ForeignKey('users.id')) FarmerID = db.Column(db.Integer, db.ForeignKey('farmers.id')) RouteID = db.Column(db.Integer, db.ForeignKey('routes.id'))
class DynamicData(db.Model): __tablename__ = 'dynamic_data' id = db.Column(db.Integer, primary_key = True) static_data_id = db.Column(db.Integer, db.ForeignKey('static_data.id'), nullable=False) static_data = db.relationship('StaticData', back_populates='snap_shots') time_stamp = db.Column(db.String(255)) upload_speed = db.Column(db.Integer) download_speed = db.Column(db.Integer) active_connection = db.Column(db.Boolean)
class Book(db.Model): __tablename__ = 'books' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(50)) year = db.Column(db.Integer) author_id = db.Column(db.Integer, db.ForeignKey('authors.id'), nullable=False) def __init__(self, title, year, author_id=None): self.title = title self.year = year self.author_id = author_id def create(self): db.session.add(self) db.session.commit() return self
class Finding(db.Model): __tablename__ = 'findings' id = db.Column(db.Integer, primary_key=True) work_item_id = db.Column(db.Integer, db.ForeignKey('work_items.id')) series_id = db.Column(db.Integer, db.ForeignKey('series.id')) finding_uid = db.Column(db.Integer) status = db.Column(db.String) label = db.Column(db.String(50)) key_slice = db.Column(db.Integer) visualization_type = db.Column(db.String) locations = db.Column(db.String) original_locations = db.Column(db.String) order = db.Column(db.Integer) comment = db.Column(db.String) input_source_index = db.Column(Integer, server_default='0', nullable=False) contour = db.Column(db.String, server_default=None) def __init__(self, work_item_id, series_id, finding_uid, status, label, key_slice, visualization_type, locations, order, original_locations=None, comment=None, input_source_index=0, contour=None): self.work_item_id = work_item_id self.series_id = series_id self.finding_uid = finding_uid self.status = status self.label = label self.key_slice = key_slice self.visualization_type = visualization_type self.locations = locations self.order = order self.original_locations = original_locations self.comment = comment self.input_source_index = input_source_index self.contour = contour def __repr__(self): return "<Finding(finding_uid='{}', status='{}', key_slice='{}')>".format( self.finding_uid, self.status, self.key_slice) def to_json_dict(self): return { 'id': self.id, 'series_id': self.series_id, 'finding_uid': self.finding_uid, 'label': self.label, 'status': self.status, 'key_slice': self.key_slice, 'visualization_type': self.visualization_type, 'locations': json.loads(self.locations), 'original_locations': None if self.original_locations is None else json.loads( self.original_locations), 'comment': self.comment, 'order': self.order, 'input_source_index': self.input_source_index, 'contour': None if self.contour is None else json.loads(self.contour) }
class WorkItem(db.Model): __tablename__ = 'work_items' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) uid = db.Column(db.String) # Study Instance UID accession_number = db.Column(db.String, index=True) patient_name = db.Column(db.String) patient_id = db.Column(db.String) study_date = db.Column(db.String) study_time = db.Column(db.String) body_part = db.Column(db.String, db.Enum(*DEFAULT_WINDOW_DEFS.keys())) status = db.Column(db.String) finalized_as = db.Column(db.String, db.Enum('positive', 'negative')) created_on = db.Column(db.DateTime, server_default=db.func.now()) updated_on = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now()) comment = db.Column(db.String) massive_bleeding = db.Column(db.Boolean, default=False) favorite = db.Column(db.Boolean, default=False) analyzed_by_aidoc = db.Column(db.Boolean, default=False) location = db.Column(db.String, db.Enum(*patientLocations)) order_by = db.Column(db.Integer) series = db.relationship('Series', order_by='Series.created_on') findings = db.relationship('Finding', order_by='Finding.order') db.UniqueConstraint('user_id', 'uid', name='user_work_item_uq') def __init__(self, user_id, uid, accession_number, patient_name, patient_id, study_date, study_time, body_part, status='pending', analyzed_by_aidoc=True): self.user_id = user_id self.uid = uid self.accession_number = accession_number self.patient_name = patient_name self.patient_id = patient_id self.study_date = study_date self.study_time = study_time self.body_part = body_part self.status = status self.analyzed_by_aidoc = analyzed_by_aidoc def __repr__(self): return "<WorkItem(uid='%s', accession_number='%s', patient_name='%s', body_part='%s', status='%s')>" %\ (self.uid, self.accession_number, self.patient_name, self.body_part, self.status) def get_patient_location(self): if self.location is not None: return self.location else: def generate_patient_location(): if self.patient_name: return patientLocations[int(string2hash(self.patient_name)) % len(patientLocations)] else: return patientLocations[0] return generate_patient_location() def to_json_dict(self): dt = self.format_study_datetime() # calculate AI Findings column ai_findings = self.calc_ai_findings() return { 'uid': self.uid, 'accessionNumber': self.accession_number, 'patientName': self.patient_name, 'patientId': self.patient_id if self.patient_id else '-', 'patientLocation': self.get_patient_location(), 'studyTime': dt, 'bodyPart': self.body_part, 'status': self.status, 'massiveBleeding': self.massive_bleeding, 'favorite': self.favorite, 'finalized_as': self.finalized_as if self.finalized_as else '', 'analyzed_by_aidoc': True if self.analyzed_by_aidoc is None else self.analyzed_by_aidoc, 'ai_findings': ai_findings, 'order_by': self.order_by } def calc_ai_findings(self): ai_findings_set = set() for f in self.findings: ai_findings_set.add(f.label) if len(ai_findings_set) < 3: return ', '.join(ai_findings_set) else: return 'Multi-Trauma' def format_study_datetime(self): if self.study_date and self.study_time: try: # handle milliseconds study_time = self.study_time[0:6] dt = datetime.strptime(self.study_date + study_time, '%Y%m%d%H%M%S') dt = dt.strftime(current_app.config.get('DATETIME_FORMAT')) except Exception: dt = '-' else: dt = '-' return dt