Skip to content

fix(patients): default deceased/active on patient create (COG-117) - #30

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1780429695-cog-117-fix-patient-create
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1780429695-cog-117-fix-patient-create

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Companion backend fix for the New Patients page (COG-117, frontend in demos-coghealth-ehr-web#35).

POST /v1/patients returned 500 whenever the client omitted deceased:

ERROR: null value in column "deceased" of relation "patients" violates not-null constraint

Root cause: PatientMapper.toEntity (MapStruct) builds a new entity and calls patient.deceased(dto.getDeceased()) unconditionally, overwriting the entity's @Builder.Default deceased = false with null. The DB column is deceased BOOLEAN NOT NULL DEFAULT FALSE, but the explicit null in the generated INSERT bypasses the DB default → constraint violation. The new patient intake form does not (and should not) send deceased, so registration always failed end-to-end. active has the same latent issue (form happens to send true).

Fix — add defaultValue to the create mapping so an unset value falls back to the entity/DB default:

@Mapping(target = "active", source = "active", defaultValue = "true")
@Mapping(target = "deceased", source = "deceased", defaultValue = "false")
Patient toEntity(PatientDTO dto);

Generated toEntity now does if (dto.getDeceased() != null) ... else patient.deceased(false) (same for active). updateEntityFromDto is unchanged (already ignores nulls). A client that explicitly sends deceased/active is still respected.

Verified against a fresh Flyway-built DB: POST /v1/patients with the form's payload now returns 201 with deceased:false and the address persisted.

No tests added — the repo currently has no test source tree (src/test absent); change verified manually end-to-end via the frontend form.

Link to Devin session: https://app.devin.ai/sessions/bac7d1fcc3b542809fe47cf1a15957a2
Requested by: @tobydrinkall


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)

POST /v1/patients returned 500 (deceased NOT NULL violation): the MapStruct toEntity create mapping overwrote the entity's deceased=false / active=true defaults with null when the client omitted them. The New Patient intake form (COG-117) does not send deceased, so registration always failed. Add defaultValue mappings so create falls back to false/true when unset.

Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant