Process is stuck while invoking a function from Hyperledger fabric test network

27 Views Asked by At

I already installed chaincode on test network now I am trying to invoke this function addNewPatients(its logic is given below) but only curser is blinking does not give any response or error Tried to invoke many times but its same

async addNewPatients(ctx, patientName, aadhaar, age, gender, mobileNo, address){
    
    
    const patient = await ctx.stub.getStateByPartialCompositeKey('hospitalName.patient', [aadhaar]).catch(err => console.log(err));
    if(!patient||patient.length===0){
        const patientCounter = await ctx.stub.getState('patientCounter').catch(err => console.log(err));
        let thisPatientID = 'INPK';

        if (!patientCounter || patientCounter.length === 0) {
        thisPatientID += '000000001'; // Start with "INPK000000001" if no patients exist yet
        } 
        else {
        const counter = parseInt(patientCounter.toString());
        thisPatientID += (counter + 1).toString().padStart(9, "0");
        }
        const patientKey = await ctx.stub.createCompositeKey('hospitalName.patient', [thisPatientID, aadhaar])
        const patientDetails = {
            patientID: thisPatientID,
            Name: patientName,
            Aadhaar: aadhaar,
            Age: age,
            Gender: gender,
            contactInfo: mobileNo,
            Address : address,
            
        };
        
        await ctx.stub.putState(patientKey, Buffer.from(JSON.stringify(patientDetails)));
        await ctx.stub.putState('patientCounter', Buffer.from(thisPatientID.substring(4)));
        return patientDetails;
        
    }
    else{
        throw new Error("This patient with aadhaar"+ aadhaar + "already exists")
}
}

I tried many times to re-run but same issue

0

There are 0 best solutions below