Skip to content

Commit

Permalink
changes and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Dec 10, 2024
1 parent f3309bd commit 9e5f18f
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
31 changes: 31 additions & 0 deletions models/n_provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const sequelize = require("../db_config");
const Sequelize = require("sequelize");
const Joi = require("joi");

const NProvider = sequelize.sequelize.define(
"tbl_nishauri_provider", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},

family_name:Sequelize.STRING,
given_name:Sequelize.STRING,
national_id:Sequelize.INTEGER,
salutation:Sequelize.STRING,
license_number:Sequelize.STRING,
board_number:Sequelize.STRING,
cadre:Sequelize.STRING,
gender:Sequelize.STRING,
facility_code:Sequelize.INTEGER,
user_id:Sequelize.INTEGER
}, {
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "tbl_nishauri_provider"
}
);
exports.NProvider = NProvider;
105 changes: 105 additions & 0 deletions routes/processes/nishauri_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const { NBloodPressure } = require("../../models/n_blood_pressure");
const { NBloodSugar } = require("../../models/n_blood_sugar");
const { NMenstrual } = require("../../models/n_menstrual");
const { Nroles } = require("../../models/n_roles");
const { NProvider } = require("../../models/n_provider");

generateOtp = function (size) {
const zeros = "0".repeat(size - 1);
Expand Down Expand Up @@ -6126,5 +6127,109 @@ router.get(

}
);

// API route to fetch practitioner data by national ID
router.post(
"/practitioner",
passport.authenticate("jwt", { session: false }),
async (req, res) => {
let { nationalId, user_id } = req.body;

try {
let user = await NUsers.findOne({
where: { id: base64.decode(user_id) }
});

if (!user) {
return res.status(404).json({ message: "User not found" });
}

let response = await axios.get(
`${process.env.HIE_ENDPOINT}?national-id=${nationalId}`,
{
auth: {
username: process.env.HIE_USERNAME,
password: process.env.HIE_PASSWORD
}
}
);

let practitioner = response.data;

let existing_provider = await NProvider.findOne({
where: {
user_id: base64.decode(user_id)
}
});

let cadre = practitioner.extension.find(
(ext) =>
ext.url ===
"https://shr.tiberbuapps.com/fhir/StructureDefinition/professional-cadre"
).valueCoding.display;
let nationalIdValue = practitioner.identifier.find((id) =>
id.type.coding.some((code) => code.display === "National ID")
).value;
let boardNo = practitioner.identifier.find((id) =>
id.type.coding.some(
(code) => code.display === "Board Registration Number"
)
).value;
let status = practitioner.active;
let { family, given, prefix } = practitioner.name[0];
let gender = practitioner.gender;
let currentLicenseNumber = practitioner.qualification[0].extension.find(
(ext) =>
ext.url ===
"https://shr.tiberbuapps.com/fhir/StructureDefinition/current-license-number"
).valueString;

let providerData = {
family_name: family,
given_name: given.join(" "),
salutation: prefix ? prefix.join(" ") : null,
national_id: nationalIdValue,
license_number: currentLicenseNumber,
board_number: boardNo,
cadre,
gender,
user_id: base64.decode(user_id)
};

if (existing_provider) {
await NProvider.update(providerData, {
where: {
user_id: base64.decode(user_id)
}
});
return res.status(200).json({
success: true,
message: "Provider details updated successfully",
provider: await NProvider.findOne({
where: { user_id: base64.decode(user_id) }
})
});
} else {
let provider = await NProvider.create(providerData);

res.status(200).json({
message: "Provider saved successfully",
provider: await NProvider.findOne({
where: { user_id: base64.decode(user_id) }
})
});
}
} catch (error) {
let practitioner = error.response.data;
if (practitioner.resourceType === "OperationOutcome") {
let errorMessage = practitioner.issue[0].diagnostics;
let errorCode = error.response.data.issue[0].code;
return res.status(400).json({ code: errorCode, message: errorMessage });
}
res.status(500).json({ message: "Internal server error" });
}
}
);

module.exports = router;
//module.exports = { router, users };

0 comments on commit 9e5f18f

Please sign in to comment.