Skip to content

Commit

Permalink
partial fix for #226
Browse files Browse the repository at this point in the history
Enables creation of Questionnaire and QuestionnaireResponse in a
transaction Bundle if order is Questionnaire before
QuestionnaireResponse.
  • Loading branch information
hhund committed Oct 8, 2024
1 parent 361d360 commit 2650244
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public Optional<String> reasonCreateAllowed(Connection connection, Identity iden
{
if (identity.isLocalIdentity() && identity.hasDsfRole(FhirServerRole.CREATE))
{
Optional<String> errors = newResourceOk(newResource, EnumSet.of(QuestionnaireResponseStatus.INPROGRESS));
Optional<String> errors = newResourceOk(connection, newResource,
EnumSet.of(QuestionnaireResponseStatus.INPROGRESS));
if (errors.isEmpty())
{
// TODO implement unique criteria based on UserTask.id when implemented as identifier
Expand All @@ -70,7 +71,7 @@ public Optional<String> reasonCreateAllowed(Connection connection, Identity iden
}
}

private Optional<String> newResourceOk(QuestionnaireResponse newResource,
private Optional<String> newResourceOk(Connection connection, QuestionnaireResponse newResource,
EnumSet<QuestionnaireResponseStatus> allowedStatus)
{
List<String> errors = new ArrayList<>();
Expand All @@ -90,7 +91,7 @@ private Optional<String> newResourceOk(QuestionnaireResponse newResource,
getItemAndValidate(newResource, CODESYSTEM_DSF_BPMN_USER_TASK_VALUE_USER_TASK_ID, errors);

String questionnaireUrlAndVersion = newResource.getQuestionnaire();
if (!questionnaireExists(questionnaireUrlAndVersion))
if (!questionnaireExists(connection, questionnaireUrlAndVersion))
{
errors.add(
"Questionnaire ressource referenced via canonical QuestionnaireResponse.questionnaire does not exist");
Expand Down Expand Up @@ -149,12 +150,12 @@ private Optional<String> getItemAndValidate(QuestionnaireResponse newResource, S
return Optional.of(value.getValue());
}

private boolean questionnaireExists(String questionnaireUrlAndVersion)
private boolean questionnaireExists(Connection connection, String questionnaireUrlAndVersion)
{
try
{
Optional<Questionnaire> questionnaire = daoProvider.getQuestionnaireDao()
.readByUrlAndVersion(questionnaireUrlAndVersion);
.readByUrlAndVersionWithTransaction(connection, questionnaireUrlAndVersion);

return questionnaire.isPresent();
}
Expand Down Expand Up @@ -188,7 +189,7 @@ public Optional<String> reasonUpdateAllowed(Connection connection, Identity iden
{
if (identity.isLocalIdentity() && identity.hasDsfRole(FhirServerRole.UPDATE))
{
Optional<String> errors = newResourceOk(newResource,
Optional<String> errors = newResourceOk(connection, newResource,
EnumSet.of(QuestionnaireResponseStatus.COMPLETED, QuestionnaireResponseStatus.STOPPED));
if (errors.isEmpty())
{
Expand Down

0 comments on commit 2650244

Please sign in to comment.