Skip to content

Commit

Permalink
Merge pull request #175 from dinesh-aot/COMP-275
Browse files Browse the repository at this point in the history
Ispection requirements model
  • Loading branch information
nitheesh-aot authored Dec 24, 2024
2 parents 14904f0 + db40a98 commit 04fe26e
Show file tree
Hide file tree
Showing 14 changed files with 1,337 additions and 30 deletions.

Large diffs are not rendered by default.

329 changes: 329 additions & 0 deletions compliance-api/migrations/versions/a684c47ac3e8_document_types.py

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion compliance-api/src/compliance_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@
from .complaint import (
Complaint, ComplaintReqOrderDetail, ComplaintReqScheduleBDetail, ComplaintRequirementDetail, ComplaintSource,
ComplaintSourceContact, ComplaintStatusEnum)
from .compliance_finding import ComplianceFindingOption, ComplianceFindingOptionEnum
from .continuation_report import ContinuationReport, ContinuationReportKey
from .db import db, ma, migrate
from .document_type import DocumentType
from .enforcement_action import EnforcementActionOption, EnforcementActionOptionEnum
from .inspection import (
Inspection, InspectionAgency, InspectionAttendance, InspectionAttendanceOption, InspectionAttendanceOptionEnum,
InspectionFirstnation, InspectionInitiationOption, InspectionOfficer, InspectionOtherAttendance,
InspectionStatusEnum, InspectionType, InspectionTypeOption, IRStatusOption)
InspectionReqDetailDocument, InspectionReqSourceDetail, InspectionRequirement, InspectionStatusEnum, InspectionType,
InspectionTypeOption, IRStatusOption)
from .position import Position
from .project import Project
from .req_source_document_map import RequirementSourceDocumentMap
from .requirement_source import RequirementSource
from .staff_user import StaffUser
from .topic import Topic
Expand Down
19 changes: 19 additions & 0 deletions compliance-api/src/compliance_api/models/compliance_finding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Compliance finding model."""

from enum import Enum

from .option_base_model import OptionModel


class ComplianceFindingOptionEnum(Enum):
"""ComplianceFindingEnum."""

IN = 1
OUT = 2
NOT_DETERMINED = 3


class ComplianceFindingOption(OptionModel):
"""ComplianceFinding."""

__tablename__ = "compliance_finding_options"
9 changes: 9 additions & 0 deletions compliance-api/src/compliance_api/models/document_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""DocumentType Model."""

from .option_base_model import OptionModel


class DocumentType(OptionModel):
"""DocumentType Model."""

__tablename__ = "document_types"
24 changes: 24 additions & 0 deletions compliance-api/src/compliance_api/models/enforcement_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""EnforcementActionModel."""
from enum import Enum

from .option_base_model import OptionModel


class EnforcementActionOptionEnum(Enum):
"""EnforcementActionOptionEnum."""

TO_BE_DETERMINED = 1
NOT_APPLICABLE = 2
NOTICE_OF_NON_COMPLIANCE = 3
WARNING_LETTER = 4
ORDER = 5
REFERRAL_TO_ADMINISTRATIVE_PENALTY = 6
REFERRAL_TO_ANOTHER_AGENCY = 7
VIOLATION_TICKET = 8
PROSECUTION_RECOMMENTDATAION = 10


class EnforcementActionOption(OptionModel):
"""Requirement source."""

__tablename__ = "enforcement_action_options"
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
from .inspection_option import (
InspectionAttendanceOption, InspectionInitiationOption, InspectionTypeOption, IRStatusOption)
from .inspection_other_attendance import InspectionOtherAttendance
from .inspection_req_detail_doc import InspectionReqDetailDocument
from .inspection_req_source_detail import InspectionReqSourceDetail
from .inspection_requirement import InspectionRequirement
from .inspection_type import InspectionType
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""InspectionRequirementDetailDocument Model."""

from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship

from ..base_model import BaseModelVersioned


class InspectionReqDetailDocument(BaseModelVersioned):
"""InspectionReqDetailDocument Model."""

__tablename__ = "inspection_req_detail_documents"

