️ Support Compressed Records

This commit is contained in:
Johnathan Gilday 2023-03-22 14:58:52 -04:00
parent e25efc2296
commit 35e8f20c8c
No known key found for this signature in database

View file

@ -10,6 +10,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;
import java.util.zip.ZipInputStream;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -31,26 +32,14 @@ class RecordsTransferController {
}
@PostMapping("/records-transfers")
public NewRecordModel newRecordsTransfer(@RequestParam final String patientId, @RequestBody final InputStream body)
throws IOException, SQLException {
validatePatientId(patientId);
final var id = saveToRecordsSystem(body);
return new NewRecordModel(id);
}
/**
* @param patientId id of the patient
* @throws SQLException when there is a problem with the database
* @throws IllegalArgumentException when the patient does not exist
*/
private void validatePatientId(final String patientId) throws SQLException {
final Connection connection = dataSource.getConnection();
final PreparedStatement statement = connection.prepareStatement("SELECT * FROM patients WHERE id = ?");
statement.setString(1, patientId);
final ResultSet rs = statement.executeQuery();
if (!rs.next()) {
throw new IllegalArgumentException("Patient with id " + patientId + " does not exist");
public NewRecordModel newRecordsTransfer(@RequestParam("zipped") boolean zipped, @RequestBody InputStream body)
throws IOException {
final InputStream is = zipped ? new ZipInputStream(body) : body;
final String id;
try (is) {
id = saveToRecordsSystem(is);
}
return new NewRecordModel(id);
}
private String saveToRecordsSystem(final InputStream is) throws IOException {