import { currentDate, MongooseModule, } from "../../helpers"; import * as uuid from "uuid"; import { mongooseLeanVirtuals } from "mongoose-lean-virtuals"; import { IncidentEventSchema } from "../incident-event"; import { CADPersonSchema, CallerSchema, IncidentFilterLabelSchema, RadioChannelSchema, RecordSchema, ReportNumberSchema, SharedSourceSchema, SharedToSchema, } from "./common-incident"; import { GeoPointSchema } from "./geojson"; import { CADCommentOptsTypes, CADCommentType, CADUnitType, APNNotificationTypeType, CADPriorIncidentType, CADIncidentSchemaType, } from "../../types/cad-incident"; export function CADIncidentSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const IncidentEvent = IncidentEventSchema(mongoose); const GeoPoint = GeoPointSchema(mongoose); // Share incident properties - copy to managed incidents const CADPerson = CADPersonSchema(mongoose); CADPerson.set("toJSON", { versionKey: false, }); const Caller = CallerSchema(mongoose); Caller.set("toJSON", { versionKey: false, }); const FilterLabel = IncidentFilterLabelSchema(mongoose); FilterLabel.set("toJSON", { versionKey: false, }); const RadioChannel = RadioChannelSchema(mongoose); RadioChannel.set("toJSON", { versionKey: false, }); const RecordValue = RecordSchema(mongoose); RecordValue.set("toJSON", { versionKey: false, }); const ReportNumber = ReportNumberSchema(mongoose); ReportNumber.set("toJSON", { versionKey: false, }); const SharedSource = SharedSourceSchema(mongoose); SharedSource.set("toJSON", { versionKey: false, }); const SharedTo = SharedToSchema(mongoose); SharedTo.set("toJSON", { versionKey: false, }); // Currently, supporting type: "ack", item: "knife" const CADCommentOpts = new Schema({ type: { type: String, }, item: { type: String, }, }, { _id: false, id: false, }); CADCommentOpts.set("toJSON", { }); const CADComment = new Schema({ Comment: { type: String, }, CommentSource: { type: String, }, CommentDateTime: { type: String, }, CommentConfidential: { type: Boolean, default: false }, CommentOpts: { type: CADCommentOpts, } }, { _id: false, id: false, }); CADComment.set("toJSON", { versionKey: false, }); const CADUnit = new Schema({ UnitID: { type: String, required: true, }, UnitDispatchNumber: { type: String, required: true, }, AlarmAtDispatch: { type: String, }, TimeDispatched: { type: String, }, TimeEnroute: { type: String, }, TimeArrived: { type: String, }, TimeStaged: { type: String, }, TimeCleared: { type: String, }, TimeAtHospital: { type: String, }, TimePatient: { type: String, }, TimeTransport: { type: String, }, TimeTransporting: { type: String, }, PersonnelCount: { type: Number, }, Personnel: [CADPerson], // Supplied by Tablet Command // Consider moving this to events (?) uuid: { type: String, default: uuid.v4, }, }, { _id: false, id: false, }); CADUnit.set("toJSON", { versionKey: false, }); const APNNotificationType = new Schema({ name: { type: String, }, value: { type: String, }, }, { _id: false, id: false, }); APNNotificationType.set("toJSON", { versionKey: false, }); const CADPriorIncident = new Schema({ Address: { type: String, }, Comment: { type: [CADComment], }, IncidentDateTime: { type: String, }, IncidentNumber: { type: String, }, Jurisdiction: { type: String, }, Problem: { type: String, }, Suite: { type: String, }, }, { _id: false, id: false, }); CADPriorIncident.set("toJSON", { versionKey: false, }); // Main schema const modelSchema = new Schema({ _id: { type: Schema.Types.ObjectId, auto: true, }, uuid: { type: String, default: uuid.v4, }, departmentId: { type: String, default: "", required: true, }, AgencyID: { type: String, default: "", }, IncidentNumber: { type: String, required: true, }, TransactionID: { type: String, default: "", }, // Incident Specific AgencyIncidentCallTypeDescription: { type: String, }, AgencyIncidentCallType: { type: String, }, AgencyIncidentCallSubTypeDescription: { type: String, }, AgencyIncidentCallSubType: { type: String, }, AgencyIncidentPriorityDescription: { type: String, }, PulsePointIncidentCallType: { type: String, }, PulsePointDeterminantCode: { type: String, }, AlarmLevel: { type: String, }, CommandName: { type: String, }, FireMap: { type: String, }, TBMap: { type: String, }, MapPages: { type: String, }, TacticalChannel: { type: String, }, TacticalAltChannel: { type: String, }, CommandChannel: { type: String, }, // Dates EntryDateTime: { type: String, }, ClosedDateTime: { type: String, }, CallReceivedDateTime: { type: String, }, DispatchDateTime: { type: String, }, IncidentLastUpdate: { type: String, }, EnrouteDateTime: { type: String, }, OnSceneDateTime: { type: String, }, modified_date: { type: String, }, modified_unix_date: { type: Number, }, modified: { type: Date, default: currentDate, }, start_unix_date: { type: Number, }, closed_unix_date: { type: Number, }, queued_at: { type: Number, }, scheduled_at: { type: Number, }, ignored: { type: Boolean, default: false, }, blocked: { type: Boolean, default: false, }, expiration_date: { type: Date, default: null, }, // Address fields StreetName: { type: String, }, StreetSuffix: { type: String, }, Predirectional: { type: String, }, Postdirectional: { type: String, }, CityOrLocality: { type: String, }, StateOrProvince: { type: String, }, // Legacy StateOfProvince: { type: String, }, CommonPlaceName: { type: String, }, CommonPlaceNameCopy: { type: String, }, CrossStreet1: { type: String, }, CrossStreet2: { type: String, }, StreetNumber: { type: String, }, Building: { type: String, }, Floor: { type: String, }, Suite: { type: String, }, City: { type: String, }, County: { type: String, }, PostalCode: { type: String, }, CrossStreetName: { type: String, }, LocationComment: { type: String, }, // TC Address full_address: { type: String, }, address: { type: String, }, cross_streets: { type: String, }, // Prior History PriorIncidentChanged: { type: Boolean, }, PriorIncident: { type: [CADPriorIncident], default: [], }, // Caller CallerNumber: { type: String, default: "", }, ReportNumber: { type: [ReportNumber], default: [], }, radioChannels: { type: [RadioChannel], default: [], }, // Coordinate Latitude: { type: Number, }, Longitude: { type: Number, }, coordinate: { type: GeoPoint, default: null, }, Comment: { type: [CADComment], default: [], }, units: { type: [CADUnit], default: [], }, events: { type: [IncidentEvent], // setting types as object, because it does not work with importing IncidentEvent default: [], }, // Tablet Command Internal fields preference_location: { type: String, }, // Training simulation: { type: Boolean, default: false, }, simulationId: { type: String, default: "", }, simulationSequences: { type: [Number], default: [], }, // used by cad simulator closeIn: { type: Number, }, notify: { type: Boolean, default: true, }, rts: { type: Boolean, default: true, }, is_closed: { type: Boolean, default: false, }, notificationType: { type: [APNNotificationType], default: [], }, // Used by incident sharing sharedTo: { type: [SharedTo], default: [], }, // Include current department name, to share with external departments // other properties are set at output sharedSource: { type: SharedSource, }, callers: { type: [Caller], default: [], }, skipCommentProcessing: { type: Boolean, default: false, }, filterLabel: { type: FilterLabel, default: {}, }, // ? record: { type: RecordValue, }, }, { autoIndex: false, // Set collection and strict after importing // collection: "massive_incident_cad", // strict: false, // Because we accept all kind of data in }); modelSchema.virtual("id").get(function(this: CADIncidentSchemaType) { return this._id.toString(); }); modelSchema.set("toJSON", { virtuals: true, versionKey: false, }); modelSchema.plugin(mongooseLeanVirtuals); return modelSchema; }