diff --git a/DB/import.sh b/DB/import.sh index 4157485..08593bd 100755 --- a/DB/import.sh +++ b/DB/import.sh @@ -25,7 +25,7 @@ sed -i 's/\x0//g' /home/tanshu/Programming/luthor/DB/csv/k-offices.csv docker run -it -v /home/tanshu/Programming/luthor/DB/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres luthor -c "\copy offices(old_id, old_department_id, name, address, email) from /mnt/k-offices.csv"' docker run -it -v /home/tanshu/Programming/luthor/DB/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres luthor -c "\copy role_permissions(old_user_id, old_permission_id) from /mnt/l-user-roles.csv"' sed -i 's/\x0//g' /home/tanshu/Programming/luthor/DB/csv/m-cases.csv -docker run -it -v /home/tanshu/Programming/luthor/DB/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres luthor -c "\copy cases(old_id, office_file_number, court_case_number, year, title, docket_number, receipt_date, limitation_date, filing_date, appear_on_behalf_of, question_of_law, aor_name, opposing_council_aor, lower_court_case_number, date_of_impugned_judgement, brief_description, remarks, slp_counter, contact_detail, case_connected_with, old_court_id, old_department_id, old_office_id, old_case_type_id, old_act_id, old_nature_id, old_court_status_id, old_office_status_id, opposing_council_detail, bunch_cases) from /mnt/m-cases.csv with delimiter E'\''\t'\'' null as '\'''\''"' +docker run -it -v /home/tanshu/Programming/luthor/DB/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres luthor -c "\copy cases(old_id, old_office_file_number, office_file_number, court_case_number, year, title, docket_number, receipt_date, limitation_date, filing_date, appear_on_behalf_of, question_of_law, aor_name, opposing_council_aor, lower_court_case_number, date_of_impugned_judgement, brief_description, remarks, slp_counter, contact_detail, case_connected_with, old_court_id, old_department_id, old_office_id, old_case_type_id, old_act_id, old_nature_id, old_court_status_id, old_office_status_id, opposing_council_detail, bunch_cases) from /mnt/m-cases.csv with delimiter E'\''\t'\'' null as '\'''\''"' #docker run -it -v /home/tanshu/Programming/luthor/DB/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres luthor -c "\copy contacts(old_id, old_office_id, old_department_id, brief, next_hearing_date, court_status_id, court_number, item_number) from /mnt/n-contact-persons.csv"' sed -i 's/\x0//g' /home/tanshu/Programming/luthor/DB/csv/o-hearings.csv docker run -it -v /home/tanshu/Programming/luthor/DB/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres luthor -c "\copy hearings(old_id, old_case_id, judges, brief, next_hearing_date, old_court_status_id, court_number, item_number) from /mnt/o-hearings.csv with delimiter E'\''\t'\'' null as '\'''\''"' diff --git a/luthor/alembic/versions/74058d75b7a0_initial_commit.py b/luthor/alembic/versions/74058d75b7a0_initial_commit.py index 2ff56f6..fb57eb8 100644 --- a/luthor/alembic/versions/74058d75b7a0_initial_commit.py +++ b/luthor/alembic/versions/74058d75b7a0_initial_commit.py @@ -166,7 +166,8 @@ def upgrade(): "cases", sa.Column("id", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False), sa.Column("old_id", sa.Integer(), nullable=False), - sa.Column("office_file_number", sa.Unicode(length=255), nullable=False), + sa.Column("old_office_file_number", sa.Unicode(length=255), nullable=False), + sa.Column("office_file_number", sa.Integer(), nullable=False), sa.Column("court_case_number", sa.Unicode(length=255), nullable=True), sa.Column("year", sa.Unicode(length=255), nullable=False), sa.Column("title", sa.Unicode(length=255), nullable=True), @@ -221,7 +222,6 @@ def upgrade(): ["case_source_id"], ["case_sources.id"], name=op.f("fk_cases_case_source_id_case_sources") ), sa.PrimaryKeyConstraint("id", name=op.f("pk_cases")), - sa.UniqueConstraint("office_file_number", name=op.f("uq_cases_office_file_number")), ) op.create_index(op.f("ix_cases_date_of_impugned_judgement"), "cases", ["date_of_impugned_judgement"], unique=False) op.create_index(op.f("ix_cases_filing_date"), "cases", ["filing_date"], unique=False) diff --git a/luthor/alembic/versions/87a06eaadd34_finish_import.py b/luthor/alembic/versions/87a06eaadd34_finish_import.py index 07a0a9b..0b96fbf 100644 --- a/luthor/alembic/versions/87a06eaadd34_finish_import.py +++ b/luthor/alembic/versions/87a06eaadd34_finish_import.py @@ -320,7 +320,7 @@ def add_case_sources(): ) op.execute(sources.insert().values(name="HLC Cases", prefix="HRC")) op.execute(sources.insert().values(name="HUDA Cases", prefix="AHC")) - op.execute(sources.insert().values(name="Private Cases", prefix="APC")) + op.execute(sources.insert().values(id="08efc7cc-e4a1-4d24-bcba-58ca9bc29994", name="Private Cases", prefix="APC")) op.execute(sources.insert().values(name="Board & Corp. Cases", prefix="A")) op.execute(sources.insert().values(name="Opinion Cases", prefix="AOC")) op.execute(sources.insert().values(name="Misc", prefix="Misc")) @@ -329,19 +329,21 @@ def add_case_sources(): cases = table( "cases", - column("office_file_number", sa.Unicode(length=255)), + column("old_office_file_number", sa.Unicode(length=255)), column("case_source_id", postgresql.UUID(as_uuid=True)), ) op.execute( cases.update( values={ "case_source_id": select([sources.c.id]).where( - cases.c.office_file_number.ilike(sources.c.prefix + "-%") + cases.c.old_office_file_number.ilike(sources.c.prefix + "-%") ) } ) ) op.alter_column('cases', 'case_source_id', existing_type=postgresql.UUID(), nullable=False) + op.drop_column("cases", "old_office_file_number") + op.create_unique_constraint(op.f("uq_cases_office_file_number"), "cases", ["office_file_number", "case_source_id"]) def upgrade(): diff --git a/luthor/luthor/models/case_source.py b/luthor/luthor/models/case_source.py index a14a6b5..1c28f0f 100644 --- a/luthor/luthor/models/case_source.py +++ b/luthor/luthor/models/case_source.py @@ -23,3 +23,7 @@ class CaseSource(Base): self.name = name self.prefix = prefix self.id = id_ + + @classmethod + def private(cls): + return uuid.UUID("08efc7cc-e4a1-4d24-bcba-58ca9bc29994") diff --git a/luthor/luthor/routers/case.py b/luthor/luthor/routers/case.py index ce5347b..15e3970 100644 --- a/luthor/luthor/routers/case.py +++ b/luthor/luthor/routers/case.py @@ -1,11 +1,13 @@ import uuid +from datetime import date from typing import List import luthor.schemas.case as schemas from fastapi import APIRouter, Depends, HTTPException, Security, status -from sqlalchemy import desc +from luthor.models.case_source import CaseSource +from sqlalchemy import desc, func from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.orm import Session @@ -164,13 +166,27 @@ def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user) return [case_info(item) for item in db.query(Case).order_by(desc(Case.receipt_date)).all()] +@router.get("/id/{case_type_id}", response_model=int) +def show_case_type_id( + case_type_id: uuid.UUID, + db: Session = Depends(get_db), + user: UserToken = Security(get_user, scopes=["cases"]), +) -> int: + code = db.query(func.max(Case.office_file_number)).filter(Case.case_source_id == case_type_id).one()[0] + code = 1 if code is None else code + 1 + return code + + @router.get("/list/{source_id}", response_model=List[schemas.Case]) def show_list_of_source( source_id: uuid.UUID, db: Session = Depends(get_db), user: UserToken = Depends(get_user) ) -> List[schemas.Case]: return [ case_info(item) - for item in db.query(Case).filter(Case.case_source_id == source_id).order_by(desc(Case.receipt_date)).all() + for item in db.query(Case) + .filter(Case.case_source_id == source_id) + .order_by(desc(Case.office_file_number)) + .all() ] @@ -187,6 +203,9 @@ def show_id( def case_info(item: Case) -> schemas.Case: return schemas.Case( id=item.id, + caseSource=schemas.CaseSourceLink( + id=item.case_source.id, name=item.case_source.name, prefix=item.case_source.prefix + ), officeFileNumber=item.office_file_number if item.office_file_number is not None else "", courtCaseNumber=item.court_case_number if item.court_case_number is not None else "", year=item.year, @@ -229,7 +248,9 @@ def case_info(item: Case) -> schemas.Case: def case_blank() -> schemas.CaseBlank: return schemas.CaseBlank( + caseSource=schemas.CaseSourceLink(id=CaseSource.private(), name="Private Cases"), officeFileNumber="", + receiptDate=date.today(), courtCaseNumber="", year="", title="", diff --git a/luthor/luthor/schemas/case.py b/luthor/luthor/schemas/case.py index fbb3b1a..6c2e363 100644 --- a/luthor/luthor/schemas/case.py +++ b/luthor/luthor/schemas/case.py @@ -7,6 +7,7 @@ from pydantic import BaseModel, Field, validator from . import to_camel from .act import ActLink +from .case_source import CaseSourceLink from .case_type import CaseTypeLink from .court import CourtLink from .court_status import CourtStatusLink @@ -39,6 +40,7 @@ class CaseIn(BaseModel): case_connected_with: str bunch_cases: str + case_source: CaseSourceLink court: Optional[CourtLink] department: Optional[DepartmentLink] office: Optional[OfficeLink] diff --git a/luthor/luthor/schemas/case_source.py b/luthor/luthor/schemas/case_source.py index c4468e9..5eb17cc 100644 --- a/luthor/luthor/schemas/case_source.py +++ b/luthor/luthor/schemas/case_source.py @@ -32,6 +32,7 @@ class CaseSourceBlank(BaseModel): class CaseSourceLink(BaseModel): id_: uuid.UUID = Field(...) name: Optional[str] + prefix: Optional[str] class Config: fields = {"id_": "id"} diff --git a/otis/src/app/cases/case-detail/case-detail.component.html b/otis/src/app/cases/case-detail/case-detail.component.html index d83dc29..cde3c53 100644 --- a/otis/src/app/cases/case-detail/case-detail.component.html +++ b/otis/src/app/cases/case-detail/case-detail.component.html @@ -12,6 +12,14 @@ fxLayoutGap="20px" fxLayoutGap.lt-md="0px" > + + Source + + + {{ cs.name }} + + + Office File Number { const data = value as { item: Case; + caseSources: CaseSource[]; caseTypes: CaseType[]; courts: Court[]; departments: Department[]; @@ -93,6 +96,7 @@ export class CaseDetailComponent implements OnInit, AfterViewInit { acts: Act[]; natures: Nature[]; }; + this.caseSources = data.caseSources; this.caseTypes = data.caseTypes; this.courts = data.courts; this.departments = data.departments; @@ -107,6 +111,7 @@ export class CaseDetailComponent implements OnInit, AfterViewInit { showItem(item: Case) { this.item = item; this.form.setValue({ + caseSource: this.item.caseSource.id, officeFileNumber: this.item.officeFileNumber, courtCaseNumber: this.item.courtCaseNumber, year: this.item.year, @@ -144,11 +149,21 @@ export class CaseDetailComponent implements OnInit, AfterViewInit { officeStatus: this.item.officeStatus ? this.item.officeStatus.id : '', courtStatus: this.item.courtStatus ? this.item.courtStatus.id : '', }); - this.offices = (this.form.get('department') as FormControl).valueChanges.pipe( - startWith(this.item.department ? this.item.department.id : ''), - distinctUntilChanged(), - switchMap((x) => this.officeService.filteredList(x)), - ); + (this.form.get('caseSource') as FormControl).valueChanges + .pipe( + startWith(this.item.caseSource.id), + distinctUntilChanged(), + switchMap((x) => this.ser.newOfficeFileNumber(x)), + ) + .subscribe((x) => { + if ( + this.item.officeFileNumber === null || + this.item.officeFileNumber === undefined || + this.item.officeFileNumber === '' + ) { + this.form.patchValue({ officeFileNumber: x }); + } + }); } ngAfterViewInit() { diff --git a/otis/src/app/cases/case-list/case-list.component.html b/otis/src/app/cases/case-list/case-list.component.html index 16935ab..38b7737 100644 --- a/otis/src/app/cases/case-list/case-list.component.html +++ b/otis/src/app/cases/case-list/case-list.component.html @@ -30,7 +30,9 @@ File No. {{ row.officeFileNumber }}{{ row.caseSource.prefix }}-{{ row.officeFileNumber }} diff --git a/otis/src/app/cases/case-list/case-list.component.ts b/otis/src/app/cases/case-list/case-list.component.ts index 45940ce..e560f99 100644 --- a/otis/src/app/cases/case-list/case-list.component.ts +++ b/otis/src/app/cases/case-list/case-list.component.ts @@ -48,12 +48,13 @@ export class CaseListComponent implements OnInit { ngOnInit() { this.route.data.subscribe((value) => { - const data = value as { list: Case[]; caseSources: CaseSource[] }; + const data = value as { caseSources: CaseSource[] }; this.caseSources = data.caseSources; - this.list = observableOf(data.list); - + this.form.setValue({ + caseSource: '08efc7cc-e4a1-4d24-bcba-58ca9bc29994', + }); this.list = (this.form.get('caseSource') as FormControl).valueChanges.pipe( - startWith(''), + startWith('08efc7cc-e4a1-4d24-bcba-58ca9bc29994'), distinctUntilChanged(), switchMap((x) => this.ser.list(x)), ); diff --git a/otis/src/app/cases/case.service.ts b/otis/src/app/cases/case.service.ts index df340ff..4f512ba 100644 --- a/otis/src/app/cases/case.service.ts +++ b/otis/src/app/cases/case.service.ts @@ -56,4 +56,12 @@ export class CaseService { .delete(`${url}/${id}`, httpOptions) .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } + + newOfficeFileNumber(caseTypeId: string): Observable { + return this.http + .get(`${url}/id/${caseTypeId}`) + .pipe( + catchError(this.log.handleError(serviceName, `get newOfficeFileNumber=${caseTypeId}`)), + ) as Observable; + } } diff --git a/otis/src/app/cases/cases-routing.module.ts b/otis/src/app/cases/cases-routing.module.ts index fda21fa..9a52426 100644 --- a/otis/src/app/cases/cases-routing.module.ts +++ b/otis/src/app/cases/cases-routing.module.ts @@ -31,7 +31,7 @@ const advocatesRoutes: Routes = [ }, resolve: { caseSources: CaseSourceListResolver, - list: CaseListResolver, + // list: CaseListResolver, }, }, { @@ -43,6 +43,7 @@ const advocatesRoutes: Routes = [ }, resolve: { item: CaseResolver, + caseSources: CaseSourceListResolver, caseTypes: CaseTypeListResolver, courts: CourtListResolver, departments: DepartmentListResolver, @@ -61,6 +62,7 @@ const advocatesRoutes: Routes = [ }, resolve: { item: CaseResolver, + caseSources: CaseSourceListResolver, caseTypes: CaseTypeListResolver, courts: CourtListResolver, departments: DepartmentListResolver, diff --git a/otis/src/app/core/case.ts b/otis/src/app/core/case.ts index 5c86eba..d13d098 100644 --- a/otis/src/app/core/case.ts +++ b/otis/src/app/core/case.ts @@ -1,4 +1,5 @@ import { Act } from './act'; +import { CaseSource } from './case-source'; import { CaseType } from './case-type'; import { Court } from './court'; import { CourtStatus } from './court-status'; @@ -9,6 +10,7 @@ import { OfficeStatus } from './office-status'; export class Case { id: string | undefined; + caseSource: CaseSource; officeFileNumber: string; courtCaseNumber: string; year: string; @@ -41,6 +43,7 @@ export class Case { public constructor(init?: Partial) { this.id = undefined; + this.caseSource = new CaseSource(); this.officeFileNumber = ''; this.courtCaseNumber = ''; this.year = '';