Skip to content

Commit

Permalink
resolves #80
Browse files Browse the repository at this point in the history
  • Loading branch information
ismael-sarmento-jr committed Sep 1, 2015
1 parent fa79ae1 commit 32c9dcb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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() {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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){
Expand All @@ -156,6 +179,7 @@ public IResourceEntity constructEntityFromResource(IResource resource) {
this.person.setId(patientRef);
}

this.startDate = md.getWhenPrepared();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down

0 comments on commit 32c9dcb

Please sign in to comment.