2020-07-30 14:23:51 +02:00
|
|
|
import pick from 'lodash/pick';
|
2020-08-06 08:18:57 +02:00
|
|
|
import cloneDeep from 'lodash/cloneDeep';
|
2020-06-19 08:43:22 +02:00
|
|
|
import {IdModel} from './id.model';
|
|
|
|
import {MaterialModel} from './material.model';
|
|
|
|
import {MeasurementModel} from './measurement.model';
|
2020-06-22 10:22:45 +02:00
|
|
|
import {BaseModel} from './base.model';
|
2020-06-19 08:43:22 +02:00
|
|
|
|
2020-06-22 10:22:45 +02:00
|
|
|
export class SampleModel extends BaseModel {
|
2020-06-19 08:43:22 +02:00
|
|
|
_id: IdModel = null;
|
|
|
|
color = '';
|
|
|
|
number = '';
|
|
|
|
type = '';
|
|
|
|
batch = '';
|
2020-08-06 08:18:57 +02:00
|
|
|
condition: {condition_template: string, [prop: string]: string} = {condition_template: null};
|
2020-06-19 08:43:22 +02:00
|
|
|
material_id: IdModel = null;
|
|
|
|
material: MaterialModel;
|
2020-06-26 11:09:59 +02:00
|
|
|
measurements: MeasurementModel[] = [];
|
2020-06-19 08:43:22 +02:00
|
|
|
note_id: IdModel = null;
|
|
|
|
user_id: IdModel = null;
|
2020-08-06 08:18:57 +02:00
|
|
|
validate = false;
|
2020-07-30 14:23:51 +02:00
|
|
|
notes: {
|
|
|
|
comment: string,
|
|
|
|
sample_references: {sample_id: IdModel, relation: string}[],
|
|
|
|
custom_fields: {[prop: string]: string}
|
|
|
|
} = {comment: '', sample_references: [], custom_fields: {}};
|
2020-07-27 17:52:03 +02:00
|
|
|
added: Date = null;
|
2020-06-19 08:43:22 +02:00
|
|
|
|
|
|
|
deserialize(input: any): this {
|
|
|
|
Object.assign(this, input);
|
|
|
|
if (input.hasOwnProperty('material')) {
|
|
|
|
this.material = new MaterialModel().deserialize(input.material);
|
|
|
|
this.material_id = input.material._id;
|
|
|
|
}
|
|
|
|
if (input.hasOwnProperty('measurements')) {
|
|
|
|
this.measurements = input.measurements.map(e => new MeasurementModel().deserialize(e));
|
|
|
|
}
|
2020-07-27 17:52:03 +02:00
|
|
|
if (input.hasOwnProperty('added')) {
|
|
|
|
this.added = new Date(input.added);
|
|
|
|
}
|
2020-06-19 08:43:22 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendFormat() {
|
2020-08-06 08:18:57 +02:00
|
|
|
return pick(this.conditionTemplateCheck(), ['color', 'type', 'batch', 'condition', 'material_id', 'notes']);
|
|
|
|
}
|
|
|
|
|
|
|
|
private conditionTemplateCheck() {
|
|
|
|
const res = cloneDeep(this);
|
|
|
|
if (res.condition.condition_template === null) {
|
|
|
|
res.condition = {};
|
|
|
|
}
|
|
|
|
return res;
|
2020-06-19 08:43:22 +02:00
|
|
|
}
|
|
|
|
}
|