First Version

This commit is contained in:
abhay-raizada
2024-03-13 19:15:37 +05:30
parent 6b9afc2c8f
commit cd7973f49d
10 changed files with 1560 additions and 336 deletions

58
formstr/formstr.ts Normal file
View File

@@ -0,0 +1,58 @@
import {SimplePool} from 'nostr-tools';
import {V1FormSpec} from '@formstr/sdk/dist/interfaces';
const defaultRelays = ['wss://relay.primal.net/', 'wss://relay.hllo.live'];
export const getFormTemplate = async (formId: string): Promise<{}> => {
console.log('inside getFormTemplate');
const pool = new SimplePool();
let formIdPubkey = formId;
let relayList = defaultRelays;
console.log('everything initialised');
const filter = {
kinds: [0],
authors: [formIdPubkey], //formId is the npub of the form
};
console.log('getting kind0', filter);
pool
.get(relayList, filter, {maxWait: 10})
.then(
value => {
console.log('got kind0', value);
return;
},
reason => {
console.log('failed to get because', reason);
return;
},
)
.catch(reason => {
console.log('Errored', reason);
return;
});
console.log('after promise');
try {
console.log('inside try');
console.log(
'Event',
await pool.querySync(relayList, filter, {maxWait: 10}),
);
// console.log('fetching...', fetch('https://github.com'));
console.log('Main thread is stuck');
} catch (e) {
console.log('inside catch');
console.log('error is', e);
}
console.log('After everything');
pool.close(relayList);
let formTemplate;
// if (kind0) {
// formTemplate = JSON.parse(kind0.content);
// } else {
// throw Error('Form template not found');
// }
return {};
};

121
formstr/sample.json Normal file
View File

@@ -0,0 +1,121 @@
{
"name": "X Pharmacy ",
"schemaVersion": "v1",
"settings": {
"titleImageUrl": "https://www.studentdoctor.net/wp-content/uploads/2018/08/20180815_prescription.png",
"description": "Testing formstr for getting prescriptions",
"thankYouPage": true
},
"fields": [
{
"question": "Location",
"answerType": "dropdown",
"answerSettings": {
"choices": [
{
"label": "Narnia",
"choiceId": "ae9DZi"
},
{
"label": "Hogwarts",
"choiceId": "Dx4gyn"
},
{
"label": "Mordor",
"choiceId": "oWygzo"
},
{
"label": "Tattooine",
"choiceId": "dLgxns"
}
],
"required": true
},
"questionId": "V7yEc2"
},
{
"question": "Patient",
"answerType": "label",
"answerSettings": {},
"questionId": "BPfwxq"
},
{
"question": "Name",
"answerType": "shortText",
"answerSettings": {},
"questionId": "HLydbI"
},
{
"question": "Date Of Birth ",
"answerType": "date",
"answerSettings": {},
"questionId": "lzpBhA"
},
{
"question": "Address",
"answerType": "paragraph",
"answerSettings": {},
"questionId": "Mvajrv"
},
{
"question": "Phone",
"answerType": "shortText",
"answerSettings": {},
"questionId": "PjTnfM"
},
{
"question": "Allergies",
"answerType": "shortText",
"answerSettings": {},
"questionId": "UMfscG"
},
{
"question": "Current Meds ",
"answerType": "shortText",
"answerSettings": {},
"questionId": "Cc8lih"
},
{
"question": "Medications",
"answerType": "label",
"answerSettings": {},
"questionId": "0R7uhf"
},
{
"question": "Name",
"answerType": "shortText",
"answerSettings": {},
"questionId": "WXJScB"
},
{
"question": "Dosage Form",
"answerType": "shortText",
"answerSettings": {},
"questionId": "BxEwHQ"
},
{
"question": "Strength",
"answerType": "shortText",
"answerSettings": {},
"questionId": "q2nC6e"
},
{
"question": "Quantiy ",
"answerType": "number",
"answerSettings": {},
"questionId": "fz68UV"
},
{
"question": "Re-fills",
"answerType": "shortText",
"answerSettings": {},
"questionId": "9SdbyN"
},
{
"question": "Directions",
"answerType": "paragraph",
"answerSettings": {},
"questionId": "6FrcPv"
}
]
}