mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
se agregaron cambios para correr con couchDb
This commit is contained in:
parent
7085eff9f6
commit
9d501e96a6
6 changed files with 183 additions and 22 deletions
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
{
|
||||
"index": {
|
||||
"fields": ["patientDocumentNumber", "status", "fechaDeAutorizacion"]
|
||||
},
|
||||
"ddoc": "recetas-index",
|
||||
"name": "indexRecetas",
|
||||
"type": "json"
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"index": {
|
||||
"fields": ["patientDocumentNumber", "status", "expirationDate"]
|
||||
},
|
||||
"ddoc": "vacunas-index",
|
||||
"name": "indexVacunas",
|
||||
"type": "json"
|
||||
}
|
||||
34
asset-transfer-basic/chaincode-go/chaincode/go.mod
Normal file
34
asset-transfer-basic/chaincode-go/chaincode/go.mod
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
module chaincode
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.11
|
||||
|
||||
require (
|
||||
github.com/hyperledger/fabric-chaincode-go/v2 v2.3.0
|
||||
github.com/hyperledger/fabric-contract-api-go/v2 v2.2.0
|
||||
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7
|
||||
github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go v0.0.0-20250727184722-4c97d4c12b1e
|
||||
github.com/stretchr/testify v1.10.0
|
||||
google.golang.org/protobuf v1.36.5
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||
github.com/go-openapi/spec v0.21.0 // indirect
|
||||
github.com/go-openapi/swag v0.23.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
||||
golang.org/x/net v0.34.0 // indirect
|
||||
golang.org/x/sys v0.29.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
|
||||
google.golang.org/grpc v1.71.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
83
asset-transfer-basic/chaincode-go/chaincode/go.sum
Normal file
83
asset-transfer-basic/chaincode-go/chaincode/go.sum
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
||||
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
||||
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
||||
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
|
||||
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
|
||||
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
|
||||
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
|
||||
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hyperledger/fabric-chaincode-go/v2 v2.3.0 h1:NB/QO2t4R5f6Nz/oREqZeaE4splHI2U9gqndfEQZreo=
|
||||
github.com/hyperledger/fabric-chaincode-go/v2 v2.3.0/go.mod h1:c3zA3gOL/V53a0v1TGgHe8nifeH6daG/UrmJs79I9pI=
|
||||
github.com/hyperledger/fabric-contract-api-go/v2 v2.2.0 h1:rmUoBmciB0GL/miqcbJmJbgp5QTWoJUrZo+CNxrNLF4=
|
||||
github.com/hyperledger/fabric-contract-api-go/v2 v2.2.0/go.mod h1:FeWeO/jwGjiME7ak3GufqKIcwkejtzrDG4QxbfKydWs=
|
||||
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7 h1:sQ5qv8vQQfwewa1JlCiSCC8dLElmaU2/frLolpgibEY=
|
||||
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7/go.mod h1:bJnwzfv03oZQeCc863pdGTDgf5nmCy6Za3RAE7d2XsQ=
|
||||
github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go v0.0.0-20250727184722-4c97d4c12b1e h1:PubzIFRuAyLC23CLNfRnlYJiD4WCOXlW8F/wHbkQmyo=
|
||||
github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go v0.0.0-20250727184722-4c97d4c12b1e/go.mod h1:VDQwEYJgjcpC/+OsPdo995AsEm2gOjhN0Xju2/21gxk=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
|
||||
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
|
||||
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
|
||||
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
|
||||
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
|
||||
go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=
|
||||
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
|
||||
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
|
||||
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
|
||||
google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=
|
||||
google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
|
||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
@ -33,28 +33,29 @@ type Receta struct {
|
|||
Practitioner string `json:"practitioner"`
|
||||
PractitionerDocumentNumber string `json:"practitionerDocumentNumber"`
|
||||
Signature string `json:"signature"`
|
||||
Matricula string `json:"matricula"`
|
||||
Matricula string `json:"matricula"`
|
||||
}
|
||||
|
||||
type Vacuna struct {
|
||||
ID string `json:"id"` // identificador único para el ledger
|
||||
Identifier string `json:"identifier"`
|
||||
Status string `json:"status"` // podés validarlo con enums si querés
|
||||
StatusChange string `json:"statusChange"` // como string (ISO8601)
|
||||
Status string `json:"status"`
|
||||
StatusChange string `json:"statusChange"`
|
||||
StatusReason string `json:"statusReason"`
|
||||
VaccinateCode string `json:"vaccinateCode"`
|
||||
AdministradedProduct string `json:"administradedProduct"`
|
||||
Manufacturer string `json:"manufacturer"`
|
||||
LotNumber string `json:"lotNumber"`
|
||||
ExpirationDate string `json:"expirationDate"` // como string ISO8601
|
||||
ExpirationDate string `json:"expirationDate"`
|
||||
PatientDocumentNumber string `json:"patientDocumentNumber"`
|
||||
Reactions string `json:"reactions"` // puede ser un string o una estructura si querés después
|
||||
Reactions string `json:"reactions"`
|
||||
Practitioner string `json:"practitioner"`
|
||||
PractitionerDocumentNumber string `json:"practitionerDocumentNumber"`
|
||||
Matricula string `json:"matricula"`
|
||||
Matricula string `json:"matricula"`
|
||||
}
|
||||
|
||||
type Estado string
|
||||
|
||||
const (
|
||||
EstadoDraft Estado = "draft"
|
||||
EstadoActive Estado = "active"
|
||||
|
|
@ -360,37 +361,63 @@ func (s *SmartContract) GetMultipleRecetas(ctx contractapi.TransactionContextInt
|
|||
return recetas, nil
|
||||
}
|
||||
|
||||
// TODO: adaptar los campos para que se tengan un identificar de usuarios ademas del DNI
|
||||
func (s *SmartContract) GetRecetasPorDniYEstado(ctx contractapi.TransactionContextInterface, dni string, estado string) ([]*Receta, error) {
|
||||
if dni == "" || estado == "" {
|
||||
return nil, fmt.Errorf("el dni y el estado son obligatorios")
|
||||
func (s *SmartContract) GetVacunasPorDniYEstados(ctx contractapi.TransactionContextInterface, dni string, estados []string, pageSize int32, bookmark string) ([]*Vacuna, string, error) {
|
||||
if dni == "" {
|
||||
return nil, "", fmt.Errorf("el dni es obligatorio")
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
return nil, "", fmt.Errorf("el pageSize debe ser mayor a 0")
|
||||
}
|
||||
// agrego el filtro por DNI
|
||||
selector := map[string]interface{}{
|
||||
"patientDocumentNumber": dni,
|
||||
}
|
||||
// Luego por estados
|
||||
if len(estados) > 0 {
|
||||
if len(estados) == 1 {
|
||||
selector["status"] = estados[0]
|
||||
} else {
|
||||
selector["status"] = map[string]interface{}{
|
||||
"$in": estados,
|
||||
}
|
||||
}
|
||||
}
|
||||
// Armo la query
|
||||
query := map[string]interface{}{
|
||||
"selector": selector,
|
||||
"sort": []map[string]string{
|
||||
{"fechaDeAutorizacion": "desc"},
|
||||
},
|
||||
}
|
||||
|
||||
resultsIterator, err := ctx.GetStub().GetStateByRange("", "")
|
||||
queryJSON, err := json.Marshal(query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error al obtener datos del ledger: %v", err)
|
||||
return nil, "", fmt.Errorf("error al construir query JSON: %v", err)
|
||||
}
|
||||
// ejecuto la querry
|
||||
resultsIterator, responseMetadata, err := ctx.GetStub().GetQueryResultWithPagination(string(queryJSON), pageSize, bookmark)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("error al ejecutar query con paginación: %v", err)
|
||||
}
|
||||
defer resultsIterator.Close()
|
||||
|
||||
var recetasFiltradas []*Receta
|
||||
var vacunas []*Vacuna
|
||||
for resultsIterator.HasNext() {
|
||||
queryResponse, err := resultsIterator.Next()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
var receta Receta
|
||||
err = json.Unmarshal(queryResponse.Value, &receta)
|
||||
var vacuna Vacuna
|
||||
err = json.Unmarshal(queryResponse.Value, &vacuna)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
continue // ignoramos entradas inválidas
|
||||
}
|
||||
|
||||
if receta.PatientDocumentNumber == dni && receta.Status == estado {
|
||||
recetasFiltradas = append(recetasFiltradas, &receta)
|
||||
}
|
||||
vacunas = append(vacunas, &vacuna)
|
||||
}
|
||||
|
||||
return recetasFiltradas, nil
|
||||
// devuelvo las vacunas y el bookmark
|
||||
return vacunas, responseMetadata.Bookmark, nil
|
||||
}
|
||||
|
||||
func (s *SmartContract) CreateVacuna(ctx contractapi.TransactionContextInterface, vacuna Vacuna) error {
|
||||
|
|
|
|||
BIN
basic.tar.gz
Normal file
BIN
basic.tar.gz
Normal file
Binary file not shown.
Loading…
Reference in a new issue