id = Column(
Integer,
primary_key=True,
autoincrement=True,
comment="The unique identifier",
)
req_detail_id = Column(
Integer,
ForeignKey(
"inspection_req_source_details.id",
name="inspection_req_detail_documents_req_detail_id_fkey",
),
comment="The unique identifier of the requirement detail",
nullable=False,
)
document_type_id = Column(
Integer,
ForeignKey(
"document_types.id", name="inspection_req_detail_documents_document_id_fkey"
),
comment="The unique identifier of the document type",
nullable=False,
)
document_title = Column(String, nullable=False, comment="The title of the document")
section_number = Column(
String,
nullable=True,
comment="The highlighted section number in the uploaded document",
)
section_title = Column(
String,
nullable=True,
comment="The title of the section associated with the document",
)
description = Column(
String, nullable=True, comment="Additional description of the document"
)
requirement_source_detail = relationship(
"InspectionReqSourceDetail", foreign_keys=[req_detail_id], lazy="select"
)
document_type = relationship(
"DocumentType", foreign_keys=[document_type_id], lazy="select"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""InspectionRequirementSourceDetail Model."""

from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship

from ..base_model import BaseModelVersioned


class InspectionReqSourceDetail(BaseModelVersioned):
"""InspectionReqSourceDetail."""

__tablename__ = "inspection_req_source_details"
id = Column(
Integer,
primary_key=True,
autoincrement=True,
comment="The unique identifier",
)
requirement_id = Column(
Integer,
ForeignKey(
"inspection_requirements.id", name="inspection_req_detail_req_id_fkey"
),
nullable=False,
comment="The requirement id",
)
requirement_source_id = Column(
Integer,
ForeignKey(
"requirement_sources.id", name="inspection_req_detail_source_id_fkey"
),
nullable=False,
comment="The source of the requirement",
)
section_number = Column(
String,
nullable=True,
comment="The optional section number associated with requirement sources"
"(Act (2018), Schedule A, Compliance Agreement, Act (2002))",
)
condition_number = Column(
String,
nullable=True,
comment="The optional condition number associated with rquirement sources(Schedule B, EAC Certificate)",
)
amendment_number = Column(
String,
nullable=True,
comment="The optional amendment number if the requirement source is EAC Amendment",
)
title = Column(
String, nullable=True, comment="The title of the requirement source detail"
)
description = Column(
String,
nullable=True,
comment="The description of the requirement source detail",
)
inspection_requirement = relationship(
"InspectionRequirement", foreign_keys=[requirement_id], lazy="select"
)
requirement_source = relationship(
"RequirementSource", foreign_keys=[requirement_source_id], lazy="joined"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""InspectionRequirement Model."""

from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship

from ..base_model import BaseModelVersioned


class InspectionRequirement(BaseModelVersioned):
"""InspectionRequirementModel."""

__tablename__ = "inspection_requirements"
id = Column(
Integer,
primary_key=True,
autoincrement=True,
comment="The unique identifier",
)
inspection_id = Column(
Integer,
ForeignKey("inspections.id", name="inspection_requirements_inspection_id_fkey"),
nullable=False,
comment="The unique identifier of the inspection",
)
summary = Column(String, nullable=False, comment="The summary of the requirement")
topic_id = Column(
Integer,
ForeignKey("topics.id", name="inspection_requirements_topic_id_fkey"),
nullable=False,
comment="The topic of the requirement",
)
enforcement_action_id = Column(
Integer,
ForeignKey(
"enforcement_action_options.id",
name="insepction_requirements_enforcement_action_fkey",
),
nullable=False,
comment="The enforcement action taken on the requirement",
)
compliance_finding_id = Column(
Integer,
ForeignKey(
"compliance_finding_options.id",
name="inspection_req_compliance_finding_fkey",
),
nullable=False,
comment="Compliance finding of the requirement",
)
findings = Column(
String, comment="The findings of the requirement"
)
inspection = relationship("Inspection", foreign_keys=[inspection_id], lazy="select")
topic = relationship("Topic", foreign_keys=[topic_id], lazy="joined")
enforcement_action = relationship(
"EnforcementActionOption", foreign_keys=[enforcement_action_id], lazy="joined"
)
compliance_finding = relationship(
"ComplianceFindingOption", foreign_keys=[compliance_finding_id], lazy="joined"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""RequirementSourceDocumentMap Model."""

from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship

from .base_model import BaseModelVersioned


class RequirementSourceDocumentMap(BaseModelVersioned):
"""RequirementSourceDocumentMap Model."""

__tablename__ = "requirement_source_document_maps"

id = Column(
Integer, primary_key=True, autoincrement=True, comment="The unique identifier"
)
requirement_source_id = Column(
Integer,
ForeignKey("requirement_sources.id", name="req_source_map_req_source_id_fkey"),
)
document_type_id = Column(
Integer,
ForeignKey("document_types.id", name="req_doc_type_id_document_types_id_fkey"),
)
requirement_source = relationship(
"RequirementSource", foreign_keys=[requirement_source_id], lazy="joined"
)
document_type = relationship(
"DocumentType", foreign_keys=[document_type_id], lazy="joined"
)
6 changes: 4 additions & 2 deletions compliance-api/src/compliance_api/models/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class Topic(BaseModelVersioned):

__tablename__ = "topics"

id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(150), nullable=False)
id = Column(
Integer, primary_key=True, autoincrement=True, comment="The unique identifier"
)
name = Column(String(150), nullable=False, comment="Name of the topic")

@classmethod
def get_by_name(cls, topic: str) -> Topic:
Expand Down
30 changes: 18 additions & 12 deletions compliance-web/src/components/App/CaseFiles/CaseFileDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import DrawerActionBarBottom from "@/components/Shared/Drawer/DrawerActionBarBottom";
import DrawerActionBarTop from "@/components/Shared/Drawer/DrawerActionBarTop";
import DrawerTitleBar from "@/components/Shared/Drawer/DrawerTitleBar";
import { KC_USER_GROUPS, useIsRolesAllowed } from "@/hooks/useAuthorization";
import {
useCreateCaseFile,
useInitiationsData,
useUpdateCaseFile,
} from "@/hooks/useCaseFiles";
import { useStaffUsersData } from "@/hooks/useStaff";
import { useProjectsData } from "@/hooks/useProjects";
import { useStaffUsersData } from "@/hooks/useStaff";
import { CaseFile, CaseFileAPIData, CaseFileFormData } from "@/models/CaseFile";
import { Initiation } from "@/models/Initiation";
import { Project } from "@/models/Project";
import { StaffUser } from "@/models/Staff";
import router from "@/router/router";
import { useMenuStore } from "@/store/menuStore";
import { formatAuthorization } from "@/utils/appUtils";
import { UNAPPROVED_PROJECT_ID } from "@/utils/constants";
import dateUtils from "@/utils/dateUtils";
import { yupResolver } from "@hookform/resolvers/yup";
import { Box } from "@mui/material";
import dayjs, { Dayjs } from "dayjs";
import { useCallback, useEffect, useMemo } from "react";
import { FormProvider, useForm } from "react-hook-form";
import * as yup from "yup";
import CaseFileForm from "./CaseFileForm";
import dateUtils from "@/utils/dateUtils";
import DrawerTitleBar from "@/components/Shared/Drawer/DrawerTitleBar";
import { useCallback, useEffect, useMemo } from "react";
import dayjs, { Dayjs } from "dayjs";
import { useMenuStore } from "@/store/menuStore";
import DrawerActionBarTop from "@/components/Shared/Drawer/DrawerActionBarTop";
import DrawerActionBarBottom from "@/components/Shared/Drawer/DrawerActionBarBottom";
import { KC_USER_GROUPS } from "@/hooks/useAuthorization";
import { useIsRolesAllowed } from "@/hooks/useAuthorization";
import { UNAPPROVED_PROJECT_ID } from "@/utils/constants";
import { formatAuthorization } from "@/utils/appUtils";

type CaseFileDrawerProps = {
onSubmit: (submitMsg: string) => void;
Expand Down Expand Up @@ -118,6 +118,12 @@ const CaseFileDrawer: React.FC<CaseFileDrawerProps> = ({
? "Changes saved successfully."
: `Case File ${data.case_file_number} was successfully created`
);
if (!caseFile) {
router.navigate({
to:`/ce-database/case-files/$caseFileNumber`,
params: { caseFileNumber: data.case_file_number }
});
}
reset();
},
[caseFile, onSubmit, reset]
Expand Down
Loading

0 comments on commit 04fe26e

Please sign in to comment.