Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.hl7.fhir.dstu3.model.MedicationAdministration does not copy a dosage.extension of type Duration #1723

Open
matheisco opened this issue Aug 23, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@matheisco
Copy link

Describe the bug
.copy() of org.hl7.fhir.dstu3.model.MedicationAdministration does not copy a dosage.extension of type Duration

To Reproduce

  • Create MedicationAdministration instance which includes a Duration in dosage.extension
  • Create a copy using .copy()

Expected behavior
The copy is exactly the same.

Environment

  • HAPI FHIR Version: 7.4.0
  • JDK: 21

Additional context
The culprit seems to be the missing Duration.copy() implementation. As I understand it, it was fixed for R4 in hapifhir/hapi-fhir#1820, but the issue is still present for STU3

Code to reproduce:

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
import org.hl7.fhir.dstu3.model.Duration;
import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.dstu3.model.MedicationAdministration;
import org.hl7.fhir.dstu3.model.SimpleQuantity;

import java.util.List;

public class MedicationAdministrationCopyDefect {

    public static void main(String[] ignoreMe) throws Exception {
        IParser parser = FhirContext.forDstu3().newJsonParser().setPrettyPrint(true);
        MedicationAdministration beforeCopy = createMedAdminWithDosageDurationExtension();
        MedicationAdministration afterCopy = beforeCopy.copy();

        System.out.println("---- BEFORE COPY (BEGIN)");
        System.out.println(parser.encodeResourceToString(beforeCopy));
        System.out.println("---- BEFORE COPY (END)");
        System.out.println();
        System.out.println("---- AFTER COPY (BEGIN)");
        System.out.println(parser.encodeResourceToString(afterCopy));
        System.out.println("---- AFTER COPY (END)");
    }

    private static MedicationAdministration createMedAdminWithDosageDurationExtension() {
        MedicationAdministration resource = new MedicationAdministration();
        resource.setId("12345");
        var dosage = new MedicationAdministration.MedicationAdministrationDosageComponent();
        dosage.setDose((SimpleQuantity) new SimpleQuantity().setValue(40))
                .setExtension(List.of(new Extension()
                        .setUrl("http://duration")
                        .setValue(new Duration().setValue(5340000))));
        resource.setDosage(dosage);
        return resource;
    }
}

Output:

---- BEFORE COPY (BEGIN)
{
  "resourceType": "MedicationAdministration",
  "id": "12345",
  "dosage": {
    "extension": [ {
      "url": "http://duration",
      "valueDuration": {
        "value": 5340000
      }
    } ],
    "dose": {
      "value": 40
    }
  }
}
---- BEFORE COPY (END)

---- AFTER COPY (BEGIN)
{
  "resourceType": "MedicationAdministration",
  "id": "12345",
  "dosage": {
    "dose": {
      "value": 40
    }
  }
}
---- AFTER COPY (END)
@jamesagnew jamesagnew transferred this issue from hapifhir/hapi-fhir Aug 23, 2024
@dotasek dotasek added the bug Something isn't working label Aug 30, 2024
@matheisco
Copy link
Author

Please consider fixing this bug, we rely on a correct copy implementation in production.

grahamegrieve pushed a commit that referenced this issue Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants