From c911d9f7ecd5a9aa84c03eeb050649f2b1c26adb Mon Sep 17 00:00:00 2001 From: Anjalee Narenthiren Date: Sat, 18 Nov 2023 02:03:10 -0500 Subject: [PATCH] Fix saving (everything except date works) --- client/src/FormPage/PageTwo.tsx | 38 ++++--- client/src/ReferralView/ReferralViewPage.tsx | 12 +- client/src/ReferralView/VictimCrime.tsx | 20 +++- server/src/controllers/referral.controller.ts | 40 ++++--- server/src/models/referral.model.ts | 6 +- server/src/services/referral.service.ts | 103 ++++++++++-------- 6 files changed, 137 insertions(+), 82 deletions(-) diff --git a/client/src/FormPage/PageTwo.tsx b/client/src/FormPage/PageTwo.tsx index 07b8436c..321afb98 100644 --- a/client/src/FormPage/PageTwo.tsx +++ b/client/src/FormPage/PageTwo.tsx @@ -79,12 +79,12 @@ export default function PageTwo({ data, setData }: Props) { const [homicideDate, sethomicideDate] = React.useState(); let homicideFields; - if (data.crimeType == 'Homicide') { + if (data?.crimeType == 'Homicide') { homicideFields = (
@@ -115,7 +115,7 @@ export default function PageTwo({ data, setData }: Props) { Type Of Crime / Victimization - setData({ ...data, incidentAddress: event.target.value }) + setData({ + ...data, + incidentAddressObj: { + ...(data?.incidentAddressObj || {}), + street: event.target.value, + }, + }) } /> - setData({ ...data, incidentAddressZip: event.target.value }) + setData({ + ...data, + incidentAddressObj: { + ...(data?.incidentAddressObj || {}), + zipcode: event.target.value, + }, + }) } /> @@ -213,9 +225,9 @@ export default function PageTwo({ data, setData }: Props) { Incident Reported to the Police? + -
{!referral ? ( @@ -151,19 +151,19 @@ export default function FormPage({ globalProps, setGlobalProps }: GlobalProps) { - + - + - + - + - + ) : ( diff --git a/client/src/ReferralView/VictimCrime.tsx b/client/src/ReferralView/VictimCrime.tsx index 1c7cae60..40b8c73b 100644 --- a/client/src/ReferralView/VictimCrime.tsx +++ b/client/src/ReferralView/VictimCrime.tsx @@ -218,24 +218,36 @@ export default function PageTwo({ referral, setReferral }: Props) { - setData({ ...data, incidentAddress: event.target.value }) + setData({ + ...data, + incidentAddressObj: { + ...(data?.incidentAddressObj || {}), + street: event.target.value, + }, + }) } /> - setData({ ...data, incidentAddressZip: event.target.value }) + setData({ + ...data, + incidentAddressObj: { + ...(data?.incidentAddressObj || {}), + zipcode: event.target.value, + }, + }) } /> diff --git a/server/src/controllers/referral.controller.ts b/server/src/controllers/referral.controller.ts index 53dc6db8..b6ff5d4b 100644 --- a/server/src/controllers/referral.controller.ts +++ b/server/src/controllers/referral.controller.ts @@ -741,6 +741,8 @@ const updateReferral = async ( const { id } = req.params; const { + staffName, + status, departmentInCharge, program, staffAssigned, @@ -758,7 +760,6 @@ const updateReferral = async ( survivorAge, survivorSchoolOrCommunitySite, survivorGrade, - survivorPreferredContactMethod, isGuardianResponsible, guardianName, guardianRelationship, @@ -766,9 +767,10 @@ const updateReferral = async ( guardianPhone, guardianEmail, guardianPreferredContactMethod, - survivorAddressObj, survivorEmailAddress, + survivorAddressObj, survivorPhoneNumber, + survivorPreferredContactMethod, notesFromOrg, primaryLanguage, relationshipToVictim, @@ -792,17 +794,24 @@ const updateReferral = async ( homMNum, homCaseInformation, historyOfCommunication, + victimServicesOutcome, + counsellingServicesOutcome, + youthServicesOutcome, outreachLetterSent, transferredToCCWaitlist, followUpLetterSent, transferredToETO, - victimServicesOutcome, - counsellingServicesOutcome, - youthServicesOutcome, - reportedToPolice + incidentAddressObj, + incidentAddressZip, + incidentAddressCity, + incidentAddressState, + serviceRequestedVictim, + otherServiceRequestedVictim, + reportedToPolice, + victimName, + victimGender, + date, } = req.body; - // console.log("survivorAddressObj") - // console.log(survivorAddressObj) if ( isReferral === undefined || @@ -858,6 +867,7 @@ const updateReferral = async ( const prevReferral = await getReferralById(id); const referral = await updateReferralById( id, + staffName, status, departmentInCharge, program, @@ -876,7 +886,6 @@ const updateReferral = async ( survivorAge, survivorSchoolOrCommunitySite, survivorGrade, - survivorPreferredContactMethod, isGuardianResponsible, guardianName, guardianRelationship, @@ -884,9 +893,10 @@ const updateReferral = async ( guardianPhone, guardianEmail, guardianPreferredContactMethod, - survivorAddressObj, survivorEmailAddress, + survivorAddressObj, survivorPhoneNumber, + survivorPreferredContactMethod, notesFromOrg, primaryLanguage, relationshipToVictim, @@ -910,14 +920,18 @@ const updateReferral = async ( homMNum, homCaseInformation, historyOfCommunication, + victimServicesOutcome, + counsellingServicesOutcome, + youthServicesOutcome, outreachLetterSent, transferredToCCWaitlist, followUpLetterSent, transferredToETO, - victimServicesOutcome, - counsellingServicesOutcome, - youthServicesOutcome, + incidentAddressObj, reportedToPolice, + victimName, + victimGender, + date ); const staffEmail = staffAssigned?.email; diff --git a/server/src/models/referral.model.ts b/server/src/models/referral.model.ts index 5183d22a..3d088fed 100644 --- a/server/src/models/referral.model.ts +++ b/server/src/models/referral.model.ts @@ -88,7 +88,7 @@ const addressItemSchema = new mongoose.Schema({ type: String, required: false, }, - zip: { + zipcode: { type: String, required: false, }, @@ -560,6 +560,10 @@ const ReferralSchema = new mongoose.Schema({ type: addressItemSchema, required: false, }, + reportedToPolice: { + type: Boolean, + required: false, + }, victimName: { type: String, required: true, diff --git a/server/src/services/referral.service.ts b/server/src/services/referral.service.ts index ae904e14..dfbd5f46 100644 --- a/server/src/services/referral.service.ts +++ b/server/src/services/referral.service.ts @@ -162,12 +162,13 @@ const getReferralById = async (id: string) => { const updateReferralById = async ( id: string, + staffName: string | undefined, status: string, - departmentInCharge: string, - program: string, - staffAssigned: IUser, - therapistAssigned: string, - isReferral: boolean, + departmentInCharge: string | undefined, + program: string | undefined, + staffAssigned: IUser | null | undefined, + therapistAssigned: string | undefined, + isReferral: boolean | null, survivorName: string, serviceRequested: string, agencyThatReferred: string, @@ -176,54 +177,59 @@ const updateReferralById = async ( agencyRepPhone: string, survivorGender: string, survivorRace: string, - survivorDOB: Date, - survivorAge: number, - survivorSchoolOrCommunitySite: string, - survivorGrade: number, - survivorPreferredContactMethod: string, - isGuardianResponsible: boolean, + survivorDOB: Date | null, + survivorAge: number | undefined, + survivorSchoolOrCommunitySite: string | undefined, + survivorGrade: number | null | undefined, + isGuardianResponsible: boolean | null | undefined, guardianName: string, - guardianRelationship: string, - guardianAddressObj: addressItem, + guardianRelationship: string | undefined, + guardianAddressObj: addressItem | undefined, guardianPhone: string, guardianEmail: string, guardianPreferredContactMethod: string, - survivorAddressObj: addressItem, survivorEmailAddress: string, + survivorAddressObj: addressItem | undefined, survivorPhoneNumber: string, + survivorPreferredContactMethod: string, notesFromOrg: string, primaryLanguage: string, relationshipToVictim: string, - crimeDCNum: string, - crimeDistrict: string, - crimeDate: Date, + crimeDCNum: string | undefined, + crimeDistrict: string | undefined, + crimeDate: Date | null, crimeType: string, - isGunViolence: boolean, + isGunViolence: boolean | null, homDecedent: string, - homDateOfDeath: Date, + homDateOfDeath: Date | null, homType: string, - homLocation: string, - homAddressObj: addressItem, - homZipCode: string, - homDecedentAge: number, - homDecedentSex: string, - homDecedentRace: string, - homDecedentEthnicity: string, - homFMVNum: string, - homMEONum: string, - homMNum: string, - homCaseInformation: string, - historyOfCommunication: Array, - outreachLetterSent: boolean, - transferredToCCWaitlist: boolean, - followUpLetterSent: boolean, - transferredToETO: boolean, - victimServicesOutcome: victimServicesOutcomeItem, - counsellingServicesOutcome: counsellingServicesOutcomeItem, - youthServicesOutcome: youthServicesOutcomeItem, - reportedToPolice: boolean, + homLocation: string | undefined, + homAddressObj: addressItem | undefined, + homZipCode: string | undefined, + homDecedentAge: number | null | undefined, + homDecedentSex: string | undefined, + homDecedentRace: string | undefined, + homDecedentEthnicity: string | undefined, + homFMVNum: string | undefined, + homMEONum: string | undefined, + homMNum: string | undefined, + homCaseInformation: string | undefined, + historyOfCommunication: Array | null | undefined, + victimServicesOutcome: victimServicesOutcomeItem | null | undefined, + counsellingServicesOutcome: counsellingServicesOutcomeItem | null | undefined, + youthServicesOutcome: youthServicesOutcomeItem | null | undefined, + outreachLetterSent: boolean | null | undefined, + transferredToCCWaitlist: boolean | null | undefined, + followUpLetterSent: boolean | null | undefined, + transferredToETO: boolean | null | undefined, + incidentAddressObj: addressItem | undefined, + reportedToPolice: boolean | null, + victimName: string | undefined, + victimGender: string | undefined, + date: Date | null, ) => { const updateQuery = { + staffName, status, departmentInCharge, program, @@ -242,7 +248,6 @@ const updateReferralById = async ( survivorAge, survivorSchoolOrCommunitySite, survivorGrade, - survivorPreferredContactMethod, isGuardianResponsible, guardianName, guardianRelationship, @@ -250,9 +255,10 @@ const updateReferralById = async ( guardianPhone, guardianEmail, guardianPreferredContactMethod, - survivorAddressObj, survivorEmailAddress, + survivorAddressObj, survivorPhoneNumber, + survivorPreferredContactMethod, notesFromOrg, primaryLanguage, relationshipToVictim, @@ -276,16 +282,23 @@ const updateReferralById = async ( homMNum, homCaseInformation, historyOfCommunication, + victimServicesOutcome, + counsellingServicesOutcome, + youthServicesOutcome, outreachLetterSent, transferredToCCWaitlist, followUpLetterSent, transferredToETO, - victimServicesOutcome, - counsellingServicesOutcome, - youthServicesOutcome, + incidentAddressObj, reportedToPolice, + victimName, + victimGender, + date }; - return Referral.findByIdAndUpdate(id, updateQuery, { new: true }).exec(); + const ret = await Referral.findByIdAndUpdate(id, updateQuery, { new: true }).exec(); + // console.log(ret); + + return ret; }; const addToCommunicationHistory = async (