small fixes

This commit is contained in:
FrancoPandolfo 2025-04-08 22:38:02 +00:00
parent 44e3f4210d
commit 8cf57afda0
8 changed files with 38 additions and 99 deletions

View file

@ -98,6 +98,12 @@ The Fabric test network is used to deploy and run this sample. Follow these step
./gradlew run
```
- To run the SiMeDi **Java** sample application:
```shell
cd maven-API-SiMeDi
./mvnw spring-boot:run
```
## Clean up
When you are finished, you can bring down the test network (from the `test-network` folder). The command will remove all the nodes of the test network, and delete any ledger data that you created.

View file

@ -51,7 +51,7 @@ func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface)
recetas := []Receta{
{
ID: "receta1",
Identificador "rece1234"
Identificador: "rece1234",
Owner: "Tomoko",
PrescripcionAnteriorId: "presc123",
Status: "active",
@ -70,7 +70,7 @@ func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface)
},
{
ID: "receta2",
Identificador "rece1235"
Identificador: "rece1235",
Owner: "Alice",
PrescripcionAnteriorId: "presc456",
Status: "completed",
@ -324,7 +324,7 @@ func (s *SmartContract) VacunaExists(ctx contractapi.TransactionContextInterface
return vacunaJSON != nil, nil
}
unc (s *SmartContract) ReadVacuna(ctx contractapi.TransactionContextInterface, id string) (*Vacuna, error) {
func (s *SmartContract) ReadVacuna(ctx contractapi.TransactionContextInterface, id string) (*Vacuna, error) {
vacunaJSON, err := ctx.GetStub().GetState(id)
if err != nil {
return nil, fmt.Errorf("error al leer del ledger: %v", err)

View file

@ -96,8 +96,11 @@ public class RecetaController {
recetaService.entregarReceta(id);
return new ResponseEntity<>(HttpStatus.OK);
} catch (EndorseException | SubmitException | CommitStatusException | CommitException | IOException | GatewayException e) {
e.printStackTrace();
} catch (EndorseException | SubmitException | CommitStatusException | CommitException e) {
e.printStackTrace(); // o algún log específico
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (GatewayException e) {
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

View file

@ -1,14 +0,0 @@
package com.code.hyperledger.models;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AssetIdDto {
private String Dni;
private String TimeStamp;
}

View file

@ -1,31 +0,0 @@
package com.code.hyperledger.models;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Receta {
private String id;
private String identifier;
private String owner;
private String prescripcionAnteriorId;
private String status;
//@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private String statusChange;
private String prioridad;
private String medicacion;
private String razon;
private String notas;
private String periodoDeTratamiento;
private String instruccionesTratamiento;
private String periodoDeValidez;
private String dniPaciente;
//@JsonFormat(pattern = "yyyy-MM-dd")
private String fechaDeAutorizacion;
private int cantidad;
//@JsonFormat(pattern = "yyyy-MM-dd")
private String expectedSupplyDuration;
}

View file

@ -1,30 +0,0 @@
package com.code.hyperledger.models;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RecetaDto {
private String identifier;
private String owner;
private String prescripcionAnteriorId;
private String status;
//@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private String statusChange;
private String prioridad;
private String medicacion;
private String razon;
private String notas;
private String periodoDeTratamiento;
private String instruccionesTratamiento;
private String periodoDeValidez;
private String dniPaciente;
//@JsonFormat(pattern = "yyyy-MM-dd")
private String fechaDeAutorizacion;
private int cantidad;
//@JsonFormat(pattern = "yyyy-MM-dd")
private String expectedSupplyDuration;
}

View file

@ -1,6 +1,6 @@
package com.code.hyperledger.services;
import com.code.hyperledger.coso.Receta;
import com.code.hyperledger.models.Receta;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -17,9 +17,9 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.Identity;
import org.hyperledger.fabric.client.identity.Identity;
import java.security.InvalidKeyException;
import java.security.Signer;
import org.hyperledger.fabric.client.identity.Signer;
import java.security.cert.CertificateException;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -144,20 +144,19 @@ public class RecetaService {
objectMapper.getTypeFactory().constructCollectionType(List.class, Receta.class));
}
}
public void entregarReceta(String recetaId)
throws CommitStatusException, EndorseException, CommitException, SubmitException {
contract.submitTransaction("EntregarReceta", recetaId);
throws CommitStatusException, EndorseException, CommitException, SubmitException {
contract.submitTransaction("EntregarReceta", recetaId);
}
public List<Receta> obtenerRecetasPorDniYEstado(String dni, String estado) throws GatewayException, IOException {
if (dni == null || dni.isBlank() || estado == null || estado.isBlank()) {
throw new IllegalArgumentException("DNI y estado son obligatorios");
}
public List<Receta> obtenerRecetasPorDniYEstado(String dni, String estado) throws GatewayException, IOException {
if (dni == null || dni.isBlank() || estado == null || estado.isBlank()) {
throw new IllegalArgumentException("DNI y estado son obligatorios");
}
var evaluateResult = contract.evaluateTransaction("GetRecetasPorDniYEstado", dni, estado);
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(evaluateResult,
objectMapper.getTypeFactory().constructCollectionType(List.class, Receta.class));
var evaluateResult = contract.evaluateTransaction("GetRecetasPorDniYEstado", dni, estado);
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(evaluateResult,
objectMapper.getTypeFactory().constructCollectionType(List.class, Receta.class));
}
}

View file

@ -99,11 +99,17 @@ public class VacunaService {
contract.submitTransaction(
"CreateVacuna",
vacuna.getId(),
vacuna.getNombre(),
vacuna.getLaboratorio(),
vacuna.getFechaAplicacion(),
vacuna.getIdentificador(),
vacuna.getStatus(),
vacuna.getStatusChange(),
vacuna.getStatusReason(),
vacuna.getVaccinateCode(),
vacuna.getAdministradedProduct(),
vacuna.getManufacturer(),
vacuna.getLotNumber(),
vacuna.getExpirationDate(),
vacuna.getDniPaciente(),
vacuna.getEstado()
vacuna.getReactions()
);
}