Commit 667b5afb authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'practitioner-requests-from-patients' into 'master'

patient request from practitioners completed

See merge request !37
parents 5da353b3 0e0f58ec
import React, { useEffect, useState } from "react";
import { View, Text, StyleSheet, Button } from "react-native";
import { LOCALBACKEND } from "../../env";
import AsyncStorage from "@react-native-async-storage/async-storage";
export default function PatientAllPractitioners({ navigation, router }) {
const [data, setData] = useState([]);
const [stellarPublicKey, setStellarPublicKey] = useState("");
useEffect(() => {
fetchData();
});
}, []);
const fetchData = async () => {
try {
......@@ -15,8 +17,11 @@ export default function PatientAllPractitioners({ navigation, router }) {
const response = await fetch(practitionerUrl);
const json = await response.json();
setData(json.data);
} catch (error) {
console.error("Error fetching data:", error);
} catch (errorWhenFetchingPractitionerData) {
console.error(
"Error fetching practitioner data:",
errorWhenFetchingPractitionerData
);
}
};
......@@ -31,7 +36,40 @@ export default function PatientAllPractitioners({ navigation, router }) {
);
};
const handleRequest = (item) => {
const handleRequest = async (item) => {
try {
const value = await AsyncStorage.getItem("patientStellarPublicKey");
if (value != null) {
setStellarPublicKey(value);
//build the JSON to create the request
const reqObj = {
patient: value,
practitionerKey: item.publickey,
};
const reqUrl = LOCALBACKEND + `/patient/request`;
try {
const reqResponse = await fetch(reqUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(reqObj),
});
const responseData = await reqResponse.json();
} catch (errorWhenSendingReqObj) {
console.log("Error when sending request to practitioner");
}
} else {
console.log("Empty key");
}
} catch (errorWhenPublicKey) {
console.error(
"Error fetching public key from async storage data:",
errorWhenPublicKey
);
}
// Handle the request for the specific item by requesting the practitioner
console.log("Requested:", item);
};
......
......@@ -20,7 +20,8 @@
"react-native": "0.71.7",
"react-native-crypto-js": "^1.0.0",
"react-native-datepicker": "^1.7.2",
"react-native-simple-radio-button": "^2.7.4"
"react-native-simple-radio-button": "^2.7.4",
"react-native-toast-message": "^2.1.6"
},
"devDependencies": {
"@babel/core": "^7.20.0"
......@@ -11391,6 +11392,15 @@
"resolved": "https://registry.npmjs.org/react-native-simple-radio-button/-/react-native-simple-radio-button-2.7.4.tgz",
"integrity": "sha512-QOZNmJUn0ViBGU+at7wAG/uGzd5PfXi0kMHr9lfTCLXknW/f9f2fOVjxjdHvOCdf/zA/eMJBjGjtusSDzQf1+w=="
},
"node_modules/react-native-toast-message": {
"version": "2.1.6",
"resolved": "https://registry.npmjs.org/react-native-toast-message/-/react-native-toast-message-2.1.6.tgz",
"integrity": "sha512-VctXuq20vmRa9AE13acaNZhrLcS3FaBS2zEevS3+vhBsnVZYG0FIlWIis9tVnpnNxUb3ART+BWtwQjzSttXTng==",
"peerDependencies": {
"react": "*",
"react-native": "*"
}
},
"node_modules/react-native/node_modules/promise": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz",
......@@ -22112,6 +22122,12 @@
"resolved": "https://registry.npmjs.org/react-native-simple-radio-button/-/react-native-simple-radio-button-2.7.4.tgz",
"integrity": "sha512-QOZNmJUn0ViBGU+at7wAG/uGzd5PfXi0kMHr9lfTCLXknW/f9f2fOVjxjdHvOCdf/zA/eMJBjGjtusSDzQf1+w=="
},
"react-native-toast-message": {
"version": "2.1.6",
"resolved": "https://registry.npmjs.org/react-native-toast-message/-/react-native-toast-message-2.1.6.tgz",
"integrity": "sha512-VctXuq20vmRa9AE13acaNZhrLcS3FaBS2zEevS3+vhBsnVZYG0FIlWIis9tVnpnNxUb3ART+BWtwQjzSttXTng==",
"requires": {}
},
"react-refresh": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.4.3.tgz",
......
......@@ -21,7 +21,8 @@
"react-native": "0.71.7",
"react-native-crypto-js": "^1.0.0",
"react-native-datepicker": "^1.7.2",
"react-native-simple-radio-button": "^2.7.4"
"react-native-simple-radio-button": "^2.7.4",
"react-native-toast-message": "^2.1.6"
},
"devDependencies": {
"@babel/core": "^7.20.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment