Some fixes. Added csv.
This commit is contained in:
86
Node/src/convertToJson.ts
Normal file
86
Node/src/convertToJson.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import reader from "xlsx";
|
||||
import { getJsDateFromExcel } from "excel-date-to-js";
|
||||
|
||||
import { readdirSync, writeFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const excelPath = join(__dirname, "..", "..", "Excel");
|
||||
|
||||
const excelFiles = readdirSync(excelPath);
|
||||
|
||||
const readExcel = (filePath: string) => {
|
||||
let data: unknown[] = [];
|
||||
const file = reader.readFile(filePath);
|
||||
const sheets = file.SheetNames;
|
||||
for (let i = 0; i < sheets.length; i++) {
|
||||
const temp = reader.utils.sheet_to_json(file.Sheets[file.SheetNames[i]]);
|
||||
temp.forEach((res) => {
|
||||
data.push(res);
|
||||
});
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
const recordsToJson = () => {
|
||||
let i = 0;
|
||||
let records: any[] = [];
|
||||
excelFiles.every((file) => {
|
||||
if (!file.includes("raw_") && !file.includes("lock")) {
|
||||
const excelFile = join(excelPath, file);
|
||||
const data = readExcel(excelFile);
|
||||
const klinika_emer = file.split("_")[0];
|
||||
const klinika: any = {
|
||||
emer: klinika_emer,
|
||||
shtrimi: [],
|
||||
};
|
||||
data.every((record: any) => {
|
||||
i++;
|
||||
if (record.EMER !== "" && record.MBIEMER !== "") {
|
||||
let datelindja = null;
|
||||
let data_shtrimit = null;
|
||||
try {
|
||||
datelindja = getJsDateFromExcel(record.DATELINDJA_KORIGJ);
|
||||
data_shtrimit = getJsDateFromExcel(record.DT_SHTRIMI_KORIGJ);
|
||||
} catch (error) {
|
||||
console.log(i, record.EMER, record.MBIEMER);
|
||||
// return false;
|
||||
}
|
||||
const trajtimi = {
|
||||
trajtimi:
|
||||
record["TRAJTIMI SPITALOR Urgjence"] ||
|
||||
record["TRAJTIMI SPITALOR Pavion"],
|
||||
};
|
||||
const diagnoza = {
|
||||
emer: record.DIAGNOZA,
|
||||
kodi_dg_icd_9: record["Kodi DG ICD-9"],
|
||||
};
|
||||
const pacienti = {
|
||||
emer: record.EMER,
|
||||
mbiemer: record.MBIEMER,
|
||||
mosha: record.MOSHA,
|
||||
datelindja,
|
||||
gjinia: record.GJINIA,
|
||||
error: record.ERROR,
|
||||
};
|
||||
const shtrimi = {
|
||||
nr: i,
|
||||
data_shtrimit,
|
||||
dite_qendrimi: record["DITE QENDRIMI NE SPITAL"],
|
||||
pacienti,
|
||||
diagnoza,
|
||||
trajtimi,
|
||||
};
|
||||
klinika.shtrimi.push(shtrimi);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
records.push(klinika);
|
||||
console.log(`Mbaroi ${klinika_emer}`);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const jsonFile = join(__dirname, "..", "..", "JSON", "records.json");
|
||||
writeFileSync(jsonFile, JSON.stringify(records));
|
||||
};
|
||||
|
||||
export default recordsToJson;
|
||||
@@ -1,57 +1,22 @@
|
||||
import reader from "xlsx";
|
||||
import { getJsDateFromExcel } from "excel-date-to-js";
|
||||
import PocketBase from "pocketbase";
|
||||
|
||||
import { readdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const excelPath = join(__dirname, "..", "..", "Excel");
|
||||
|
||||
const excelFiles = readdirSync(excelPath);
|
||||
|
||||
const readExcel = (filePath: string) => {
|
||||
let data: unknown[] = [];
|
||||
const file = reader.readFile(filePath);
|
||||
const sheets = file.SheetNames;
|
||||
for (let i = 0; i < sheets.length; i++) {
|
||||
const temp = reader.utils.sheet_to_json(file.Sheets[file.SheetNames[i]]);
|
||||
temp.forEach((res) => {
|
||||
data.push(res);
|
||||
});
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
excelFiles.forEach((file) => {
|
||||
if (!file.includes("raw_") && !file.includes("lock")) {
|
||||
const excelFile = join(excelPath, file);
|
||||
const data = readExcel(excelFile);
|
||||
data.forEach((record: any) => {
|
||||
if (
|
||||
record.DATELINDJA_KORIGJ !== "" &&
|
||||
record.DATELINDJA_KORIGJ !== "DEKLARUAR"
|
||||
) {
|
||||
const pacient = {
|
||||
emer: record.EMER,
|
||||
mbiemer: record.MBIEMER,
|
||||
mosha: record.MOSHA,
|
||||
datelindja: getJsDateFromExcel(record.DATELINDJA_KORIGJ),
|
||||
error: record.ERROR,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const loginToPocketBase = async () => {
|
||||
const client = new PocketBase("http://127.0.0.1:8090");
|
||||
const adminAuthData = await client.admins.authViaEmail(
|
||||
"test@example.com",
|
||||
"123456"
|
||||
);
|
||||
console.log(adminAuthData);
|
||||
};
|
||||
import { run } from "./kuzzle";
|
||||
|
||||
// import recordsToJson from "./convertToJson";
|
||||
(async () => {
|
||||
await loginToPocketBase();
|
||||
const kuzzle = await run();
|
||||
if (kuzzle) {
|
||||
const credentials = {
|
||||
username: "julian.cuni",
|
||||
password: "MatraPaPuPa..11",
|
||||
};
|
||||
try {
|
||||
const jwt = await kuzzle.auth.login("local", credentials);
|
||||
// const apiKey = await kuzzle.auth.createApiKey("Sigfox API key");
|
||||
} catch (error: any) {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
// (async () => {
|
||||
// await login();
|
||||
// })();
|
||||
|
||||
27
Node/src/kuzzle.ts
Normal file
27
Node/src/kuzzle.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Kuzzle, WebSocket, Http } from "kuzzle-sdk";
|
||||
|
||||
const kuzzle = new Kuzzle(new Http("localhost"));
|
||||
|
||||
kuzzle.on("networkError", (error: any) => {
|
||||
console.error("Network Error: ", error);
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
try {
|
||||
// Connects to the Kuzzle server
|
||||
await kuzzle.connect();
|
||||
// Creates an index
|
||||
// await kuzzle.index.create("nyc-open-data");
|
||||
// // Creates a collection
|
||||
// await kuzzle.collection.create("nyc-open-data", "yellow-taxi", {});
|
||||
// console.log("nyc-open-data/yellow-taxi ready!");
|
||||
return kuzzle;
|
||||
} catch (error: any) {
|
||||
console.error(error.message);
|
||||
}
|
||||
// finally {
|
||||
// kuzzle.disconnect();
|
||||
// }
|
||||
return null;
|
||||
};
|
||||
export { run };
|
||||
37
Node/src/sdb.ts
Normal file
37
Node/src/sdb.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
const Surreal = require("surrealdb.js");
|
||||
|
||||
const db = new Surreal("https://baas.microservices.al/rpc");
|
||||
async function main() {
|
||||
try {
|
||||
await db.use("fluxem", "fluxem");
|
||||
|
||||
const token = await db.signin({
|
||||
NS: "fluxem",
|
||||
DB: "fluxem",
|
||||
SC: "allusers",
|
||||
email: "test@acme.com",
|
||||
pass: "some password",
|
||||
marketing: true,
|
||||
tags: ["rust", "golang", "javascript"],
|
||||
});
|
||||
|
||||
let created = await db.create("person", {
|
||||
title: "Founder & CEO",
|
||||
name: {
|
||||
first: "Tobie",
|
||||
last: "Morgan Hitchcock",
|
||||
},
|
||||
marketing: true,
|
||||
identifier: Math.random().toString(36).substr(2, 10),
|
||||
});
|
||||
|
||||
// await db.invalidate();
|
||||
|
||||
// const res = await db.authenticate(token)
|
||||
console.log("token", created);
|
||||
} catch (e) {
|
||||
console.error("ERROR", e);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user