import { ShareIncidentRuleKind } from "../../constants"; import { MongooseModule, currentDate, } from "../../helpers"; import { CADPersonSchemaType, CallerType, IncidentFilterLabelType, RadioChannelSchemaType, RecordSchemaType, ReportNumberSchemaType, ShareReasonSchemaType, SharedSourceSchemaType, SharedToEventSchemaType, SharedToSchemaType, } from "../../types/common-incident"; // Properties shared between CAD and Managed Incident // They are copied on iOS export function CADPersonSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const Person = new Schema({ PersonnelID: { type: String, }, PersonnelName: { type: String, }, PersonnelRank: { type: String, default: "" }, PersonnelWorkCode: { type: String, default: "" }, PersonnelNote: { type: String, default: "" }, }, { _id: false, id: false, }); return Person; } export function CallerSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const Item = new Schema({ // Should match CallerId: { type: String, default: "", }, Latitude: { type: Number, }, Longitude: { type: Number, }, LocationUpdatedAt: { type: Date, }, // Somewhat optional Altitude: { type: Number, }, Application: { type: String, }, Source: { type: String, }, Address: { type: String, }, UncertaintyRadius: { type: Number, }, }, { _id: false, id: false, toJSON: { versionKey: false, } }); return Item; } export function RadioChannelSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const RadioChannel = new Schema({ name: { type: String, default: "", }, channel: { type: String, default: "", }, url: { type: String, default: "", }, channelDescription: { type: String, default: "", }, tone: { type: String, default: "", }, }, { _id: false, id: false, toJSON: { versionKey: false, } }); return RadioChannel; } export function RecordSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const Record = new Schema({ name: { type: String, default: "" }, value: { type: String, default: "", }, }, { _id: false, id: false, toJSON: { versionKey: false, } }); return Record; } export function ReportNumberSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const ReportNumber = new Schema({ name: { type: String, default: "", }, number: { type: String, default: "", }, }, { _id: false, id: false, toJSON: { versionKey: false, } }); return ReportNumber; } export function ShareReasonSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const ShareReason = new Schema({ name: { type: String, default: "", }, date: { type: Date, default: currentDate, }, ruleType: { type: String, default: ShareIncidentRuleKind.None, }, kNegative: { type: [String], default: [], }, kPositive: { type: [String], default: [], }, }, { _id: false, id: false, toJSON: { versionKey: false, }, }); return ShareReason; } export function SharedToSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const ShareReason = ShareReasonSchema(mongoose); const SharedTo = new Schema({ departmentId: { type: String, default: "", }, userId: { type: String, default: "", }, // Department Name name: { type: String, default: "", }, startAt: { type: Date, default: currentDate, }, expireAt: { type: Date, default: currentDate, }, active: { type: Boolean, default: true, // overwritten later, when expireAt is older than now }, reasons: { type: [ShareReason], default: [], }, sendNotification: { type: Boolean, default: false, }, }, { _id: false, id: false, toJSON: { versionKey: false, } }); return SharedTo; } export function SharedSourceSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const ShareReason = ShareReasonSchema(mongoose); const SharedSource = new Schema({ // Department Name (always matches record .departmentId) name: { type: String, default: "", }, // Output overwritten by backend when record is included in another department's list isExternal: { type: Boolean, default: false, }, // Output will be overwritten by backend startAt: { type: Date, }, expireAt: { type: Date, }, reasons: { type: [ShareReason], default: [], } }, { _id: false, id: false, toJSON: { versionKey: false, } }); return SharedSource; } export function SharedToEventSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const SharedToEvent = new Schema({ departmentId: { type: String, default: "", }, userId: { type: String, default: "", }, expireAt: { type: Date, default: new Date("2025-01-02T03:04:05Z"), // Date in the past }, updatedAt: { type: Date, default: new Date("2025-01-02T03:04:05Z"), // Date in the past }, active: { type: Boolean, default: false, }, }, { _id: false, id: false, toJSON: { versionKey: false, } }); return SharedToEvent; } export function IncidentFilterLabelSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const IncidentFilterLabel = new Schema({ // Area options areaCalOES: { type: [String], default: [], }, areaUnit: { type: [String], default: [], }, county: { type: [String], default: [], }, // Other generic options agencyId: { type: [String], default: [], }, city: { type: [String], default: [], }, radioName: { type: [String], default: [], }, showNoUnits: { type: [Boolean], default: [true], }, }, { _id: false, id: false, toJSON: { versionKey: false, }, }); return IncidentFilterLabel; }