Skip to content

Commit

Permalink
Composition fix. BuildDCD fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRileyGTRI committed Jun 2, 2022
1 parent 8d40fb4 commit 9909a1e
Show file tree
Hide file tree
Showing 2 changed files with 428 additions and 385 deletions.
166 changes: 104 additions & 62 deletions src/main/java/edu/gatech/chai/VRDR/model/DeathCertificate.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,105 @@
package edu.gatech.chai.VRDR.model;

import java.util.Date;

import org.hl7.fhir.r4.model.Composition;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.Resource;

import ca.uhn.fhir.model.api.annotation.ResourceDef;
import edu.gatech.chai.VRDR.model.util.CommonUtil;
import edu.gatech.chai.VRDR.model.util.DeathCertificateUtil;

@ResourceDef(name = "Composition", profile = "http://hl7.org/fhir/us/vrdr/StructureDefinition/vrdr-death-certificate")
public class DeathCertificate extends Composition {
public DeathCertificate() {
super();
CommonUtil.initResource(this);
setType(DeathCertificateUtil.typeFixedValue);
setStatus(DeathCertificateUtil.status);
setDate(new Date());
}

public DeathCertificate(DeathCertification resource) {
this();
addEvent(resource);
}

private CompositionAttesterComponent addAttesterCommon() {
CompositionAttesterComponent component = new CompositionAttesterComponent();
component.setMode(CompositionAttestationMode.LEGAL);
return component;
}

public void addAttester(Patient resource, Date time) {
addAttesterBase(resource,time);
}

public void addAttester(Practitioner resource, Date time) {
addAttesterBase(resource,time);
}

public void addAttester(Organization resource, Date time) {
addAttesterBase(resource,time);
}

private void addAttesterBase(Resource resource,Date time) {
CompositionAttesterComponent component = addAttesterCommon();
component.setTime(time);
component.setParty(new Reference(resource.getId()));
addAttester(component);
}

public void addEvent(DeathCertification resource) {
CompositionEventComponent component = new CompositionEventComponent();
component.addCode(DeathCertificateUtil.eventCodeFixedValue);
component.addDetail(new Reference(resource.getId()));
addEvent(component);
}

package edu.gatech.chai.VRDR.model;

import java.util.Date;

import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Composition;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.Resource;

import ca.uhn.fhir.model.api.annotation.ResourceDef;
import edu.gatech.chai.VRDR.model.util.CommonUtil;
import edu.gatech.chai.VRDR.model.util.DeathCertificateUtil;

@ResourceDef(name = "Composition", profile = "http://hl7.org/fhir/us/vrdr/StructureDefinition/vrdr-death-certificate")
public class DeathCertificate extends Composition {
public DeathCertificate() {
super();
CommonUtil.initResource(this);
setType(DeathCertificateUtil.typeFixedValue);
setStatus(DeathCertificateUtil.status);
setDate(new Date());
}

public DeathCertificate(CompositionStatus status, Decedent decedent, DeathCertificationProcedure resource) {
this();
setStatus(status);
setSubject(new Reference(decedent));
addEvent(resource);
}

public DeathCertificate(DeathCertificationProcedure resource) {
this();
addEvent(resource);
}

private CompositionAttesterComponent addAttesterCommon() {
CompositionAttesterComponent component = new CompositionAttesterComponent();
component.setMode(CompositionAttestationMode.LEGAL);
return component;
}

public void addAttester(Patient resource, Date time) {
addAttesterBase(resource,time);
}

public void addAttester(Practitioner resource, Date time) {
addAttesterBase(resource,time);
}

public void addAttester(Organization resource, Date time) {
addAttesterBase(resource,time);
}

private void addAttesterBase(Resource resource,Date time) {
CompositionAttesterComponent component = addAttesterCommon();
component.setTime(time);
component.setParty(new Reference(resource.getId()));
addAttester(component);
}

public void addEvent(DeathCertificationProcedure resource) {
CompositionEventComponent component = new CompositionEventComponent();
component.addCode(DeathCertificateUtil.eventCodeFixedValue);
component.addDetail(new Reference(resource.getId()));
addEvent(component);
}

public void addResource(Resource resource) {
if(CommonUtil.assignableFrom(resource.getClass(), DeathCertificateUtil.decedentDemographicResources)) {
addResource(resource, DeathCertificateUtil.decendentDemographicsSectionCode);
}
else if(CommonUtil.assignableFrom(resource.getClass(), DeathCertificateUtil.deathInvestigationResources)) {
addResource(resource, DeathCertificateUtil.deathInvestigationSectionCode);
}
else if(CommonUtil.assignableFrom(resource.getClass(), DeathCertificateUtil.deathCertificationResources)) {
addResource(resource, DeathCertificateUtil.deathCertificationSectionCode);
}
else if(CommonUtil.assignableFrom(resource.getClass(), DeathCertificateUtil.decedentDispositionResources)) {
addResource(resource, DeathCertificateUtil.decedentDispositionSectionCode);
}
else if(CommonUtil.assignableFrom(resource.getClass(), DeathCertificateUtil.codedContentResources)) {
addResource(resource, DeathCertificateUtil.codedContentSectionCode);
}
}

public void addResource(Resource resource, CodeableConcept sectionCode) {
SectionComponent section = findOrCreateSection(sectionCode);
section.addEntry(new Reference(resource.getId()));
}

public SectionComponent findOrCreateSection(CodeableConcept sectionCode) {
for(SectionComponent section: this.getSection()) {
if(section.getCode().equals(sectionCode)) {
return section;
}
}
SectionComponent newSection = new SectionComponent();
newSection.setCode(sectionCode);
this.addSection(newSection);
return newSection;
}
}
Loading

0 comments on commit 9909a1e

Please sign in to comment.