Skip to content

Commit

Permalink
updating assigned cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Jan 12, 2024
1 parent 75e6045 commit 47afaf0
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
3 changes: 2 additions & 1 deletion models/case_assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const caseAssign = sequelize.sequelize.define(
relationship: Sequelize.TEXT,
start_date: Sequelize.DATEONLY,
end_date: Sequelize.DATEONLY,
created_by: Sequelize.INTEGER
created_by: Sequelize.INTEGER,
updated_by: Sequelize.INTEGER
},
{
timestamps: true,
Expand Down
107 changes: 107 additions & 0 deletions routes/processes/case.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,23 @@ router.post("/assign", async (req, res) => {
clinic_number
}
});
let get_facility = await masterFacility.findOne({
where: {
code: check_client.mfl_code
},
attributes: ["code", "name"]
});

if (!check_client)
return res.json({
success: false,
message: `Clinic number ${clinic_number} does not exist in the system`
});
if (check_client.mfl_code != check_user.facility_id)
return res.json({
success: false,
message: `Client ${clinic_number} does not belong to your facility, the client belongs to ${get_facility.name}`
});

let check_user = await User.findOne({
where: {
Expand Down Expand Up @@ -90,4 +101,100 @@ router.post("/assign", async (req, res) => {
}
});

router.put("/assign/update/:clinicNumber", async (req, res) => {
const clinicNumber = req.params.clinicNumber;

let phone_no = req.body.phone_no;
let reason_assign = req.body.reason_assign;
let other_reason = req.body.other_reason;
let provider_id = req.body.provider_id;
let relationship = req.body.relationship;
let start_date = req.body.start_date;
let end_date = req.body.end_date;
let today = moment(new Date().toDateString()).format("YYYY-MM-DD");

try {
let client = await Client.findOne({
where: {
clinic_number: clinicNumber
}
});

if (!client) {
return res.status(404).json({
success: false,
message: `Clinic number ${clinicNumber} does not exist in the system`
});
}

let check_user = await User.findOne({
where: {
phone_no
}
});

if (!check_user)
return res.json({
success: false,
message: `Phone number ${phone_no} does not exist in the system`
});
if (client.status != "Active")
return res.json({
success: false,
message: `Client: ${clinic_number} is not active in the system.`
});
if (check_user.status != "Active")
return res.json({
success: false,
message: `Phone number: ${phone_no} is not active in the system.`
});

let existingCase = await caseAssign.findOne({
where: {
client_id: client.id
}
});

if (!existingCase) {
return res.status(404).json({
success: false,
message: `Client: ${clinicNumber} has not been assigned to a case`
});
}

return caseAssign
.update(
{
reason_assign: reason_assign,
provider_id: provider_id,
other_reason: other_reason,
relationship: relationship,
start_date: start_date,
end_date: end_date,
updated_at: today,
updated_by: check_user.id
},
{ where: { client_id: client.id } }
)
.then(([updated]) => {
if (updated > 0) {
return res.status(200).json({
success: true,
message: `Client: ${clinicNumber} case details have been updated successfully`
});
} else {
return res.status(404).json({
success: false,
message: `Client: ${clinicNumber} case details were not found or could not be updated`
});
}
});
} catch (error) {
return res.status(500).json({
success: false,
message: `Error occurred while updating the case. Please try again.`
});
}
});

module.exports = router;

0 comments on commit 47afaf0

Please sign in to comment.