Skip to content

Commit

Permalink
saving home visit checklist cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Jan 24, 2024
1 parent e252311 commit 2042b64
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 3 deletions.
44 changes: 44 additions & 0 deletions models/case_home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const sequelize = require("../db_config");
const Sequelize = require("sequelize");

const caseHome = sequelize.sequelize.define(
"tbl_case_home_visit",
{
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
client_id: Sequelize.INTEGER,
family_member_name: Sequelize.TEXT,
telephone_no: {
type: Sequelize.STRING
},
landmark: Sequelize.TEXT,
patient_independent: Sequelize.TEXT,
basic_need: Sequelize.TEXT,
sexual_partner: Sequelize.TEXT,
disclosed_hiv_status: Sequelize.TEXT,
disclosed_person: Sequelize.TEXT,
arv_stored: Sequelize.TEXT,
arv_taken: Sequelize.TEXT,
social_support_household: Sequelize.TEXT,
social_support_community: Sequelize.TEXT,
non_clinical_services: Sequelize.TEXT,
mental_health: Sequelize.TEXT,
stress_situation: Sequelize.TEXT,
use_drug: Sequelize.TEXT,
side_effect: Sequelize.TEXT,
other_note: Sequelize.TEXT,
created_by: Sequelize.INTEGER,
updated_by: Sequelize.INTEGER
},
{
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "tbl_case_home_visit"
}
);
exports.caseHome = caseHome;
99 changes: 96 additions & 3 deletions routes/processes/case.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const express = require("express");
const moment = require("moment");
const _ = require("lodash");
const Op = require("sequelize").Op;
const { Op, Sequelize } = require("sequelize");
const router = express.Router();
const { date } = require("joi");
const { caseAssign } = require("../../models/case_assign");
const { Client } = require("../../models/client");
const { User } = require("../../models/user");
const { masterFacility } = require("../../models/master_facility");
const { caseHome } = require("../../models/case_home");

router.post("/assign", async (req, res) => {
let phone_no = req.body.phone_no;
Expand Down Expand Up @@ -204,7 +205,7 @@ router.get("/search", async (req, res) => {

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

Expand All @@ -221,7 +222,7 @@ router.get("/search", async (req, res) => {
});

if (!client) {
return res.status(404).json({
return res.json({
success: false,
message: `Clinic number ${clinicNumber} does not exist in the system`
});
Expand Down Expand Up @@ -270,4 +271,96 @@ router.get("/search", async (req, res) => {
}
});

router.post("/home/visit", async (req, res) => {
let phone_no = req.body.phone_no;
let clinic_number = req.body.clinic_number;
let family_member_name = req.body.family_member_name;
let telephone_no = req.body.telephone_no;
let landmark = req.body.landmark;
let patient_independent = req.body.patient_independent;
let basic_need = req.body.basic_need;
let sexual_partner = req.body.sexual_partner;
let disclosed_hiv_status = req.body.disclosed_hiv_status;
let disclosed_person = req.body.disclosed_person;
let arv_stored = req.body.arv_stored;
let arv_taken = req.body.arv_taken;
let social_support_household = req.body.social_support_household;
let social_support_community = req.body.social_support_community;
let non_clinical_services = req.body.non_clinical_services;
let mental_health = req.body.mental_health;
let stress_situation = req.body.stress_situation;
let use_drug = req.body.use_drug;
let side_effect = req.body.side_effect;
let other_note = req.body.other_note;
let today = moment(new Date().toDateString()).format("YYYY-MM-DD");

let check_client = await Client.findOne({
where: {
clinic_number
}
});
let get_facility = await masterFacility.findOne({
where: {
code: check_client.mfl_code
},
attributes: ["code", "name"]
});
let check_user = await User.findOne({
where: {
phone_no
}
});

let existingVisit = await caseHome.findOne({
where: {
client_id: check_client.id,
[Op.and]: [
Sequelize.literal(`DATE(created_at) = '${today}'`)
]
}
});

if (existingVisit) {
return res.status(400).json({
success: false,
message: `Home Visit details for Client: ${clinic_number} have already been captured today`
});
}else {
try {
await caseHome.create({
client_id: check_client.id,
family_member_name: family_member_name,
telephone_no: telephone_no,
landmark: landmark,
patient_independent: patient_independent,
basic_need: basic_need,
sexual_partner: sexual_partner,
disclosed_hiv_status: disclosed_hiv_status,
disclosed_person: disclosed_person,
arv_stored: arv_stored,
arv_taken: arv_taken,
social_support_household: social_support_household,
social_support_community: social_support_community,
non_clinical_services: non_clinical_services,
mental_health: mental_health,
stress_situation: stress_situation,
use_drug: use_drug,
side_effect: side_effect,
other_note: other_note,
created_at: today,
created_by: check_user.id
});
return res.status(200).json({
success: true,
message: `Client ${clinic_number} details has been successfully captured`
});
} catch (error) {
return res.status(500).json({
success: false,
message: `Error occurred while capturing details. Please try again.`
});
}
}
});

module.exports = router;

0 comments on commit 2042b64

Please sign in to comment.