From f1d60807eb58d470185f6b21b95ed58cfb97bc34 Mon Sep 17 00:00:00 2001 From: avicenan Date: Mon, 27 Apr 2026 17:20:24 +0700 Subject: [PATCH] fix(laboratory): service to examination type relation --- src/entity/emr/emr_laboratory_order_item_results.ts | 8 -------- src/entity/emr/emr_laboratory_order_items.ts | 3 +++ src/entity/examination_type.ts | 9 ++------- src/entity/service.ts | 5 +++++ 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/entity/emr/emr_laboratory_order_item_results.ts b/src/entity/emr/emr_laboratory_order_item_results.ts index 42d36be..e68b66e 100644 --- a/src/entity/emr/emr_laboratory_order_item_results.ts +++ b/src/entity/emr/emr_laboratory_order_item_results.ts @@ -31,23 +31,15 @@ export class EmrLaboratoryOrderItemResult { @JoinColumn() examination_detail: ExaminationDetail; - /** Denormalized: examination type name from examination_type.name */ - @Column({ type: "text", nullable: true }) - examination_type: string; - - /** Denormalized: examination detail name from examination_detail.name */ @Column({ type: "text", nullable: true }) examination_detail_name: string; - /** Denormalized: measurement unit from measurement_unit.unit */ @Column({ nullable: true, length: 256 }) measurement_unit: string; - /** Denormalized: reference range as flat string from reference_range */ @Column({ type: "text", nullable: true }) reference_range: string; - /** The actual examination result value that can be filled */ @Column({ type: "text", nullable: true }) examination_result: string; diff --git a/src/entity/emr/emr_laboratory_order_items.ts b/src/entity/emr/emr_laboratory_order_items.ts index 62fe2d1..e71d36e 100644 --- a/src/entity/emr/emr_laboratory_order_items.ts +++ b/src/entity/emr/emr_laboratory_order_items.ts @@ -32,6 +32,9 @@ export class EmrLaboratoryOrderItem { @JoinColumn() service: Service; + @Column({ type: "text", nullable: true }) + examination_type_name: string; + @Column({ type: "timestamp", nullable: true }) examination_time: Date; diff --git a/src/entity/examination_type.ts b/src/entity/examination_type.ts index cec944c..e3ceeb7 100644 --- a/src/entity/examination_type.ts +++ b/src/entity/examination_type.ts @@ -6,7 +6,7 @@ import { UpdateDateColumn, DeleteDateColumn, ManyToMany, - JoinTable, + OneToMany, } from 'typeorm'; import { Status } from '../types/status'; @@ -29,12 +29,7 @@ export class ExaminationType { }) status: Status; - @ManyToMany(() => Service, { onDelete: 'NO ACTION' }) - @JoinTable({ - name: 'examination_type_services', - joinColumn: { name: 'examination_type_id', referencedColumnName: 'id' }, - inverseJoinColumn: { name: 'service_id', referencedColumnName: 'id' }, - }) + @OneToMany(() => Service, (service) => service.examination_type) services: Service[]; @CreateDateColumn() diff --git a/src/entity/service.ts b/src/entity/service.ts index 870b6db..8e3c551 100644 --- a/src/entity/service.ts +++ b/src/entity/service.ts @@ -17,6 +17,7 @@ import { Room } from './room'; import { ExaminationDetail } from './examination_detail'; import { Status } from '../types/status'; import { ServiceFare } from './service_fare'; +import { ExaminationType } from './examination_type'; @Entity('services') export class Service { @@ -50,6 +51,10 @@ export class Service { }) rooms: Room[]; + @ManyToOne(() => ExaminationType, { onDelete: 'NO ACTION' }) + @JoinColumn({ name: 'examination_type_id' }) + examination_type: ExaminationType; + @ManyToMany(() => ExaminationDetail, { onDelete: 'NO ACTION' }) @JoinTable({ name: 'service_examinations',