Added the office_file_number to case in frontend.

Get new office file number in new case.
Convert the office_file_number field in the databse to integer
This commit is contained in:
Amritanshu Agrawal 2021-01-13 10:00:13 +05:30
parent 15f04b4cf1
commit 6e37690736
14 changed files with 89 additions and 20 deletions

View File

@ -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 '\'''\''"'

View File

@ -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)

View File

@ -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():

View File

@ -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")

View File

@ -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="",

View File

@ -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]

View File

@ -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"}

View File

@ -12,6 +12,14 @@
fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"
>
<mat-form-field fxFlex>
<mat-label>Source</mat-label>
<mat-select placeholder="Source" formControlName="caseSource">
<mat-option *ngFor="let cs of caseSources" [value]="cs.id">
{{ cs.name }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field fxFlex>
<mat-label>Office File Number</mat-label>
<input

View File

@ -8,6 +8,7 @@ import { distinctUntilChanged, startWith, switchMap } from 'rxjs/operators';
import { Act } from '../../core/act';
import { Case } from '../../core/case';
import { CaseSource } from '../../core/case-source';
import { CaseType } from '../../core/case-type';
import { Court } from '../../core/court';
import { CourtStatus } from '../../core/court-status';
@ -28,6 +29,7 @@ import { CaseService } from '../case.service';
export class CaseDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
form: FormGroup;
caseSources: CaseSource[] = [];
caseTypes: CaseType[] = [];
courts: Court[] = [];
departments: Department[] = [];
@ -45,10 +47,10 @@ export class CaseDetailComponent implements OnInit, AfterViewInit {
private fb: FormBuilder,
private toaster: ToasterService,
private ser: CaseService,
private officeService: OfficeService,
) {
// Create form
this.form = this.fb.group({
caseSource: '',
officeFileNumber: '',
courtCaseNumber: '',
year: '',
@ -85,6 +87,7 @@ export class CaseDetailComponent implements OnInit, AfterViewInit {
this.route.data.subscribe((value) => {
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() {

View File

@ -30,7 +30,9 @@
<ng-container matColumnDef="officeFileNumber">
<mat-header-cell *matHeaderCellDef>File No.</mat-header-cell>
<mat-cell *matCellDef="let row"
><a [routerLink]="['/cases', row.id]">{{ row.officeFileNumber }}</a></mat-cell
><a [routerLink]="['/cases', row.id]"
>{{ row.caseSource.prefix }}-{{ row.officeFileNumber }}</a
></mat-cell
>
</ng-container>

View File

@ -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)),
);

View File

@ -56,4 +56,12 @@ export class CaseService {
.delete<Case>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Case>;
}
newOfficeFileNumber(caseTypeId: string): Observable<number> {
return this.http
.get<number>(`${url}/id/${caseTypeId}`)
.pipe(
catchError(this.log.handleError(serviceName, `get newOfficeFileNumber=${caseTypeId}`)),
) as Observable<number>;
}
}

View File

@ -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,

View File

@ -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<Case>) {
this.id = undefined;
this.caseSource = new CaseSource();
this.officeFileNumber = '';
this.courtCaseNumber = '';
this.year = '';