@Search private List<IBaseResource> searchForPatients() { // Create an organization Organization org = new Organization(); org.setId("Organization/65546"); org.setName("Test Organization"); // Create a patient Patient patient = new Patient(); patient.setId("Patient/1333"); patient.addIdentifier().setSystem("urn:mrns").setValue("253345"); patient.getManagingOrganization().setResource(org); // Here we return only the patient object, which has links to other resources List<IBaseResource> retVal = new ArrayList<IBaseResource>(); retVal.add(patient); return retVal; } // END SNIPPET: addIncludes
/** * The "@Search" annotation indicates that this method supports the * search operation. You may have many different method annotated with * this annotation, to support many different search criteria. This * example searches by family name. * * @param theIdentifier * This operation takes one parameter which is the search criteria. It is * annotated with the "@Required" annotation. This annotation takes one argument, * a string containing the name of the search criteria. The datatype here * is StringDt, but there are other possible parameter types depending on the * specific search criteria. * @return * This method returns a list of Patients. This list may contain multiple * matching resources, or it may also be empty. */ @Search() public List<Patient> getPatient(@RequiredParam(name = Patient.SP_FAMILY) StringDt theFamilyName) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00001"); patient.addName(); patient.getName().get(0).addFamily("Test"); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.MALE); return Collections.singletonList(patient); }
/** * The "@Search" annotation indicates that this method supports the * search operation. You may have many different method annotated with * this annotation, to support many different search criteria. This * example searches by family name. * * @param theFamilyName * This operation takes one parameter which is the search criteria. It is * annotated with the "@Required" annotation. This annotation takes one argument, * a string containing the name of the search criteria. The datatype here * is StringParam, but there are other possible parameter types depending on the * specific search criteria. * @return * This method returns a list of Patients. This list may contain multiple * matching resources, or it may also be empty. */ @Search() public List<Patient> getPatient(@RequiredParam(name = Patient.SP_FAMILY) StringParam theFamilyName) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00001"); patient.addName(); patient.getName().get(0).addFamily(theFamilyName.getValue()); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.MALE); return Collections.singletonList(patient); }
/** * The "@Read" annotation indicates that this method supports the * read operation. It takes one argument, the Resource type being returned. * * @param theId * The read operation takes one parameter, which must be of type * IdDt and must be annotated with the "@Read.IdParam" annotation. * @return * Returns a resource matching this identifier, or null if none exists. */ @Read() public Patient getResourceById(@IdParam IdDt theId) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00002"); patient.addName().addFamily("Test"); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.FEMALE); return patient; }
/** * The "@Read" annotation indicates that this method supports the * read operation. Read operations should return a single resource * instance. * * @param theId * The read operation takes one parameter, which must be of type * IdDt and must be annotated with the "@Read.IdParam" annotation. * @return * Returns a resource matching this identifier, or null if none exists. */ @Read() public Patient getResourceById(@IdParam IdDt theId) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00002"); patient.addName().addFamily("Test"); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.FEMALE); return patient; }
public void fluent() throws DataFormatException { FhirContext ctx = new FhirContext(Patient.class, Observation.class); String encoded; //START SNIPPET: encodeMsgFluent Patient patient = new Patient(); patient.addIdentifier().setSystem("http://example.com/fictitious-mrns").setValue("MRN001"); patient.addName().setUse(NameUseEnum.OFFICIAL).addFamily("Tester").addGiven("John").addGiven("Q"); encoded = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(encoded); //END SNIPPET: encodeMsgFluent }
public static void manualContained() { // START SNIPPET: manualContained // Create an organization, and give it a local ID Organization org = new Organization(); org.setId("#localOrganization"); org.getNameElement().setValue("Contained Test Organization"); // Create a patient Patient patient = new Patient(); patient.setId("Patient/1333"); patient.addIdentifier().setSystem("urn:mrns").setValue("253345"); // Set the reference, and manually add the contained resource patient.getManagingOrganization().setReference("#localOrganization"); patient.getContained().getContainedResources().add(org); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(encoded); // END SNIPPET: manualContained }
@SuppressWarnings("unused") public static void main(String[] args) throws DataFormatException, IOException { Patient patient = new Patient(); patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:fake:mrns").setValue("7000135"); patient.addIdentifier().setUse(IdentifierUseEnum.SECONDARY).setSystem("urn:fake:otherids").setValue("3287486"); patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("Junior"); patient.setGender(AdministrativeGenderEnum.MALE); FhirContext ctx = FhirContext.forDstu2(); String xmlEncoded = ctx.newXmlParser().encodeResourceToString(patient); String jsonEncoded = ctx.newJsonParser().encodeResourceToString(patient); MyClientInterface client = ctx.newRestfulClient(MyClientInterface.class, "http://foo/fhir"); IdentifierDt searchParam = new IdentifierDt("urn:someidentifiers", "7000135"); List<Patient> clients = client.findPatientsByIdentifier(searchParam); }
IdentifierDt id = patient.addIdentifier(); id.setSystem("http://example.com/fictitious-mrns"); id.setValue("MRN001");
public static void main(String[] args) throws DataFormatException, IOException { //START SNIPPET: example1 Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:foo").setValue("7000135"); patient.addName().addFamily("Smith").addGiven("John").addGiven("Edward"); patient.addAddress().addLine("742 Evergreen Terrace").setCity("Springfield").setState("ZZ"); FhirContext ctx = FhirContext.forDstu2(); // Use the narrative generator ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); // Encode the output, including the narrative String output = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(output); //END SNIPPET: example1 }
patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:example").setValue("7000135");
/** * Gets the first repetition for <b>identifier</b> (id), * creating it if it does not already exist. * * <p> * <b>Definition:</b> * An identifier for this patient * </p> */ public IdentifierDt getIdentifierFirstRep() { if (getIdentifier().isEmpty()) { return addIdentifier(); } return getIdentifier().get(0); }
patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:example").setValue("7000135");
patient.addIdentifier() .setSystem("http://acme.org/mrns") .setValue("12345");
patient.addIdentifier().setSystem("urn:system").setValue("12345"); patient.addName().addFamily("Smith").addGiven("John"); patient.addIdentifier().setSystem("http://hospital.com").setValue("123445"); patient.addName().addFamily("Smith").addGiven("John"); patient.addIdentifier().setSystem("urn:system").setValue("12345"); patient.addName().addFamily("Smith").addGiven("John");