diff --git a/gt-fhir-entities/src/main/java/edu/gatech/i3l/fhir/dstu2/entities/DrugExposurePrescriptionDispensed.java b/gt-fhir-entities/src/main/java/edu/gatech/i3l/fhir/dstu2/entities/DrugExposurePrescriptionDispensed.java index 209c16b..c15be24 100644 --- a/gt-fhir-entities/src/main/java/edu/gatech/i3l/fhir/dstu2/entities/DrugExposurePrescriptionDispensed.java +++ b/gt-fhir-entities/src/main/java/edu/gatech/i3l/fhir/dstu2/entities/DrugExposurePrescriptionDispensed.java @@ -1,6 +1,7 @@ package edu.gatech.i3l.fhir.dstu2.entities; import java.math.BigDecimal; +import java.util.Date; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -18,6 +19,7 @@ import ca.uhn.fhir.model.dstu2.composite.QuantityDt; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu2.resource.MedicationDispense; +import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; import edu.gatech.i3l.fhir.jpa.entity.IResourceEntity; @@ -40,6 +42,10 @@ public final class DrugExposurePrescriptionDispensed extends DrugExposurePrescri @NotNull private Person person; + @Column(name="drug_exposure_start_date", nullable=false) + @NotNull + private Date startDate; + @Column(name="quantity") private BigDecimal quantity; @@ -48,6 +54,7 @@ public final class DrugExposurePrescriptionDispensed extends DrugExposurePrescri @ManyToOne(cascade={CascadeType.MERGE}) @JoinColumn(name="drug_concept_id") + @NotNull private Concept medication; public Person getPerson() { @@ -90,6 +97,14 @@ public void setDrugExposureType(Concept drugExposureType) { this.drugExposureType = drugExposureType; } + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + @Override public FhirVersionEnum getFhirVersion() { return FhirVersionEnum.DSTU2; @@ -112,7 +127,7 @@ public String translateSearchParam(String theSearchParam) { case MedicationDispense.SP_PATIENT: return "person"; case MedicationDispense.SP_MEDICATION: - return "medication.name"; + return "medication"; default: break; } @@ -125,6 +140,7 @@ public IResource getRelatedResource() { resource.setId(this.getIdDt()); resource.setPatient(new ResourceReferenceDt(new IdDt(Person.RESOURCE_TYPE, this.person.getId()))); resource.setMedication(new ResourceReferenceDt(new IdDt("Medication", this.medication.getId()))); + resource.setWhenPrepared(new DateTimeDt(this.startDate)); if(this.quantity != null){ QuantityDt quantity = new QuantityDt(); quantity.setValue(this.quantity); @@ -148,6 +164,13 @@ public IResourceEntity constructEntityFromResource(IResource resource) { } else { this.drugExposureType.setId(Omop4ConceptsFixedIds.PRESCRIPTION_DISP_PHARMACY.getConceptId()); } + /* Set drug concept(medication) */ + Long medicationRef = md.getMedication().getReference().getIdPartAsLong(); + if(medicationRef != null){ + if(this.medication == null) + this.medication = new Concept(); + this.medication.setId(medicationRef); + } /* Set patient */ Long patientRef = md.getPatient().getReference().getIdPartAsLong(); if(patientRef != null){ @@ -156,6 +179,7 @@ public IResourceEntity constructEntityFromResource(IResource resource) { this.person.setId(patientRef); } + this.startDate = md.getWhenPrepared(); return this; } diff --git a/gt-fhir-entities/src/main/java/edu/gatech/i3l/fhir/dstu2/entities/DrugExposurePrescriptionWritten.java b/gt-fhir-entities/src/main/java/edu/gatech/i3l/fhir/dstu2/entities/DrugExposurePrescriptionWritten.java index c705780..a227264 100644 --- a/gt-fhir-entities/src/main/java/edu/gatech/i3l/fhir/dstu2/entities/DrugExposurePrescriptionWritten.java +++ b/gt-fhir-entities/src/main/java/edu/gatech/i3l/fhir/dstu2/entities/DrugExposurePrescriptionWritten.java @@ -76,8 +76,7 @@ public final class DrugExposurePrescriptionWritten extends DrugExposurePrescript * @fhir encounter */ @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.MERGE}) - @JoinColumn(name="visit_occurrence_id", nullable=false) - @NotNull + @JoinColumn(name="visit_occurrence_id") private VisitOccurrenceComplement visitOccurrence; /**